Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agenda format function #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions org-ql-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ e.g. `org-ql-search' as desired."
:type '(alist :key-type string
:value-type function))

(defcustom org-ql-agenda-format-function
#'org-ql-agenda-default-format-function
"Function used to format entries in `org-ql-agenda-block'.

This function receives two arguments: a map-like data containing
strings which can be used for formatting agenda entries, and a plist
returned by `org-element-headline-parser'.
"
:group 'org-ql
:type 'function)

;;;; Macros

;; TODO: DRY these two macros.
Expand Down Expand Up @@ -479,6 +490,8 @@ return an empty string."
for symbol = (intern (cl-subseq (symbol-name key) 1))
unless (member symbol '(parent))
append (list symbol val)))
(marker (or (org-element-property :org-hd-marker element)
(org-element-property :org-marker element)))
;; TODO: --add-faces is used to add the :relative-due-date property, but that fact is
;; hidden by doing it through --add-faces (which calls --add-scheduled-face and
;; --add-deadline-face), and doing it in this form that gets the title hides it even more.
Expand All @@ -494,8 +507,7 @@ return an empty string."
;; NOTE: Tag inheritance cannot be used here unless markers are added, otherwise
;; we can't go to the item's buffer to look for inherited tags. (Or does
;; `org-element-headline-parser' parse inherited tags too? I forget...)
(if-let ((marker (or (org-element-property :org-hd-marker element)
(org-element-property :org-marker element))))
(if marker
(with-current-buffer (marker-buffer marker)
;; I wish `org-get-tags' used the correct buffer automatically.
(org-get-tags marker (not org-use-tag-inheritance)))
Expand All @@ -509,7 +521,6 @@ return an empty string."
(s-join ":" it)
(s-wrap it ":")
(org-add-props it nil 'face 'org-tag))))
;; (category (org-element-property :category element))
(priority-string (-some->> (org-element-property :priority element)
(char-to-string)
(format "[#%s]")
Expand All @@ -520,7 +531,17 @@ return an empty string."
(due-string (pcase (org-element-property :relative-due-date element)
('nil "")
(string (format " %s " (org-add-props string nil 'face 'org-ql-agenda-due-date)))))
(string (s-join " " (-non-nil (list todo-keyword priority-string title due-string tag-string)))))
(category (when marker
(with-current-buffer (marker-buffer marker)
(org-get-category marker))))
(string (funcall org-ql-agenda-format-function
`((todo . ,todo-keyword)
(priority . ,priority-string)
(title . ,title)
(due . ,due-string)
(tags . ,tag-string)
(category . ,category))
element)))
(remove-list-of-text-properties 0 (length string) '(line-prefix) string)
;; Add all the necessary properties and faces to the whole string
(--> string
Expand All @@ -531,6 +552,20 @@ return an empty string."
'tags tag-list
'org-habit-p habit-property)))))

(defun org-ql-agenda-default-format-function (map _element)
"Default function used to format entries in org-ql-agenda.

MAP is a map-like data structure containing some information
commonly used for agenda entries, which can be accessed using
`map-elt' function from map.el.

This should be the default value for `org-ql-agenda-format-function'."
(s-join " " (-non-nil (list (map-elt map 'todo)
(map-elt map 'priority)
(map-elt map 'title)
(map-elt map 'due)
(map-elt map 'tags)))))

(defun org-ql-agenda--add-faces (element)
"Return ELEMENT with deadline and scheduled faces added."
(->> element
Expand Down