diff options
| author | Karl Heuer | 1996-07-11 23:35:37 +0000 |
|---|---|---|
| committer | Karl Heuer | 1996-07-11 23:35:37 +0000 |
| commit | d5c847bb697d1934b49329f25e4075850d32cf2b (patch) | |
| tree | 1339d5664f9b4073e6d9e0f327731065cb64e9bb | |
| parent | cd837fee274766aa38a9e0a4520fe739f1b344ba (diff) | |
| download | emacs-d5c847bb697d1934b49329f25e4075850d32cf2b.tar.gz emacs-d5c847bb697d1934b49329f25e4075850d32cf2b.zip | |
(mouse-drag-region): Cope if stop-point is nil.
(mouse-major-mode-menu-compute-equiv-keys): Deleted.
(mouse-major-mode-menu-1): Copy the top levels of structure,
if we use all of MENUBAR.
Set mouse-major-mode-menu-prefix.
(mouse-major-mode-menu): Total rewrite.
| -rw-r--r-- | lisp/mouse.el | 102 |
1 files changed, 61 insertions, 41 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index ac8a1f2b466..1f7124e90fb 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -47,43 +47,42 @@ | |||
| 47 | ;; Switch to the window clicked on, because otherwise | 47 | ;; Switch to the window clicked on, because otherwise |
| 48 | ;; the mode's commands may not make sense. | 48 | ;; the mode's commands may not make sense. |
| 49 | (interactive "@e") | 49 | (interactive "@e") |
| 50 | (let ((newmap (make-sparse-keymap)) | 50 | (let (;; This is where mouse-major-mode-menu-prefix |
| 51 | (unread-command-events (list event))) | 51 | ;; returns the prefix we should use (after menu-bar). |
| 52 | ;; Make a keymap in which our last command leads to a menu | 52 | ;; It is either nil or (SOME-SYMBOL). |
| 53 | (define-key newmap (vector (car event)) | 53 | (mouse-major-mode-menu-prefix nil) |
| 54 | (nconc (make-sparse-keymap (concat mode-name " Mode")) | 54 | ;; Make a keymap in which our last command leads to a menu |
| 55 | (cdr (mouse-major-mode-menu-1 | 55 | (newmap (make-sparse-keymap (concat mode-name " Mode"))) |
| 56 | (and (current-local-map) | 56 | result) |
| 57 | (lookup-key (current-local-map) [menu-bar])))))) | 57 | ;; Make our menu inherit from the desired keymap |
| 58 | (mouse-major-mode-menu-compute-equiv-keys newmap) | 58 | ;; which we want to display as the menu now. |
| 59 | ;; Make NEWMAP override the usual definition | 59 | (set-keymap-parent newmap |
| 60 | ;; of the mouse button that got us here. | 60 | (mouse-major-mode-menu-1 |
| 61 | ;; Then read the user's menu choice. | 61 | (and (current-local-map) |
| 62 | (let* ((minor-mode-map-alist | 62 | (lookup-key (current-local-map) [menu-bar])))) |
| 63 | (cons (cons t newmap) minor-mode-map-alist)) | 63 | (setq result (x-popup-menu t (list newmap))) |
| 64 | ;; read-key-sequence quits if the user aborts the menu. | 64 | (if result |
| 65 | ;; If that happens, do nothing silently. | 65 | (let ((command (key-binding |
| 66 | (keyseq (condition-case nil | 66 | (apply 'vector (append '(menu-bar) |
| 67 | (read-key-sequence "") | 67 | mouse-major-mode-menu-prefix |
| 68 | (quit nil))) | 68 | result))))) |
| 69 | (command (if keyseq (lookup-key newmap keyseq)))) | 69 | (if command |
| 70 | (if command | 70 | (command-execute command)))))) |
| 71 | (command-execute command))))) | ||
| 72 | 71 | ||
| 73 | ;; Compute and cache the equivalent keys in MENU and all its submenus. | 72 | ;; Compute and cache the equivalent keys in MENU and all its submenus. |
| 74 | (defun mouse-major-mode-menu-compute-equiv-keys (menu) | 73 | ;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu) |
| 75 | (and (eq (car menu) 'keymap) | 74 | ;;; (and (eq (car menu) 'keymap) |
| 76 | (x-popup-menu nil menu)) | 75 | ;;; (x-popup-menu nil menu)) |
| 77 | (while menu | 76 | ;;; (while menu |
| 78 | (and (consp (car menu)) | 77 | ;;; (and (consp (car menu)) |
| 79 | (consp (cdr (car menu))) | 78 | ;;; (consp (cdr (car menu))) |
| 80 | (let ((tail (cdr (car menu)))) | 79 | ;;; (let ((tail (cdr (car menu)))) |
| 81 | (while (and (consp tail) | 80 | ;;; (while (and (consp tail) |
| 82 | (not (eq (car tail) 'keymap))) | 81 | ;;; (not (eq (car tail) 'keymap))) |
| 83 | (setq tail (cdr tail))) | 82 | ;;; (setq tail (cdr tail))) |
| 84 | (if (consp tail) | 83 | ;;; (if (consp tail) |
| 85 | (mouse-major-mode-menu-compute-equiv-keys tail)))) | 84 | ;;; (mouse-major-mode-menu-compute-equiv-keys tail)))) |
| 86 | (setq menu (cdr menu)))) | 85 | ;;; (setq menu (cdr menu)))) |
| 87 | 86 | ||
| 88 | ;; Given a mode's menu bar keymap, | 87 | ;; Given a mode's menu bar keymap, |
| 89 | ;; if it defines exactly one menu bar menu, | 88 | ;; if it defines exactly one menu bar menu, |
| @@ -97,10 +96,29 @@ | |||
| 97 | (if (consp (car tail)) | 96 | (if (consp (car tail)) |
| 98 | (if submap | 97 | (if submap |
| 99 | (setq submap t) | 98 | (setq submap t) |
| 100 | (setq submap (cdr (car tail))))) | 99 | (setq submap (car tail)))) |
| 101 | (setq tail (cdr tail))) | 100 | (setq tail (cdr tail))) |
| 102 | (if (eq submap t) menubar | 101 | (if (eq submap t) |
| 103 | (cdr submap))))) | 102 | ;; We have more than one submap, so we want to |
| 103 | ;; return a keymap just like menubar. | ||
| 104 | ;; But first copy the top level structure of the menu, | ||
| 105 | ;; enough so that adding equiv-keys to this copy | ||
| 106 | ;; won't alter menubar itself. | ||
| 107 | ;; This is a kludge, and next version | ||
| 108 | ;; we'll change the menu bar code not to mind | ||
| 109 | ;; if there are X equiv keys there. | ||
| 110 | (let ((newmap (copy-sequence menubar))) | ||
| 111 | (setq menubar newmap) | ||
| 112 | (while newmap | ||
| 113 | (if (consp (car newmap)) | ||
| 114 | (setcar newmap (cons (car (car newmap)) | ||
| 115 | (cons (nth 1 (car newmap)) | ||
| 116 | (nthcdr 2 (car newmap)))))) | ||
| 117 | (setq newmap (cdr newmap))) | ||
| 118 | (setq mouse-major-mode-menu-prefix nil) | ||
| 119 | menubar) | ||
| 120 | (setq mouse-major-mode-menu-prefix (list (car submap))) | ||
| 121 | (cdr (cdr submap)))))) | ||
| 104 | 122 | ||
| 105 | ;; Commands that operate on windows. | 123 | ;; Commands that operate on windows. |
| 106 | 124 | ||
| @@ -516,7 +534,7 @@ remains active. Otherwise, it remains until the next input event." | |||
| 516 | ;; end-of-range is used only in the single-click case. | 534 | ;; end-of-range is used only in the single-click case. |
| 517 | ;; It is the place where the drag has reached so far | 535 | ;; It is the place where the drag has reached so far |
| 518 | ;; (but not outside the window where the drag started). | 536 | ;; (but not outside the window where the drag started). |
| 519 | (let (event end end-point (end-of-range (point))) | 537 | (let (event end end-point last-end-point (end-of-range (point))) |
| 520 | (track-mouse | 538 | (track-mouse |
| 521 | (while (progn | 539 | (while (progn |
| 522 | (setq event (read-event)) | 540 | (setq event (read-event)) |
| @@ -526,6 +544,8 @@ remains active. Otherwise, it remains until the next input event." | |||
| 526 | nil | 544 | nil |
| 527 | (setq end (event-end event) | 545 | (setq end (event-end event) |
| 528 | end-point (posn-point end)) | 546 | end-point (posn-point end)) |
| 547 | (if end-point | ||
| 548 | (setq last-end-point end-point)) | ||
| 529 | 549 | ||
| 530 | (cond | 550 | (cond |
| 531 | ;; Are we moving within the original window? | 551 | ;; Are we moving within the original window? |
| @@ -574,11 +594,11 @@ remains active. Otherwise, it remains until the next input event." | |||
| 574 | (cons event unread-command-events))) | 594 | (cons event unread-command-events))) |
| 575 | (if (not (= (overlay-start mouse-drag-overlay) | 595 | (if (not (= (overlay-start mouse-drag-overlay) |
| 576 | (overlay-end mouse-drag-overlay))) | 596 | (overlay-end mouse-drag-overlay))) |
| 577 | (let* ((stop-point (posn-point (event-end event))) | 597 | (let* ((stop-point (or (posn-point (event-end event)) last-end-point)) |
| 578 | ;; The end that comes from where we ended the drag. | 598 | ;; The end that comes from where we ended the drag. |
| 579 | ;; Point goes here. | 599 | ;; Point goes here. |
| 580 | (region-termination | 600 | (region-termination |
| 581 | (if (< stop-point start-point) | 601 | (if (and stop-point (< stop-point start-point)) |
| 582 | (overlay-start mouse-drag-overlay) | 602 | (overlay-start mouse-drag-overlay) |
| 583 | (overlay-end mouse-drag-overlay))) | 603 | (overlay-end mouse-drag-overlay))) |
| 584 | ;; The end that comes from where we started the drag. | 604 | ;; The end that comes from where we started the drag. |