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