0
|
1 ;;; viper-mous.el --- mouse support for Viper
|
|
2
|
82
|
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
|
0
|
4
|
|
5 ;; This file is part of GNU Emacs.
|
|
6
|
|
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
8 ;; it under the terms of the GNU General Public License as published by
|
|
9 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
10 ;; any later version.
|
|
11
|
|
12 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 ;; GNU General Public License for more details.
|
|
16
|
|
17 ;; You should have received a copy of the GNU General Public License
|
|
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 ;; Boston, MA 02111-1307, USA.
|
|
21
|
|
22 ;; Code
|
|
23
|
80
|
24 (provide 'viper-mous)
|
0
|
25
|
|
26 ;; compiler pacifier
|
|
27 (defvar double-click-time)
|
|
28 (defvar mouse-track-multi-click-time)
|
181
|
29 (defvar viper-search-start-marker)
|
|
30 (defvar viper-local-search-start-marker)
|
|
31 (defvar viper-search-history)
|
|
32 (defvar viper-s-string)
|
|
33 (defvar viper-re-search)
|
80
|
34
|
163
|
35 ;; loading happens only in non-interactive compilation
|
|
36 ;; in order to spare non-viperized emacs from being viperized
|
|
37 (if noninteractive
|
|
38 (eval-when-compile
|
|
39 (let ((load-path (cons (expand-file-name ".") load-path)))
|
|
40 (or (featurep 'viper-util)
|
|
41 (load "viper-util.el" nil nil 'nosuffix))
|
|
42 (or (featurep 'viper-cmd)
|
|
43 (load "viper-cmd.el" nil nil 'nosuffix))
|
|
44 )))
|
80
|
45 ;; end pacifier
|
|
46
|
|
47 (require 'viper-util)
|
16
|
48
|
82
|
49
|
175
|
50 (defgroup viper-mouse nil
|
|
51 "Support for Viper special mouse-bound commands"
|
181
|
52 :prefix "viper-"
|
175
|
53 :group 'viper)
|
|
54
|
0
|
55
|
|
56 ;;; Variables
|
|
57
|
|
58 ;; Variable used for catching the switch-frame event.
|
|
59 ;; If non-nil, indicates that previous-frame should be the selected
|
181
|
60 ;; one. Used by viper-mouse-click-get-word. Not a user option.
|
|
61 (defvar viper-frame-of-focus nil)
|
0
|
62
|
|
63 ;; Frame that was selected before the switch-frame event.
|
181
|
64 (defconst viper-current-frame-saved (selected-frame))
|
0
|
65
|
181
|
66 (defcustom viper-surrounding-word-function 'viper-surrounding-word
|
0
|
67 "*Function that determines what constitutes a word for clicking events.
|
|
68 Takes two parameters: a COUNT, indicating how many words to return,
|
|
69 and CLICK-COUNT, telling whether this is the first click, a double-click,
|
175
|
70 or a tripple-click."
|
|
71 :type 'boolean
|
|
72 :group 'viper-mouse)
|
0
|
73
|
|
74 ;; time interval in millisecond within which successive clicks are
|
|
75 ;; considered related
|
181
|
76 (defcustom viper-multiclick-timeout (if (viper-window-display-p)
|
|
77 (if viper-xemacs-p
|
175
|
78 mouse-track-multi-click-time
|
|
79 double-click-time)
|
|
80 500)
|
|
81 "*Time interval in millisecond within which successive mouse clicks are
|
|
82 considered related."
|
|
83 :type 'integer
|
|
84 :group 'viper-mouse)
|
0
|
85
|
|
86 ;; current event click count; XEmacs only
|
181
|
87 (defvar viper-current-click-count 0)
|
0
|
88 ;; time stamp of the last click event; XEmacs only
|
181
|
89 (defvar viper-last-click-event-timestamp 0)
|
0
|
90
|
|
91 ;; Local variable used to toggle wraparound search on click.
|
181
|
92 (viper-deflocalvar viper-mouse-click-search-noerror t)
|
0
|
93
|
|
94 ;; Local variable used to delimit search after wraparound.
|
181
|
95 (viper-deflocalvar viper-mouse-click-search-limit nil)
|
0
|
96
|
|
97 ;; remembers prefix argument to pass along to commands invoked by second
|
|
98 ;; click.
|
|
99 ;; This is needed because in Emacs (not XEmacs), assigning to preix-arg
|
|
100 ;; causes Emacs to count the second click as if it was a single click
|
181
|
101 (defvar viper-global-prefix-argument nil)
|
|
102
|
|
103
|
|
104 ;; same keys, but parsed
|
|
105 (defvar viper-mouse-up-search-key-parsed nil)
|
|
106 (defvar viper-mouse-down-search-key-parsed nil)
|
|
107 (defvar viper-mouse-up-insert-key-parsed nil)
|
|
108 (defvar viper-mouse-down-insert-key-parsed nil)
|
|
109
|
0
|
110
|
|
111
|
|
112
|
|
113 ;;; Code
|
|
114
|
181
|
115 (defsubst viper-multiclick-p ()
|
|
116 (not (viper-sit-for-short viper-multiclick-timeout t)))
|
0
|
117
|
|
118 ;; Returns window where click occurs
|
181
|
119 (defsubst viper-mouse-click-window (click)
|
|
120 (if viper-xemacs-p
|
0
|
121 (event-window click)
|
|
122 (posn-window (event-start click))))
|
|
123
|
|
124 ;; Returns window where click occurs
|
181
|
125 (defsubst viper-mouse-click-frame (click)
|
|
126 (window-frame (viper-mouse-click-window click)))
|
0
|
127
|
|
128 ;; Returns the buffer of the window where click occurs
|
181
|
129 (defsubst viper-mouse-click-window-buffer (click)
|
|
130 (window-buffer (viper-mouse-click-window click)))
|
0
|
131
|
|
132 ;; Returns the name of the buffer in the window where click occurs
|
181
|
133 (defsubst viper-mouse-click-window-buffer-name (click)
|
|
134 (buffer-name (viper-mouse-click-window-buffer click)))
|
0
|
135
|
|
136 ;; Returns position of a click
|
181
|
137 (defsubst viper-mouse-click-posn (click)
|
|
138 (if viper-xemacs-p
|
0
|
139 (event-point click)
|
|
140 (posn-point (event-start click))))
|
|
141
|
|
142
|
181
|
143 (defun viper-surrounding-word (count click-count)
|
0
|
144 "Returns word surrounding point according to a heuristic.
|
|
145 COUNT indicates how many regions to return.
|
|
146 If CLICK-COUNT is 1, `word' is a word in Vi sense.
|
|
147 If CLICK-COUNT is 2,then `word' is a Word in Vi sense.
|
|
148 If the character clicked on is a non-separator and is non-alphanumeric but
|
|
149 is adjacent to an alphanumeric symbol, then it is considered alphanumeric
|
|
150 for the purpose of this command. If this character has a matching
|
|
151 character, such as `\(' is a match for `\)', then the matching character is
|
|
152 also considered alphanumeric.
|
|
153 For convenience, in Lisp modes, `-' is considered alphanumeric.
|
|
154
|
|
155 If CLICK-COUNT is 3 or more, returns the line clicked on with leading and
|
|
156 trailing space and tabs removed. In that case, the first argument, COUNT,
|
|
157 is ignored."
|
|
158 (let ((modifiers "")
|
|
159 beg skip-flag result
|
|
160 word-beg)
|
|
161 (if (> click-count 2)
|
|
162 (save-excursion
|
|
163 (beginning-of-line)
|
181
|
164 (viper-skip-all-separators-forward 'within-line)
|
0
|
165 (setq beg (point))
|
|
166 (end-of-line)
|
|
167 (setq result (buffer-substring beg (point))))
|
|
168
|
181
|
169 (if (and (not (viper-looking-at-alphasep))
|
|
170 (or (save-excursion (viper-backward-char-carefully)
|
|
171 (viper-looking-at-alpha))
|
|
172 (save-excursion (viper-forward-char-carefully)
|
|
173 (viper-looking-at-alpha))))
|
0
|
174 (setq modifiers
|
|
175 (cond ((looking-at "\\\\") "\\\\")
|
|
176 ((looking-at "-") "C-C-")
|
|
177 ((looking-at "[][]") "][")
|
|
178 ((looking-at "[()]") ")(")
|
|
179 ((looking-at "[{}]") "{}")
|
|
180 ((looking-at "[<>]") "<>")
|
|
181 ((looking-at "[`']") "`'")
|
|
182 ((looking-at "\\^") "\\^")
|
181
|
183 ((viper-looking-at-separator) "")
|
0
|
184 (t (char-to-string (following-char))))
|
|
185 ))
|
|
186
|
|
187 ;; Add `-' to alphanum, if it wasn't added and if we are in Lisp
|
|
188 (or (looking-at "-")
|
|
189 (not (string-match "lisp" (symbol-name major-mode)))
|
|
190 (setq modifiers (concat modifiers "C-C-")))
|
|
191
|
|
192
|
|
193 (save-excursion
|
181
|
194 (cond ((> click-count 1) (viper-skip-nonseparators 'backward))
|
|
195 ((viper-looking-at-alpha modifiers)
|
|
196 (viper-skip-alpha-backward modifiers))
|
|
197 ((not (viper-looking-at-alphasep modifiers))
|
|
198 (viper-skip-nonalphasep-backward))
|
0
|
199 (t (if (> click-count 1)
|
181
|
200 (viper-skip-nonseparators 'backward)
|
|
201 (viper-skip-alpha-backward modifiers))))
|
0
|
202
|
|
203 (setq word-beg (point))
|
|
204
|
|
205 (setq skip-flag nil) ; don't move 1 char forw the first time
|
|
206 (while (> count 0)
|
181
|
207 (if skip-flag (viper-forward-char-carefully 1))
|
0
|
208 (setq skip-flag t) ; now always move 1 char forward
|
|
209 (if (> click-count 1)
|
181
|
210 (viper-skip-nonseparators 'forward)
|
|
211 (viper-skip-alpha-forward modifiers))
|
0
|
212 (setq count (1- count)))
|
|
213
|
|
214 (setq result (buffer-substring word-beg (point))))
|
|
215 ) ; if
|
|
216 ;; XEmacs doesn't have set-text-properties, but there buffer-substring
|
|
217 ;; doesn't return properties together with the string, so it's not needed.
|
181
|
218 (if viper-emacs-p
|
0
|
219 (set-text-properties 0 (length result) nil result))
|
|
220 result
|
|
221 ))
|
|
222
|
|
223
|
181
|
224 (defun viper-mouse-click-get-word (click count click-count)
|
0
|
225 "Returns word surrounding the position of a mouse click.
|
|
226 Click may be in another window. Current window and buffer isn't changed.
|
|
227 On single or double click, returns the word as determined by
|
181
|
228 `viper-surrounding-word-function'."
|
0
|
229
|
|
230 (let ((click-word "")
|
181
|
231 (click-pos (viper-mouse-click-posn click))
|
|
232 (click-buf (viper-mouse-click-window-buffer click)))
|
0
|
233 (or (natnump count) (setq count 1))
|
|
234 (or (natnump click-count) (setq click-count 1))
|
|
235
|
|
236 (save-excursion
|
|
237 (save-window-excursion
|
|
238 (if click-pos
|
|
239 (progn
|
|
240 (set-buffer click-buf)
|
|
241
|
|
242 (goto-char click-pos)
|
|
243 (setq click-word
|
181
|
244 (funcall viper-surrounding-word-function count click-count)))
|
0
|
245 (error "Click must be over a window."))
|
|
246 click-word))))
|
|
247
|
|
248
|
181
|
249 (defun viper-mouse-click-insert-word (click arg)
|
0
|
250 "Insert word clicked or double-clicked on.
|
|
251 With prefix argument, N, insert that many words.
|
|
252 This command must be bound to a mouse click.
|
|
253 The double-click action of the same mouse button must not be bound
|
|
254 \(or it must be bound to the same function\).
|
181
|
255 See `viper-surrounding-word' for the definition of a word in this case."
|
0
|
256 (interactive "e\nP")
|
181
|
257 (if viper-frame-of-focus ;; to handle clicks in another frame
|
|
258 (select-frame viper-frame-of-focus))
|
0
|
259
|
|
260 ;; turn arg into a number
|
|
261 (cond ((integerp arg) nil)
|
|
262 ;; prefix arg is a list when one hits C-u then command
|
|
263 ((and (listp arg) (integerp (car arg)))
|
|
264 (setq arg (car arg)))
|
|
265 (t (setq arg 1)))
|
|
266
|
181
|
267 (if (not (eq (key-binding viper-mouse-down-insert-key-parsed)
|
|
268 'viper-mouse-catch-frame-switch))
|
|
269 () ; do nothing
|
|
270 (let (click-count interrupting-event)
|
|
271 (if (and
|
|
272 (viper-multiclick-p)
|
|
273 ;; This trick checks if there is a pending mouse event if so, we use
|
|
274 ;; this latter event and discard the current mouse click If the next
|
|
275 ;; pending event is not a mouse event, we execute the current mouse
|
|
276 ;; event
|
|
277 (progn
|
|
278 (setq interrupting-event (viper-read-event))
|
|
279 (viper-mouse-event-p last-input-event)))
|
|
280 (progn ; interrupted wait
|
|
281 (setq viper-global-prefix-argument arg)
|
|
282 ;; count this click for XEmacs
|
|
283 (viper-event-click-count click))
|
|
284 ;; uninterrupted wait or the interrupting event wasn't a mouse event
|
|
285 (setq click-count (viper-event-click-count click))
|
|
286 (if (> click-count 1)
|
|
287 (setq arg viper-global-prefix-argument
|
|
288 viper-global-prefix-argument nil))
|
|
289 (insert (viper-mouse-click-get-word click arg click-count))
|
|
290 (if (and interrupting-event
|
|
291 (eventp interrupting-event)
|
|
292 (not (viper-mouse-event-p interrupting-event)))
|
|
293 (viper-set-unread-command-events interrupting-event))
|
|
294 ))))
|
0
|
295
|
|
296 ;; arg is an event. accepts symbols and numbers, too
|
181
|
297 (defun viper-mouse-event-p (event)
|
0
|
298 (if (eventp event)
|
|
299 (string-match "\\(mouse-\\|frame\\|screen\\|track\\)"
|
181
|
300 (prin1-to-string (viper-event-key event)))))
|
0
|
301
|
|
302 ;; XEmacs has no double-click events. So, we must simulate.
|
|
303 ;; So, we have to simulate event-click-count.
|
181
|
304 (defun viper-event-click-count (click)
|
|
305 (if viper-xemacs-p
|
0
|
306 (progn
|
|
307 ;; if more than 1 second
|
181
|
308 (if (> (- (event-timestamp click) viper-last-click-event-timestamp)
|
|
309 viper-multiclick-timeout)
|
|
310 (setq viper-current-click-count 0))
|
|
311 (setq viper-last-click-event-timestamp (event-timestamp click)
|
|
312 viper-current-click-count (1+ viper-current-click-count)))
|
0
|
313 (event-click-count click)))
|
|
314
|
|
315
|
|
316
|
181
|
317 (defun viper-mouse-click-search-word (click arg)
|
0
|
318 "Find the word clicked or double-clicked on. Word may be in another window.
|
|
319 With prefix argument, N, search for N-th occurrence.
|
|
320 This command must be bound to a mouse click. The double-click action of the
|
|
321 same button must not be bound \(or it must be bound to the same function\).
|
181
|
322 See `viper-surrounding-word' for the details on what constitutes a word for
|
0
|
323 this command."
|
|
324 (interactive "e\nP")
|
181
|
325 (if viper-frame-of-focus ;; to handle clicks in another frame
|
|
326 (select-frame viper-frame-of-focus))
|
|
327 (if (not (eq (key-binding viper-mouse-down-search-key-parsed)
|
|
328 'viper-mouse-catch-frame-switch))
|
|
329 () ; do nothing
|
|
330 (let ((previous-search-string viper-s-string)
|
|
331 click-word click-count)
|
0
|
332
|
181
|
333 (if (and
|
|
334 (viper-multiclick-p)
|
|
335 ;; This trick checks if there is a pending mouse event if so, we use
|
|
336 ;; this latter event and discard the current mouse click If the next
|
|
337 ;; pending event is not a mouse event, we execute the current mouse
|
|
338 ;; event
|
|
339 (progn
|
|
340 (viper-read-event)
|
|
341 (viper-mouse-event-p last-input-event)))
|
|
342 (progn ; interrupted wait
|
|
343 (setq viper-global-prefix-argument
|
|
344 (or viper-global-prefix-argument arg))
|
|
345 ;; remember command that was before the multiclick
|
|
346 (setq this-command last-command)
|
|
347 ;; make sure we counted this event---needed for XEmacs only
|
|
348 (viper-event-click-count click))
|
|
349 ;; uninterrupted wait
|
|
350 (setq click-count (viper-event-click-count click))
|
|
351 (setq click-word (viper-mouse-click-get-word click nil click-count))
|
|
352
|
|
353 (if (> click-count 1)
|
|
354 (setq arg viper-global-prefix-argument
|
|
355 viper-global-prefix-argument nil))
|
|
356 (setq arg (or arg 1))
|
|
357
|
|
358 (viper-deactivate-mark)
|
|
359 (if (or (not (string= click-word viper-s-string))
|
|
360 (not (markerp viper-search-start-marker))
|
|
361 (not (equal (marker-buffer viper-search-start-marker)
|
|
362 (current-buffer)))
|
|
363 (not (eq last-command 'viper-mouse-click-search-word)))
|
0
|
364 (progn
|
181
|
365 (setq viper-search-start-marker (point-marker)
|
|
366 viper-local-search-start-marker viper-search-start-marker
|
|
367 viper-mouse-click-search-noerror t
|
|
368 viper-mouse-click-search-limit nil)
|
|
369
|
|
370 ;; make search string known to Viper
|
|
371 (setq viper-s-string (if viper-re-search
|
|
372 (regexp-quote click-word)
|
|
373 click-word))
|
|
374 (if (not (string= viper-s-string (car viper-search-history)))
|
|
375 (setq viper-search-history
|
|
376 (cons viper-s-string viper-search-history)))
|
|
377 ))
|
|
378
|
|
379 (push-mark nil t)
|
|
380 (while (> arg 0)
|
|
381 (viper-forward-word 1)
|
|
382 (condition-case nil
|
|
383 (progn
|
|
384 (if (not (search-forward
|
|
385 click-word viper-mouse-click-search-limit
|
|
386 viper-mouse-click-search-noerror))
|
|
387 (progn
|
|
388 (setq viper-mouse-click-search-noerror nil)
|
|
389 (setq viper-mouse-click-search-limit
|
|
390 (save-excursion
|
|
391 (if (and
|
|
392 (markerp viper-local-search-start-marker)
|
|
393 (marker-buffer viper-local-search-start-marker))
|
|
394 (goto-char viper-local-search-start-marker))
|
|
395 (viper-line-pos 'end)))
|
|
396
|
|
397 (goto-char (point-min))
|
|
398 (search-forward click-word
|
|
399 viper-mouse-click-search-limit nil)))
|
|
400 (goto-char (match-beginning 0))
|
|
401 (message "Searching for: %s" viper-s-string)
|
|
402 (if (<= arg 1) ; found the right occurrence of the pattern
|
|
403 (progn
|
|
404 (viper-adjust-window)
|
|
405 (viper-flash-search-pattern)))
|
|
406 )
|
|
407 (error (beep 1)
|
|
408 (if (or (not (string= click-word previous-search-string))
|
|
409 (not (eq last-command 'viper-mouse-click-search-word)))
|
|
410 (message "`%s': String not found in %s"
|
|
411 viper-s-string (buffer-name (current-buffer)))
|
|
412 (message
|
|
413 "`%s': Last occurrence in %s. Back to beginning of search"
|
|
414 click-word (buffer-name (current-buffer)))
|
|
415 (setq arg 1) ;; to terminate the loop
|
|
416 (sit-for 2))
|
|
417 (setq viper-mouse-click-search-noerror t)
|
|
418 (setq viper-mouse-click-search-limit nil)
|
|
419 (if (and (markerp viper-local-search-start-marker)
|
|
420 (marker-buffer viper-local-search-start-marker))
|
|
421 (goto-char viper-local-search-start-marker))))
|
|
422 (setq arg (1- arg)))
|
|
423 ))))
|
0
|
424
|
181
|
425 (defun viper-mouse-catch-frame-switch (event arg)
|
0
|
426 "Catch the event of switching frame.
|
181
|
427 Usually is bound to a `down-mouse' event to work properly. See sample
|
163
|
428 bindings in the Viper manual."
|
0
|
429 (interactive "e\nP")
|
181
|
430 (setq viper-frame-of-focus nil)
|
|
431 ;; pass prefix arg along to viper-mouse-click-search/insert-word
|
0
|
432 (setq prefix-arg arg)
|
|
433 (if (eq last-command 'handle-switch-frame)
|
181
|
434 (setq viper-frame-of-focus viper-current-frame-saved))
|
|
435 ;; make Emacs forget that it executed viper-mouse-catch-frame-switch
|
0
|
436 (setq this-command last-command))
|
|
437
|
|
438 ;; Called just before switching frames. Saves the old selected frame.
|
|
439 ;; Sets last-command to handle-switch-frame (this is done automatically in
|
|
440 ;; Emacs.
|
|
441 ;; The semantics of switching frames is different in Emacs and XEmacs.
|
|
442 ;; In Emacs, if you select-frame A while mouse is over frame B and then
|
|
443 ;; start typing, input goes to frame B, which becomes selected.
|
|
444 ;; In XEmacs, input will go to frame A. This may be a bug in one of the
|
|
445 ;; Emacsen, but also may be a design decision.
|
|
446 ;; Also, in Emacs sending input to frame B generates handle-switch-frame
|
|
447 ;; event, while in XEmacs it doesn't.
|
|
448 ;; All this accounts for the difference in the behavior of
|
181
|
449 ;; viper-mouse-click-* commands when you click in a frame other than the one
|
0
|
450 ;; that was the last to receive input. In Emacs, focus will be in frame A
|
181
|
451 ;; until you do something other than viper-mouse-click-* command.
|
0
|
452 ;; In XEmacs, you have to manually select frame B (with the mouse click) in
|
|
453 ;; order to shift focus to frame B.
|
181
|
454 (defsubst viper-remember-current-frame (frame)
|
0
|
455 (setq last-command 'handle-switch-frame
|
181
|
456 viper-current-frame-saved (selected-frame)))
|
|
457
|
|
458
|
|
459 ;; The key is of the form (MODIFIER ... BUTTON-NUMBER)
|
|
460 ;; Converts into a valid mouse button spec for the appropriate version of
|
|
461 ;; Emacs. EVENT-TYPE is either `up' or `down'. Up returns button-up key; down
|
|
462 ;; returns button-down key.
|
|
463 (defun viper-parse-mouse-key (key-var event-type)
|
|
464 (let ((key (eval key-var))
|
|
465 button-spec meta-spec shift-spec control-spec key-spec)
|
|
466 (if (null key)
|
|
467 ;; just return nil
|
|
468 ()
|
|
469 (setq button-spec
|
|
470 (cond ((memq 1 key)
|
|
471 (if viper-emacs-p
|
|
472 (if (eq 'up event-type)
|
|
473 "mouse-1" "down-mouse-1")
|
|
474 (if (eq 'up event-type)
|
|
475 'button1up 'button1)))
|
|
476 ((memq 2 key)
|
|
477 (if viper-emacs-p
|
|
478 (if (eq 'up event-type)
|
|
479 "mouse-2" "down-mouse-2")
|
|
480 (if (eq 'up event-type)
|
|
481 'button2up 'button2)))
|
|
482 ((memq 3 key)
|
|
483 (if viper-emacs-p
|
|
484 (if (eq 'up event-type)
|
|
485 "mouse-3" "down-mouse-3")
|
|
486 (if (eq 'up event-type)
|
|
487 'button3up 'button3)))
|
|
488 (t (error
|
|
489 "%S: invalid button number, %S" key-var key)))
|
|
490 meta-spec
|
|
491 (if (memq 'meta key)
|
|
492 (if viper-emacs-p "M-" 'meta)
|
|
493 (if viper-emacs-p "" nil))
|
|
494 shift-spec
|
|
495 (if (memq 'shift key)
|
|
496 (if viper-emacs-p "S-" 'shift)
|
|
497 (if viper-emacs-p "" nil))
|
|
498 control-spec
|
|
499 (if (memq 'control key)
|
|
500 (if viper-emacs-p "C-" 'control)
|
|
501 (if viper-emacs-p "" nil)))
|
|
502
|
|
503 (setq key-spec (if viper-emacs-p
|
|
504 (vector
|
|
505 (intern
|
|
506 (concat
|
|
507 control-spec meta-spec shift-spec button-spec)))
|
|
508 (vector
|
|
509 (delq
|
|
510 nil
|
|
511 (list
|
|
512 control-spec meta-spec shift-spec button-spec)))))
|
|
513 )))
|
|
514
|
|
515 (defun viper-unbind-mouse-search-key ()
|
|
516 (if viper-mouse-up-search-key-parsed
|
|
517 (global-unset-key viper-mouse-up-search-key-parsed))
|
|
518 (if viper-mouse-down-search-key-parsed
|
|
519 (global-unset-key viper-mouse-down-search-key-parsed))
|
|
520 (setq viper-mouse-up-search-key-parsed nil
|
|
521 viper-mouse-down-search-key-parsed nil))
|
|
522
|
|
523 (defun viper-unbind-mouse-insert-key ()
|
|
524 (if viper-mouse-up-insert-key-parsed
|
|
525 (global-unset-key viper-mouse-up-insert-key-parsed))
|
|
526 (if viper-mouse-down-insert-key-parsed
|
|
527 (global-unset-key viper-mouse-down-insert-key-parsed))
|
|
528 (setq viper-mouse-up-insert-key-parsed nil
|
|
529 viper-mouse-down-insert-key-parsed nil))
|
|
530
|
|
531 ;; If FORCE, bind even if this mouse action is already bound to something else
|
|
532 (defun viper-bind-mouse-search-key (&optional force)
|
|
533 (setq viper-mouse-up-search-key-parsed
|
|
534 (viper-parse-mouse-key 'viper-mouse-search-key 'up)
|
|
535 viper-mouse-down-search-key-parsed
|
|
536 (viper-parse-mouse-key 'viper-mouse-search-key 'down))
|
|
537 (cond ((or (null viper-mouse-up-search-key-parsed)
|
|
538 (null viper-mouse-down-search-key-parsed))
|
|
539 nil) ; just quit
|
|
540 ((and (null force)
|
|
541 (key-binding viper-mouse-up-search-key-parsed)
|
|
542 (not (eq (key-binding viper-mouse-up-search-key-parsed)
|
|
543 'viper-mouse-click-search-word)))
|
|
544 (message
|
|
545 "%S already bound to a mouse event. Viper mouse-search feature disabled"
|
|
546 viper-mouse-up-search-key-parsed))
|
|
547 ((and (null force)
|
|
548 (key-binding viper-mouse-down-search-key-parsed)
|
|
549 (not (eq (key-binding viper-mouse-down-search-key-parsed)
|
|
550 'viper-mouse-catch-frame-switch)))
|
|
551 (message
|
|
552 "%S already bound to a mouse event. Viper mouse-search feature disabled"
|
|
553 viper-mouse-down-search-key-parsed))
|
|
554 (t
|
|
555 (global-set-key viper-mouse-up-search-key-parsed
|
|
556 'viper-mouse-click-search-word)
|
|
557 (global-set-key viper-mouse-down-search-key-parsed
|
|
558 'viper-mouse-catch-frame-switch))))
|
|
559
|
|
560 ;; If FORCE, bind even if this mouse action is already bound to something else
|
|
561 (defun viper-bind-mouse-insert-key (&optional force)
|
|
562 (setq viper-mouse-up-insert-key-parsed
|
|
563 (viper-parse-mouse-key 'viper-mouse-insert-key 'up)
|
|
564 viper-mouse-down-insert-key-parsed
|
|
565 (viper-parse-mouse-key 'viper-mouse-insert-key 'down))
|
|
566 (cond ((or (null viper-mouse-up-insert-key-parsed)
|
|
567 (null viper-mouse-down-insert-key-parsed))
|
|
568 nil) ; just quit
|
|
569 ((and (null force)
|
|
570 (key-binding viper-mouse-up-insert-key-parsed)
|
|
571 (not (eq (key-binding viper-mouse-up-insert-key-parsed)
|
|
572 'viper-mouse-click-insert-word)))
|
|
573 (message
|
|
574 "%S already bound to a mouse event. Viper mouse-insert feature disabled"
|
|
575 viper-mouse-up-insert-key-parsed))
|
|
576 ((and (null force)
|
|
577 (key-binding viper-mouse-down-insert-key-parsed)
|
|
578 (not (eq (key-binding viper-mouse-down-insert-key-parsed)
|
|
579 'viper-mouse-catch-frame-switch)))
|
|
580 (message
|
|
581 "%S already bound to a mouse event. Viper mouse-insert feature disabled"
|
|
582 viper-mouse-down-insert-key-parsed))
|
|
583 (t
|
|
584 (global-set-key viper-mouse-up-insert-key-parsed
|
|
585 'viper-mouse-click-insert-word)
|
|
586 (global-set-key viper-mouse-down-insert-key-parsed
|
|
587 'viper-mouse-catch-frame-switch))))
|
|
588
|
|
589 (defun viper-reset-mouse-search-key (symb val)
|
|
590 (viper-unbind-mouse-search-key)
|
|
591 (set symb val)
|
|
592 (viper-bind-mouse-search-key 'force))
|
|
593
|
|
594 (defun viper-reset-mouse-insert-key (symb val)
|
|
595 (viper-unbind-mouse-insert-key)
|
|
596 (set symb val)
|
|
597 (viper-bind-mouse-insert-key 'force))
|
|
598
|
|
599
|
|
600 (defcustom viper-mouse-search-key '(meta shift 1)
|
|
601 "*Key used to click-search in Viper.
|
|
602 Must be a list that specifies the mouse button and modifiers. The supported
|
|
603 modifiers are `meta', `shift', and `control'. For instance, `(meta shift 1)'
|
|
604 means that holding the meta and shift keys down and clicking on a word with
|
|
605 mouse button 1 will initiate search for that word in the buffer that was
|
|
606 current just before the click. This buffer may be different from the one where
|
|
607 the click occurred."
|
|
608 :type 'list
|
|
609 :set 'viper-reset-mouse-search-key
|
|
610 :group 'viper-mouse)
|
|
611
|
|
612 (defcustom viper-mouse-insert-key '(meta shift 2)
|
|
613 "*Key used to click-insert in Viper.
|
|
614 Must be a list that specifies the mouse button and modifiers. The supported
|
|
615 modifiers are `meta', `shift', and `control'. For instance, `(meta shift 2)'
|
|
616 means that holding the meta and shift keys down and clicking on a word with
|
|
617 mouse button 2 will insert that word at the cursor in the buffer that was
|
|
618 current just before the click. This buffer may be different from the one where
|
|
619 the click occurred."
|
|
620 :type 'list
|
|
621 :set 'viper-reset-mouse-insert-key
|
|
622 :group 'viper-mouse)
|
|
623
|
0
|
624
|
|
625
|
175
|
626 ;;; Local Variables:
|
181
|
627 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
|
175
|
628 ;;; End:
|
|
629
|
0
|
630
|
|
631 ;;; viper-mous.el ends here
|