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