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