diff options
| author | Michael Albinus | 2018-11-24 14:01:53 +0100 |
|---|---|---|
| committer | Michael Albinus | 2018-11-24 14:01:53 +0100 |
| commit | dcacff41958d6dc12baf05e7e9de13d1ab5b09ae (patch) | |
| tree | e654337015837553725fd4127807f807d0cf4cfb | |
| parent | a7d9c38da52f413410e17a65d1e90b89edb6cbc4 (diff) | |
| parent | 57b14370cd6d221b123eab98adfed8d12229057f (diff) | |
| download | emacs-dcacff41958d6dc12baf05e7e9de13d1ab5b09ae.tar.gz emacs-dcacff41958d6dc12baf05e7e9de13d1ab5b09ae.zip | |
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/isearch.el | 255 | ||||
| -rw-r--r-- | lisp/tmm.el | 42 |
3 files changed, 278 insertions, 22 deletions
| @@ -687,6 +687,9 @@ the shift key. | |||
| 687 | *** Isearch now remembers the regexp-based search mode for words/symbols | 687 | *** Isearch now remembers the regexp-based search mode for words/symbols |
| 688 | and case-sensitivity together with search strings in the search ring. | 688 | and case-sensitivity together with search strings in the search ring. |
| 689 | 689 | ||
| 690 | --- | ||
| 691 | *** Isearch now has its own tool-bar and menu-bar menu. | ||
| 692 | |||
| 690 | ** Debugger | 693 | ** Debugger |
| 691 | 694 | ||
| 692 | +++ | 695 | +++ |
diff --git a/lisp/isearch.el b/lisp/isearch.el index 5099fb39f65..5913ea8a6b8 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -54,6 +54,7 @@ | |||
| 54 | ;;; Code: | 54 | ;;; Code: |
| 55 | 55 | ||
| 56 | (eval-when-compile (require 'cl-lib)) | 56 | (eval-when-compile (require 'cl-lib)) |
| 57 | (declare-function tmm-menubar-keymap "tmm.el") | ||
| 57 | 58 | ||
| 58 | ;; Some additional options and constants. | 59 | ;; Some additional options and constants. |
| 59 | 60 | ||
| @@ -489,6 +490,164 @@ This is like `describe-bindings', but displays only Isearch keys." | |||
| 489 | 490 | ||
| 490 | ;; Define isearch-mode keymap. | 491 | ;; Define isearch-mode keymap. |
| 491 | 492 | ||
| 493 | (defun isearch-tmm-menubar () | ||
| 494 | "Run `tmm-menubar' while `isearch-mode' is enabled." | ||
| 495 | (interactive) | ||
| 496 | (require 'tmm) | ||
| 497 | (run-hooks 'menu-bar-update-hook) | ||
| 498 | (let ((command nil)) | ||
| 499 | (let ((menu-bar (tmm-menubar-keymap))) | ||
| 500 | (with-isearch-suspended | ||
| 501 | (setq command (let ((isearch-mode t)) ; Show bindings from | ||
| 502 | ; `isearch-mode-map' in | ||
| 503 | ; tmm's prompt. | ||
| 504 | (tmm-prompt menu-bar nil nil t))))) | ||
| 505 | (call-interactively command))) | ||
| 506 | |||
| 507 | (defvar isearch-menu-bar-commands | ||
| 508 | '(isearch-tmm-menubar menu-bar-open mouse-minor-mode-menu) | ||
| 509 | "List of commands that can open a menu during Isearch.") | ||
| 510 | |||
| 511 | (defvar isearch-menu-bar-yank-map | ||
| 512 | (let ((map (make-sparse-keymap))) | ||
| 513 | (define-key map [isearch-yank-pop] | ||
| 514 | '(menu-item "Previous kill" isearch-yank-pop | ||
| 515 | :help "Replace previous yanked kill on search string")) | ||
| 516 | (define-key map [isearch-yank-kill] | ||
| 517 | '(menu-item "Current kill" isearch-yank-kill | ||
| 518 | :help "Append current kill to search string")) | ||
| 519 | (define-key map [isearch-yank-line] | ||
| 520 | '(menu-item "Rest of line" isearch-yank-line | ||
| 521 | :help "Yank the rest of the current line on search string")) | ||
| 522 | (define-key map [isearch-yank-symbol-or-char] | ||
| 523 | '(menu-item "Symbol/char" | ||
| 524 | isearch-yank-symbol-or-char | ||
| 525 | :help "Yank next symbol or char on search string")) | ||
| 526 | (define-key map [isearch-yank-word-or-char] | ||
| 527 | '(menu-item "Word/char" | ||
| 528 | isearch-yank-word-or-char | ||
| 529 | :help "Yank next word or char on search string")) | ||
| 530 | (define-key map [isearch-yank-char] | ||
| 531 | '(menu-item "Char" isearch-yank-char | ||
| 532 | :help "Yank char at point on search string")) | ||
| 533 | map)) | ||
| 534 | |||
| 535 | (defvar isearch-menu-bar-map | ||
| 536 | (let ((map (make-sparse-keymap "Isearch"))) | ||
| 537 | (define-key map [isearch-complete] | ||
| 538 | '(menu-item "Complete current search string" isearch-complete | ||
| 539 | :help "Complete current search string over search history")) | ||
| 540 | (define-key map [isearch-complete-separator] | ||
| 541 | '(menu-item "--")) | ||
| 542 | (define-key map [isearch-query-replace-regexp] | ||
| 543 | '(menu-item "Replace search string as regexp" isearch-query-replace-regexp | ||
| 544 | :help "Replace matches for current search string as regexp")) | ||
| 545 | (define-key map [isearch-query-replace] | ||
| 546 | '(menu-item "Replace search string" isearch-query-replace | ||
| 547 | :help "Replace matches for current search string")) | ||
| 548 | (define-key map [isearch-occur] | ||
| 549 | '(menu-item "Show all matches for search string" isearch-occur | ||
| 550 | :help "Show all matches for current search string")) | ||
| 551 | (define-key map [isearch-highlight-regexp] | ||
| 552 | '(menu-item "Highlight all matches for search string" | ||
| 553 | isearch-highlight-regexp | ||
| 554 | :help "Highlight all matches for current search string")) | ||
| 555 | (define-key map [isearch-search-replace-separator] | ||
| 556 | '(menu-item "--")) | ||
| 557 | (define-key map [isearch-toggle-specified-input-method] | ||
| 558 | '(menu-item "Turn on specific input method" | ||
| 559 | isearch-toggle-specified-input-method | ||
| 560 | :help "Turn on specific input method for search")) | ||
| 561 | (define-key map [isearch-toggle-input-method] | ||
| 562 | '(menu-item "Toggle input method" isearch-toggle-input-method | ||
| 563 | :help "Toggle input method for search")) | ||
| 564 | (define-key map [isearch-input-method-separator] | ||
| 565 | '(menu-item "--")) | ||
| 566 | (define-key map [isearch-char-by-name] | ||
| 567 | '(menu-item "Search for char by name" isearch-char-by-name | ||
| 568 | :help "Search for character by name")) | ||
| 569 | (define-key map [isearch-quote-char] | ||
| 570 | '(menu-item "Search for literal char" isearch-quote-char | ||
| 571 | :help "Search for literal char")) | ||
| 572 | (define-key map [isearch-special-char-separator] | ||
| 573 | '(menu-item "--")) | ||
| 574 | (define-key map [isearch-toggle-word] | ||
| 575 | '(menu-item "Word matching" isearch-toggle-word | ||
| 576 | :help "Word matching" | ||
| 577 | :button (:toggle | ||
| 578 | . (eq isearch-regexp-function 'word-search-regexp)))) | ||
| 579 | (define-key map [isearch-toggle-symbol] | ||
| 580 | '(menu-item "Symbol matching" isearch-toggle-symbol | ||
| 581 | :help "Symbol matching" | ||
| 582 | :button (:toggle | ||
| 583 | . (eq isearch-regexp-function | ||
| 584 | 'isearch-symbol-regexp)))) | ||
| 585 | (define-key map [isearch-toggle-regexp] | ||
| 586 | '(menu-item "Regexp matching" isearch-toggle-regexp | ||
| 587 | :help "Regexp matching" | ||
| 588 | :button (:toggle . isearch-regexp))) | ||
| 589 | (define-key map [isearch-toggle-invisible] | ||
| 590 | '(menu-item "Invisible text matching" isearch-toggle-invisible | ||
| 591 | :help "Invisible text matching" | ||
| 592 | :button (:toggle . isearch-invisible))) | ||
| 593 | (define-key map [isearch-toggle-char-fold] | ||
| 594 | '(menu-item "Character folding matching" isearch-toggle-char-fold | ||
| 595 | :help "Character folding matching" | ||
| 596 | :button (:toggle | ||
| 597 | . (eq isearch-regexp-function | ||
| 598 | 'char-fold-to-regexp)))) | ||
| 599 | (define-key map [isearch-toggle-case-fold] | ||
| 600 | '(menu-item "Case folding matching" isearch-toggle-case-fold | ||
| 601 | :help "Case folding matching" | ||
| 602 | :button (:toggle . isearch-case-fold-search))) | ||
| 603 | (define-key map [isearch-toggle-lax-whitespace] | ||
| 604 | '(menu-item "Lax whitespace matching" isearch-toggle-lax-whitespace | ||
| 605 | :help "Lax whitespace matching" | ||
| 606 | :button (:toggle . isearch-lax-whitespace))) | ||
| 607 | (define-key map [isearch-toggle-separator] | ||
| 608 | '(menu-item "--")) | ||
| 609 | (define-key map [isearch-yank-menu] | ||
| 610 | `(menu-item "Yank on search string" ,isearch-menu-bar-yank-map)) | ||
| 611 | (define-key map [isearch-edit-string] | ||
| 612 | '(menu-item "Edit current search string" isearch-edit-string | ||
| 613 | :help "Edit current search string")) | ||
| 614 | (define-key map [isearch-ring-retreat] | ||
| 615 | '(menu-item "Edit previous search string" isearch-ring-retreat | ||
| 616 | :help "Edit previous search string in Isearch history")) | ||
| 617 | (define-key map [isearch-ring-advance] | ||
| 618 | '(menu-item "Edit next search string" isearch-ring-advance | ||
| 619 | :help "Edit next search string in Isearch history")) | ||
| 620 | (define-key map [isearch-del-char] | ||
| 621 | '(menu-item "Delete last char from search string" isearch-del-char | ||
| 622 | :help "Delete last character from search string")) | ||
| 623 | (define-key map [isearch-delete-char] | ||
| 624 | '(menu-item "Undo last input item" isearch-delete-char | ||
| 625 | :help "Undo the effect of the last Isearch command")) | ||
| 626 | (define-key map [isearch-repeat-backward] | ||
| 627 | '(menu-item "Repeat search backward" isearch-repeat-backward | ||
| 628 | :help "Repeat current search backward")) | ||
| 629 | (define-key map [isearch-repeat-forward] | ||
| 630 | '(menu-item "Repeat search forward" isearch-repeat-forward | ||
| 631 | :help "Repeat current search forward")) | ||
| 632 | (define-key map [isearch-nonincremental] | ||
| 633 | '(menu-item "Nonincremental search" isearch-exit | ||
| 634 | :help "Start nonincremental search" | ||
| 635 | :visible (string-equal isearch-string ""))) | ||
| 636 | (define-key map [isearch-exit] | ||
| 637 | '(menu-item "Finish search" isearch-exit | ||
| 638 | :help "Finish search leaving point where it is" | ||
| 639 | :visible (not (string-equal isearch-string "")))) | ||
| 640 | (define-key map [isearch-abort] | ||
| 641 | '(menu-item "Remove characters not found" isearch-abort | ||
| 642 | :help "Quit current search" | ||
| 643 | :visible (not isearch-success))) | ||
| 644 | (define-key map [isearch-cancel] | ||
| 645 | `(menu-item "Cancel search" isearch-cancel | ||
| 646 | :help "Cancel current search and return to starting point" | ||
| 647 | :filter ,(lambda (binding) | ||
| 648 | (if isearch-success 'isearch-abort binding)))) | ||
| 649 | map)) | ||
| 650 | |||
| 492 | (defvar isearch-mode-map | 651 | (defvar isearch-mode-map |
| 493 | (let ((i 0) | 652 | (let ((i 0) |
| 494 | (map (make-keymap))) | 653 | (map (make-keymap))) |
| @@ -598,9 +757,59 @@ This is like `describe-bindings', but displays only Isearch keys." | |||
| 598 | ;; characters to the search string. See iso-transl.el. | 757 | ;; characters to the search string. See iso-transl.el. |
| 599 | (define-key map "\C-x8\r" 'isearch-char-by-name) | 758 | (define-key map "\C-x8\r" 'isearch-char-by-name) |
| 600 | 759 | ||
| 760 | (define-key map [menu-bar search-menu] | ||
| 761 | (list 'menu-item "Isearch" isearch-menu-bar-map)) | ||
| 762 | (define-key map [remap tmm-menubar] 'isearch-tmm-menubar) | ||
| 763 | |||
| 601 | map) | 764 | map) |
| 602 | "Keymap for `isearch-mode'.") | 765 | "Keymap for `isearch-mode'.") |
| 603 | 766 | ||
| 767 | (defvar isearch-tool-bar-old-map nil | ||
| 768 | "Variable holding the old local value of `tool-bar-map', if any.") | ||
| 769 | |||
| 770 | (defun isearch-tool-bar-image (image-name) | ||
| 771 | "Return an image specification for IMAGE-NAME." | ||
| 772 | (eval (tool-bar--image-expression image-name))) | ||
| 773 | |||
| 774 | (defvar isearch-tool-bar-map | ||
| 775 | (let ((map (make-sparse-keymap))) | ||
| 776 | (define-key map [isearch-describe-mode] | ||
| 777 | (list 'menu-item "Help" 'isearch-describe-mode | ||
| 778 | :help "Get help for Isearch" | ||
| 779 | :image '(isearch-tool-bar-image "help"))) | ||
| 780 | (define-key map [isearch-occur] | ||
| 781 | (list 'menu-item "Show hits" 'isearch-occur | ||
| 782 | :help "Show each search hit" | ||
| 783 | :image '(isearch-tool-bar-image "index"))) | ||
| 784 | (define-key map [isearch-query-replace] | ||
| 785 | (list 'menu-item "Replace" 'isearch-query-replace | ||
| 786 | :help "Replace search string" | ||
| 787 | :image '(isearch-tool-bar-image "search-replace"))) | ||
| 788 | (define-key map [isearch-delete-char] | ||
| 789 | (list 'menu-item "Undo" 'isearch-delete-char | ||
| 790 | :help "Undo last input item" | ||
| 791 | :image '(isearch-tool-bar-image "undo"))) | ||
| 792 | (define-key map [isearch-exit] | ||
| 793 | (list 'menu-item "Finish" 'isearch-exit | ||
| 794 | :help "Finish search leaving point where it is" | ||
| 795 | :image '(isearch-tool-bar-image "exit") | ||
| 796 | :visible '(not (string-equal isearch-string "")))) | ||
| 797 | (define-key map [isearch-cancel] | ||
| 798 | (list 'menu-item "Abort" 'isearch-cancel | ||
| 799 | :help "Abort search" | ||
| 800 | :image '(isearch-tool-bar-image "close") | ||
| 801 | :filter (lambda (binding) | ||
| 802 | (if isearch-success 'isearch-abort binding)))) | ||
| 803 | (define-key map [isearch-repeat-forward] | ||
| 804 | (list 'menu-item "Repeat forward" 'isearch-repeat-forward | ||
| 805 | :help "Repeat search forward" | ||
| 806 | :image '(isearch-tool-bar-image "right-arrow"))) | ||
| 807 | (define-key map [isearch-repeat-backward] | ||
| 808 | (list 'menu-item "Repeat backward" 'isearch-repeat-backward | ||
| 809 | :help "Repeat search backward" | ||
| 810 | :image '(isearch-tool-bar-image "left-arrow"))) | ||
| 811 | map)) | ||
| 812 | |||
| 604 | (defvar minibuffer-local-isearch-map | 813 | (defvar minibuffer-local-isearch-map |
| 605 | (let ((map (make-sparse-keymap))) | 814 | (let ((map (make-sparse-keymap))) |
| 606 | (set-keymap-parent map minibuffer-local-map) | 815 | (set-keymap-parent map minibuffer-local-map) |
| @@ -731,11 +940,19 @@ Each element is an `isearch--state' struct where the slots are | |||
| 731 | 940 | ||
| 732 | ;; Minor-mode-alist changes - kind of redundant with the | 941 | ;; Minor-mode-alist changes - kind of redundant with the |
| 733 | ;; echo area, but if isearching in multiple windows, it can be useful. | 942 | ;; echo area, but if isearching in multiple windows, it can be useful. |
| 943 | ;; Also, clicking the mode-line indicator pops up | ||
| 944 | ;; `isearch-menu-bar-map'. | ||
| 734 | 945 | ||
| 735 | (or (assq 'isearch-mode minor-mode-alist) | 946 | (or (assq 'isearch-mode minor-mode-alist) |
| 736 | (nconc minor-mode-alist | 947 | (nconc minor-mode-alist |
| 737 | (list '(isearch-mode isearch-mode)))) | 948 | (list '(isearch-mode isearch-mode)))) |
| 738 | 949 | ||
| 950 | ;; We add an entry for `isearch-mode' to `minor-mode-map-alist' so | ||
| 951 | ;; that `isearch-menu-bar-map' can show on the menu bar. | ||
| 952 | (or (assq 'isearch-mode minor-mode-map-alist) | ||
| 953 | (nconc minor-mode-map-alist | ||
| 954 | (list (cons 'isearch-mode isearch-mode-map)))) | ||
| 955 | |||
| 739 | (defvar-local isearch-mode nil) ;; Name of the minor mode, if non-nil. | 956 | (defvar-local isearch-mode nil) ;; Name of the minor mode, if non-nil. |
| 740 | 957 | ||
| 741 | (define-key global-map "\C-s" 'isearch-forward) | 958 | (define-key global-map "\C-s" 'isearch-forward) |
| @@ -989,6 +1206,10 @@ used to set the value of `isearch-regexp-function'." | |||
| 989 | isearch-original-minibuffer-message-timeout minibuffer-message-timeout | 1206 | isearch-original-minibuffer-message-timeout minibuffer-message-timeout |
| 990 | minibuffer-message-timeout nil) | 1207 | minibuffer-message-timeout nil) |
| 991 | 1208 | ||
| 1209 | (if (local-variable-p 'tool-bar-map) | ||
| 1210 | (setq isearch-tool-bar-old-map tool-bar-map)) | ||
| 1211 | (setq-local tool-bar-map isearch-tool-bar-map) | ||
| 1212 | |||
| 992 | ;; We must bypass input method while reading key. When a user type | 1213 | ;; We must bypass input method while reading key. When a user type |
| 993 | ;; printable character, appropriate input method is turned on in | 1214 | ;; printable character, appropriate input method is turned on in |
| 994 | ;; minibuffer to read multibyte characters. | 1215 | ;; minibuffer to read multibyte characters. |
| @@ -1155,6 +1376,12 @@ NOPUSH is t and EDIT is t." | |||
| 1155 | (setq input-method-function isearch-input-method-function) | 1376 | (setq input-method-function isearch-input-method-function) |
| 1156 | (kill-local-variable 'input-method-function)) | 1377 | (kill-local-variable 'input-method-function)) |
| 1157 | 1378 | ||
| 1379 | (if isearch-tool-bar-old-map | ||
| 1380 | (progn | ||
| 1381 | (setq-local tool-bar-map isearch-tool-bar-old-map) | ||
| 1382 | (setq isearch-tool-bar-old-map nil)) | ||
| 1383 | (kill-local-variable 'tool-bar-map)) | ||
| 1384 | |||
| 1158 | (force-mode-line-update) | 1385 | (force-mode-line-update) |
| 1159 | 1386 | ||
| 1160 | ;; If we ended in the middle of some intangible text, | 1387 | ;; If we ended in the middle of some intangible text, |
| @@ -1187,9 +1414,17 @@ NOPUSH is t and EDIT is t." | |||
| 1187 | 1414 | ||
| 1188 | (and (not edit) isearch-recursive-edit (exit-recursive-edit))) | 1415 | (and (not edit) isearch-recursive-edit (exit-recursive-edit))) |
| 1189 | 1416 | ||
| 1417 | (defvar isearch-mouse-commands '(mouse-minor-mode-menu) | ||
| 1418 | "List of mouse commands that are allowed during Isearch.") | ||
| 1419 | |||
| 1190 | (defun isearch-mouse-leave-buffer () | 1420 | (defun isearch-mouse-leave-buffer () |
| 1191 | "Exit Isearch unless the mouse command is allowed in Isearch." | 1421 | "Exit Isearch unless the mouse command is allowed in Isearch. |
| 1192 | (unless (eq (get this-command 'isearch-scroll) t) | 1422 | |
| 1423 | Mouse commands are allowed in Isearch if they have a non-nil | ||
| 1424 | `isearch-scroll' property or if they are listed in | ||
| 1425 | `isearch-mouse-commands'." | ||
| 1426 | (unless (or (memq this-command isearch-mouse-commands) | ||
| 1427 | (eq (get this-command 'isearch-scroll) t)) | ||
| 1193 | (isearch-done))) | 1428 | (isearch-done))) |
| 1194 | 1429 | ||
| 1195 | (defun isearch-update-ring (string &optional regexp) | 1430 | (defun isearch-update-ring (string &optional regexp) |
| @@ -1457,7 +1692,11 @@ You can update the global isearch variables by setting new values to | |||
| 1457 | 1692 | ||
| 1458 | ;; Reinvoke the pending search. | 1693 | ;; Reinvoke the pending search. |
| 1459 | (isearch-search) | 1694 | (isearch-search) |
| 1460 | (isearch-push-state) ; this pushes the correct state | 1695 | ;; If no code has changed the search parameters, then pushing |
| 1696 | ;; a new state of Isearch should not be necessary. | ||
| 1697 | (unless (and isearch-cmds | ||
| 1698 | (equal (car isearch-cmds) (isearch--get-state))) | ||
| 1699 | (isearch-push-state)) ; this pushes the correct state | ||
| 1461 | (isearch-update) | 1700 | (isearch-update) |
| 1462 | (if isearch-nonincremental | 1701 | (if isearch-nonincremental |
| 1463 | (progn | 1702 | (progn |
| @@ -2581,7 +2820,12 @@ See more for options in `search-exit-option'." | |||
| 2581 | ;; `set-transient-map' thingy like `universal-argument--mode'. | 2820 | ;; `set-transient-map' thingy like `universal-argument--mode'. |
| 2582 | ((not (eq overriding-terminal-local-map isearch--saved-overriding-local-map))) | 2821 | ((not (eq overriding-terminal-local-map isearch--saved-overriding-local-map))) |
| 2583 | ;; Don't exit Isearch for isearch key bindings. | 2822 | ;; Don't exit Isearch for isearch key bindings. |
| 2584 | ((commandp (lookup-key isearch-mode-map key nil))) | 2823 | ((or (commandp (lookup-key isearch-mode-map key nil)) |
| 2824 | (commandp | ||
| 2825 | (lookup-key | ||
| 2826 | `(keymap (tool-bar menu-item nil ,isearch-tool-bar-map)) key)))) | ||
| 2827 | ;; Allow key bindings that open a menubar. | ||
| 2828 | ((memq this-command isearch-menu-bar-commands)) | ||
| 2585 | ;; Optionally edit the search string instead of exiting. | 2829 | ;; Optionally edit the search string instead of exiting. |
| 2586 | ((eq search-exit-option 'edit) | 2830 | ((eq search-exit-option 'edit) |
| 2587 | (setq this-command 'isearch-edit-string)) | 2831 | (setq this-command 'isearch-edit-string)) |
| @@ -2645,7 +2889,8 @@ See more for options in `search-exit-option'." | |||
| 2645 | (when isearch-forward | 2889 | (when isearch-forward |
| 2646 | (goto-char isearch-pre-move-point)) | 2890 | (goto-char isearch-pre-move-point)) |
| 2647 | (isearch-search-and-update))) | 2891 | (isearch-search-and-update))) |
| 2648 | (setq isearch-pre-move-point nil)))) | 2892 | (setq isearch-pre-move-point nil))) |
| 2893 | (force-mode-line-update)) | ||
| 2649 | 2894 | ||
| 2650 | (defun isearch-quote-char (&optional count) | 2895 | (defun isearch-quote-char (&optional count) |
| 2651 | "Quote special characters for incremental search. | 2896 | "Quote special characters for incremental search. |
diff --git a/lisp/tmm.el b/lisp/tmm.el index ff6277419df..4e3f25441cb 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el | |||
| @@ -42,6 +42,23 @@ | |||
| 42 | (defvar tmm-next-shortcut-digit) | 42 | (defvar tmm-next-shortcut-digit) |
| 43 | (defvar tmm-table-undef) | 43 | (defvar tmm-table-undef) |
| 44 | 44 | ||
| 45 | (defun tmm-menubar-keymap () | ||
| 46 | "Return the current menu-bar keymap. | ||
| 47 | |||
| 48 | The ordering of the return value respects `menu-bar-final-items'." | ||
| 49 | (let ((menu-bar '()) | ||
| 50 | (menu-end '())) | ||
| 51 | (map-keymap | ||
| 52 | (lambda (key binding) | ||
| 53 | (push (cons key binding) | ||
| 54 | ;; If KEY is the name of an item that we want to put last, | ||
| 55 | ;; move it to the end. | ||
| 56 | (if (memq key menu-bar-final-items) | ||
| 57 | menu-end | ||
| 58 | menu-bar))) | ||
| 59 | (tmm-get-keybind [menu-bar])) | ||
| 60 | `(keymap ,@(nreverse menu-bar) ,@(nreverse menu-end)))) | ||
| 61 | |||
| 45 | ;;;###autoload (define-key global-map "\M-`" 'tmm-menubar) | 62 | ;;;###autoload (define-key global-map "\M-`" 'tmm-menubar) |
| 46 | ;;;###autoload (define-key global-map [menu-bar mouse-1] 'tmm-menubar-mouse) | 63 | ;;;###autoload (define-key global-map [menu-bar mouse-1] 'tmm-menubar-mouse) |
| 47 | 64 | ||
| @@ -58,19 +75,8 @@ to invoke `tmm-menubar' instead, customize the variable | |||
| 58 | (interactive) | 75 | (interactive) |
| 59 | (run-hooks 'menu-bar-update-hook) | 76 | (run-hooks 'menu-bar-update-hook) |
| 60 | ;; Obey menu-bar-final-items; put those items last. | 77 | ;; Obey menu-bar-final-items; put those items last. |
| 61 | (let ((menu-bar '()) | 78 | (let ((menu-bar (tmm-menubar-keymap)) |
| 62 | (menu-end '()) | ||
| 63 | menu-bar-item) | 79 | menu-bar-item) |
| 64 | (map-keymap | ||
| 65 | (lambda (key binding) | ||
| 66 | (push (cons key binding) | ||
| 67 | ;; If KEY is the name of an item that we want to put last, | ||
| 68 | ;; move it to the end. | ||
| 69 | (if (memq key menu-bar-final-items) | ||
| 70 | menu-end | ||
| 71 | menu-bar))) | ||
| 72 | (tmm-get-keybind [menu-bar])) | ||
| 73 | (setq menu-bar `(keymap ,@(nreverse menu-bar) ,@(nreverse menu-end))) | ||
| 74 | (if x-position | 80 | (if x-position |
| 75 | (let ((column 0) | 81 | (let ((column 0) |
| 76 | prev-key) | 82 | prev-key) |
| @@ -154,7 +160,7 @@ specify nil for this variable." | |||
| 154 | (defvar tmm--history nil) | 160 | (defvar tmm--history nil) |
| 155 | 161 | ||
| 156 | ;;;###autoload | 162 | ;;;###autoload |
| 157 | (defun tmm-prompt (menu &optional in-popup default-item) | 163 | (defun tmm-prompt (menu &optional in-popup default-item no-execute) |
| 158 | "Text-mode emulation of calling the bindings in keymap. | 164 | "Text-mode emulation of calling the bindings in keymap. |
| 159 | Creates a text-mode menu of possible choices. You can access the elements | 165 | Creates a text-mode menu of possible choices. You can access the elements |
| 160 | in the menu in two ways: | 166 | in the menu in two ways: |
| @@ -165,7 +171,9 @@ The last alternative is currently a hack, you cannot use mouse reliably. | |||
| 165 | MENU is like the MENU argument to `x-popup-menu': either a | 171 | MENU is like the MENU argument to `x-popup-menu': either a |
| 166 | keymap or an alist of alists. | 172 | keymap or an alist of alists. |
| 167 | DEFAULT-ITEM, if non-nil, specifies an initial default choice. | 173 | DEFAULT-ITEM, if non-nil, specifies an initial default choice. |
| 168 | Its value should be an event that has a binding in MENU." | 174 | Its value should be an event that has a binding in MENU. |
| 175 | NO-EXECUTE, if non-nil, means to return the command the user selects | ||
| 176 | instead of executing it." | ||
| 169 | ;; If the optional argument IN-POPUP is t, | 177 | ;; If the optional argument IN-POPUP is t, |
| 170 | ;; then MENU is an alist of elements of the form (STRING . VALUE). | 178 | ;; then MENU is an alist of elements of the form (STRING . VALUE). |
| 171 | ;; That is used for recursive calls only. | 179 | ;; That is used for recursive calls only. |
| @@ -268,7 +276,7 @@ Its value should be an event that has a binding in MENU." | |||
| 268 | ;; We just did the inner level of a -popup menu. | 276 | ;; We just did the inner level of a -popup menu. |
| 269 | choice) | 277 | choice) |
| 270 | ;; We just did the outer level. Do the inner level now. | 278 | ;; We just did the outer level. Do the inner level now. |
| 271 | (not-menu (tmm-prompt choice t)) | 279 | (not-menu (tmm-prompt choice t nil no-execute)) |
| 272 | ;; We just handled a menu keymap and found another keymap. | 280 | ;; We just handled a menu keymap and found another keymap. |
| 273 | ((keymapp choice) | 281 | ((keymapp choice) |
| 274 | (if (symbolp choice) | 282 | (if (symbolp choice) |
| @@ -276,11 +284,11 @@ Its value should be an event that has a binding in MENU." | |||
| 276 | (condition-case nil | 284 | (condition-case nil |
| 277 | (require 'mouse) | 285 | (require 'mouse) |
| 278 | (error nil)) | 286 | (error nil)) |
| 279 | (tmm-prompt choice)) | 287 | (tmm-prompt choice nil nil no-execute)) |
| 280 | ;; We just handled a menu keymap and found a command. | 288 | ;; We just handled a menu keymap and found a command. |
| 281 | (choice | 289 | (choice |
| 282 | (if chosen-string | 290 | (if chosen-string |
| 283 | (progn | 291 | (if no-execute choice |
| 284 | (setq last-command-event chosen-string) | 292 | (setq last-command-event chosen-string) |
| 285 | (call-interactively choice)) | 293 | (call-interactively choice)) |
| 286 | choice))))) | 294 | choice))))) |