diff options
| author | Po Lu | 2023-07-19 08:21:43 +0800 |
|---|---|---|
| committer | Po Lu | 2023-07-19 08:21:43 +0800 |
| commit | a4087f59558ae29f6dacaa6550eb4326912fe65e (patch) | |
| tree | 7f8c0f66730947cd77cfa6726ec895d1cd0ddb35 | |
| parent | dec15620d8c79d41808de9a5cbf6ad08f7399212 (diff) | |
| download | emacs-a4087f59558ae29f6dacaa6550eb4326912fe65e.tar.gz emacs-a4087f59558ae29f6dacaa6550eb4326912fe65e.zip | |
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.
| -rw-r--r-- | lisp/mouse.el | 48 |
1 files 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'." | |||
| 220 | (list (completing-read | 220 | (list (completing-read |
| 221 | "Minor mode indicator: " | 221 | "Minor mode indicator: " |
| 222 | (describe-minor-mode-completion-table-for-indicator)))) | 222 | (describe-minor-mode-completion-table-for-indicator)))) |
| 223 | ;; If INDICATOR is a string object and `mode-line-compact' might be | 223 | ;; If INDICATOR is a string object, WINDOW is set, and |
| 224 | ;; enabled, look for the word at its position and use that instead. | 224 | ;; `mode-line-compact' might be enabled, find a string in |
| 225 | (when (and (consp indicator) | 225 | ;; `minor-mode-alist' that is present within the INDICATOR and whose |
| 226 | window | 226 | ;; extents within INDICATOR contain the position of the object |
| 227 | (with-selected-window window | 227 | ;; within the string. |
| 228 | mode-line-compact)) | 228 | (when window |
| 229 | (with-temp-buffer | 229 | (catch 'found |
| 230 | (insert (car indicator)) | 230 | (with-selected-window window |
| 231 | (goto-char (cdr indicator)) | 231 | (let ((alist minor-mode-alist) string position) |
| 232 | (if-let ((thing (thing-at-point 'word))) | 232 | (when (and (consp indicator) mode-line-compact) |
| 233 | (setq indicator thing) | 233 | (with-temp-buffer |
| 234 | (setq indicator (car indicator))))) | 234 | (insert (car indicator)) |
| 235 | (dolist (menu alist) | ||
| 236 | ;; If this is a valid minor mode menu entry, | ||
| 237 | (when (and (consp menu) | ||
| 238 | (setq string (format-mode-line (cadr menu) | ||
| 239 | nil window)) | ||
| 240 | (> (length string) 0)) | ||
| 241 | ;; Start searching for an appearance of (cdr menu). | ||
| 242 | (goto-char (point-min)) | ||
| 243 | (while (search-forward string nil 0) | ||
| 244 | ;; If the position of the string object is | ||
| 245 | ;; contained within, set indicator to the minor | ||
| 246 | ;; mode in question. | ||
| 247 | (setq position (1+ (cdr indicator))) | ||
| 248 | (and (>= position (match-beginning 0)) | ||
| 249 | (<= position (match-end 0)) | ||
| 250 | (setq indicator (car menu)) | ||
| 251 | (throw 'found nil))))))))))) | ||
| 235 | ;; If INDICATOR is still a cons, use its car. | 252 | ;; If INDICATOR is still a cons, use its car. |
| 236 | (when (consp indicator) | 253 | (when (consp indicator) |
| 237 | (setq indicator (car indicator))) | 254 | (setq indicator (car indicator))) |
| 238 | (let* ((minor-mode (lookup-minor-mode-from-indicator indicator)) | 255 | (let* ((minor-mode (if (symbolp indicator) |
| 256 | ;; indicator being set to a symbol means that | ||
| 257 | ;; the loop above has already found a | ||
| 258 | ;; matching minor mode. | ||
| 259 | indicator | ||
| 260 | (lookup-minor-mode-from-indicator indicator))) | ||
| 239 | (mm-fun (or (get minor-mode :minor-mode-function) minor-mode))) | 261 | (mm-fun (or (get minor-mode :minor-mode-function) minor-mode))) |
| 240 | (unless minor-mode (error "Cannot find minor mode for `%s'" indicator)) | 262 | (unless minor-mode (error "Cannot find minor mode for `%s'" indicator)) |
| 241 | (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist))) | 263 | (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist))) |