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