emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Insert outline breadcrumbs just before headings text in agenda view
@ 2021-08-31 14:02 Shankar Rao
  0 siblings, 0 replies; only message in thread
From: Shankar Rao @ 2021-08-31 14:02 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3137 bytes --]

 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)
                           (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

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)

(advice-add #'org-agenda-format-item :filter-args

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

[-- Attachment #2: Type: text/html, Size: 4025 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-31 14:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 14:02 Insert outline breadcrumbs just before headings text in agenda view Shankar Rao

Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).