emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Insert outline breadcrumbs just before headings text in agenda view


From: Shankar Rao
Subject: Insert outline breadcrumbs just before headings text in agenda view
Date: Tue, 31 Aug 2021 16:02:00 +0200

In Emacs org-mode, I have a set of TODOs in the following format:
* H1
** H2
*** H3
**** TODO [#A] File Taxes
If I activate breadcrumbs in org-agenda-prefix-format (i.e., by
doing (setf (alist-get 'agenda org-agenda-prefix-format)
" %i %-12:c%?-12t% s%b")), when I look at the agenda-todo view, it
shows up as:
H1->H2->H3->TODO [#A] File Taxes
However, I would like it to instead be displayed like this:
TODO [#A] H1->H2->H3->File Taxes
I asked about this on Reddit and Stack Exchange, and since it 
appeared that no one had already come up with a solution for
this, I decided to cook up my own using an advice function:
(defvar org-agenda-breadcrumbs-level 1 "Highest level subtree to include in Org agenda breadcrumb.") (defun org-agenda-breadcrumbs-string () "Create formatted string with outline of Org subtree at point. The outline goes up to subtree level `org-agenda-breadcrumbs-level` and the subtree headings are separated by `org-agenda-breadcrumbs-separator`." (org-format-outline-path (nthcdr (1- org-agenda-breadcrumbs-level) (org-get-outline-path)) (1- (frame-width)) nil org-agenda-breadcrumbs-separator)) (defun org-agenda-insert-breadcrumbs-before-text (args) "In Org agenda, insert outline breadcrumbs just before heading text in ARGS. This is an advice function for use with `org-agenda-format-item` by doing: (advice-add #'org-agenda-format-item :filter-args #'org-agenda-insert-breadcrumbs-before-text) Since ARGS is the list of arguments to be passed to `org-agenda-format-item`, the second list element of ARGS contains the heading text to be modified." (org-with-point-at (org-get-at-bol 'org-marker) (let* ((txt (org-get-heading t t t t)) (index (or (cl-search txt (cadr args)) 0)) (bc (let ((s (org-agenda-breadcrumbs-string))) (if (eq "" s)
""
(concat s org-agenda-breadcrumbs-separator)))))
(setf (substring (cadr args) index index) bc) args))) (advice-add #'org-agenda-format-item :filter-args #'org-agenda-insert-breadcrumbs-before-text)
In my init.el, because I don't want the top level headings in the
outline breadcrumbs, I also have the following:

(setq org-agenda-breadcrumbs-level 2) In my opinion, a feature like this is of sufficiently broad
interest that it should be included in Org so that it can be enabled
without the use of an advice function. However, it's not clear to me
what would be the best interface for configuring it. For example,
it doesn't make sense to add an option for this to
org-agenda-prefix-format, since this modifies the heading text
rather than the prefix.
If people agree that this feature is of broad interest, and have
suggestions on a good configuration interface, I would be happy
to submit this as a patch.

Shankar Rao

reply via email to

[Prev in Thread] Current Thread [Next in Thread]