GNU bug report logs - #45147
Org-like cycling in outline-minor-mode

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Wed, 9 Dec 2020 19:23:01 UTC

Severity: wishlist

Tags: fixed, patch

Fixed in version 28.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45147 in the body.
You can then email your comments to 45147 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 09 Dec 2020 19:23:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 09 Dec 2020 19:23:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Org-like cycling in outline-minor-mode
Date: Wed, 09 Dec 2020 21:15:14 +0200
[Message part 1 (text/plain, inline)]
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.

[outline-minor-mode-cycle.patch (text/x-diff, inline)]
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:

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 09 Dec 2020 20:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 09 Dec 2020 22:03:15 +0200
[Message part 1 (text/plain, inline)]
> 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:

[outline-minor-mode-cycle.png (image/png, inline)]
[outline-minor-mode-cycle-2.patch (text/x-diff, inline)]
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))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Mon, 14 Dec 2020 20:39:02 GMT) Full text and rfc822 format available.

Message #11 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Mon, 14 Dec 2020 22:35:44 +0200
[Message part 1 (text/plain, inline)]
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:

[outline-minor-mode-cycle-3.patch (text/x-diff, inline)]
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))

Severity set to 'wishlist' from 'normal' Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Mon, 14 Dec 2020 20:39:03 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Mon, 14 Dec 2020 20:39:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 16 Dec 2020 21:06:02 GMT) Full text and rfc822 format available.

Message #18 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 16 Dec 2020 22:28:51 +0200
[Message part 1 (text/plain, inline)]
As proposed in bug#41198, here is the support for outline-minor-mode
in the 'C-h b' Help buffer:

[outline-describe-bindings.patch (text/x-diff, inline)]
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))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 03 Mar 2021 19:15:02 GMT) Full text and rfc822 format available.

Message #21 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 03 Mar 2021 21:12:39 +0200
> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Sun, 16 May 2021 15:52:02 GMT) Full text and rfc822 format available.

Message #24 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Sun, 16 May 2021 17:51:16 +0200
Juri Linkov <juri <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Sun, 16 May 2021 18:28:01 GMT) Full text and rfc822 format available.

Message #27 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Sun, 16 May 2021 20:53:49 +0300
>>> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Mon, 17 May 2021 13:58:02 GMT) Full text and rfc822 format available.

Message #30 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Mon, 17 May 2021 15:57:33 +0200
Juri Linkov <juri <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Tue, 18 May 2021 20:28:01 GMT) Full text and rfc822 format available.

Message #33 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Tue, 18 May 2021 23:12:46 +0300
[Message part 1 (text/plain, inline)]
> 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):

[describe-bindings-after-hook.patch (text/x-diff, inline)]
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.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 19 May 2021 12:11:01 GMT) Full text and rfc822 format available.

Message #36 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: larsi <at> gnus.org, 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 19 May 2021 15:10:37 +0300
> From: Juri Linkov <juri <at> linkov.net>
> Date: Tue, 18 May 2021 23:12:46 +0300
> Cc: 45147 <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 19 May 2021 16:32:02 GMT) Full text and rfc822 format available.

Message #39 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 19 May 2021 19:14:47 +0300
[Message part 1 (text/plain, inline)]
>> +(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:

[describe-bindings-outline.patch (text/x-diff, inline)]
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.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Wed, 19 May 2021 17:29:01 GMT) Full text and rfc822 format available.

Message #42 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: larsi <at> gnus.org, 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Wed, 19 May 2021 20:28:52 +0300
> From: Juri Linkov <juri <at> linkov.net>
> Cc: larsi <at> gnus.org,  45147 <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45147; Package emacs. (Thu, 20 May 2021 18:38:01 GMT) Full text and rfc822 format available.

Message #45 received at 45147 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, 45147 <at> debbugs.gnu.org
Subject: Re: bug#45147: Org-like cycling in outline-minor-mode
Date: Thu, 20 May 2021 21:37:18 +0300
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.




Added tag(s) fixed. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Thu, 20 May 2021 18:38:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.0.50, send any further explanations to 45147 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Thu, 20 May 2021 18:38:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 18 Jun 2021 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 304 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.