Mercurial > emacs
annotate lisp/emulation/viper-mous.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | 22c1e47f66e1 |
children | 3a37d4348914 |
rev | line source |
---|---|
13337 | 1 ;;; viper-mous.el --- mouse support for Viper |
2 | |
18047 | 3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
11288 | 4 |
10789 | 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 | |
14169 | 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. | |
10789 | 21 |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14586
diff
changeset
|
22 ;; Code |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14586
diff
changeset
|
23 |
18047 | 24 (provide 'viper-mous) |
10789 | 25 |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14586
diff
changeset
|
26 ;; compiler pacifier |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14586
diff
changeset
|
27 (defvar double-click-time) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14586
diff
changeset
|
28 (defvar mouse-track-multi-click-time) |
19079 | 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) | |
18047 | 34 |
18172 | 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 ))) | |
18047 | 45 ;; end pacifier |
46 | |
47 (require 'viper-util) | |
48 | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14586
diff
changeset
|
49 |
18839 | 50 (defgroup viper-mouse nil |
51 "Support for Viper special mouse-bound commands" | |
19079 | 52 :prefix "viper-" |
18839 | 53 :group 'viper) |
54 | |
10789 | 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 | |
19079 | 60 ;; one. Used by viper-mouse-click-get-word. Not a user option. |
61 (defvar viper-frame-of-focus nil) | |
10789 | 62 |
63 ;; Frame that was selected before the switch-frame event. | |
19079 | 64 (defconst viper-current-frame-saved (selected-frame)) |
10789 | 65 |
19079 | 66 (defcustom viper-surrounding-word-function 'viper-surrounding-word |
10789 | 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, | |
18839 | 70 or a tripple-click." |
71 :type 'boolean | |
72 :group 'viper-mouse) | |
10789 | 73 |
74 ;; time interval in millisecond within which successive clicks are | |
75 ;; considered related | |
19079 | 76 (defcustom viper-multiclick-timeout (if (viper-window-display-p) |
77 (if viper-xemacs-p | |
18839 | 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) | |
10789 | 85 |
86 ;; current event click count; XEmacs only | |
19079 | 87 (defvar viper-current-click-count 0) |
10789 | 88 ;; time stamp of the last click event; XEmacs only |
19079 | 89 (defvar viper-last-click-event-timestamp 0) |
10789 | 90 |
91 ;; Local variable used to toggle wraparound search on click. | |
19079 | 92 (viper-deflocalvar viper-mouse-click-search-noerror t) |
10789 | 93 |
94 ;; Local variable used to delimit search after wraparound. | |
19079 | 95 (viper-deflocalvar viper-mouse-click-search-limit nil) |
10789 | 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 | |
19079 | 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 | |
10789 | 110 |
111 | |
112 | |
113 ;;; Code | |
114 | |
19079 | 115 (defsubst viper-multiclick-p () |
116 (not (viper-sit-for-short viper-multiclick-timeout t))) | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
117 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
118 ;; Returns window where click occurs |
19079 | 119 (defsubst viper-mouse-click-window (click) |
120 (if viper-xemacs-p | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
121 (event-window click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
122 (posn-window (event-start click)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
123 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
124 ;; Returns window where click occurs |
19079 | 125 (defsubst viper-mouse-click-frame (click) |
126 (window-frame (viper-mouse-click-window click))) | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
127 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
128 ;; Returns the buffer of the window where click occurs |
19079 | 129 (defsubst viper-mouse-click-window-buffer (click) |
130 (window-buffer (viper-mouse-click-window click))) | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
131 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
132 ;; Returns the name of the buffer in the window where click occurs |
19079 | 133 (defsubst viper-mouse-click-window-buffer-name (click) |
134 (buffer-name (viper-mouse-click-window-buffer click))) | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
135 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
136 ;; Returns position of a click |
19079 | 137 (defsubst viper-mouse-click-posn (click) |
138 (if viper-xemacs-p | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
139 (event-point click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
140 (posn-point (event-start click)))) |
10789 | 141 |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
142 |
19079 | 143 (defun viper-surrounding-word (count click-count) |
10789 | 144 "Returns word surrounding point according to a heuristic. |
145 COUNT indicates how many regions to return. | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
146 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
|
147 If CLICK-COUNT is 2,then `word' is a Word in Vi sense. |
10789 | 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. | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
153 For convenience, in Lisp modes, `-' is considered alphanumeric. |
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 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
|
156 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
|
157 is ignored." |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
158 (let ((modifiers "") |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
159 beg skip-flag result |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
160 word-beg) |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
161 (if (> click-count 2) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
162 (save-excursion |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
163 (beginning-of-line) |
19079 | 164 (viper-skip-all-separators-forward 'within-line) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
165 (setq beg (point)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
166 (end-of-line) |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
167 (setq result (buffer-substring beg (point)))) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
168 |
19079 | 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)))) | |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
174 (setq modifiers |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
175 (cond ((looking-at "\\\\") "\\\\") |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
176 ((looking-at "-") "C-C-") |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
177 ((looking-at "[][]") "][") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
178 ((looking-at "[()]") ")(") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
179 ((looking-at "[{}]") "{}") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
180 ((looking-at "[<>]") "<>") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
181 ((looking-at "[`']") "`'") |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
182 ((looking-at "\\^") "\\^") |
19079 | 183 ((viper-looking-at-separator) "") |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
184 (t (char-to-string (following-char)))) |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
185 )) |
10789 | 186 |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
187 ;; Add `-' to alphanum, if it wasn't added and if we are in Lisp |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
188 (or (looking-at "-") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
189 (not (string-match "lisp" (symbol-name major-mode))) |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
190 (setq modifiers (concat modifiers "C-C-"))) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
191 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
192 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
193 (save-excursion |
19079 | 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)) | |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
199 (t (if (> click-count 1) |
19079 | 200 (viper-skip-nonseparators 'backward) |
201 (viper-skip-alpha-backward modifiers)))) | |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
202 |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
203 (setq word-beg (point)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
204 |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
205 (setq skip-flag nil) ; don't move 1 char forw the first time |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
206 (while (> count 0) |
19079 | 207 (if skip-flag (viper-forward-char-carefully 1)) |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
208 (setq skip-flag t) ; now always move 1 char forward |
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
209 (if (> click-count 1) |
19079 | 210 (viper-skip-nonseparators 'forward) |
211 (viper-skip-alpha-forward modifiers)) | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
212 (setq count (1- count))) |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
213 |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
214 (setq result (buffer-substring word-beg (point)))) |
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
215 ) ; if |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
216 ;; XEmacs doesn't have set-text-properties, but there buffer-substring |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
217 ;; doesn't return properties together with the string, so it's not needed. |
19079 | 218 (if viper-emacs-p |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
219 (set-text-properties 0 (length result) nil result)) |
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
220 result |
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
221 )) |
10789 | 222 |
223 | |
19079 | 224 (defun viper-mouse-click-get-word (click count click-count) |
10789 | 225 "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
|
226 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
|
227 On single or double click, returns the word as determined by |
19079 | 228 `viper-surrounding-word-function'." |
10789 | 229 |
230 (let ((click-word "") | |
19079 | 231 (click-pos (viper-mouse-click-posn click)) |
232 (click-buf (viper-mouse-click-window-buffer click))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
233 (or (natnump count) (setq count 1)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
234 (or (natnump click-count) (setq click-count 1)) |
10789 | 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 | |
19079 | 244 (funcall viper-surrounding-word-function count click-count))) |
10789 | 245 (error "Click must be over a window.")) |
246 click-word)))) | |
247 | |
248 | |
19079 | 249 (defun viper-mouse-click-insert-word (click arg) |
10789 | 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\). | |
19079 | 255 See `viper-surrounding-word' for the definition of a word in this case." |
10789 | 256 (interactive "e\nP") |
19079 | 257 (if viper-frame-of-focus ;; to handle clicks in another frame |
258 (select-frame viper-frame-of-focus)) | |
19756 | 259 (if (or (not (eq (key-binding viper-mouse-down-insert-key-parsed) |
260 'viper-mouse-catch-frame-switch)) | |
261 (not (eq (key-binding viper-mouse-up-insert-key-parsed) | |
262 'viper-mouse-click-insert-word)) | |
263 (and viper-xemacs-p (not (event-over-text-area-p click)))) | |
264 () ; do nothing, if binding isn't right or not over text | |
265 ;; turn arg into a number | |
266 (cond ((integerp arg) nil) | |
267 ;; prefix arg is a list when one hits C-u then command | |
268 ((and (listp arg) (integerp (car arg))) | |
269 (setq arg (car arg))) | |
270 (t (setq arg 1))) | |
271 | |
272 (if (not (eq (key-binding viper-mouse-down-insert-key-parsed) | |
273 'viper-mouse-catch-frame-switch)) | |
274 () ; do nothing | |
275 (let (click-count interrupting-event) | |
276 (if (and | |
277 (viper-multiclick-p) | |
278 ;; This trick checks if there is a pending mouse event if so, we | |
279 ;; use this latter event and discard the current mouse click If | |
280 ;; the next pending event is not a mouse event, we execute the | |
281 ;; current mouse event | |
282 (progn | |
283 (setq interrupting-event (viper-read-event)) | |
284 (viper-mouse-event-p last-input-event))) | |
285 (progn ; interrupted wait | |
286 (setq viper-global-prefix-argument arg) | |
287 ;; count this click for XEmacs | |
288 (viper-event-click-count click)) | |
289 ;; uninterrupted wait or the interrupting event wasn't a mouse event | |
290 (setq click-count (viper-event-click-count click)) | |
291 (if (> click-count 1) | |
292 (setq arg viper-global-prefix-argument | |
293 viper-global-prefix-argument nil)) | |
294 (insert (viper-mouse-click-get-word click arg click-count)) | |
295 (if (and interrupting-event | |
296 (eventp interrupting-event) | |
297 (not (viper-mouse-event-p interrupting-event))) | |
298 (viper-set-unread-command-events interrupting-event)) | |
299 ))))) | |
10789 | 300 |
301 ;; arg is an event. accepts symbols and numbers, too | |
19079 | 302 (defun viper-mouse-event-p (event) |
10789 | 303 (if (eventp event) |
304 (string-match "\\(mouse-\\|frame\\|screen\\|track\\)" | |
19079 | 305 (prin1-to-string (viper-event-key event))))) |
10789 | 306 |
307 ;; XEmacs has no double-click events. So, we must simulate. | |
308 ;; So, we have to simulate event-click-count. | |
19079 | 309 (defun viper-event-click-count (click) |
310 (if viper-xemacs-p | |
10789 | 311 (progn |
312 ;; if more than 1 second | |
19079 | 313 (if (> (- (event-timestamp click) viper-last-click-event-timestamp) |
314 viper-multiclick-timeout) | |
315 (setq viper-current-click-count 0)) | |
316 (setq viper-last-click-event-timestamp (event-timestamp click) | |
317 viper-current-click-count (1+ viper-current-click-count))) | |
10789 | 318 (event-click-count click))) |
319 | |
320 | |
321 | |
19079 | 322 (defun viper-mouse-click-search-word (click arg) |
10789 | 323 "Find the word clicked or double-clicked on. Word may be in another window. |
324 With prefix argument, N, search for N-th occurrence. | |
325 This command must be bound to a mouse click. The double-click action of the | |
326 same button must not be bound \(or it must be bound to the same function\). | |
19079 | 327 See `viper-surrounding-word' for the details on what constitutes a word for |
10789 | 328 this command." |
329 (interactive "e\nP") | |
19079 | 330 (if viper-frame-of-focus ;; to handle clicks in another frame |
331 (select-frame viper-frame-of-focus)) | |
19756 | 332 (if (or (not (eq (key-binding viper-mouse-down-search-key-parsed) |
333 'viper-mouse-catch-frame-switch)) | |
334 (not (eq (key-binding viper-mouse-up-search-key-parsed) | |
335 'viper-mouse-click-search-word)) | |
336 (and viper-xemacs-p (not (event-over-text-area-p click)))) | |
337 () ; do nothing, if binding isn't right or not over text | |
19079 | 338 (let ((previous-search-string viper-s-string) |
339 click-word click-count) | |
10789 | 340 |
19079 | 341 (if (and |
342 (viper-multiclick-p) | |
343 ;; This trick checks if there is a pending mouse event if so, we use | |
344 ;; this latter event and discard the current mouse click If the next | |
345 ;; pending event is not a mouse event, we execute the current mouse | |
346 ;; event | |
347 (progn | |
348 (viper-read-event) | |
349 (viper-mouse-event-p last-input-event))) | |
350 (progn ; interrupted wait | |
351 (setq viper-global-prefix-argument | |
352 (or viper-global-prefix-argument arg)) | |
353 ;; remember command that was before the multiclick | |
354 (setq this-command last-command) | |
355 ;; make sure we counted this event---needed for XEmacs only | |
356 (viper-event-click-count click)) | |
357 ;; uninterrupted wait | |
358 (setq click-count (viper-event-click-count click)) | |
359 (setq click-word (viper-mouse-click-get-word click nil click-count)) | |
360 | |
361 (if (> click-count 1) | |
362 (setq arg viper-global-prefix-argument | |
363 viper-global-prefix-argument nil)) | |
364 (setq arg (or arg 1)) | |
365 | |
366 (viper-deactivate-mark) | |
367 (if (or (not (string= click-word viper-s-string)) | |
368 (not (markerp viper-search-start-marker)) | |
369 (not (equal (marker-buffer viper-search-start-marker) | |
370 (current-buffer))) | |
371 (not (eq last-command 'viper-mouse-click-search-word))) | |
10789 | 372 (progn |
19079 | 373 (setq viper-search-start-marker (point-marker) |
374 viper-local-search-start-marker viper-search-start-marker | |
375 viper-mouse-click-search-noerror t | |
376 viper-mouse-click-search-limit nil) | |
377 | |
378 ;; make search string known to Viper | |
379 (setq viper-s-string (if viper-re-search | |
380 (regexp-quote click-word) | |
381 click-word)) | |
382 (if (not (string= viper-s-string (car viper-search-history))) | |
383 (setq viper-search-history | |
384 (cons viper-s-string viper-search-history))) | |
385 )) | |
386 | |
387 (push-mark nil t) | |
388 (while (> arg 0) | |
389 (viper-forward-word 1) | |
390 (condition-case nil | |
391 (progn | |
392 (if (not (search-forward | |
393 click-word viper-mouse-click-search-limit | |
394 viper-mouse-click-search-noerror)) | |
395 (progn | |
396 (setq viper-mouse-click-search-noerror nil) | |
397 (setq viper-mouse-click-search-limit | |
398 (save-excursion | |
399 (if (and | |
400 (markerp viper-local-search-start-marker) | |
401 (marker-buffer viper-local-search-start-marker)) | |
402 (goto-char viper-local-search-start-marker)) | |
403 (viper-line-pos 'end))) | |
404 | |
405 (goto-char (point-min)) | |
406 (search-forward click-word | |
407 viper-mouse-click-search-limit nil))) | |
408 (goto-char (match-beginning 0)) | |
409 (message "Searching for: %s" viper-s-string) | |
410 (if (<= arg 1) ; found the right occurrence of the pattern | |
411 (progn | |
412 (viper-adjust-window) | |
413 (viper-flash-search-pattern))) | |
414 ) | |
415 (error (beep 1) | |
416 (if (or (not (string= click-word previous-search-string)) | |
417 (not (eq last-command 'viper-mouse-click-search-word))) | |
418 (message "`%s': String not found in %s" | |
419 viper-s-string (buffer-name (current-buffer))) | |
420 (message | |
421 "`%s': Last occurrence in %s. Back to beginning of search" | |
422 click-word (buffer-name (current-buffer))) | |
423 (setq arg 1) ;; to terminate the loop | |
424 (sit-for 2)) | |
425 (setq viper-mouse-click-search-noerror t) | |
426 (setq viper-mouse-click-search-limit nil) | |
427 (if (and (markerp viper-local-search-start-marker) | |
428 (marker-buffer viper-local-search-start-marker)) | |
429 (goto-char viper-local-search-start-marker)))) | |
430 (setq arg (1- arg))) | |
431 )))) | |
10789 | 432 |
19079 | 433 (defun viper-mouse-catch-frame-switch (event arg) |
10789 | 434 "Catch the event of switching frame. |
19203 | 435 Usually is bound to a `down-mouse' event to work properly. See sample |
18129 | 436 bindings in the Viper manual." |
10789 | 437 (interactive "e\nP") |
19079 | 438 (setq viper-frame-of-focus nil) |
439 ;; pass prefix arg along to viper-mouse-click-search/insert-word | |
10789 | 440 (setq prefix-arg arg) |
441 (if (eq last-command 'handle-switch-frame) | |
19079 | 442 (setq viper-frame-of-focus viper-current-frame-saved)) |
443 ;; make Emacs forget that it executed viper-mouse-catch-frame-switch | |
10789 | 444 (setq this-command last-command)) |
445 | |
446 ;; Called just before switching frames. Saves the old selected frame. | |
447 ;; Sets last-command to handle-switch-frame (this is done automatically in | |
448 ;; Emacs. | |
449 ;; The semantics of switching frames is different in Emacs and XEmacs. | |
450 ;; In Emacs, if you select-frame A while mouse is over frame B and then | |
451 ;; start typing, input goes to frame B, which becomes selected. | |
452 ;; In XEmacs, input will go to frame A. This may be a bug in one of the | |
453 ;; Emacsen, but also may be a design decision. | |
454 ;; Also, in Emacs sending input to frame B generates handle-switch-frame | |
455 ;; event, while in XEmacs it doesn't. | |
456 ;; All this accounts for the difference in the behavior of | |
19079 | 457 ;; viper-mouse-click-* commands when you click in a frame other than the one |
10789 | 458 ;; that was the last to receive input. In Emacs, focus will be in frame A |
19079 | 459 ;; until you do something other than viper-mouse-click-* command. |
10789 | 460 ;; In XEmacs, you have to manually select frame B (with the mouse click) in |
461 ;; order to shift focus to frame B. | |
19079 | 462 (defsubst viper-remember-current-frame (frame) |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
463 (setq last-command 'handle-switch-frame |
19079 | 464 viper-current-frame-saved (selected-frame))) |
465 | |
466 | |
467 ;; The key is of the form (MODIFIER ... BUTTON-NUMBER) | |
468 ;; Converts into a valid mouse button spec for the appropriate version of | |
469 ;; Emacs. EVENT-TYPE is either `up' or `down'. Up returns button-up key; down | |
470 ;; returns button-down key. | |
471 (defun viper-parse-mouse-key (key-var event-type) | |
472 (let ((key (eval key-var)) | |
473 button-spec meta-spec shift-spec control-spec key-spec) | |
474 (if (null key) | |
475 ;; just return nil | |
476 () | |
477 (setq button-spec | |
478 (cond ((memq 1 key) | |
479 (if viper-emacs-p | |
480 (if (eq 'up event-type) | |
481 "mouse-1" "down-mouse-1") | |
482 (if (eq 'up event-type) | |
483 'button1up 'button1))) | |
484 ((memq 2 key) | |
485 (if viper-emacs-p | |
486 (if (eq 'up event-type) | |
487 "mouse-2" "down-mouse-2") | |
488 (if (eq 'up event-type) | |
489 'button2up 'button2))) | |
490 ((memq 3 key) | |
491 (if viper-emacs-p | |
492 (if (eq 'up event-type) | |
493 "mouse-3" "down-mouse-3") | |
494 (if (eq 'up event-type) | |
495 'button3up 'button3))) | |
496 (t (error | |
497 "%S: invalid button number, %S" key-var key))) | |
498 meta-spec | |
499 (if (memq 'meta key) | |
500 (if viper-emacs-p "M-" 'meta) | |
501 (if viper-emacs-p "" nil)) | |
502 shift-spec | |
503 (if (memq 'shift key) | |
504 (if viper-emacs-p "S-" 'shift) | |
505 (if viper-emacs-p "" nil)) | |
506 control-spec | |
507 (if (memq 'control key) | |
508 (if viper-emacs-p "C-" 'control) | |
509 (if viper-emacs-p "" nil))) | |
510 | |
511 (setq key-spec (if viper-emacs-p | |
512 (vector | |
513 (intern | |
514 (concat | |
515 control-spec meta-spec shift-spec button-spec))) | |
516 (vector | |
517 (delq | |
518 nil | |
519 (list | |
520 control-spec meta-spec shift-spec button-spec))))) | |
521 ))) | |
522 | |
523 (defun viper-unbind-mouse-search-key () | |
524 (if viper-mouse-up-search-key-parsed | |
525 (global-unset-key viper-mouse-up-search-key-parsed)) | |
526 (if viper-mouse-down-search-key-parsed | |
527 (global-unset-key viper-mouse-down-search-key-parsed)) | |
528 (setq viper-mouse-up-search-key-parsed nil | |
529 viper-mouse-down-search-key-parsed nil)) | |
530 | |
531 (defun viper-unbind-mouse-insert-key () | |
532 (if viper-mouse-up-insert-key-parsed | |
533 (global-unset-key viper-mouse-up-insert-key-parsed)) | |
534 (if viper-mouse-down-insert-key-parsed | |
535 (global-unset-key viper-mouse-down-insert-key-parsed)) | |
536 (setq viper-mouse-up-insert-key-parsed nil | |
537 viper-mouse-down-insert-key-parsed nil)) | |
538 | |
539 ;; If FORCE, bind even if this mouse action is already bound to something else | |
540 (defun viper-bind-mouse-search-key (&optional force) | |
541 (setq viper-mouse-up-search-key-parsed | |
542 (viper-parse-mouse-key 'viper-mouse-search-key 'up) | |
543 viper-mouse-down-search-key-parsed | |
544 (viper-parse-mouse-key 'viper-mouse-search-key 'down)) | |
545 (cond ((or (null viper-mouse-up-search-key-parsed) | |
546 (null viper-mouse-down-search-key-parsed)) | |
547 nil) ; just quit | |
548 ((and (null force) | |
549 (key-binding viper-mouse-up-search-key-parsed) | |
550 (not (eq (key-binding viper-mouse-up-search-key-parsed) | |
551 'viper-mouse-click-search-word))) | |
552 (message | |
553 "%S already bound to a mouse event. Viper mouse-search feature disabled" | |
554 viper-mouse-up-search-key-parsed)) | |
555 ((and (null force) | |
556 (key-binding viper-mouse-down-search-key-parsed) | |
557 (not (eq (key-binding viper-mouse-down-search-key-parsed) | |
558 'viper-mouse-catch-frame-switch))) | |
559 (message | |
560 "%S already bound to a mouse event. Viper mouse-search feature disabled" | |
561 viper-mouse-down-search-key-parsed)) | |
562 (t | |
563 (global-set-key viper-mouse-up-search-key-parsed | |
564 'viper-mouse-click-search-word) | |
565 (global-set-key viper-mouse-down-search-key-parsed | |
566 'viper-mouse-catch-frame-switch)))) | |
567 | |
568 ;; If FORCE, bind even if this mouse action is already bound to something else | |
569 (defun viper-bind-mouse-insert-key (&optional force) | |
570 (setq viper-mouse-up-insert-key-parsed | |
571 (viper-parse-mouse-key 'viper-mouse-insert-key 'up) | |
572 viper-mouse-down-insert-key-parsed | |
573 (viper-parse-mouse-key 'viper-mouse-insert-key 'down)) | |
574 (cond ((or (null viper-mouse-up-insert-key-parsed) | |
575 (null viper-mouse-down-insert-key-parsed)) | |
576 nil) ; just quit | |
577 ((and (null force) | |
578 (key-binding viper-mouse-up-insert-key-parsed) | |
579 (not (eq (key-binding viper-mouse-up-insert-key-parsed) | |
580 'viper-mouse-click-insert-word))) | |
581 (message | |
582 "%S already bound to a mouse event. Viper mouse-insert feature disabled" | |
583 viper-mouse-up-insert-key-parsed)) | |
584 ((and (null force) | |
585 (key-binding viper-mouse-down-insert-key-parsed) | |
586 (not (eq (key-binding viper-mouse-down-insert-key-parsed) | |
587 'viper-mouse-catch-frame-switch))) | |
588 (message | |
589 "%S already bound to a mouse event. Viper mouse-insert feature disabled" | |
590 viper-mouse-down-insert-key-parsed)) | |
591 (t | |
592 (global-set-key viper-mouse-up-insert-key-parsed | |
593 'viper-mouse-click-insert-word) | |
594 (global-set-key viper-mouse-down-insert-key-parsed | |
595 'viper-mouse-catch-frame-switch)))) | |
596 | |
597 (defun viper-reset-mouse-search-key (symb val) | |
598 (viper-unbind-mouse-search-key) | |
599 (set symb val) | |
600 (viper-bind-mouse-search-key 'force)) | |
601 | |
602 (defun viper-reset-mouse-insert-key (symb val) | |
603 (viper-unbind-mouse-insert-key) | |
604 (set symb val) | |
605 (viper-bind-mouse-insert-key 'force)) | |
606 | |
607 | |
608 (defcustom viper-mouse-search-key '(meta shift 1) | |
609 "*Key used to click-search in Viper. | |
610 Must be a list that specifies the mouse button and modifiers. The supported | |
611 modifiers are `meta', `shift', and `control'. For instance, `(meta shift 1)' | |
612 means that holding the meta and shift keys down and clicking on a word with | |
613 mouse button 1 will initiate search for that word in the buffer that was | |
614 current just before the click. This buffer may be different from the one where | |
615 the click occurred." | |
616 :type 'list | |
617 :set 'viper-reset-mouse-search-key | |
618 :group 'viper-mouse) | |
619 | |
620 (defcustom viper-mouse-insert-key '(meta shift 2) | |
621 "*Key used to click-insert in Viper. | |
622 Must be a list that specifies the mouse button and modifiers. The supported | |
623 modifiers are `meta', `shift', and `control'. For instance, `(meta shift 2)' | |
624 means that holding the meta and shift keys down and clicking on a word with | |
625 mouse button 2 will insert that word at the cursor in the buffer that was | |
626 current just before the click. This buffer may be different from the one where | |
627 the click occurred." | |
628 :type 'list | |
629 :set 'viper-reset-mouse-insert-key | |
630 :group 'viper-mouse) | |
631 | |
10789 | 632 |
633 | |
18839 | 634 ;;; Local Variables: |
19079 | 635 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun) |
18839 | 636 ;;; End: |
637 | |
10789 | 638 |
639 ;;; viper-mous.el ends here |