From: Sam Steingold Date: Fri, 2 May 2008 14:37:39 +0000 (+0000) Subject: * vc.el (vc-dir-mode-map): Enable mouse bindings. X-Git-Tag: emacs-pretest-23.0.90~5875 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5ad4f91cb233c9e277871ed494fcde48d26540d0;p=emacs.git * 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. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 125b38a4574..9d7bab9d327 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2008-05-02 Sam Steingold + + * 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 * progmodes/gdb-ui.el (gdb-info-breakpoints-custom): Don't diff --git a/lisp/subr.el b/lisp/subr.el index 6629589d5ba..7e09de7f3e4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -828,6 +828,11 @@ in the current Emacs session, then this function may return nil." "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 diff --git a/lisp/vc.el b/lisp/vc.el index f1286aece5e..426f7660eda 100644 --- a/lisp/vc.el +++ b/lisp/vc.el @@ -2991,10 +2991,8 @@ specific headers." (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 @@ specific headers." '("----") 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 @@ If a prefix argument is given, move by that many lines." (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 @@ share the same state." (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 @@ that share the same state." (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 ()