dotfiles/.emacs.d/functions.org

1.5 KiB

Custom Elisp Functions

As of now, I haven't added anything here, though I do expect to start adding some custom functions as I learn more about Elisp.

Capture Template Functions

These functions are for my org roam daily capture template.

(defun jm/daily-todos-filter-tasks (helper query files)
  (let ((entries (org-map-entries helper query files)))
    (mapconcat #'identity (delq nil entries) "\n")))

(defun jm/daily-todos-format-link ()
  (let ((item-name (org-entry-get nil "ITEM"))
        (item-id (or (org-entry-get nil "ID")
                     (car (org-property-values "ID")))))
    (when (stringp item-id)
      (format "- [ ] [[id:%s][%s]]" item-id item-name))))


(defun jm/daily-todos-get-priority (priority)
  (jm/daily-todos-filter-tasks
   (lambda ()
     (when (equal priority (org-entry-get nil "PRIORITY"))
       (jm/daily-todos-format-link)))
   "TODO=\"IN PROGRESS\""
   (org-agenda-files)))


(defun jm/daily-todos-get-due-today ()
  (jm/daily-todos-filter-tasks
   (lambda ()
     (when (member (org-get-todo-state) '("TODO" "IN PROGRESS"))
       (jm/daily-todos-format-link)))
   (format-time-string
    "DEADLINE<=\"<%Y-%m-%d>\""
    (or (org-capture-get :default-time) (current-time)))
   (org-agenda-files)))

(defun jm/daily-todos-dynamic-habits (habit week-days)
  (let* ((org-date (or (org-capture-get :default-time) (current-time)))
         (today (downcase (format-time-string "%a" org-date))))
    (when (seq-contains-p week-days today) habit)))