diff options
author | Ihor Radchenko <yantar92@posteo.net> | 2024-01-06 12:41:17 +0100 |
---|---|---|
committer | Ihor Radchenko <yantar92@posteo.net> | 2024-01-06 12:41:17 +0100 |
commit | 1537548defb3b5fac8598311dc9068aaab2dc0fd (patch) | |
tree | 080ce000ab770391a284e4c289d7d5614887b5fb | |
parent | c03e94e8aa07e733658602d22f936abfa997d196 (diff) |
lisp/org-toc.el: Switch to lexical binding
* lisp/org-toc.el (org-toc-get-headlines-status): Remove under
let-binding. Use `cl-pushnew' instead of dynamic `add-to-list'.
(org-toc--help-message):
(org-toc-help): Refactor, extracting help message into a separate
internal variable. This is done to avoid modifying constant string
for side effect repeatedly.
-rw-r--r-- | lisp/org-toc.el | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/lisp/org-toc.el b/lisp/org-toc.el index 92ca31c..73a8eea 100644 --- a/lisp/org-toc.el +++ b/lisp/org-toc.el @@ -1,4 +1,4 @@ -;;; org-toc.el --- Table of contents for Org-mode buffer +;;; org-toc.el --- Table of contents for Org-mode buffer -*- lexical-binding: t; -*- ;; Copyright 2007-2021 Free Software Foundation, Inc. ;; @@ -456,30 +456,25 @@ current table of contents to it." (defun org-toc-get-headlines-status () "Return an alist of headlines and their associated folding status." - (let (output ovs) + (let (output) (save-excursion (goto-char (point-min)) (while (and (not (eobp)) (goto-char (next-overlay-change (point)))) (when (looking-at org-outline-regexp-bol) - (add-to-list - 'output + (cl-pushnew (cons (buffer-substring-no-properties (match-beginning 0) (save-excursion (end-of-line) (point))) (overlay-get - (car (overlays-at (point))) 'status)))))) + (car (overlays-at (point))) 'status)) + output)))) ;; return an alist like (("* Headline" . 'status)) output)) -;; In Org TOC buffer, hide headlines below the first level. -(defun org-toc-help () - "Display a quick help message in the echo-area for `org-toc-mode'." - (interactive) - (let ((st-start 0) - (help-message - "\[space\] show heading \[1-4\] hide headlines below this level +(defvar org-toc--help-message + "\[space\] show heading \[1-4\] hide headlines below this level \[TAB\] jump to heading \[F\] toggle follow mode (currently %s) \[return\] jump and delete others windows \[i\] toggle info mode (currently %s) \[S-TAB\] cycle subtree (in Org) \[S\] toggle show subtree mode (currently %s) @@ -487,17 +482,25 @@ status." \[:\] cycle subtree (in TOC) \[c\] toggle column view (currently %s) \[n/p\] next/previous heading \[s\] save TOC configuration \[f/b\] next/previous heading of same level -\[q\] quit the TOC \[g\] restore last TOC configuration")) - (while (string-match "\\[[^]]+\\]" help-message st-start) - (add-text-properties (match-beginning 0) - (match-end 0) '(face bold) help-message) - (setq st-start (match-end 0))) - (message help-message - (if org-toc-follow-mode "on" "off") - (if org-toc-info-mode "on" "off") - (if org-toc-show-subtree-mode "on" "off") - (if org-toc-recenter-mode (format "on, line %s" org-toc-recenter) "off") - (if org-toc-columns-shown "on" "off")))) +\[q\] quit the TOC \[g\] restore last TOC configuration" + "Help message used by `org-toc-help'.") + +(let ((st-start 0)) + (while (string-match "\\[[^]]+\\]" org-toc--help-message st-start) + (add-text-properties (match-beginning 0) + (match-end 0) '(face bold) org-toc--help-message) + (setq st-start (match-end 0)))) + +;; In Org TOC buffer, hide headlines below the first level. +(defun org-toc-help () + "Display a quick help message in the echo-area for `org-toc-mode'." + (interactive) + (message org-toc--help-message + (if org-toc-follow-mode "on" "off") + (if org-toc-info-mode "on" "off") + (if org-toc-show-subtree-mode "on" "off") + (if org-toc-recenter-mode (format "on, line %s" org-toc-recenter) "off") + (if org-toc-columns-shown "on" "off"))) ;;;;########################################################################## |