Mercurial > emacs
comparison lisp/mouse.el @ 15642:6a3622bb0f31
(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.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 11 Jul 1996 23:35:37 +0000 |
parents | 186632053420 |
children | 6ad5994053af |
comparison
equal
deleted
inserted
replaced
15641:d966f03cdcab | 15642:6a3622bb0f31 |
---|---|
45 (defun mouse-major-mode-menu (event) | 45 (defun mouse-major-mode-menu (event) |
46 "Pop up a mode-specific menu of mouse commands." | 46 "Pop up a mode-specific menu of mouse commands." |
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, |
90 ;; return just that menu. | 89 ;; return just that menu. |
91 ;; Otherwise return a menu for all of them. | 90 ;; Otherwise return a menu for all of them. |
95 submap) | 94 submap) |
96 (while tail | 95 (while tail |
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 |
107 (defun mouse-minibuffer-check (event) | 125 (defun mouse-minibuffer-check (event) |
108 (let ((w (posn-window (event-start event)))) | 126 (let ((w (posn-window (event-start event)))) |
514 (window-buffer start-window))) | 532 (window-buffer start-window))) |
515 (deactivate-mark) | 533 (deactivate-mark) |
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)) |
523 (or (mouse-movement-p event) | 541 (or (mouse-movement-p event) |
524 (eq (car-safe event) 'switch-frame))) | 542 (eq (car-safe event) 'switch-frame))) |
525 (if (eq (car-safe event) 'switch-frame) | 543 (if (eq (car-safe event) 'switch-frame) |
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? |
532 ((and (eq (posn-window end) start-window) | 552 ((and (eq (posn-window end) start-window) |
533 (integer-or-marker-p end-point)) | 553 (integer-or-marker-p end-point)) |
572 (delete-overlay mouse-drag-overlay) | 592 (delete-overlay mouse-drag-overlay) |
573 (setq unread-command-events | 593 (setq unread-command-events |
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. |
585 ;; Mark goes there. | 605 ;; Mark goes there. |
586 (region-commencement | 606 (region-commencement |