;;; viper-mous.el --- mouse support for Viper
-;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 1997, 2001, 2002, 2003, 2004,
+;; 2005, 2006 Free Software Foundation, Inc.
-;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
;; This file is part of GNU Emacs.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(defgroup viper-mouse nil
- "Support for Viper special mouse-bound commands"
+ "Support for Viper special mouse-bound commands."
:prefix "viper-"
:group 'viper)
\f
;;; Variables
-
+
;; Variable used for catching the switch-frame event.
;; If non-nil, indicates that previous-frame should be the selected
;; one. Used by viper-mouse-click-get-word. Not a user option.
(defvar viper-frame-of-focus nil)
-
+
;; Frame that was selected before the switch-frame event.
-(defconst viper-current-frame-saved (selected-frame))
-
+(defvar viper-current-frame-saved (selected-frame))
+
(defcustom viper-surrounding-word-function 'viper-surrounding-word
"*Function that determines what constitutes a word for clicking events.
-Takes two parameters: a COUNT, indicating how many words to return,
+Takes two parameters: a COUNT, indicating how many words to return,
and CLICK-COUNT, telling whether this is the first click, a double-click,
or a tripple-click."
:type 'symbol
:group 'viper-mouse)
-
+
;; time interval in millisecond within which successive clicks are
;; considered related
(defcustom viper-multiclick-timeout (if (viper-window-display-p)
;; Local variable used to toggle wraparound search on click.
(viper-deflocalvar viper-mouse-click-search-noerror t)
-
+
;; Local variable used to delimit search after wraparound.
(viper-deflocalvar viper-mouse-click-search-limit nil)
-
+
;; remembers prefix argument to pass along to commands invoked by second
;; click.
;; This is needed because in Emacs (not XEmacs), assigning to preix-arg
;; Returns window where click occurs
(defun viper-mouse-click-window (click)
- (let ((win (if viper-xemacs-p
- (event-window click)
- (posn-window (event-start click)))))
+ (let ((win (viper-cond-compile-for-xemacs-or-emacs
+ (event-window click) ; xemacs
+ (posn-window (event-start click)) ; emacs
+ )))
(if (window-live-p win)
win
(error "Click was not over a live window"))))
;; Returns position of a click
(defsubst viper-mouse-click-posn (click)
- (if viper-xemacs-p
- (event-point click)
- (posn-point (event-start click))))
-
+ (viper-cond-compile-for-xemacs-or-emacs
+ (event-point click) ; xemacs
+ (posn-point (event-start click)) ; emacs
+ ))
+
(defun viper-surrounding-word (count click-count)
"Returns word surrounding point according to a heuristic.
(setq beg (point))
(end-of-line)
(setq result (buffer-substring beg (point))))
-
+
(if (and (not (viper-looking-at-alphasep))
(or (save-excursion (viper-backward-char-carefully)
(viper-looking-at-alpha))
(t (char-to-string (following-char))))
)
))
-
+
;; Add `-' to alphanum, if it wasn't added and if we are in Lisp
(or (looking-at "-")
(not (string-match "lisp" (symbol-name major-mode)))
(setq modifiers (concat modifiers "C-C-")))
-
-
+
+
(save-excursion
(cond ((> click-count 1) (viper-skip-nonseparators 'backward))
((viper-looking-at-alpha modifiers)
(viper-skip-alpha-backward modifiers))))
(setq word-beg (point))
-
+
(setq skip-flag nil) ; don't move 1 char forw the first time
(while (> count 0)
(if skip-flag (viper-forward-char-carefully 1))
Click may be in another window. Current window and buffer isn't changed.
On single or double click, returns the word as determined by
`viper-surrounding-word-function'."
-
+
(let ((click-word "")
(click-pos (viper-mouse-click-posn click))
(click-buf (viper-mouse-click-window-buffer click)))
(or (natnump count) (setq count 1))
(or (natnump click-count) (setq click-count 1))
-
+
(save-excursion
(save-window-excursion
(if click-pos
(progn
(set-buffer click-buf)
-
+
(goto-char click-pos)
(setq click-word
(funcall viper-surrounding-word-function count click-count)))
((and (listp arg) (integerp (car arg)))
(setq arg (car arg)))
(t (setq arg 1)))
-
+
(if (not (eq (key-binding viper-mouse-down-insert-key-parsed)
'viper-mouse-catch-frame-switch))
() ; do nothing
(not (viper-mouse-event-p interrupting-event)))
(viper-set-unread-command-events interrupting-event))
)))))
-
+
;; Arg is an event. Accepts symbols and numbers, too
(defun viper-mouse-event-p (event)
(if (eventp event)
(string-match "\\(mouse-\\|frame\\|screen\\|track\\)"
(prin1-to-string (viper-event-key event)))))
-
+
;; XEmacs has no double-click events. So, we must simulate.
;; So, we have to simulate event-click-count.
(defun viper-event-click-count (click)
- (if viper-xemacs-p
- (viper-event-click-count-xemacs click)
- (event-click-count click)))
-
+ (viper-cond-compile-for-xemacs-or-emacs
+ (viper-event-click-count-xemacs click) ; xemacs
+ (event-click-count click) ; emacs
+ ))
+
;; kind of semaphore for updating viper-current-click-count
(defvar viper-counting-clicks-p nil)
-(defun viper-event-click-count-xemacs (click)
- (let ((time-delta (- (event-timestamp click)
- viper-last-click-event-timestamp))
- inhibit-quit)
- (while viper-counting-clicks-p
- (ignore))
- (setq viper-counting-clicks-p t)
- (if (> time-delta viper-multiclick-timeout)
- (setq viper-current-click-count 0))
- (discard-input)
- (setq viper-current-click-count (1+ viper-current-click-count)
- viper-last-click-event-timestamp (event-timestamp click))
- (setq viper-counting-clicks-p nil)
- (if (viper-sit-for-short viper-multiclick-timeout t)
- viper-current-click-count
- 0)
- ))
-
+(viper-cond-compile-for-xemacs-or-emacs
+ (defun viper-event-click-count-xemacs (click)
+ (let ((time-delta (- (event-timestamp click)
+ viper-last-click-event-timestamp))
+ inhibit-quit)
+ (while viper-counting-clicks-p
+ (ignore))
+ (setq viper-counting-clicks-p t)
+ (if (> time-delta viper-multiclick-timeout)
+ (setq viper-current-click-count 0))
+ (discard-input)
+ (setq viper-current-click-count (1+ viper-current-click-count)
+ viper-last-click-event-timestamp (event-timestamp click))
+ (setq viper-counting-clicks-p nil)
+ (if (viper-sit-for-short viper-multiclick-timeout t)
+ viper-current-click-count
+ 0)
+ ))
+ nil ; emacs
+ )
+
(defun viper-mouse-click-search-word (click arg)
"Find the word clicked or double-clicked on. Word may be in another window.
() ; do nothing, if binding isn't right or not over text
(let ((previous-search-string viper-s-string)
click-word click-count)
-
+
(if (and
(viper-multiclick-p)
;; This trick checks if there is a pending mouse event if so, we use
;; uninterrupted wait
(setq click-count (viper-event-click-count click))
(setq click-word (viper-mouse-click-get-word click nil click-count))
-
+
(if (> click-count 1)
(setq arg viper-global-prefix-argument
viper-global-prefix-argument nil))
(setq arg (or arg 1))
-
+
(viper-deactivate-mark)
(if (or (not (string= click-word viper-s-string))
(not (markerp viper-search-start-marker))
viper-local-search-start-marker viper-search-start-marker
viper-mouse-click-search-noerror t
viper-mouse-click-search-limit nil)
-
+
;; make search string known to Viper
(setq viper-s-string (if viper-re-search
(regexp-quote click-word)
(setq viper-search-history
(cons viper-s-string viper-search-history)))
))
-
+
(push-mark nil t)
(while (> arg 0)
(viper-forward-word 1)
(marker-buffer viper-local-search-start-marker))
(goto-char viper-local-search-start-marker))
(viper-line-pos 'end)))
-
+
(goto-char (point-min))
(search-forward click-word
viper-mouse-click-search-limit nil)))
click-word (buffer-name (current-buffer)))
(setq arg 1) ;; to terminate the loop
(sit-for 2))
- (setq viper-mouse-click-search-noerror t)
+ (setq viper-mouse-click-search-noerror t)
(setq viper-mouse-click-search-limit nil)
(if (and (markerp viper-local-search-start-marker)
(marker-buffer viper-local-search-start-marker))
(goto-char viper-local-search-start-marker))))
(setq arg (1- arg)))
))))
-
+
(defun viper-mouse-catch-frame-switch (event arg)
"Catch the event of switching frame.
Usually is bound to a `down-mouse' event to work properly. See sample
(setq viper-frame-of-focus viper-current-frame-saved))
;; make Emacs forget that it executed viper-mouse-catch-frame-switch
(setq this-command last-command))
-
+
;; Called just before switching frames. Saves the old selected frame.
;; Sets last-command to handle-switch-frame (this is done automatically in
-;; Emacs.
+;; Emacs.
;; The semantics of switching frames is different in Emacs and XEmacs.
;; In Emacs, if you select-frame A while mouse is over frame B and then
;; start typing, input goes to frame B, which becomes selected.
(cond ((or (null viper-mouse-up-search-key-parsed)
(null viper-mouse-down-search-key-parsed))
nil) ; just quit
- ((and (null force)
+ ((and (null force)
(key-binding viper-mouse-up-search-key-parsed)
(not (eq (key-binding viper-mouse-up-search-key-parsed)
'viper-mouse-click-search-word)))
- (message
+ (message
"%S already bound to a mouse event. Viper mouse-search feature disabled"
viper-mouse-up-search-key-parsed))
- ((and (null force)
+ ((and (null force)
(key-binding viper-mouse-down-search-key-parsed)
(not (eq (key-binding viper-mouse-down-search-key-parsed)
'viper-mouse-catch-frame-switch)))
(message
"%S already bound to a mouse event. Viper mouse-search feature disabled"
viper-mouse-down-search-key-parsed))
- (t
+ (t
(global-set-key viper-mouse-up-search-key-parsed
'viper-mouse-click-search-word)
(global-set-key viper-mouse-down-search-key-parsed
(key-binding viper-mouse-up-insert-key-parsed)
(not (eq (key-binding viper-mouse-up-insert-key-parsed)
'viper-mouse-click-insert-word)))
- (message
+ (message
"%S already bound to a mouse event. Viper mouse-insert feature disabled"
viper-mouse-up-insert-key-parsed))
((and (null force)
(message
"%S already bound to a mouse event. Viper mouse-insert feature disabled"
viper-mouse-down-insert-key-parsed))
- (t
+ (t
(global-set-key viper-mouse-up-insert-key-parsed
'viper-mouse-click-insert-word)
(global-set-key viper-mouse-down-insert-key-parsed
(integer :tag "Button"))
:set 'viper-reset-mouse-insert-key
:group 'viper-mouse)
-
+
;;; Local Variables:
;;; End:
+;;; arch-tag: e56b2390-06c4-4dd1-96f5-c7876e2d8c2f
;;; viper-mous.el ends here