Mercurial > emacs
annotate lisp/emulation/viper-mous.el @ 12802:74615e68b2cd
New node, Tips for Defining.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 08 Aug 1995 06:15:53 +0000 |
parents | 9dedaee6ee1c |
children | e5d4ba91148f |
rev | line source |
---|---|
10789 | 1 ;;; viper-mous.el -- Mouse support for Viper |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
2 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
11288 | 3 |
10789 | 4 ;; This file is part of GNU Emacs. |
5 | |
6 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
7 ;; it under the terms of the GNU General Public License as published by | |
8 ;; the Free Software Foundation; either version 2, or (at your option) | |
9 ;; any later version. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 ;; GNU General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | |
20 | |
21 (require 'viper-util) | |
22 | |
23 | |
24 ;;; Variables | |
25 | |
26 ;; Variable used for catching the switch-frame event. | |
27 ;; If non-nil, indicates that previous-frame should be the selected | |
28 ;; one. Used by vip-mouse-click-get-word. Not a user option. | |
29 (defvar vip-frame-of-focus nil) | |
30 | |
31 ;; Frame that was selected before the switch-frame event. | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
32 (defconst vip-current-frame-saved (selected-frame)) |
10789 | 33 |
34 (defvar vip-surrounding-word-function 'vip-surrounding-word | |
35 "*Function that determines what constitutes a word for clicking events. | |
36 Takes two parameters: a COUNT, indicating how many words to return, | |
37 and CLICK-COUNT, telling whether this is the first click, a double-click, | |
38 or a tripple-click.") | |
39 | |
40 ;; time interval in millisecond within which successive clicks are | |
41 ;; considered related | |
42 (defconst vip-multiclick-timeout (if vip-xemacs-p | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
43 mouse-track-multi-click-time |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
44 double-click-time) |
10789 | 45 "*Time interval in millisecond within which successive clicks are |
46 considered related.") | |
47 | |
48 ;; current event click count; XEmacs only | |
49 (defvar vip-current-click-count 0) | |
50 ;; time stamp of the last click event; XEmacs only | |
51 (defvar vip-last-click-event-timestamp 0) | |
52 | |
53 ;; Local variable used to toggle wraparound search on click. | |
54 (vip-deflocalvar vip-mouse-click-search-noerror t) | |
55 | |
56 ;; Local variable used to delimit search after wraparound. | |
57 (vip-deflocalvar vip-mouse-click-search-limit nil) | |
58 | |
59 ;; remembers prefix argument to pass along to commands invoked by second | |
60 ;; click. | |
61 ;; This is needed because in Emacs (not XEmacs), assigning to preix-arg | |
62 ;; causes Emacs to count the second click as if it was a single click | |
63 (defvar vip-global-prefix-argument nil) | |
64 | |
65 | |
66 | |
67 ;;; Code | |
68 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
69 (defsubst vip-multiclick-p () |
10789 | 70 (not (vip-sit-for-short vip-multiclick-timeout t))) |
71 | |
72 (defun vip-surrounding-word (count click-count) | |
73 "Returns word surrounding point according to a heuristic. | |
74 COUNT indicates how many regions to return. | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
75 If CLICK-COUNT is 1, `word' is a word in Vi sense. |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
76 If CLICK-COUNT is 2,then `word' is a Word in Vi sense. |
10789 | 77 If the character clicked on is a non-separator and is non-alphanumeric but |
78 is adjacent to an alphanumeric symbol, then it is considered alphanumeric | |
79 for the purpose of this command. If this character has a matching | |
80 character, such as `\(' is a match for `\)', then the matching character is | |
81 also considered alphanumeric. | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
82 For convenience, in Lisp modes, `-' is considered alphanumeric. |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
83 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
84 If CLICK-COUNT is 3 or more, returns the line clicked on with leading and |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
85 trailing space and tabs removed. In that case, the first argument, COUNT, |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
86 is ignored." |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
87 (if (> click-count 2) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
88 (let (beg) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
89 (save-excursion |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
90 (beginning-of-line) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
91 (skip-chars-forward " \t") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
92 (setq beg (point)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
93 (end-of-line) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
94 (buffer-substring beg (point)))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
95 (let* ((basic-alpha "_a-zA-Z0-9") ;; it is important for `_' to come first |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
96 (basic-alpha-B "[_a-zA-Z0-9]") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
97 (basic-nonalphasep-B vip-NONALPHASEP-B) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
98 (end-modifiers "") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
99 (start-modifiers "") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
100 vip-ALPHA vip-ALPHA-B |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
101 vip-NONALPHA vip-NONALPHA-B |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
102 vip-ALPHASEP vip-ALPHASEP-B |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
103 vip-NONALPHASEP vip-NONALPHASEP-B |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
104 skip-flag |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
105 one-char-word-func word-function-forw word-function-back word-beg) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
106 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
107 (if (and (looking-at basic-nonalphasep-B) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
108 (or (save-excursion (vip-backward-char-carefully) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
109 (looking-at basic-alpha-B)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
110 (save-excursion (vip-forward-char-carefully) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
111 (looking-at basic-alpha-B)))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
112 (setq start-modifiers |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
113 (cond ((looking-at "\\\\") "\\\\") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
114 ((looking-at "-") "") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
115 ((looking-at "[][]") "][") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
116 ((looking-at "[()]") ")(") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
117 ((looking-at "[{}]") "{}") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
118 ((looking-at "[<>]") "<>") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
119 ((looking-at "[`']") "`'") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
120 ((looking-at "\\^") "") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
121 ((looking-at vip-SEP-B) "") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
122 (t (char-to-string (following-char)))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
123 end-modifiers |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
124 (cond ((looking-at "-") "C-C-") ;; note the C-C trick |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
125 ((looking-at "\\^") "^") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
126 (t "")))) |
10789 | 127 |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
128 ;; Add `-' to alphanum, if it wasn't added and in we are in Lisp |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
129 (or (looking-at "-") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
130 (not (string-match "lisp" (symbol-name major-mode))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
131 (setq end-modifiers (concat end-modifiers "C-C-"))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
132 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
133 (setq vip-ALPHA |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
134 (format "%s%s%s" start-modifiers basic-alpha end-modifiers) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
135 vip-ALPHA-B |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
136 (format "[%s%s%s]" start-modifiers basic-alpha end-modifiers) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
137 vip-NONALPHA (concat "^" vip-ALPHA) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
138 vip-NONALPHA-B (concat "[" vip-NONALPHA "]") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
139 vip-ALPHASEP (concat vip-ALPHA vip-SEP) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
140 vip-ALPHASEP-B |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
141 (format "[%s%s%s%s]" |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
142 start-modifiers basic-alpha vip-SEP end-modifiers) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
143 vip-NONALPHASEP (format "^%s%s" vip-SEP vip-ALPHA) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
144 vip-NONALPHASEP-B (format "[^%s%s]" vip-SEP vip-ALPHA) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
145 ) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
146 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
147 (if (> click-count 1) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
148 (setq one-char-word-func 'vip-one-char-Word-p |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
149 word-function-forw 'vip-end-of-Word |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
150 word-function-back 'vip-backward-Word) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
151 (setq one-char-word-func 'vip-one-char-word-p |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
152 word-function-forw 'vip-end-of-word |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
153 word-function-back 'vip-backward-word)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
154 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
155 (save-excursion |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
156 (cond ((> click-count 1) (skip-chars-backward vip-NONSEP)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
157 ((looking-at vip-ALPHA-B) (skip-chars-backward vip-ALPHA)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
158 ((looking-at vip-NONALPHASEP-B) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
159 (skip-chars-backward vip-NONALPHASEP)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
160 (t (funcall word-function-back 1))) |
10789 | 161 |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
162 (setq word-beg (point)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
163 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
164 (setq skip-flag t) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
165 (while (> count 0) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
166 ;; skip-flag and the test for 1-char word takes care of the |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
167 ;; special treatment that vip-end-of-word gives to 1-character |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
168 ;; words. Otherwise, clicking once on such a word will insert two |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
169 ;; words. |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
170 (if (and skip-flag (funcall one-char-word-func)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
171 (setq skip-flag (not skip-flag)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
172 (funcall word-function-forw 1)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
173 (setq count (1- count))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
174 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
175 (vip-forward-char-carefully) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
176 (buffer-substring word-beg (point))) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
177 ))) |
10789 | 178 |
179 | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
180 (defun vip-mouse-click-get-word (click count click-count) |
10789 | 181 "Returns word surrounding the position of a mouse click. |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
182 Click may be in another window. Current window and buffer isn't changed. |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
183 On single or double click, returns the word as determined by |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
184 `vip-surrounding-word-function'." |
10789 | 185 |
186 (let ((click-word "") | |
187 (click-pos (vip-mouse-click-posn click)) | |
188 (click-buf (vip-mouse-click-window-buffer click))) | |
189 (or (numberp count) (setq count 1)) | |
190 (or (numberp click-count) (setq click-count 1)) | |
191 | |
192 (save-excursion | |
193 (save-window-excursion | |
194 (if click-pos | |
195 (progn | |
196 (set-buffer click-buf) | |
197 | |
198 (goto-char click-pos) | |
199 (setq click-word | |
200 (funcall vip-surrounding-word-function count click-count))) | |
201 (error "Click must be over a window.")) | |
202 click-word)))) | |
203 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
204 ;; Returns window where click occurs |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
205 (defsubst vip-mouse-click-frame (click) |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
206 (window-frame (vip-mouse-click-window click))) |
10789 | 207 |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
208 ;; Returns window where click occurs |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
209 (defsubst vip-mouse-click-window (click) |
10789 | 210 (if vip-xemacs-p |
211 (event-window click) | |
212 (posn-window (event-start click)))) | |
213 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
214 ;; Returns the buffer of the window where click occurs |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
215 (defsubst vip-mouse-click-window-buffer (click) |
10789 | 216 (window-buffer (vip-mouse-click-window click))) |
217 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
218 ;; Returns the name of the buffer in the window where click occurs |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
219 (defsubst vip-mouse-click-window-buffer-name (click) |
10789 | 220 (buffer-name (vip-mouse-click-window-buffer click))) |
221 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
222 ;; Returns position of a click |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
223 (defsubst vip-mouse-click-posn (click) |
10789 | 224 (if vip-xemacs-p |
225 (event-point click) | |
226 (posn-point (event-start click)))) | |
227 | |
228 (defun vip-mouse-click-insert-word (click arg) | |
229 "Insert word clicked or double-clicked on. | |
230 With prefix argument, N, insert that many words. | |
231 This command must be bound to a mouse click. | |
232 The double-click action of the same mouse button must not be bound | |
233 \(or it must be bound to the same function\). | |
234 See `vip-surrounding-word' for the definition of a word in this case." | |
235 (interactive "e\nP") | |
236 (if vip-frame-of-focus ;; to handle clicks in another frame | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
237 (select-frame vip-frame-of-focus)) |
10789 | 238 |
239 ;; turn arg into a number | |
240 (cond ((numberp arg) nil) | |
241 ;; prefix arg is a list when one hits C-u then command | |
242 ((and (listp arg) (numberp (car arg))) | |
243 (setq arg (car arg))) | |
244 (t (setq arg 1))) | |
245 | |
246 (let (click-count interrupting-event) | |
247 (if (and | |
248 (vip-multiclick-p) | |
249 ;; This trick checks if there is a pending mouse event | |
250 ;; if so, we use this latter event and discard the current mouse click | |
251 ;; If the next panding event is not a mouse event, we execute | |
252 ;; the current mouse event | |
253 (progn | |
254 (setq interrupting-event (vip-read-event)) | |
255 (vip-mouse-event-p last-input-event))) | |
256 (progn ;; interrupted wait | |
257 (setq vip-global-prefix-argument arg) | |
258 ;; count this click for XEmacs | |
259 (vip-event-click-count click)) | |
260 ;; uninterrupted wait or the interrupting event wasn't a mouse event | |
261 (setq click-count (vip-event-click-count click)) | |
262 (if (> click-count 1) | |
263 (setq arg vip-global-prefix-argument | |
264 vip-global-prefix-argument nil)) | |
265 (insert (vip-mouse-click-get-word click arg click-count)) | |
266 (if (and interrupting-event | |
267 (eventp interrupting-event) | |
268 (not (vip-mouse-event-p interrupting-event))) | |
269 (vip-set-unread-command-events interrupting-event)) | |
270 ))) | |
271 | |
272 ;; arg is an event. accepts symbols and numbers, too | |
273 (defun vip-mouse-event-p (event) | |
274 (if (eventp event) | |
275 (string-match "\\(mouse-\\|frame\\|screen\\|track\\)" | |
276 (prin1-to-string (vip-event-key event))))) | |
277 | |
278 ;; XEmacs has no double-click events. So, we must simulate. | |
279 ;; So, we have to simulate event-click-count. | |
280 (defun vip-event-click-count (click) | |
281 (if vip-xemacs-p | |
282 (progn | |
283 ;; if more than 1 second | |
284 (if (> (- (event-timestamp click) vip-last-click-event-timestamp) | |
285 vip-multiclick-timeout) | |
286 (setq vip-current-click-count 0)) | |
287 (setq vip-last-click-event-timestamp (event-timestamp click) | |
288 vip-current-click-count (1+ vip-current-click-count))) | |
289 (event-click-count click))) | |
290 | |
291 | |
292 | |
293 (defun vip-mouse-click-search-word (click arg) | |
294 "Find the word clicked or double-clicked on. Word may be in another window. | |
295 With prefix argument, N, search for N-th occurrence. | |
296 This command must be bound to a mouse click. The double-click action of the | |
297 same button must not be bound \(or it must be bound to the same function\). | |
298 See `vip-surrounding-word' for the details on what constitutes a word for | |
299 this command." | |
300 (interactive "e\nP") | |
301 (if vip-frame-of-focus ;; to handle clicks in another frame | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
302 (select-frame vip-frame-of-focus)) |
10789 | 303 (let (click-word click-count |
304 (previous-search-string vip-s-string)) | |
305 | |
306 (if (and | |
307 (vip-multiclick-p) | |
308 ;; This trick checks if there is a pending mouse event | |
309 ;; if so, we use this latter event and discard the current mouse click | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
310 ;; If the next pending event is not a mouse event, we execute |
10789 | 311 ;; the current mouse event |
312 (progn | |
313 (vip-read-event) | |
314 (vip-mouse-event-p last-input-event))) | |
315 (progn ;; interrupted wait | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
316 (setq vip-global-prefix-argument |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
317 (or vip-global-prefix-argument arg)) |
10789 | 318 ;; remember command that was before the multiclick |
319 (setq this-command last-command) | |
320 ;; make sure we counted this event---needed for XEmacs only | |
321 (vip-event-click-count click)) | |
322 ;; uninterrupted wait | |
323 (setq click-count (vip-event-click-count click)) | |
324 (setq click-word (vip-mouse-click-get-word click nil click-count)) | |
325 | |
326 (if (> click-count 1) | |
327 (setq arg vip-global-prefix-argument | |
328 vip-global-prefix-argument nil)) | |
329 (setq arg (or arg 1)) | |
330 | |
331 (vip-deactivate-mark) | |
332 (if (or (not (string= click-word vip-s-string)) | |
333 (not (markerp vip-search-start-marker)) | |
334 (not (equal (marker-buffer vip-search-start-marker) | |
335 (current-buffer))) | |
336 (not (eq last-command 'vip-mouse-click-search-word))) | |
337 (progn | |
338 (setq vip-search-start-marker (point-marker) | |
339 vip-local-search-start-marker vip-search-start-marker | |
340 vip-mouse-click-search-noerror t | |
341 vip-mouse-click-search-limit nil) | |
342 | |
343 ;; make search string known to Viper | |
344 (setq vip-s-string (if vip-re-search | |
345 (regexp-quote click-word) | |
346 click-word)) | |
347 (if (not (string= vip-s-string (car vip-search-history))) | |
348 (setq vip-search-history | |
349 (cons vip-s-string vip-search-history))) | |
350 )) | |
351 | |
352 (push-mark nil t) | |
353 (while (> arg 0) | |
354 (vip-forward-word 1) | |
355 (condition-case nil | |
356 (progn | |
357 (if (not (search-forward click-word vip-mouse-click-search-limit | |
358 vip-mouse-click-search-noerror)) | |
359 (progn | |
360 (setq vip-mouse-click-search-noerror nil) | |
361 (setq vip-mouse-click-search-limit | |
362 (save-excursion | |
363 (if (and | |
364 (markerp vip-local-search-start-marker) | |
365 (marker-buffer vip-local-search-start-marker)) | |
366 (goto-char vip-local-search-start-marker)) | |
367 (vip-line-pos 'end))) | |
368 | |
369 (goto-char (point-min)) | |
370 (search-forward click-word | |
371 vip-mouse-click-search-limit nil))) | |
372 (goto-char (match-beginning 0)) | |
373 (message "Searching for: %s" vip-s-string) | |
374 (if (<= arg 1) | |
375 (vip-flash-search-pattern)) | |
376 ) | |
377 (error (beep 1) | |
378 (if (or (not (string= click-word previous-search-string)) | |
379 (not (eq last-command 'vip-mouse-click-search-word))) | |
380 (message "`%s': String not found in %s" | |
381 vip-s-string (buffer-name (current-buffer))) | |
382 (message | |
383 "`%s': Last occurrence in %s. Back to beginning of search" | |
384 click-word (buffer-name (current-buffer))) | |
385 (setq arg 1) ;; to terminate the loop | |
386 (sit-for 2)) | |
387 (setq vip-mouse-click-search-noerror t) | |
388 (setq vip-mouse-click-search-limit nil) | |
389 (if (and (markerp vip-local-search-start-marker) | |
390 (marker-buffer vip-local-search-start-marker)) | |
391 (goto-char vip-local-search-start-marker)))) | |
392 (setq arg (1- arg))) | |
393 ))) | |
394 | |
395 (defun vip-mouse-catch-frame-switch (event arg) | |
396 "Catch the event of switching frame. | |
397 Usually is bound to a 'down-mouse' event to work properly. See sample | |
398 bindings in viper.el and in the Viper manual." | |
399 (interactive "e\nP") | |
400 (setq vip-frame-of-focus nil) | |
401 ;; pass prefix arg along to vip-mouse-click-search/insert-word | |
402 (setq prefix-arg arg) | |
403 (if (eq last-command 'handle-switch-frame) | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
404 (setq vip-frame-of-focus vip-current-frame-saved)) |
10789 | 405 ;; make Emacs forget that it executed vip-mouse-catch-frame-switch |
406 (setq this-command last-command)) | |
407 | |
408 ;; Called just before switching frames. Saves the old selected frame. | |
409 ;; Sets last-command to handle-switch-frame (this is done automatically in | |
410 ;; Emacs. | |
411 ;; The semantics of switching frames is different in Emacs and XEmacs. | |
412 ;; In Emacs, if you select-frame A while mouse is over frame B and then | |
413 ;; start typing, input goes to frame B, which becomes selected. | |
414 ;; In XEmacs, input will go to frame A. This may be a bug in one of the | |
415 ;; Emacsen, but also may be a design decision. | |
416 ;; Also, in Emacs sending input to frame B generates handle-switch-frame | |
417 ;; event, while in XEmacs it doesn't. | |
418 ;; All this accounts for the difference in the behavior of | |
419 ;; vip-mouse-click-* commands when you click in a frame other than the one | |
420 ;; that was the last to receive input. In Emacs, focus will be in frame A | |
421 ;; until you do something other than vip-mouse-click-* command. | |
422 ;; In XEmacs, you have to manually select frame B (with the mouse click) in | |
423 ;; order to shift focus to frame B. | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
424 (defsubst vip-remember-current-frame (frame) |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
425 (setq last-command 'handle-switch-frame |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
426 vip-current-frame-saved (selected-frame))) |
10789 | 427 |
428 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
429 (cond ((vip-window-display-p) |
10789 | 430 (let* ((search-key (if vip-xemacs-p [(meta button1up)] [S-mouse-1])) |
431 (search-key-catch (if vip-xemacs-p | |
432 [(meta button1)] [S-down-mouse-1])) | |
433 (insert-key (if vip-xemacs-p [(meta button2up)] [S-mouse-2])) | |
434 (insert-key-catch (if vip-xemacs-p | |
435 [(meta button2)] [S-down-mouse-2])) | |
436 (search-key-unbound (and (not (key-binding search-key)) | |
437 (not (key-binding search-key-catch)))) | |
438 (insert-key-unbound (and (not (key-binding insert-key)) | |
439 (not (key-binding insert-key-catch)))) | |
440 ) | |
441 | |
442 (if search-key-unbound | |
443 (global-set-key search-key 'vip-mouse-click-search-word)) | |
444 (if insert-key-unbound | |
445 (global-set-key insert-key 'vip-mouse-click-insert-word)) | |
446 | |
447 ;; The following would be needed if you want to use the above two | |
448 ;; while clicking in another frame. If you only want to use them | |
449 ;; by clicking in another window, not frame, the bindings below | |
450 ;; aren't necessary. | |
451 | |
452 ;; These must be bound to mouse-down event for the same mouse | |
453 ;; buttons as 'vip-mouse-click-search-word and | |
454 ;; 'vip-mouse-click-insert-word | |
455 (if search-key-unbound | |
456 (global-set-key search-key-catch 'vip-mouse-catch-frame-switch)) | |
457 (if insert-key-unbound | |
458 (global-set-key insert-key-catch 'vip-mouse-catch-frame-switch)) | |
459 | |
460 (if vip-xemacs-p | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
461 (add-hook 'mouse-leave-frame-hook |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
462 'vip-remember-current-frame) |
10789 | 463 (defadvice handle-switch-frame (before vip-frame-advice activate) |
464 "Remember the selected frame before the switch-frame event." | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
465 (vip-remember-current-frame (selected-frame)))) |
10789 | 466 ))) |
467 | |
468 | |
469 | |
470 (provide 'viper-mous) | |
471 | |
472 ;;; viper-mous.el ends here |