From: Juri Linkov <juri@linkov.net>
To: 45147@debbugs.gnu.org
Subject: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 16 Dec 2020 22:28:51 +0200 [thread overview]
Message-ID: <87r1npldlw.fsf@mail.linkov.net> (raw)
In-Reply-To: <87zh2gyvkv.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 14 Dec 2020 22:35:44 +0200")
[-- Attachment #1: Type: text/plain, Size: 98 bytes --]
As proposed in bug#41198, here is the support for outline-minor-mode
in the 'C-h b' Help buffer:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: outline-describe-bindings.patch --]
[-- Type: text/x-diff, Size: 5333 bytes --]
diff --git a/lisp/help.el b/lisp/help.el
index ac5c2f1311..be366439b8 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -509,7 +509,22 @@ describe-bindings
;; Be aware that `describe-buffer-bindings' puts its output into
;; the current buffer.
(with-current-buffer (help-buffer)
- (describe-buffer-bindings buffer prefix))))
+ (describe-buffer-bindings buffer prefix)
+
+ (setq-local outline-regexp ".*:$")
+ (setq-local outline-level (lambda () 1))
+ (setq-local outline-minor-mode-cycle t)
+ (setq-local outline-minor-mode-highlight t)
+ (outline-minor-mode +1)
+ (save-excursion
+ (let ((inhibit-read-only t))
+ (goto-char (point-min))
+ (insert "Type TAB or S-TAB on headings to cycle their visibility.\n\n")
+ ;; Hide the longest body
+ (when (and (re-search-forward "Key translations" nil t)
+ (fboundp 'outline-cycle))
+ (outline-cycle))))
+ (font-lock-ensure))))
;; This function used to be in keymap.c.
(defun describe-bindings-internal (&optional menus prefix)
And here is an updated outline.el:
diff --git a/lisp/outline.el b/lisp/outline.el
index 85f9de4e1b..97aba091c5 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -175,23 +175,40 @@ outline-minor-mode-menu-bar-map
outline-mode-menu-bar-map))))))
map))
+(defvar outline-mode-cycle-map
+ (let ((map (make-sparse-keymap)))
+ (let ((binding `(menu-item
+ "" outline-cycle
+ ;; Only takes effect if point is on a heading.
+ :filter ,(lambda (cmd)
+ (when (outline-on-heading-p) cmd)))))
+ (define-key map (kbd "TAB") binding)
+ (define-key map [tab] binding)
+ (define-key map (kbd "<backtab>") #'outline-cycle-buffer))
+ map))
+
(defvar outline-mode-map
(let ((map (make-sparse-keymap)))
+ (set-keymap-parent map outline-mode-cycle-map)
(define-key map "\C-c" outline-mode-prefix-map)
(define-key map [menu-bar] outline-mode-menu-bar-map)
- ;; Only takes effect if point is on a heading.
- (define-key map (kbd "TAB")
- `(menu-item "" outline-cycle
- :filter ,(lambda (cmd)
- (when (outline-on-heading-p) cmd))))
- (define-key map (kbd "<backtab>") #'outline-cycle-buffer)
map))
(defvar outline-font-lock-keywords
'(
;; Highlight headings according to the level.
- (eval . (list (concat "^\\(?:" outline-regexp "\\).+")
- 0 '(outline-font-lock-face) nil t)))
+ (eval . (list (concat "^\\(?:" outline-regexp "\\)"
+ (if (string-match-p "\\$$" outline-regexp)
+ "" ".+"))
+ 0 '(if outline-minor-mode-cycle
+ (if outline-minor-mode-highlight
+ (list 'face (outline-font-lock-face) 'keymap outline-mode-cycle-map)
+ (list 'face nil 'keymap outline-mode-cycle-map))
+ (outline-font-lock-face))
+ nil
+ (if (or outline-minor-mode-highlight outline-minor-mode-cycle)
+ 'append
+ t))))
"Additional expressions to highlight in Outline mode.")
(defface outline-1
@@ -305,6 +322,19 @@ outline-minor-mode-prefix
(define-key outline-minor-mode-map val outline-mode-prefix-map)
(set-default sym val)))
+(defvar outline-minor-mode-highlight nil
+ "Highlight headings in `outline-minor-mode' using font-lock keywords.
+Non-nil value works well only when outline font-lock keywords
+don't conflict with the major mode's font-lock keywords.")
+;;;###autoload(put 'outline-minor-mode-highlight 'safe-local-variable 'booleanp)
+(defvar outline-minor-mode-cycle nil
+ "Enable heading cycle in `outline-minor-mode'.
+When point is on a heading line, then typing 'TAB' cycles between `hide all',
+`headings only' and `show all' (`outline-cycle'). Typing 'S-TAB' on
+a heading line cycles the whole buffer (`outline-cycle-buffer').
+Typing these keys anywhere outside heading lines uses their default bindings.")
+;;;###autoload(put 'outline-minor-mode-cycle 'safe-local-variable 'booleanp)
+
;;;###autoload
(define-minor-mode outline-minor-mode
"Toggle Outline minor mode.
@@ -314,6 +344,11 @@ outline-minor-mode
(cons outline-minor-mode-prefix outline-mode-prefix-map))
(if outline-minor-mode
(progn
+ (when (or outline-minor-mode-highlight outline-minor-mode-cycle)
+ (unless font-lock-defaults
+ (setq-local font-lock-defaults '(nil t)))
+ (font-lock-add-keywords nil outline-font-lock-keywords t)
+ (font-lock-flush))
;; Turn off this mode if we change major modes.
(add-hook 'change-major-mode-hook
(lambda () (outline-minor-mode -1))
@@ -321,6 +356,9 @@ outline-minor-mode
(setq-local line-move-ignore-invisible t)
;; Cause use of ellipses for invisible text.
(add-to-invisibility-spec '(outline . t)))
+ (when (or outline-minor-mode-highlight outline-minor-mode-cycle)
+ (font-lock-remove-keywords nil outline-font-lock-keywords)
+ (font-lock-flush))
(setq line-move-ignore-invisible nil)
;; Cause use of ellipses for invisible text.
(remove-from-invisibility-spec '(outline . t))
next prev parent reply other threads:[~2020-12-16 20:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-09 19:15 bug#45147: Org-like cycling in outline-minor-mode Juri Linkov
2020-12-09 20:03 ` Juri Linkov
2020-12-14 20:35 ` Juri Linkov
2020-12-16 20:28 ` Juri Linkov [this message]
2021-03-03 19:12 ` Juri Linkov
2021-05-16 15:51 ` Lars Ingebrigtsen
2021-05-16 17:53 ` Juri Linkov
2021-05-17 13:57 ` Lars Ingebrigtsen
2021-05-18 20:12 ` Juri Linkov
2021-05-19 12:10 ` Eli Zaretskii
2021-05-19 16:14 ` Juri Linkov
2021-05-19 17:28 ` Eli Zaretskii
2021-05-20 18:37 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1npldlw.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=45147@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).