diff options
| author | Manuel Giraud | 2024-10-30 17:24:24 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2024-11-01 14:08:29 +0200 |
| commit | 872be2bb5febc5a720d6f4dbbd2fd30561385bb6 (patch) | |
| tree | b8087bcee727d061dca1162ac8505cc658657ecd | |
| parent | 1863028742977caf0d3f3973a94ef48eb040421b (diff) | |
| download | emacs-872be2bb5febc5a720d6f4dbbd2fd30561385bb6.tar.gz emacs-872be2bb5febc5a720d6f4dbbd2fd30561385bb6.zip | |
New `tmm-menubar' shortcut display style
Bug#74111
* lisp/tmm.el (tmm-shortcut-inside-entry): New user option to
control if the shortcut character is highlighted inside the menu
entry's string.
(tmm-add-one-shortcut): Compute the new shortcut style.
(tmm-add-prompt, tmm-completion-prompt): Adapt the completion
prompt according to the shortcut display style.
(tmm-prompt): Adapt the prompt regexp.
(tmm-shortcut): Simplify default case and make it work with this
change.
* etc/NEWS: Announce the option.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/tmm.el | 73 |
2 files changed, 58 insertions, 20 deletions
| @@ -592,6 +592,11 @@ instead. | |||
| 592 | *** A new shortcut to navigate to previous menu. | 592 | *** A new shortcut to navigate to previous menu. |
| 593 | The hardcoded '^' shortcut gets you back to the previous menu. | 593 | The hardcoded '^' shortcut gets you back to the previous menu. |
| 594 | 594 | ||
| 595 | --- | ||
| 596 | *** New user option 'tmm-shortcut-inside-entry'. | ||
| 597 | When non-nil, highlight the character shortcut in the menu entry's | ||
| 598 | string instead of preprending it and `tmm-mid-prompt' to said entry. | ||
| 599 | |||
| 595 | ** Foldout | 600 | ** Foldout |
| 596 | 601 | ||
| 597 | --- | 602 | --- |
diff --git a/lisp/tmm.el b/lisp/tmm.el index 252c1e45afa..80991b246b6 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el | |||
| @@ -83,11 +83,11 @@ or else the correct item might not be found in the `*Completions*' buffer." | |||
| 83 | string)) | 83 | string)) |
| 84 | 84 | ||
| 85 | (defcustom tmm-completion-prompt | 85 | (defcustom tmm-completion-prompt |
| 86 | "Press PageUp key to reach this buffer from the minibuffer. | 86 | "Press M-v/PageUp key to reach this buffer from the minibuffer. |
| 87 | Alternatively, you can use Up/Down keys (or your History keys) to change | 87 | Alternatively, You can use Up/Down keys (or your History keys) to change |
| 88 | the item in the minibuffer, and press RET when you are done, or press | 88 | the item in the minibuffer, and press RET when you are done, or press |
| 89 | the marked letters to pick up your choice. Type ^ to go to the parent | 89 | the %s to pick up your choice. |
| 90 | menu. Type C-g or ESC ESC ESC to cancel. | 90 | Type ^ to go to the parent menu. Type C-g or ESC ESC ESC to cancel. |
| 91 | " | 91 | " |
| 92 | "Help text to insert on the top of the completion buffer. | 92 | "Help text to insert on the top of the completion buffer. |
| 93 | To save space, you can set this to nil, | 93 | To save space, you can set this to nil, |
| @@ -108,6 +108,13 @@ If you use only one of `downcase' or `upcase' for `tmm-shortcut-style', | |||
| 108 | specify nil for this variable." | 108 | specify nil for this variable." |
| 109 | :type '(choice integer (const nil))) | 109 | :type '(choice integer (const nil))) |
| 110 | 110 | ||
| 111 | (defcustom tmm-shortcut-inside-entry nil | ||
| 112 | "Highlight the shortcut character in the menu entry's string. | ||
| 113 | When non-nil, the first menu-entry's character that acts as a shortcut | ||
| 114 | will be highlighted with the `highlight' face to help identifying it. | ||
| 115 | The `tmm-mid-prompt' string is not used then." | ||
| 116 | :type 'boolean) | ||
| 117 | |||
| 111 | (defface tmm-inactive | 118 | (defface tmm-inactive |
| 112 | '((t :inherit shadow)) | 119 | '((t :inherit shadow)) |
| 113 | "Face used for inactive menu items.") | 120 | "Face used for inactive menu items.") |
| @@ -198,7 +205,8 @@ is used to go back through those sub-menus." | |||
| 198 | (setq tail (cdr tail))))) | 205 | (setq tail (cdr tail))))) |
| 199 | (let ((prompt | 206 | (let ((prompt |
| 200 | (concat "^" | 207 | (concat "^" |
| 201 | (if (stringp tmm-mid-prompt) | 208 | (if (and (stringp tmm-mid-prompt) |
| 209 | (not tmm-shortcut-inside-entry)) | ||
| 202 | (concat "." | 210 | (concat "." |
| 203 | (regexp-quote tmm-mid-prompt)))))) | 211 | (regexp-quote tmm-mid-prompt)))))) |
| 204 | (setq tmm--history | 212 | (setq tmm--history |
| @@ -283,7 +291,7 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 283 | (t | 291 | (t |
| 284 | (let* ((str (car elt)) | 292 | (let* ((str (car elt)) |
| 285 | (paren (string-search "(" str)) | 293 | (paren (string-search "(" str)) |
| 286 | (pos 0) (word 0) char) | 294 | (word 0) pos char) |
| 287 | (catch 'done ; ??? is this slow? | 295 | (catch 'done ; ??? is this slow? |
| 288 | (while (and (or (not tmm-shortcut-words) ; no limit on words | 296 | (while (and (or (not tmm-shortcut-words) ; no limit on words |
| 289 | (< word tmm-shortcut-words)) ; try n words | 297 | (< word tmm-shortcut-words)) ; try n words |
| @@ -299,17 +307,34 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 299 | (if (not (memq char tmm-short-cuts)) (throw 'done char)))) | 307 | (if (not (memq char tmm-short-cuts)) (throw 'done char)))) |
| 300 | (setq word (1+ word)) | 308 | (setq word (1+ word)) |
| 301 | (setq pos (match-end 0))) | 309 | (setq pos (match-end 0))) |
| 310 | ;; A nil value for pos means that the shortcut is not inside the | ||
| 311 | ;; string of the menu entry. | ||
| 312 | (setq pos nil) | ||
| 302 | (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit | 313 | (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit |
| 303 | (setq char tmm-next-shortcut-digit) | 314 | (setq char tmm-next-shortcut-digit) |
| 304 | (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit)) | 315 | (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit)) |
| 305 | (if (not (memq char tmm-short-cuts)) (throw 'done char))) | 316 | (if (not (memq char tmm-short-cuts)) (throw 'done char))) |
| 306 | (setq char nil)) | 317 | (setq char nil)) |
| 307 | (if char (setq tmm-short-cuts (cons char tmm-short-cuts))) | 318 | (if char (setq tmm-short-cuts (cons char tmm-short-cuts))) |
| 308 | (cons (concat (if char (concat (char-to-string char) tmm-mid-prompt) | 319 | (cons |
| 309 | ;; keep them lined up in columns | 320 | (if tmm-shortcut-inside-entry |
| 310 | (make-string (1+ (length tmm-mid-prompt)) ?\s)) | 321 | (if char |
| 311 | str) | 322 | (if pos |
| 312 | (cdr elt)))))) | 323 | ;; A character inside the menu entry. |
| 324 | (let ((res (copy-sequence str))) | ||
| 325 | (aset res pos char) | ||
| 326 | (add-text-properties pos (1+ pos) '(face highlight) res) | ||
| 327 | res) | ||
| 328 | ;; A fallback digit character: place it in front of the | ||
| 329 | ;; menu entry. | ||
| 330 | (concat (propertize (char-to-string char) 'face 'highlight) | ||
| 331 | " " str)) | ||
| 332 | (make-string 2 ?\s)) | ||
| 333 | (concat (if char (concat (char-to-string char) tmm-mid-prompt) | ||
| 334 | ;; Keep them lined up in columns. | ||
| 335 | (make-string (1+ (length tmm-mid-prompt)) ?\s)) | ||
| 336 | str)) | ||
| 337 | (cdr elt)))))) | ||
| 313 | 338 | ||
| 314 | ;; This returns the old map. | 339 | ;; This returns the old map. |
| 315 | (defun tmm-define-keys (minibuffer) | 340 | (defun tmm-define-keys (minibuffer) |
| @@ -328,7 +353,7 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 328 | (define-key map "\ev" 'tmm-goto-completions) | 353 | (define-key map "\ev" 'tmm-goto-completions) |
| 329 | (define-key map "\C-n" 'next-history-element) | 354 | (define-key map "\C-n" 'next-history-element) |
| 330 | (define-key map "\C-p" 'previous-history-element) | 355 | (define-key map "\C-p" 'previous-history-element) |
| 331 | ;; Previous menu shortcut (see `tmm-prompt') | 356 | ;; Previous menu shortcut (see `tmm-prompt'). |
| 332 | (define-key map "^" 'self-insert-and-exit)) | 357 | (define-key map "^" 'self-insert-and-exit)) |
| 333 | (prog1 (current-local-map) | 358 | (prog1 (current-local-map) |
| 334 | (use-local-map (append map (current-local-map)))))) | 359 | (use-local-map (append map (current-local-map)))))) |
| @@ -384,7 +409,12 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 384 | (let ((inhibit-read-only t) | 409 | (let ((inhibit-read-only t) |
| 385 | (window (get-buffer-window "*Completions*"))) | 410 | (window (get-buffer-window "*Completions*"))) |
| 386 | (goto-char (point-min)) | 411 | (goto-char (point-min)) |
| 387 | (insert tmm-completion-prompt) | 412 | (insert |
| 413 | (if tmm-shortcut-inside-entry | ||
| 414 | (format tmm-completion-prompt | ||
| 415 | (concat (propertize "highlighted" 'face 'highlight) " character")) | ||
| 416 | (format tmm-completion-prompt | ||
| 417 | (concat "character right before '" tmm-mid-prompt "' ")))) | ||
| 388 | (when window | 418 | (when window |
| 389 | ;; Try to show everything just inserted and preserve height of | 419 | ;; Try to show everything just inserted and preserve height of |
| 390 | ;; *Completions* window. This should fix a behavior described | 420 | ;; *Completions* window. This should fix a behavior described |
| @@ -406,13 +436,16 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 406 | (choose-completion)) | 436 | (choose-completion)) |
| 407 | ;; In minibuffer | 437 | ;; In minibuffer |
| 408 | (delete-region (minibuffer-prompt-end) (point-max)) | 438 | (delete-region (minibuffer-prompt-end) (point-max)) |
| 409 | (dolist (elt tmm-km-list) | 439 | (dolist (elt tmm-km-list) |
| 410 | (if (string= | 440 | (let ((str (car elt)) |
| 411 | (substring (car elt) 0 | 441 | (index 0)) |
| 412 | (min (1+ (length tmm-mid-prompt)) | 442 | (when tmm-shortcut-inside-entry |
| 413 | (length (car elt)))) | 443 | (if (get-char-property 0 'face str) |
| 414 | (concat (char-to-string c) tmm-mid-prompt)) | 444 | (setq index 0) |
| 415 | (setq s (car elt)))) | 445 | (let ((next (next-single-char-property-change 0 'face str))) |
| 446 | (setq index (if (= (length str) next) 0 next))))) | ||
| 447 | (if (= (aref str index) c) | ||
| 448 | (setq s str)))) | ||
| 416 | (insert s) | 449 | (insert s) |
| 417 | (exit-minibuffer))))) | 450 | (exit-minibuffer))))) |
| 418 | 451 | ||