changeset 94556:8d02ae7cb729

* vc.el (vc-dir-mode-map): Enable mouse bindings. (vc-at-event): New macro: run the body at the even location. (vc-dir-menu, vc-dir-toggle-mark): Use it. (vc-dir-mark-file, vc-dir-unmark-file): Move only on non-mouse events. * subr.d (mouse-event-p): Check if the even is mouse-related.
author Sam Steingold <sds@gnu.org>
date Fri, 02 May 2008 14:37:39 +0000
parents e33c27238da2
children 620608825355
files lisp/ChangeLog lisp/subr.el lisp/vc.el
diffstat 3 files changed, 34 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri May 02 12:43:30 2008 +0000
+++ b/lisp/ChangeLog	Fri May 02 14:37:39 2008 +0000
@@ -1,3 +1,11 @@
+2008-05-02  Sam Steingold  <sds@gnu.org>
+
+	* vc.el (vc-dir-mode-map): Enable mouse bindings.
+	(vc-at-event): New macro: run the body at the even location.
+	(vc-dir-menu, vc-dir-toggle-mark): Use it.
+	(vc-dir-mark-file, vc-dir-unmark-file): Move only on non-mouse events.
+	* subr.d (mouse-event-p): Check if the even is mouse-related.
+
 2008-05-02  Nick Roberts  <nickrob@snap.net.nz>
 
 	* progmodes/gdb-ui.el (gdb-info-breakpoints-custom): Don't
--- a/lisp/subr.el	Fri May 02 12:43:30 2008 +0000
+++ b/lisp/subr.el	Fri May 02 14:37:39 2008 +0000
@@ -828,6 +828,11 @@
   "Return non-nil if OBJECT is a mouse movement event."
   (eq (car-safe object) 'mouse-movement))
 
+(defun mouse-event-p (object)
+  "Return non-nil if OBJECT is a mouse click event."
+  ;; is this really correct? maybe remove mouse-movement?
+  (memq (event-basic-type object) '(mouse-1 mouse-2 mouse-3 mouse-movement)))
+
 (defsubst event-start (event)
   "Return the starting position of EVENT.
 If EVENT is a mouse or key press or a mouse click, this returns the location
--- a/lisp/vc.el	Fri May 02 12:43:30 2008 +0000
+++ b/lisp/vc.el	Fri May 02 14:37:39 2008 +0000
@@ -2991,10 +2991,8 @@
     (define-key map "q" 'quit-window)
     (define-key map "g" 'vc-dir-refresh)
     (define-key map "\C-c\C-c" 'vc-dir-kill-dir-status-process)
-    ;; Does not work unless mouse sets point.  Functions like vc-dir-find-file
-    ;; need to find the file from the mouse position, not `point'.
-    ;; (define-key map [(down-mouse-3)] 'vc-dir-menu)
-    ;; (define-key map [(mouse-2)] 'vc-dir-toggle-mark)
+    (define-key map [(down-mouse-3)] 'vc-dir-menu)
+    (define-key map [(mouse-2)] 'vc-dir-toggle-mark)
 
     ;; Hook up the menu.
     (define-key map [menu-bar vc-dir-mode]
@@ -3022,10 +3020,21 @@
 	      '("----")
 	      ext-binding))))
 
+(defmacro vc-at-event (event &rest body)
+  "Evaluate `body' wich point located at event-start of `event'.
+If `body' uses `event', it should be a variable,
+ otherwise it will be evaluated twice."
+  (let ((posn (gensym "vc-at-event-posn")))
+    `(let ((,posn (event-start ,event)))
+       (save-excursion
+         (set-buffer (window-buffer (posn-window ,posn)))
+         (goto-char (posn-point ,posn))
+         ,@body))))
+
 (defun vc-dir-menu (e)
   "Popup the VC status menu."
   (interactive "e")
-  (popup-menu vc-dir-menu-map e))
+  (vc-at-event e (popup-menu vc-dir-menu-map e)))
 
 (defvar vc-dir-tool-bar-map
   (let ((map (make-sparse-keymap)))
@@ -3416,7 +3425,7 @@
 	      (and (not isdir) (not (vc-dir-parent-marked-p crt))))
       (setf (vc-dir-fileinfo->marked file) t)
       (ewoc-invalidate vc-ewoc crt)
-      (unless arg
+      (unless (or arg (mouse-event-p last-command-event))
 	(vc-dir-next-line 1)))))
 
 (defun vc-dir-mark ()
@@ -3481,7 +3490,8 @@
          (file (ewoc-data crt)))
     (setf (vc-dir-fileinfo->marked file) nil)
     (ewoc-invalidate vc-ewoc crt)
-    (vc-dir-next-line 1)))
+    (unless (mouse-event-p last-command-event)
+      (vc-dir-next-line 1))))
 
 (defun vc-dir-unmark ()
   "Unmark the current file or all files in the region.
@@ -3545,15 +3555,15 @@
 	(vc-dir-unmark-file)
       (vc-dir-mark-file))))
 
-(defun vc-dir-toggle-mark ()
-  (interactive)
-  (vc-dir-mark-unmark 'vc-dir-toggle-mark-file))
+(defun vc-dir-toggle-mark (e)
+  (interactive "e")
+  (vc-at-event e (vc-dir-mark-unmark 'vc-dir-toggle-mark-file)))
 
 (defun vc-dir-register ()
   "Register the marked files, or the current file if no marks."
   (interactive)
   ;; FIXME: Just pass the fileset to vc-register.
-  (mapc (lambda (arg) (vc-register nil arg)) 
+  (mapc (lambda (arg) (vc-register nil arg))
 	(or (vc-dir-marked-files) (list (vc-dir-current-file)))))
 
 (defun vc-dir-delete-file ()