[-- Attachment #1: Type: text/plain, Size: 790 bytes --] As suggested in bug#41198, here is a patch that adds two new options (disabled by default): - outline-minor-mode-font-lock that enables outline font-lock in outline-minor-mode - outline-minor-mode-cycle that enables heading cycle in outline-minor-mode And at the end of the patch are two examples that enable this feature in the files etc/compilation.txt and etc/grep.txt. So visiting these files will highlight their outline headers, and will allow typing 'TAB' to cycle between `hide all', `headings only' and `show all' when point is on the heading line. Typing 'S-TAB' on the heading line cycles the whole buffer. Typing these keys anywhere outside heading lines uses their default bindings, so TAB will go to the next link, and S-TAB will navigate back to the previous link. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: outline-minor-mode-cycle.patch --] [-- Type: text/x-diff, Size: 4231 bytes --] diff --git a/lisp/outline.el b/lisp/outline.el index 85f9de4e1b..b6973e60dd 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -175,10 +175,8 @@ outline-minor-mode-menu-bar-map outline-mode-menu-bar-map)))))) map)) -(defvar outline-mode-map +(defvar outline-mode-cycle-map (let ((map (make-sparse-keymap))) - (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 @@ -187,11 +185,22 @@ outline-mode-map (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) + map)) + (defvar outline-font-lock-keywords '( ;; Highlight headings according to the level. (eval . (list (concat "^\\(?:" outline-regexp "\\).+") - 0 '(outline-font-lock-face) nil t))) + 0 '(if outline-minor-mode-cycle + (list 'face (outline-font-lock-face) + 'local-map outline-mode-cycle-map) + (outline-font-lock-face)) + nil t))) "Additional expressions to highlight in Outline mode.") (defface outline-1 @@ -305,6 +314,19 @@ outline-minor-mode-prefix (define-key outline-minor-mode-map val outline-mode-prefix-map) (set-default sym val))) +(defvar outline-minor-mode-font-lock nil + "Enable outline font-lock in `outline-minor-mode'. +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-font-lock '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 +336,9 @@ outline-minor-mode (cons outline-minor-mode-prefix outline-mode-prefix-map)) (if outline-minor-mode (progn + (when outline-minor-mode-font-lock + (font-lock-add-keywords nil outline-font-lock-keywords) + (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 +346,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 outline-minor-mode-font-lock + (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)) diff --git a/etc/compilation.txt b/etc/compilation.txt index 7e406389d4..5f28ca1d13 100644 --- a/etc/compilation.txt +++ b/etc/compilation.txt @@ -692,3 +692,11 @@ COPYING PERMISSIONS: You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. + + +;;; Local Variables: +;;; outline-minor-mode-font-lock: t +;;; outline-minor-mode-cycle: t +;;; outline-regexp: "\\*\\_>" +;;; eval: (outline-minor-mode 1) +;;; End: diff --git a/etc/grep.txt b/etc/grep.txt index 19a3b4b47b..0f03609762 100644 --- a/etc/grep.txt +++ b/etc/grep.txt @@ -118,4 +123,7 @@ COPYING PERMISSIONS: ;;; Local Variables: ;;; eval: (let ((inhibit-read-only t) (compilation-filter-start (point-min))) (save-excursion (goto-char (point-max)) (grep-filter) (set-buffer-modified-p nil))) ;;; buffer-read-only: t +;;; outline-minor-mode-font-lock: t +;;; outline-minor-mode-cycle: t +;;; eval: (outline-minor-mode 1) ;;; End:
[-- Attachment #1: Type: text/plain, Size: 357 bytes --] > As suggested in bug#41198, here is a patch that adds > two new options (disabled by default): Here is a better patch. It makes possible to enable outline-minor-mode in any buffer, e.g. in prog mode, when outline-minor-mode-cycle is set to non-nil. Then typing S-TAB will collapse all headings, and TAB will expand the current function body, like this: [-- Attachment #2: outline-minor-mode-cycle.png --] [-- Type: image/png, Size: 96638 bytes --] [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: outline-minor-mode-cycle-2.patch --] [-- Type: text/x-diff, Size: 3588 bytes --] diff --git a/lisp/outline.el b/lisp/outline.el index 85f9de4e1b..67e1a5dcdc 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -175,10 +175,8 @@ outline-minor-mode-menu-bar-map outline-mode-menu-bar-map)))))) map)) -(defvar outline-mode-map +(defvar outline-mode-cycle-map (let ((map (make-sparse-keymap))) - (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 @@ -187,11 +185,27 @@ outline-mode-map (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) + map)) + (defvar outline-font-lock-keywords '( ;; Highlight headings according to the level. (eval . (list (concat "^\\(?:" outline-regexp "\\).+") - 0 '(outline-font-lock-face) nil t))) + 0 '(if outline-minor-mode-cycle + (if outline-minor-mode-font-lock + (list 'face (outline-font-lock-face) + 'local-map outline-mode-cycle-map) + (list 'face nil 'local-map outline-mode-cycle-map)) + (outline-font-lock-face)) + nil + (if (or outline-minor-mode-font-lock outline-minor-mode-cycle) + 'append + t)))) "Additional expressions to highlight in Outline mode.") (defface outline-1 @@ -305,6 +319,19 @@ outline-minor-mode-prefix (define-key outline-minor-mode-map val outline-mode-prefix-map) (set-default sym val))) +(defvar outline-minor-mode-font-lock nil + "Enable outline font-lock in `outline-minor-mode'. +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-font-lock '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 +341,9 @@ outline-minor-mode (cons outline-minor-mode-prefix outline-mode-prefix-map)) (if outline-minor-mode (progn + (when (or outline-minor-mode-font-lock outline-minor-mode-cycle) + (font-lock-add-keywords nil outline-font-lock-keywords) + (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 +351,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-font-lock 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))
[-- Attachment #1: Type: text/plain, Size: 579 bytes --] severity 45147 wishlist tags 45147 + patch quit >> As suggested in bug#41198, here is a patch that adds >> two new options (disabled by default): > > Here is a better patch. It makes possible to enable > outline-minor-mode in any buffer, e.g. in prog mode, > when outline-minor-mode-cycle is set to non-nil. > Then typing S-TAB will collapse all headings, and > TAB will expand the current function body, like this: This patch also allows using only outline-minor-mode-cycle without highlighting heading with outline-minor-mode-font-lock that is useful in prog-mode buffers: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: outline-minor-mode-cycle-3.patch --] [-- Type: text/x-diff, Size: 4219 bytes --] diff --git a/lisp/outline.el b/lisp/outline.el index 85f9de4e1b..db10e2667f 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -175,23 +175,43 @@ 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))) + 0 '(if outline-minor-mode-cycle + (if outline-minor-mode-font-lock + (list 'face (outline-font-lock-face) + 'local-map (make-composed-keymap + outline-mode-cycle-map + (current-local-map))) + (list 'face nil 'local-map (make-composed-keymap + outline-mode-cycle-map + (current-local-map)))) + (outline-font-lock-face)) + nil + (if (or outline-minor-mode-font-lock outline-minor-mode-cycle) + 'append + t)))) "Additional expressions to highlight in Outline mode.") (defface outline-1 @@ -305,6 +325,19 @@ outline-minor-mode-prefix (define-key outline-minor-mode-map val outline-mode-prefix-map) (set-default sym val))) +(defvar outline-minor-mode-font-lock nil + "Enable outline font-lock in `outline-minor-mode'. +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-font-lock '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 +347,9 @@ outline-minor-mode (cons outline-minor-mode-prefix outline-mode-prefix-map)) (if outline-minor-mode (progn + (when (or outline-minor-mode-font-lock outline-minor-mode-cycle) + (font-lock-add-keywords nil outline-font-lock-keywords) + (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 +357,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-font-lock 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))
[-- 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))
> As suggested in bug#41198, here is a patch that adds
> two new options (disabled by default):
With no objections, new options (disabled by default)
pushed to master.
Juri Linkov <juri@linkov.net> writes: >> As suggested in bug#41198, here is a patch that adds >> two new options (disabled by default): > > With no objections, new options (disabled by default) > pushed to master. Skimming this thread, I'm not quite sure whether there's anything more to be done here? The first message mentioned > - outline-minor-mode-font-lock that enables outline font-lock in > outline-minor-mode which does not seem to exist, but I'm not sure whether the second version made that unnecessary... -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no
>>> As suggested in bug#41198, here is a patch that adds >>> two new options (disabled by default): >> >> With no objections, new options (disabled by default) >> pushed to master. > > Skimming this thread, I'm not quite sure whether there's anything more > to be done here? The first message mentioned There is still an unpushed patch outline-describe-bindings.patch in https://debbugs.gnu.org/45147#18 that will enable outline-minor-mode on the output of describe-bindings. I waited when the speed of describe-bindings will be improved in bug#45379, but maybe this patch could be pushed nevertheless. >> - outline-minor-mode-font-lock that enables outline font-lock in >> outline-minor-mode > > which does not seem to exist, but I'm not sure whether the second > version made that unnecessary... outline-minor-mode-font-lock was renamed to outline-minor-mode-highlight.
Juri Linkov <juri@linkov.net> writes: > There is still an unpushed patch outline-describe-bindings.patch in > https://debbugs.gnu.org/45147#18 that will enable outline-minor-mode > on the output of describe-bindings. I waited when the speed of > describe-bindings will be improved in bug#45379, but maybe > this patch could be pushed nevertheless. I think you could push it anyway... but I think enabling outline mode (by default) in describe-bindings would be controversial, so I think there should be a user option for that behaviour. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no
[-- Attachment #1: Type: text/plain, Size: 340 bytes --] > I think you could push it anyway... but I think enabling outline mode > (by default) in describe-bindings would be controversial, so I think > there should be a user option for that behaviour. This patch adds a new user option ‘describe-bindings-after-hook’ (and also removes ‘describe-bindings-internal’ obsolete since 24.4): [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: describe-bindings-after-hook.patch --] [-- Type: text/x-diff, Size: 2648 bytes --] diff --git a/lisp/help.el b/lisp/help.el index babaf4adc7..7caf080dca 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -561,6 +561,13 @@ help--key-description-fontified 'font-lock-face 'help-key-binding 'face 'help-key-binding)) +(defcustom describe-bindings-after-hook '(describe-bindings-outline) + "Hook run at the end of `describe-bindings'." + :type 'hook + :options '(describe-bindings-outline) + :group 'help + :version "28.1") + (defun describe-bindings (&optional prefix buffer) "Display a buffer showing a list of all defined keys, and their definitions. The keys are displayed in order of precedence. @@ -578,23 +585,26 @@ 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) + (run-hooks 'describe-bindings-after-hook)))) -(defun describe-bindings-internal (&optional menus prefix) - "Show a list of all defined keys, and their definitions. -We put that list in a buffer, and display the buffer. - -The optional argument MENUS, if non-nil, says to mention menu bindings. -\(Ordinarily these are omitted from the output.) -The optional argument PREFIX, if non-nil, should be a key sequence; -then we display only bindings that start with that prefix." - (declare (obsolete describe-buffer-bindings "24.4")) - (let ((buf (current-buffer))) - (with-help-window (help-buffer) - ;; Be aware that `describe-buffer-bindings' puts its output into - ;; the current buffer. - (with-current-buffer (help-buffer) - (describe-buffer-bindings buf prefix menus))))) +(defun describe-bindings-outline () + "Hook to enable outlines in the output buffer of `describe-bindings'." + (setq-local outline-regexp ".*:$") + (setq-local outline-heading-end-regexp ":\n") + (setq-local outline-level (lambda () 1)) + (setq-local outline-minor-mode-cycle t + outline-minor-mode-highlight t) + (outline-minor-mode 1) + (save-excursion + (let ((inhibit-read-only t)) + (goto-char (point-min)) + (insert (substitute-command-keys + "\\<outline-mode-cycle-map>Type \\[outline-cycle] or \\[outline-cycle-buffer] 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))))) (defun where-is (definition &optional insert) "Print message listing key sequences that invoke the command DEFINITION.
> From: Juri Linkov <juri@linkov.net> > Date: Tue, 18 May 2021 23:12:46 +0300 > Cc: 45147@debbugs.gnu.org > > +(defcustom describe-bindings-after-hook '(describe-bindings-outline) > + "Hook run at the end of `describe-bindings'." > + :type 'hook > + :options '(describe-bindings-outline) > + :group 'help > + :version "28.1") What's the rationale for populating the hook by default? That's not what we normally do: hooks are for Lisp programs to use, not for the core functionality to invoke itself. > +(defun describe-bindings-outline () > + "Hook to enable outlines in the output buffer of `describe-bindings'." First, this is not a hook. And second, if we want a feature whereby the buffer describing bindings could be put in Outline mode, why not offer a simple option for users to customize, not a hook for users to tweak? Once again, having user options that accept only function values is user-unfriendly. Thanks.
[-- Attachment #1: Type: text/plain, Size: 1045 bytes --] >> +(defcustom describe-bindings-after-hook '(describe-bindings-outline) >> + "Hook run at the end of `describe-bindings'." >> + :type 'hook >> + :options '(describe-bindings-outline) >> + :group 'help >> + :version "28.1") > > What's the rationale for populating the hook by default? That's not > what we normally do: hooks are for Lisp programs to use, not for the > core functionality to invoke itself. This was an attempt of generalization. >> +(defun describe-bindings-outline () >> + "Hook to enable outlines in the output buffer of `describe-bindings'." > > First, this is not a hook. > > And second, if we want a feature whereby the buffer describing > bindings could be put in Outline mode, why not offer a simple option > for users to customize, not a hook for users to tweak? Once again, > having user options that accept only function values is > user-unfriendly. Function values are user-friendly when their defcustom provides human-readable tags. But in this case it's fine to have a simple option like in this patch: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: describe-bindings-outline.patch --] [-- Type: text/x-diff, Size: 1896 bytes --] diff --git a/lisp/help.el b/lisp/help.el index babaf4adc7..2409636b48 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -561,6 +561,12 @@ help--key-description-fontified 'font-lock-face 'help-key-binding 'face 'help-key-binding)) +(defcustom describe-bindings-outline t + "Non-nil enables outlines in the output buffer of `describe-bindings'." + :type 'boolean + :group 'help + :version "28.1") + (defun describe-bindings (&optional prefix buffer) "Display a buffer showing a list of all defined keys, and their definitions. The keys are displayed in order of precedence. @@ -578,7 +584,26 @@ 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) + + (when describe-bindings-outline + (setq-local outline-regexp ".*:$") + (setq-local outline-heading-end-regexp ":\n") + (setq-local outline-level (lambda () 1)) + (setq-local outline-minor-mode-cycle t + outline-minor-mode-highlight t) + (outline-minor-mode 1) + (save-excursion + (let ((inhibit-read-only t)) + (goto-char (point-min)) + (insert (substitute-command-keys + (concat "\\<outline-mode-cycle-map>Type " + "\\[outline-cycle] or \\[outline-cycle-buffer] " + "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)))))))) (defun describe-bindings-internal (&optional menus prefix) "Show a list of all defined keys, and their definitions.
> From: Juri Linkov <juri@linkov.net> > Cc: larsi@gnus.org, 45147@debbugs.gnu.org > Date: Wed, 19 May 2021 19:14:47 +0300 > > > And second, if we want a feature whereby the buffer describing > > bindings could be put in Outline mode, why not offer a simple option > > for users to customize, not a hook for users to tweak? Once again, > > having user options that accept only function values is > > user-unfriendly. > > Function values are user-friendly when their defcustom provides > human-readable tags. Only if the user uses Customize, not if he/she uses Lisp, or the interactive set-variable command. > But in this case it's fine to have a simple option like in this patch: Thanks, this is much better.
tags 45147 fixed
close 45147 28.0.50
quit
>> But in this case it's fine to have a simple option like in this patch:
>
> Thanks, this is much better.
So now pushed to master and closed.