emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master a4087f59558: Improve reliability of minor mode menu dispatch


From: Po Lu
Subject: master a4087f59558: Improve reliability of minor mode menu dispatch
Date: Tue, 18 Jul 2023 20:22:30 -0400 (EDT)

branch: master
commit a4087f59558ae29f6dacaa6550eb4326912fe65e
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Improve reliability of minor mode menu dispatch
    
    * lisp/mouse.el (minor-mode-menu-from-indicator): Instead of using the
    word at point, search for a matching enabled minor mode from the
    beginning of the string object when mode-line-compact is enabled.
---
 lisp/mouse.el | 48 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 13 deletions(-)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 1e1f0808f9f..661980f4ac2 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -220,22 +220,44 @@ items `Turn Off' and `Help'."
    (list (completing-read
          "Minor mode indicator: "
          (describe-minor-mode-completion-table-for-indicator))))
-  ;; If INDICATOR is a string object and `mode-line-compact' might be
-  ;; enabled, look for the word at its position and use that instead.
-  (when (and (consp indicator)
-             window
-             (with-selected-window window
-               mode-line-compact))
-    (with-temp-buffer
-      (insert (car indicator))
-      (goto-char (cdr indicator))
-      (if-let ((thing (thing-at-point 'word)))
-          (setq indicator thing)
-        (setq indicator (car indicator)))))
+  ;; If INDICATOR is a string object, WINDOW is set, and
+  ;; `mode-line-compact' might be enabled, find a string in
+  ;; `minor-mode-alist' that is present within the INDICATOR and whose
+  ;; extents within INDICATOR contain the position of the object
+  ;; within the string.
+  (when window
+    (catch 'found
+      (with-selected-window window
+        (let ((alist minor-mode-alist) string position)
+          (when (and (consp indicator) mode-line-compact)
+            (with-temp-buffer
+              (insert (car indicator))
+              (dolist (menu alist)
+                ;; If this is a valid minor mode menu entry,
+                (when (and (consp menu)
+                           (setq string (format-mode-line (cadr menu)
+                                                          nil window))
+                           (> (length string) 0))
+                  ;; Start searching for an appearance of (cdr menu).
+                  (goto-char (point-min))
+                  (while (search-forward string nil 0)
+                    ;; If the position of the string object is
+                    ;; contained within, set indicator to the minor
+                    ;; mode in question.
+                    (setq position (1+ (cdr indicator)))
+                    (and (>= position (match-beginning 0))
+                         (<= position (match-end 0))
+                         (setq indicator (car menu))
+                         (throw 'found nil)))))))))))
   ;; If INDICATOR is still a cons, use its car.
   (when (consp indicator)
     (setq indicator (car indicator)))
-  (let* ((minor-mode (lookup-minor-mode-from-indicator indicator))
+  (let* ((minor-mode (if (symbolp indicator)
+                         ;; indicator being set to a symbol means that
+                         ;; the loop above has already found a
+                         ;; matching minor mode.
+                         indicator
+                       (lookup-minor-mode-from-indicator indicator)))
          (mm-fun (or (get minor-mode :minor-mode-function) minor-mode)))
     (unless minor-mode (error "Cannot find minor mode for `%s'" indicator))
     (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]