(vc-fetch-master-properties): Count cvs status "Needs Patch" as
[bpt/emacs.git] / lisp / mouse.el
index d589ae4..d70d40d 100644 (file)
              (and (current-local-map)
                   (lookup-key (current-local-map) [menu-bar])))))
     (mouse-major-mode-menu-compute-equiv-keys newmap)
-    (command-execute
-     ;; Make NEWMAP override the usual definition
-     ;; of the mouse button that got us here.
-     ;; Then read the user's menu choice.
-     (let ((minor-mode-map-alist
-           (cons (cons t newmap) minor-mode-map-alist)))
-       (lookup-key newmap (read-key-sequence ""))))))
+    ;; Make NEWMAP override the usual definition
+    ;; of the mouse button that got us here.
+    ;; Then read the user's menu choice.
+    (let* ((minor-mode-map-alist
+           (cons (cons t newmap) minor-mode-map-alist))
+          ;; read-key-sequence quits if the user aborts the menu.
+          ;; If that happens, do nothing silently.
+          (keyseq (condition-case nil
+                      (read-key-sequence "")
+                    (quit nil)))
+          (command (if keyseq (lookup-key newmap keyseq))))
+      (if command
+         (command-execute command)))))
 
 ;; Compute and cache the equivalent keys in MENU and all its submenus.
 (defun mouse-major-mode-menu-compute-equiv-keys (menu)
@@ -315,8 +321,9 @@ This should be bound to a mouse drag event."
     (if (numberp (posn-point posn))
        (goto-char (posn-point posn)))
     ;; If mark is highlighted, no need to bounce the cursor.
-    (or (and transient-mark-mode
-            (framep (selected-frame)))
+    ;; On X, we highlight while dragging, thus once again no need to bounce.
+    (or transient-mark-mode
+       (eq (framep (selected-frame)) 'x)
        (sit-for 1))
     (push-mark)
     (set-mark (point))
@@ -324,7 +331,8 @@ This should be bound to a mouse drag event."
        (goto-char (posn-point end)))
     ;; Don't set this-command to kill-region, so that a following
     ;; C-w will not double the text in the kill ring.
-    (let (this-command)
+    ;; Ignore last-command so we don't append to a preceding kill.
+    (let (this-command last-command)
       (copy-region-as-kill (mark) (point)))
     (mouse-set-region-1)))
 
@@ -378,6 +386,8 @@ Upon exit, point is at the far edge of the newly visible text."
 
 (defvar mouse-selection-click-count 0)
 
+(defvar mouse-selection-click-count-buffer nil)
+
 (defun mouse-drag-region (start-event)
   "Set the region to the text that the mouse is dragged over.
 Highlight the drag area as you move the mouse.
@@ -398,6 +408,7 @@ release the mouse button.  Otherwise, it does not."
                   (1- (nth 3 bounds))))
         (click-count (1- (event-click-count start-event))))
     (setq mouse-selection-click-count click-count)
+    (setq mouse-selection-click-count-buffer (current-buffer))
     (mouse-set-point start-event)
     (let ((range (mouse-start-end start-point start-point click-count)))
       (move-overlay mouse-drag-overlay (car range) (nth 1 range)
@@ -438,12 +449,13 @@ release the mouse button.  Otherwise, it does not."
            ;; In the case of a multiple click, it gives the wrong results,
            ;; because it would fail to set up a region.
            (if (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
+               ;; In this case, we can just let the up-event execute normally.
                (progn
-                 (setq this-command fun)
                  ;; Delete the overlay before calling the function,
                  ;; because delete-overlay increases buffer-modified-tick.
                  (delete-overlay mouse-drag-overlay)
-                 (funcall fun event))
+                 (setq unread-command-events
+                       (cons event unread-command-events)))
              (if (not (= (overlay-start mouse-drag-overlay)
                          (overlay-end mouse-drag-overlay)))
                  (let (last-command this-command)
@@ -579,6 +591,7 @@ regardless of where you click."
   (run-hooks 'mouse-leave-buffer-hook)
   (or mouse-yank-at-point (mouse-set-point click))
   (setq this-command 'yank)
+  (setq mouse-selection-click-count 0)
   (yank arg))
 
 (defun mouse-kill-ring-save (click)
@@ -652,7 +665,12 @@ If you do this twice in the same position, the selection is killed."
          ;; Don't let a subsequent kill command append to this one:
          ;; prevent setting this-command to kill-region.
          (this-command this-command))
-      (if (and (mark t) (> (mod mouse-selection-click-count 3) 0))
+      (if (and (save-excursion
+                (set-buffer (window-buffer (posn-window (event-start click))))
+                (and (mark t) (> (mod mouse-selection-click-count 3) 0)
+                     ;; Don't be fooled by a recent click in some other buffer.
+                     (eq mouse-selection-click-count-buffer 
+                         (current-buffer)))))
          (if (not (and (eq last-command 'mouse-save-then-kill)
                        (equal click-posn
                               (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))