emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [PROPOSAL] New function `org-headings-to-point' and displayer.


From: Cheong Yiu Fung
Subject: Re: [PROPOSAL] New function `org-headings-to-point' and displayer.
Date: Tue, 03 Dec 2019 16:47:30 +0800
User-agent: Cyrus-JMAP/3.1.7-612-g13027cc-fmstable-20191203v1

This is really useful. Thanks!

Yiufung

On Tue, Dec 3, 2019, at 10:56 AM, Karl Fogel wrote:
> Hi.  I've been using this for a while and find it very handy.
> 
> If people like this and want it in Org Mode, I'll do the rest of the 
> work to package it up as a patch, with ChangeLog entry, NEWS, etc, and 
> post it here for review before committing.
> 
> To try it out, just evaluate both functions and then run
> 
>   `M-x org-display-headings-to-point'
> 
> from somewhere deep in an org subtree.  Comments/feedback welcome.
> 
> Best regards,
> -Karl
> 
> (defun org-headings-to-point ()
>   "Return all the Org Mode headings leading to point."
>   (when (not (eq major-mode 'org-mode))
>     (error "ERROR: this only works in Org Mode"))
>   (let ((headings (list (org-heading-components))))
>     (save-excursion
>       (save-match-data
>         (save-restriction
>           (widen)
>           (while (org-up-heading-safe)
>             (setq headings (cons (org-heading-components) headings)))))
>       headings)))
> 
> (defun org-display-headings-to-point ()
>   "Display Org Mode heading titles from level 1 to current subtree.
> Display each title on its own line, indented proportionally to its level."
>   (interactive)
>   (let* ((heading-titles (mapcar (lambda (heading)
>                                    (nth 4 heading))
>                                  (org-headings-to-point)))
>          (level 0)
>          (hierarchy (mapcar (lambda (title)
>                               (prog1
>                                   (if (zerop level)
>                                       (concat "• " title)
>                                     (concat "\n" 
>                                             (make-string (* level 2) ? )
>                                             "→ " title))
>                                 (setq level (1+ level))))
>                             heading-titles)))
>     (display-message-or-buffer (string-join hierarchy))))
> 
>



reply via email to

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