From mboxrd@z Thu Jan 1 00:00:00 1970 From: Diego Zamboni Subject: Re: [PROPOSAL] New function `org-headings-to-point' and displayer. Date: Tue, 3 Dec 2019 08:30:25 +0100 Message-ID: References: <878snui0ay.fsf@red-bean.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000001d1d300598c7acd9" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:51213) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ic2dy-0004jD-NM for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 02:30:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ic2dw-0004O7-JZ for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 02:30:46 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:36232) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ic2ds-0004Iz-MY for emacs-orgmode@gnu.org; Tue, 03 Dec 2019 02:30:42 -0500 Received: by mail-wm1-x330.google.com with SMTP id p17so2257728wma.1 for ; Mon, 02 Dec 2019 23:30:38 -0800 (PST) In-Reply-To: <878snui0ay.fsf@red-bean.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org-mode --0000000000001d1d300598c7acd9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Very nice! It works also in Narrow mode, which makes it even more useful for me. Thanks! --Diego On Tue, Dec 3, 2019 at 3:58 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 "=E2=80=A2 " title) > (concat "\n" > (make-string (* level 2) ? ) > "=E2=86=92 " title)) > (setq level (1+ level)))) > heading-titles))) > (display-message-or-buffer (string-join hierarchy)))) > > --0000000000001d1d300598c7acd9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Very nice! It works also in Narrow mode, which makes it ev= en more useful for me.

Thanks!
--Diego


On Tue, Dec 3, 2019 at 3:58 AM Karl Fogel <kfogel@red-bean.com> wrote:
Hi.=C2=A0 I've been using thi= s 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 wo= rk to package it up as a patch, with ChangeLog entry, NEWS, etc, and post i= t here for review before committing.

To try it out, just evaluate both functions and then run

=C2=A0 `M-x org-display-headings-to-point'

from somewhere deep in an org subtree.=C2=A0 Comments/feedback welcome.

Best regards,
-Karl

(defun org-headings-to-point ()
=C2=A0 "Return all the Org Mode headings leading to point."
=C2=A0 (when (not (eq major-mode 'org-mode))
=C2=A0 =C2=A0 (error "ERROR: this only works in Org Mode"))
=C2=A0 (let ((headings (list (org-heading-components))))
=C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0 =C2=A0 (save-match-data
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (save-restriction
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (widen)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (while (org-up-heading-safe)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq headings (cons (org-heading= -components) headings)))))
=C2=A0 =C2=A0 =C2=A0 headings)))

(defun org-display-headings-to-point ()
=C2=A0 "Display Org Mode heading titles from level 1 to current subtre= e.
Display each title on its own line, indented proportionally to its level.&q= uot;
=C2=A0 (interactive)
=C2=A0 (let* ((heading-titles (mapcar (lambda (heading)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(nth 4 heading))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-headings-to-point)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(level 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(hierarchy (mapcar (lambda (title)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (prog1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (zerop level)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (concat "= =E2=80=A2 " title)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (concat "\n"=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (make-string (* level 2) ? )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 "=E2=86=92 " title))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq level (1+ level))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 heading-titles)))
=C2=A0 =C2=A0 (display-message-or-buffer (string-join hierarchy))))

--0000000000001d1d300598c7acd9--