]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/outline.el (outline-minor-mode-cycle-filter): New defcustom (bug#50679)
authorJuri Linkov <juri@linkov.net>
Thu, 23 Sep 2021 16:14:56 +0000 (19:14 +0300)
committerJuri Linkov <juri@linkov.net>
Thu, 23 Sep 2021 16:14:56 +0000 (19:14 +0300)
(outline-minor-mode-cycle--bind): New helper function.
(outline-minor-mode-cycle-map): Rename from outline-mode-cycle-map.
(outline-mode-map): Revert part of 6458e16f33 to disassociate
keymaps outline-mode-map and outline-minor-mode-cycle-map.
(outline-font-lock-keywords, outline-minor-mode-highlight-buffer):
Use outline-minor-mode-cycle-map instead of outline-mode-cycle-map.

* lisp/help.el (describe-bindings): Rename outline-mode-cycle-map
to outline-minor-mode-cycle-map.

lisp/help.el
lisp/outline.el

index 29ae3404813a45ccce36834acb9ad4832dc09ff8..8f771670408ee963ad142469fa1eaaa964398c75 100644 (file)
@@ -597,7 +597,7 @@ or a buffer name."
           (let ((inhibit-read-only t))
             (goto-char (point-min))
             (insert (substitute-command-keys
-                     (concat "\\<outline-mode-cycle-map>Type "
+                     (concat "\\<outline-minor-mode-cycle-map>Type "
                              "\\[outline-cycle] or \\[outline-cycle-buffer] "
                              "on headings to cycle their visibility.\n\n")))
             ;; Hide the longest body
index 0bb74ffd64a8cf86a59812ef8006e43b50d232e3..52a94b4d9f4a4e9b6eb8953c1ad17ed1f5311009 100644 (file)
@@ -175,23 +175,45 @@ in the file it applies to.")
                                   outline-mode-menu-bar-map))))))
     map))
 
-(defvar outline-mode-cycle-map
+(defcustom outline-minor-mode-cycle-filter nil
+  "Filter out positions on the heading available for cycling."
+  :type '(choice (const :tag "Everywhere" nil)
+                 (const :tag "At line beginning" bolp)
+                 (const :tag "Not at line beginning"
+                        (lambda () (not (bolp))))
+                 (const :tag "At line end" eolp)
+                 (function :tag "Custom filter"))
+  :version "28.1")
+
+(defun outline-minor-mode-cycle--bind (map key binding &optional filter)
+  (define-key map key
+    `(menu-item
+      "" ,binding
+      ;; Filter out specific positions on the heading.
+      :filter
+      ,(or filter
+           (lambda (cmd)
+             (when (or (not (functionp outline-minor-mode-cycle-filter))
+                       (funcall outline-minor-mode-cycle-filter))
+               cmd))))))
+
+(defvar outline-minor-mode-cycle-map
   (let ((map (make-sparse-keymap)))
-    (let ((tab-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") tab-binding)
-      (define-key map (kbd "<backtab>") #'outline-cycle-buffer))
+    (outline-minor-mode-cycle--bind map (kbd "TAB") #'outline-cycle)
+    (outline-minor-mode-cycle--bind map (kbd "<backtab>") #'outline-cycle-buffer)
     map)
-  "Keymap used by `outline-mode-map' and `outline-minor-mode-cycle'.")
+  "Keymap used by `outline-minor-mode-cycle'.")
 
 (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
@@ -202,9 +224,9 @@ in the file it applies to.")
                          (if outline-minor-mode-cycle
                              (if outline-minor-mode-highlight
                                  (list 'face (outline-font-lock-face)
-                                       'keymap outline-mode-cycle-map)
+                                       'keymap outline-minor-mode-cycle-map)
                                (list 'face nil
-                                     'keymap outline-mode-cycle-map))
+                                     'keymap outline-minor-mode-cycle-map))
                            (if outline-minor-mode-highlight
                                (list 'face (outline-font-lock-face))))
                        (outline-font-lock-face))
@@ -367,7 +389,7 @@ faces to major mode's faces."
                          (not (get-text-property (point) 'face))))
             (overlay-put overlay 'face (outline-font-lock-face)))
           (when outline-minor-mode-cycle
-            (overlay-put overlay 'keymap outline-mode-cycle-map)))
+            (overlay-put overlay 'keymap outline-minor-mode-cycle-map)))
         (goto-char (match-end 0))))))
 
 ;;;###autoload