Mercurial > emacs
annotate lisp/emulation/viper-mous.el @ 18946:84b78d90cd45
(wait_reading_process_input): Initialize total_read.
Check for read_process_output giving back EIO.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 24 Jul 1997 16:58:05 +0000 |
parents | 1405083241e8 |
children | dfbef8117c6a |
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 |
18839 | 50 (defgroup viper-mouse nil |
51 "Support for Viper special mouse-bound commands" | |
52 :prefix "vip-" | |
53 :group 'viper) | |
54 | |
10789 | 55 |
56 ;;; Variables | |
57 | |
58 ;; Variable used for catching the switch-frame event. | |
59 ;; If non-nil, indicates that previous-frame should be the selected | |
60 ;; one. Used by vip-mouse-click-get-word. Not a user option. | |
61 (defvar vip-frame-of-focus nil) | |
62 | |
63 ;; 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
|
64 (defconst vip-current-frame-saved (selected-frame)) |
10789 | 65 |
18839 | 66 (defcustom vip-surrounding-word-function 'vip-surrounding-word |
10789 | 67 "*Function that determines what constitutes a word for clicking events. |
68 Takes two parameters: a COUNT, indicating how many words to return, | |
69 and CLICK-COUNT, telling whether this is the first click, a double-click, | |
18839 | 70 or a tripple-click." |
71 :type 'boolean | |
72 :group 'viper-mouse) | |
10789 | 73 |
74 ;; time interval in millisecond within which successive clicks are | |
75 ;; considered related | |
18839 | 76 (defcustom vip-multiclick-timeout (if (vip-window-display-p) |
77 (if vip-xemacs-p | |
78 mouse-track-multi-click-time | |
79 double-click-time) | |
80 500) | |
81 "*Time interval in millisecond within which successive mouse clicks are | |
82 considered related." | |
83 :type 'integer | |
84 :group 'viper-mouse) | |
10789 | 85 |
86 ;; current event click count; XEmacs only | |
87 (defvar vip-current-click-count 0) | |
88 ;; time stamp of the last click event; XEmacs only | |
89 (defvar vip-last-click-event-timestamp 0) | |
90 | |
91 ;; Local variable used to toggle wraparound search on click. | |
92 (vip-deflocalvar vip-mouse-click-search-noerror t) | |
93 | |
94 ;; Local variable used to delimit search after wraparound. | |
95 (vip-deflocalvar vip-mouse-click-search-limit nil) | |
96 | |
97 ;; remembers prefix argument to pass along to commands invoked by second | |
98 ;; click. | |
99 ;; This is needed because in Emacs (not XEmacs), assigning to preix-arg | |
100 ;; causes Emacs to count the second click as if it was a single click | |
101 (defvar vip-global-prefix-argument nil) | |
102 | |
103 | |
104 | |
105 ;;; Code | |
106 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
107 (defsubst vip-multiclick-p () |
10789 | 108 (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
|
109 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
110 ;; Returns window where click occurs |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
111 (defsubst vip-mouse-click-window (click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
112 (if vip-xemacs-p |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
113 (event-window click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
114 (posn-window (event-start click)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
115 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
116 ;; Returns window where click occurs |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
117 (defsubst vip-mouse-click-frame (click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
118 (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
|
119 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
120 ;; 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
|
121 (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
|
122 (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
|
123 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
124 ;; 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
|
125 (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
|
126 (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
|
127 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
128 ;; Returns position of a click |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
129 (defsubst vip-mouse-click-posn (click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
130 (if vip-xemacs-p |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
131 (event-point click) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
132 (posn-point (event-start click)))) |
10789 | 133 |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14233
diff
changeset
|
134 |
10789 | 135 (defun vip-surrounding-word (count click-count) |
136 "Returns word surrounding point according to a heuristic. | |
137 COUNT indicates how many regions to return. | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
138 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
|
139 If CLICK-COUNT is 2,then `word' is a Word in Vi sense. |
10789 | 140 If the character clicked on is a non-separator and is non-alphanumeric but |
141 is adjacent to an alphanumeric symbol, then it is considered alphanumeric | |
142 for the purpose of this command. If this character has a matching | |
143 character, such as `\(' is a match for `\)', then the matching character is | |
144 also considered alphanumeric. | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
145 For convenience, in Lisp modes, `-' is considered alphanumeric. |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
146 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 (let ((modifiers "") |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
151 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
|
152 word-beg) |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
153 (if (> click-count 2) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
154 (save-excursion |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
155 (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
|
156 (vip-skip-all-separators-forward 'within-line) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
157 (setq beg (point)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
158 (end-of-line) |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
159 (setq result (buffer-substring beg (point)))) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
160 |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
161 (if (and (not (vip-looking-at-alphasep)) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
162 (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
|
163 (vip-looking-at-alpha)) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
164 (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
|
165 (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
|
166 (setq modifiers |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
167 (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
|
168 ((looking-at "-") "C-C-") |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
169 ((looking-at "[][]") "][") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
170 ((looking-at "[()]") ")(") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
171 ((looking-at "[{}]") "{}") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
172 ((looking-at "[<>]") "<>") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
173 ((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
|
174 ((looking-at "\\^") "\\^") |
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
175 ((vip-looking-at-separator) "") |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
176 (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
|
177 )) |
10789 | 178 |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
179 ;; 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
|
180 (or (looking-at "-") |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
181 (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
|
182 (setq modifiers (concat modifiers "C-C-"))) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
183 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
184 |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
185 (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
|
186 (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
|
187 ((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
|
188 (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
|
189 ((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
|
190 (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
|
191 (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
|
192 (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
|
193 (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
|
194 |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
195 (setq word-beg (point)) |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
196 |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
197 (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
|
198 (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
|
199 (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
|
200 (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
|
201 (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
|
202 (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
|
203 (vip-skip-alpha-forward modifiers)) |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
204 (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
|
205 |
12898
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
206 (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
|
207 ) ; if |
13212
73b3decace33
* viper-mous.el (vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12898
diff
changeset
|
208 ;; 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
|
209 ;; 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
|
210 (if vip-emacs-p |
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
211 (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
|
212 result |
e5d4ba91148f
(vip-surrounding-word): modified to understand tripple clicks.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12694
diff
changeset
|
213 )) |
10789 | 214 |
215 | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
216 (defun vip-mouse-click-get-word (click count click-count) |
10789 | 217 "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
|
218 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
|
219 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
|
220 `vip-surrounding-word-function'." |
10789 | 221 |
222 (let ((click-word "") | |
223 (click-pos (vip-mouse-click-posn click)) | |
224 (click-buf (vip-mouse-click-window-buffer click))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
225 (or (natnump count) (setq count 1)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
226 (or (natnump click-count) (setq click-count 1)) |
10789 | 227 |
228 (save-excursion | |
229 (save-window-excursion | |
230 (if click-pos | |
231 (progn | |
232 (set-buffer click-buf) | |
233 | |
234 (goto-char click-pos) | |
235 (setq click-word | |
236 (funcall vip-surrounding-word-function count click-count))) | |
237 (error "Click must be over a window.")) | |
238 click-word)))) | |
239 | |
240 | |
241 (defun vip-mouse-click-insert-word (click arg) | |
242 "Insert word clicked or double-clicked on. | |
243 With prefix argument, N, insert that many words. | |
244 This command must be bound to a mouse click. | |
245 The double-click action of the same mouse button must not be bound | |
246 \(or it must be bound to the same function\). | |
247 See `vip-surrounding-word' for the definition of a word in this case." | |
248 (interactive "e\nP") | |
249 (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
|
250 (select-frame vip-frame-of-focus)) |
10789 | 251 |
252 ;; turn arg into a number | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
253 (cond ((integerp arg) nil) |
10789 | 254 ;; 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
|
255 ((and (listp arg) (integerp (car arg))) |
10789 | 256 (setq arg (car arg))) |
257 (t (setq arg 1))) | |
258 | |
259 (let (click-count interrupting-event) | |
260 (if (and | |
261 (vip-multiclick-p) | |
262 ;; This trick checks if there is a pending mouse event | |
263 ;; 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
|
264 ;; If the next pending event is not a mouse event, we execute |
10789 | 265 ;; the current mouse event |
266 (progn | |
267 (setq interrupting-event (vip-read-event)) | |
268 (vip-mouse-event-p last-input-event))) | |
269 (progn ;; interrupted wait | |
270 (setq vip-global-prefix-argument arg) | |
271 ;; count this click for XEmacs | |
272 (vip-event-click-count click)) | |
273 ;; uninterrupted wait or the interrupting event wasn't a mouse event | |
274 (setq click-count (vip-event-click-count click)) | |
275 (if (> click-count 1) | |
276 (setq arg vip-global-prefix-argument | |
277 vip-global-prefix-argument nil)) | |
278 (insert (vip-mouse-click-get-word click arg click-count)) | |
279 (if (and interrupting-event | |
280 (eventp interrupting-event) | |
281 (not (vip-mouse-event-p interrupting-event))) | |
282 (vip-set-unread-command-events interrupting-event)) | |
283 ))) | |
284 | |
285 ;; arg is an event. accepts symbols and numbers, too | |
286 (defun vip-mouse-event-p (event) | |
287 (if (eventp event) | |
288 (string-match "\\(mouse-\\|frame\\|screen\\|track\\)" | |
289 (prin1-to-string (vip-event-key event))))) | |
290 | |
291 ;; XEmacs has no double-click events. So, we must simulate. | |
292 ;; So, we have to simulate event-click-count. | |
293 (defun vip-event-click-count (click) | |
294 (if vip-xemacs-p | |
295 (progn | |
296 ;; if more than 1 second | |
297 (if (> (- (event-timestamp click) vip-last-click-event-timestamp) | |
298 vip-multiclick-timeout) | |
299 (setq vip-current-click-count 0)) | |
300 (setq vip-last-click-event-timestamp (event-timestamp click) | |
301 vip-current-click-count (1+ vip-current-click-count))) | |
302 (event-click-count click))) | |
303 | |
304 | |
305 | |
306 (defun vip-mouse-click-search-word (click arg) | |
307 "Find the word clicked or double-clicked on. Word may be in another window. | |
308 With prefix argument, N, search for N-th occurrence. | |
309 This command must be bound to a mouse click. The double-click action of the | |
310 same button must not be bound \(or it must be bound to the same function\). | |
311 See `vip-surrounding-word' for the details on what constitutes a word for | |
312 this command." | |
313 (interactive "e\nP") | |
314 (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
|
315 (select-frame vip-frame-of-focus)) |
10789 | 316 (let (click-word click-count |
317 (previous-search-string vip-s-string)) | |
318 | |
319 (if (and | |
320 (vip-multiclick-p) | |
321 ;; This trick checks if there is a pending mouse event | |
322 ;; 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
|
323 ;; If the next pending event is not a mouse event, we execute |
10789 | 324 ;; the current mouse event |
325 (progn | |
326 (vip-read-event) | |
327 (vip-mouse-event-p last-input-event))) | |
328 (progn ;; interrupted wait | |
12694
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
329 (setq vip-global-prefix-argument |
9dedaee6ee1c
(vip-multiclick-timeout): new default.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12140
diff
changeset
|
330 (or vip-global-prefix-argument arg)) |
10789 | 331 ;; remember command that was before the multiclick |
332 (setq this-command last-command) | |
333 ;; make sure we counted this event---needed for XEmacs only | |
334 (vip-event-click-count click)) | |
335 ;; uninterrupted wait | |
336 (setq click-count (vip-event-click-count click)) | |
337 (setq click-word (vip-mouse-click-get-word click nil click-count)) | |
338 | |
339 (if (> click-count 1) | |
340 (setq arg vip-global-prefix-argument | |
341 vip-global-prefix-argument nil)) | |
342 (setq arg (or arg 1)) | |
343 | |
344 (vip-deactivate-mark) | |
345 (if (or (not (string= click-word vip-s-string)) | |
346 (not (markerp vip-search-start-marker)) | |
347 (not (equal (marker-buffer vip-search-start-marker) | |
348 (current-buffer))) | |
349 (not (eq last-command 'vip-mouse-click-search-word))) | |
350 (progn | |
351 (setq vip-search-start-marker (point-marker) | |
352 vip-local-search-start-marker vip-search-start-marker | |
353 vip-mouse-click-search-noerror t | |
354 vip-mouse-click-search-limit nil) | |
355 | |
356 ;; make search string known to Viper | |
357 (setq vip-s-string (if vip-re-search | |
358 (regexp-quote click-word) | |
359 click-word)) | |
360 (if (not (string= vip-s-string (car vip-search-history))) | |
361 (setq vip-search-history | |
362 (cons vip-s-string vip-search-history))) | |
363 )) | |
364 | |
365 (push-mark nil t) | |
366 (while (> arg 0) | |
367 (vip-forward-word 1) | |
368 (condition-case nil | |
369 (progn | |
370 (if (not (search-forward click-word vip-mouse-click-search-limit | |
371 vip-mouse-click-search-noerror)) | |
372 (progn | |
373 (setq vip-mouse-click-search-noerror nil) | |
374 (setq vip-mouse-click-search-limit | |
375 (save-excursion | |
376 (if (and | |
377 (markerp vip-local-search-start-marker) | |
378 (marker-buffer vip-local-search-start-marker)) | |
379 (goto-char vip-local-search-start-marker)) | |
380 (vip-line-pos 'end))) | |
381 | |
382 (goto-char (point-min)) | |
383 (search-forward click-word | |
384 vip-mouse-click-search-limit nil))) | |
385 (goto-char (match-beginning 0)) | |
386 (message "Searching for: %s" vip-s-string) | |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
387 (if (<= arg 1) ; found the right occurrence of the pattern |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
388 (progn |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
389 (vip-adjust-window) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
390 (vip-flash-search-pattern))) |
10789 | 391 ) |
392 (error (beep 1) | |
393 (if (or (not (string= click-word previous-search-string)) | |
394 (not (eq last-command 'vip-mouse-click-search-word))) | |
395 (message "`%s': String not found in %s" | |
396 vip-s-string (buffer-name (current-buffer))) | |
397 (message | |
398 "`%s': Last occurrence in %s. Back to beginning of search" | |
399 click-word (buffer-name (current-buffer))) | |
400 (setq arg 1) ;; to terminate the loop | |
401 (sit-for 2)) | |
402 (setq vip-mouse-click-search-noerror t) | |
403 (setq vip-mouse-click-search-limit nil) | |
404 (if (and (markerp vip-local-search-start-marker) | |
405 (marker-buffer vip-local-search-start-marker)) | |
406 (goto-char vip-local-search-start-marker)))) | |
407 (setq arg (1- arg))) | |
408 ))) | |
409 | |
410 (defun vip-mouse-catch-frame-switch (event arg) | |
411 "Catch the event of switching frame. | |
412 Usually is bound to a 'down-mouse' event to work properly. See sample | |
18129 | 413 bindings in the Viper manual." |
10789 | 414 (interactive "e\nP") |
415 (setq vip-frame-of-focus nil) | |
416 ;; pass prefix arg along to vip-mouse-click-search/insert-word | |
417 (setq prefix-arg arg) | |
418 (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
|
419 (setq vip-frame-of-focus vip-current-frame-saved)) |
10789 | 420 ;; make Emacs forget that it executed vip-mouse-catch-frame-switch |
421 (setq this-command last-command)) | |
422 | |
423 ;; Called just before switching frames. Saves the old selected frame. | |
424 ;; Sets last-command to handle-switch-frame (this is done automatically in | |
425 ;; Emacs. | |
426 ;; The semantics of switching frames is different in Emacs and XEmacs. | |
427 ;; In Emacs, if you select-frame A while mouse is over frame B and then | |
428 ;; start typing, input goes to frame B, which becomes selected. | |
429 ;; In XEmacs, input will go to frame A. This may be a bug in one of the | |
430 ;; Emacsen, but also may be a design decision. | |
431 ;; Also, in Emacs sending input to frame B generates handle-switch-frame | |
432 ;; event, while in XEmacs it doesn't. | |
433 ;; All this accounts for the difference in the behavior of | |
434 ;; vip-mouse-click-* commands when you click in a frame other than the one | |
435 ;; that was the last to receive input. In Emacs, focus will be in frame A | |
436 ;; until you do something other than vip-mouse-click-* command. | |
437 ;; In XEmacs, you have to manually select frame B (with the mouse click) in | |
438 ;; 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
|
439 (defsubst vip-remember-current-frame (frame) |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
440 (setq last-command 'handle-switch-frame |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
441 vip-current-frame-saved (selected-frame))) |
10789 | 442 |
443 | |
18839 | 444 ;;; Local Variables: |
445 ;;; eval: (put 'vip-deflocalvar 'lisp-indent-hook 'defun) | |
446 ;;; End: | |
447 | |
10789 | 448 |
449 ;;; viper-mous.el ends here |