emacs-diffs
[Top][All Lists]
Advanced

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

master c4f8ead08d1: Fix display of minor mode menus when mode-line-compa


From: Po Lu
Subject: master c4f8ead08d1: Fix display of minor mode menus when mode-line-compact is enabled
Date: Tue, 18 Jul 2023 04:15:52 -0400 (EDT)

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

    Fix display of minor mode menus when mode-line-compact is enabled
    
    * lisp/mouse.el (minor-mode-menu-from-indicator): New arg
    WINDOW.  If INDICATOR is a string object and mode-line-compat is
    enabled within WINDOW, use the symbol within the object at its
    position instead.
    (mouse-minor-mode-menu): Pass posn-object and posn-window to
    minor-mode-menu-from-indicator.
---
 lisp/mouse.el | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 3c30361ad7d..1e1f0808f9f 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -206,8 +206,13 @@ always return a positive integer or zero."
 
 ;; Provide a mode-specific menu on a mouse button.
 
-(defun minor-mode-menu-from-indicator (indicator)
+(defun minor-mode-menu-from-indicator (indicator &optional window)
   "Show menu for minor mode specified by INDICATOR.
+
+INDICATOR is either a string object returned by `posn-object' or
+the car of such an object.  WINDOW may be the window whose mode
+line is being displayed.
+
 Interactively, INDICATOR is read using completion.
 If there is no menu defined for the minor mode, then create one with
 items `Turn Off' and `Help'."
@@ -215,6 +220,21 @@ 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 still a cons, use its car.
+  (when (consp indicator)
+    (setq indicator (car indicator)))
   (let* ((minor-mode (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))
@@ -240,8 +260,10 @@ items `Turn Off' and `Help'."
 (defun mouse-minor-mode-menu (event)
   "Show minor-mode menu for EVENT on minor modes area of the mode line."
   (interactive "@e")
-  (let ((indicator (car (nth 4 (car (cdr event))))))
-    (minor-mode-menu-from-indicator indicator)))
+  (let* ((posn (event-start event))
+         (indicator (posn-object posn))
+         (window (posn-window posn)))
+    (minor-mode-menu-from-indicator indicator window)))
 
 (defun mouse-menu-major-mode-map ()
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)



reply via email to

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