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