209
|
1 ;;; mouse.el --- window system-independent mouse support.
|
|
2
|
|
3 ;; Copyright (C) 1988, 1992-4, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems
|
|
5 ;; Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 ;; Maintainer: XEmacs Development Team
|
|
8 ;; Keywords: mouse, dumped
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
272
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
209
|
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not synched with FSF. Almost completely divergent.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This file is dumped with XEmacs (when window system support is compiled in).
|
|
32
|
|
33 ;;; Code:
|
|
34
|
|
35 (provide 'mouse)
|
|
36
|
|
37 (global-set-key 'button1 'mouse-track)
|
|
38 (global-set-key '(shift button1) 'mouse-track-adjust)
|
|
39 (global-set-key '(control button1) 'mouse-track-insert)
|
|
40 (global-set-key '(control shift button1) 'mouse-track-delete-and-insert)
|
|
41 (global-set-key '(meta button1) 'mouse-track-do-rectangle)
|
|
42
|
282
|
43 ;; drops are now handled in dragdrop.el (ograf@fga.de)
|
|
44
|
209
|
45 ;; enable drag regions (ograf@fga.de)
|
|
46 ;; if button2 is dragged from within a region, this becomes a drop
|
282
|
47 ;;
|
|
48 ;; this must be changed to the new api
|
249
|
49 (if (featurep '(or offix cde mswindows))
|
209
|
50 (global-set-key 'button2 'mouse-drag-or-yank)
|
|
51 (global-set-key 'button2 'mouse-yank))
|
|
52
|
227
|
53 (defgroup mouse nil
|
|
54 "Window system-independent mouse support."
|
|
55 :group 'editing)
|
|
56
|
209
|
57 (defcustom mouse-track-rectangle-p nil
|
|
58 "*If true, then dragging out a region with the mouse selects rectangles
|
|
59 instead of simple start/end regions."
|
|
60 :type 'boolean
|
|
61 :group 'mouse)
|
|
62
|
|
63 (defcustom mouse-yank-at-point nil
|
|
64 "*If non-nil, the function `mouse-yank' will yank text at the cursor location.
|
|
65 Otherwise, the cursor will be moved to the location of the pointer click before
|
|
66 text is inserted."
|
|
67 :type 'boolean
|
|
68 :group 'mouse)
|
|
69
|
|
70 (defcustom mouse-highlight-text 'context
|
|
71 "*Choose the default double-click highlighting behaviour.
|
|
72 If set to `context', double-click will highlight words when the mouse
|
|
73 is at a word character, or a symbol if the mouse is at a symbol
|
|
74 character.
|
|
75 If set to `word', double-click will always attempt to highlight a word.
|
|
76 If set to `symbol', double-click will always attempt to highlight a
|
|
77 symbol (the default behaviour in previous XEmacs versions)."
|
|
78 :type '(choice (const context)
|
|
79 (const word)
|
|
80 (const symbol))
|
|
81 :group 'mouse)
|
|
82
|
|
83 (defvar mouse-yank-function 'mouse-consolidated-yank
|
|
84 "Function that is called upon by `mouse-yank' to actually insert text.")
|
|
85
|
|
86 (defun mouse-consolidated-yank ()
|
|
87 (interactive)
|
|
88 (case (device-type)
|
|
89 (x (x-yank-function))
|
|
90 (tty (yank))
|
|
91 (otherwise (yank))))
|
|
92
|
|
93
|
|
94 (defun mouse-select ()
|
|
95 "Select Emacs window the mouse is on."
|
|
96 (interactive "@"))
|
|
97
|
|
98 (defun mouse-delete-window ()
|
|
99 "Delete the Emacs window the mouse is on."
|
|
100 (interactive "@")
|
|
101 (delete-window))
|
|
102
|
|
103 (defun mouse-keep-one-window ()
|
|
104 "Select Emacs window mouse is on, then kill all other Emacs windows."
|
|
105 (interactive "@")
|
|
106 (delete-other-windows))
|
|
107
|
|
108 (defun mouse-select-and-split ()
|
|
109 "Select Emacs window mouse is on, then split it vertically in half."
|
|
110 (interactive "@")
|
|
111 (split-window-vertically nil))
|
|
112
|
|
113 (defun mouse-set-point (event)
|
|
114 "Select Emacs window mouse is on, and move point to mouse position."
|
|
115 (interactive "@e")
|
|
116 (let ((window (event-window event))
|
|
117 (pos (event-point event))
|
|
118 (close-pos (event-closest-point event)))
|
|
119 (or window (error "not in a window"))
|
|
120 (select-window window)
|
|
121 (if (and pos (> pos 0))
|
|
122 ;; If the event was over a text char, it's easy.
|
|
123 (goto-char (max (min pos (point-max)) (point-min)))
|
|
124 (if (and close-pos (> close-pos 0))
|
|
125 (goto-char (max (min close-pos (point-max)) (point-min)))
|
|
126 ;; When the event occurs outside of the frame directly to the
|
|
127 ;; left or right of a modeline, close-point is nil, but
|
|
128 ;; event-over-modeline is also nil. That will drop us to this
|
|
129 ;; point. So instead of erroring, just return nil.
|
|
130 nil))))
|
|
131
|
|
132 (defun mouse-yank (event)
|
|
133 "Paste text with the mouse.
|
|
134 If the variable `mouse-yank-at-point' is nil, then pasting occurs at the
|
|
135 location of the click; otherwise, pasting occurs at the current cursor
|
|
136 location."
|
|
137 (interactive "e")
|
|
138 (and (not mouse-yank-at-point)
|
|
139 (mouse-set-point event))
|
|
140 (funcall mouse-yank-function))
|
|
141
|
|
142 (defun click-inside-extent-p (click extent)
|
272
|
143 "Return non-nil if the button event is within the primary selection-extent.
|
|
144 Return nil otherwise."
|
209
|
145 ;; stig@hackvan.com
|
|
146 (let ((ewin (event-window click))
|
|
147 (epnt (event-point click)))
|
|
148 (and ewin
|
|
149 epnt
|
|
150 extent
|
|
151 (eq (window-buffer ewin)
|
|
152 (extent-object extent))
|
|
153 (extent-start-position extent)
|
|
154 (> epnt (extent-start-position extent))
|
|
155 (> (extent-end-position extent) epnt))))
|
|
156
|
|
157 (defun click-inside-selection-p (click)
|
|
158 (or (click-inside-extent-p click primary-selection-extent)
|
|
159 (click-inside-extent-p click zmacs-region-extent)
|
|
160 ))
|
|
161
|
|
162 (defun point-inside-extent-p (extent)
|
272
|
163 "Return t if point is within the bounds of the primary selection extent.
|
|
164 Return t is point is at the end position of the extent.
|
|
165 Return nil otherwise."
|
209
|
166 ;; stig@hackvan.com
|
|
167 (and extent
|
272
|
168 (eq (current-buffer)
|
209
|
169 (extent-object extent))
|
|
170 (> (point) (extent-start-position extent))
|
|
171 (>= (extent-end-position extent) (point))))
|
|
172
|
|
173 (defun point-inside-selection-p ()
|
|
174 ;; by Stig@hackvan.com
|
|
175 (or (point-inside-extent-p primary-selection-extent)
|
|
176 (point-inside-extent-p zmacs-region-extent)))
|
|
177
|
|
178 (defun mouse-drag-or-yank (event)
|
272
|
179 "Either drag or paste the current selection.
|
|
180 If the variable `mouse-yank-at-point' is non-nil,
|
|
181 move the cursor to the location of the click before pasting.
|
|
182 This functions has to be improved. Currently it is just a (working) test."
|
209
|
183 ;; by Oliver Graf <ograf@fga.de>
|
|
184 (interactive "e")
|
|
185 (if (click-inside-extent-p event zmacs-region-extent)
|
|
186 ;; okay, this is a drag
|
|
187 (cond ((featurep 'offix)
|
|
188 (offix-start-drag-region event
|
|
189 (extent-start-position zmacs-region-extent)
|
|
190 (extent-end-position zmacs-region-extent)))
|
|
191 ((featurep 'cde)
|
|
192 ;; should also work with CDE
|
288
|
193 (cde-start-drag-region event
|
|
194 (extent-start-position zmacs-region-extent)
|
|
195 (extent-end-position zmacs-region-extent)))
|
209
|
196 (t (error "No offix or CDE support compiled in")))
|
|
197 ;; no drag, call region-funct
|
|
198 (and (not mouse-yank-at-point)
|
|
199 (mouse-set-point event))
|
|
200 (funcall mouse-yank-function))
|
|
201 )
|
|
202
|
|
203 (defun mouse-eval-sexp (click force-window)
|
|
204 "Evaluate the sexp under the mouse. Usually, this is the last sexp before
|
|
205 the click, but if you click on a left paren, then it is the sexp beginning
|
|
206 with the paren that is evaluated. Also, since strings evaluate to themselves,
|
|
207 they're fed to re-search-forward and the matched region is highlighted until
|
|
208 the mouse button is released.
|
|
209
|
|
210 Perhaps the most useful thing about this function is that the evaluation of
|
|
211 the expression which is clicked upon is relative not to the window where you
|
|
212 click, but to the current window and the current position of point. Thus,
|
|
213 you can use `mouse-eval-sexp' to interactively test code that acts upon a
|
|
214 buffer...something you cannot do with the standard `eval-last-sexp' function.
|
|
215 It's also fantastic for debugging regular expressions."
|
|
216 ;; by Stig@hackvan.com
|
|
217 (interactive "e\nP")
|
|
218 (let (exp val result-str)
|
|
219 (setq exp (save-window-excursion
|
272
|
220 (save-excursion
|
209
|
221 (mouse-set-point click)
|
|
222 (save-excursion
|
|
223 (or (looking-at "(") (forward-sexp -1))
|
|
224 (read (point-marker))))))
|
|
225 (cond ((stringp exp)
|
|
226 (if (setq val (re-search-forward exp nil t))
|
|
227 (let* ((oo (make-extent (match-beginning 0) (match-end 0))))
|
|
228 (set-extent-face oo 'highlight)
|
|
229 (set-extent-priority oo 1000)
|
|
230 ;; wait for button release...
|
|
231 (setq unread-command-event (next-command-event))
|
|
232 (delete-extent oo))
|
|
233 (message "Regex \"%s\" not found" exp)
|
|
234 (ding nil 'quiet)))
|
|
235 (t (setq val (if (fboundp 'eval-interactive)
|
|
236 (eval-interactive exp)
|
|
237 (eval exp)))))
|
|
238 (setq result-str (prin1-to-string val))
|
|
239 ;; #### -- need better test
|
|
240 (if (and (not force-window)
|
|
241 (<= (length result-str) (window-width (selected-window))))
|
|
242 (message "%s" result-str)
|
|
243 (with-output-to-temp-buffer "*Mouse-Eval*"
|
|
244 (condition-case nil
|
|
245 (pprint val)
|
|
246 (error (prin1 val))))
|
|
247 )))
|
|
248
|
|
249 (defun mouse-line-length (event)
|
|
250 "Print the length of the line indicated by the pointer."
|
|
251 (interactive "@e")
|
|
252 (save-excursion
|
|
253 (mouse-set-point event)
|
|
254 (message "Line length: %d" (- (point-at-eol) (point-at-bol))))
|
|
255 (sleep-for 1))
|
|
256
|
|
257 (defun mouse-set-mark (event)
|
|
258 "Select Emacs window mouse is on, and set mark at mouse position.
|
|
259 Display cursor at that position for a second."
|
|
260 (interactive "@e")
|
|
261 (let ((point-save (point)))
|
|
262 (unwind-protect
|
|
263 (progn (mouse-set-point event)
|
|
264 (push-mark nil t)
|
|
265 (sit-for 1))
|
|
266 (goto-char point-save))))
|
|
267
|
|
268 (defun mouse-scroll (event)
|
|
269 "Scroll point to the mouse position."
|
|
270 (interactive "@e")
|
|
271 (save-excursion
|
|
272 (mouse-set-point event)
|
|
273 (recenter 0)
|
|
274 (scroll-right (event-x event))))
|
|
275
|
|
276 (defun mouse-del-char (event)
|
|
277 "Delete the char pointed to by the mouse."
|
|
278 (interactive "@e")
|
|
279 (save-excursion
|
|
280 (mouse-set-point event)
|
|
281 (delete-char 1 nil)))
|
|
282
|
|
283 (defun mouse-kill-line (event)
|
|
284 "Kill the line pointed to by the mouse."
|
|
285 (interactive "@e")
|
|
286 (save-excursion
|
|
287 (mouse-set-point event)
|
|
288 (kill-line nil)))
|
|
289
|
|
290 (defun mouse-bury-buffer (event)
|
|
291 "Bury the buffer pointed to by the mouse, thus selecting the next one."
|
|
292 (interactive "e")
|
|
293 (save-selected-window
|
|
294 (select-window (event-window event))
|
|
295 (bury-buffer)))
|
272
|
296
|
209
|
297 (defun mouse-unbury-buffer (event)
|
|
298 "Unbury and select the most recently buried buffer."
|
|
299 (interactive "e")
|
|
300 (save-selected-window
|
|
301 (select-window (event-window event))
|
|
302 (let* ((bufs (buffer-list))
|
|
303 (entry (1- (length bufs)))
|
|
304 val)
|
|
305 (while (not (setq val (nth entry bufs)
|
|
306 val (and (/= (aref (buffer-name val) 0)
|
|
307 ? )
|
|
308 val)))
|
|
309 (setq entry (1- entry)))
|
|
310 (switch-to-buffer val))))
|
|
311
|
|
312 (defun narrow-window-to-region (m n)
|
|
313 "Narrow window to region between point and last mark"
|
|
314 (interactive "r")
|
|
315 (save-excursion
|
|
316 (save-restriction
|
|
317 (if (eq (selected-window) (next-window))
|
|
318 (split-window))
|
|
319 (goto-char m)
|
|
320 (recenter 0)
|
|
321 (if (eq (selected-window)
|
|
322 (if (zerop (minibuffer-depth))
|
|
323 (next-window)))
|
|
324 ()
|
|
325 (shrink-window (- (- (window-height) (count-lines m n)) 1))))))
|
|
326
|
|
327 (defun mouse-window-to-region (event)
|
|
328 "Narrow window to region between cursor and mouse pointer."
|
|
329 (interactive "@e")
|
|
330 (let ((point-save (point)))
|
|
331 (unwind-protect
|
|
332 (progn (mouse-set-point event)
|
|
333 (push-mark nil t)
|
|
334 (sit-for 1))
|
|
335 (goto-char point-save)
|
|
336 (narrow-window-to-region (region-beginning) (region-end)))))
|
|
337
|
|
338 (defun mouse-ignore ()
|
|
339 "Don't do anything."
|
|
340 (interactive))
|
|
341
|
|
342
|
|
343 ;;; mouse/selection tracking
|
|
344 ;;; generalized mouse-track
|
|
345
|
|
346 (defvar default-mouse-track-normalize-point-function
|
|
347 'default-mouse-track-normalize-point
|
|
348 "Function called to normalize position of point.
|
|
349 Called with two arguments: TYPE depends on the number of times that the
|
|
350 mouse has been clicked and is a member of `default-mouse-track-type-list',
|
|
351 FORWARDP determines the direction in which the point should be moved.")
|
|
352
|
|
353 (defvar mouse-track-down-hook nil
|
|
354 "Function or functions called when the user presses the mouse.
|
|
355 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
356 for any buttons with a different binding. The functions will be
|
|
357 called with two arguments: the button-press event and a click
|
|
358 count (see `mouse-track-click-hook').
|
|
359
|
|
360 If any function returns non-nil, the remaining functions will not be
|
|
361 called.
|
|
362
|
|
363 Note that most applications should take action when the mouse is
|
|
364 released, not when it is pressed.'")
|
|
365
|
|
366 (defvar mouse-track-drag-hook nil
|
|
367 "Function or functions called when the user drags the mouse.
|
|
368 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
369 for any buttons with a different binding. The functions will be
|
|
370 called with three arguments: the mouse-motion event, a click
|
|
371 count (see `mouse-track-click-hook'), and whether the call to
|
|
372 this hook occurred as a result of a drag timeout (see
|
|
373 `mouse-track-scroll-delay').
|
|
374
|
|
375 If any function returns non-nil, the remaining functions will not be
|
|
376 called.
|
|
377
|
|
378 Note that no calls to this function will be made until the user
|
|
379 initiates a drag (i.e. moves the mouse more than a certain
|
|
380 threshold in either the X or the Y direction, as defined by
|
|
381 `mouse-track-x-threshold' and `mouse-track-y-threshold').
|
|
382
|
|
383 See also `mouse-track-drag-up-hook'.")
|
|
384
|
|
385 (defvar mouse-track-drag-up-hook nil
|
|
386 "Function or functions called when the user finishes a drag.
|
|
387 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
388 for any buttons with a different binding. The functions will be
|
|
389 called with two arguments: the button-press event and a click
|
|
390 count (see `mouse-track-click-hook').
|
|
391
|
|
392 If any function returns non-nil, the remaining functions will not be
|
|
393 called.
|
|
394
|
|
395 Note that this hook will not be invoked unless the user has
|
|
396 initiated a drag, i.e. moved the mouse more than a certain threshold
|
|
397 (see `mouse-track-drag-hook'). When this function is invoked,
|
|
398 `mouse-track-drag-hook' will have been invoked at least once.
|
|
399
|
|
400 See also `mouse-track-click-hook'.")
|
|
401
|
|
402 (defvar mouse-track-click-hook nil
|
|
403 "Function or functions called when the user clicks the mouse.
|
|
404 `Clicking' means pressing and releasing the mouse without having
|
|
405 initiated a drag (i.e. without having moved more than a certain
|
|
406 threshold -- see `mouse-track-drag-hook').
|
|
407
|
|
408 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
409 for any buttons with a different binding. The functions will be
|
|
410 called with two arguments: the button-release event and a click
|
|
411 count, which specifies the number of times that the mouse has been
|
|
412 clicked in a series of clicks, each of which is separated by at most
|
|
413 `mouse-track-multi-click-time'. This can be used to implement actions
|
|
414 that are called on double clicks, triple clicks, etc.
|
|
415
|
|
416 If any function returns non-nil, the remaining functions will not be
|
|
417 called.
|
|
418
|
|
419 See also `mouse-track-drag-up-hook.")
|
|
420
|
|
421 (defvar mouse-track-up-hook nil
|
|
422 "Function or functions called when the user releases the mouse.
|
|
423 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
424 for any buttons with a different binding. The functions will be
|
|
425 called with two arguments: the button-release event and a click
|
|
426 count (see `mouse-track-click-hook').
|
|
427
|
|
428 For many applications, it is more appropriate to use one or both
|
|
429 of `mouse-track-click-hook' and `mouse-track-drag-up-hook'.")
|
|
430
|
|
431 (defvar mouse-track-cleanup-hook nil
|
|
432 "Function or functions called when `mouse-track' terminates.
|
|
433 This hook will be called in all circumstances, even upon a
|
|
434 non-local exit out of `mouse-track', and so is useful for
|
|
435 doing cleanup work such as removing extents that may have
|
|
436 been created during the operation of `mouse-track'.
|
|
437
|
|
438 Unlike all of the other mouse-track hooks, this is a \"normal\"
|
|
439 hook: the hook functions are called with no arguments, and
|
|
440 all hook functions are called regardless of their return
|
|
441 values.")
|
|
442
|
|
443 (defcustom mouse-track-multi-click-time 400
|
|
444 "*Maximum number of milliseconds allowed between clicks for a multi-click.
|
|
445 See `mouse-track-click-hook'."
|
|
446 :type 'integer
|
|
447 :group 'mouse)
|
|
448
|
|
449 (defcustom mouse-track-scroll-delay 100
|
|
450 "Maximum of milliseconds between calls to `mouse-track-drag-hook'.
|
|
451 If the user is dragging the mouse (i.e. the button is held down and
|
|
452 a drag has been initiated) and does not move the mouse for this many
|
|
453 milliseconds, the hook will be called with t as the value of the
|
|
454 WAS-TIMEOUT parameter. This can be used to implement scrolling
|
|
455 in a selection when the user drags the mouse out the window it
|
|
456 was in.
|
|
457
|
|
458 A value of nil disables the timeout feature."
|
|
459 :type '(choice integer (const :tag "Disabled" nil))
|
|
460 :group 'mouse)
|
|
461
|
|
462 (defvar mouse-track-x-threshold '(face-width 'default)
|
|
463 "Minimum number of pixels in the X direction for a drag to be initiated.
|
|
464 If the mouse is moved more than either the X or Y threshold while the
|
|
465 button is held down (see also `mouse-track-y-threshold'), then a drag
|
|
466 is initiated; otherwise the gesture is considered to be a click.
|
|
467 See `mouse-track'.
|
|
468
|
|
469 The value should be either a number of a form to be evaluated to
|
|
470 produce a number.")
|
|
471
|
|
472 (defvar mouse-track-y-threshold '(face-height 'default)
|
|
473 "Minimum number of pixels in the Y direction for a drag to be initiated.
|
|
474 If the mouse is moved more than either the X or Y threshold while the
|
|
475 button is held down (see also `mouse-track-x-threshold'), then a drag
|
|
476 is initiated; otherwise the gesture is considered to be a click.
|
|
477 See `mouse-track'.
|
|
478
|
|
479 The value should be either a number of a form to be evaluated to
|
|
480 produce a number.")
|
|
481
|
|
482 ;; these variables are private to mouse-track.
|
|
483 (defvar mouse-track-up-time nil)
|
|
484 (defvar mouse-track-up-x nil)
|
|
485 (defvar mouse-track-up-y nil)
|
|
486 (defvar mouse-track-timeout-id nil)
|
|
487 (defvar mouse-track-click-count nil)
|
|
488
|
|
489 (defun mouse-track-set-timeout (event)
|
|
490 (if mouse-track-timeout-id
|
|
491 (disable-timeout mouse-track-timeout-id))
|
|
492 (if mouse-track-scroll-delay
|
|
493 (setq mouse-track-timeout-id
|
|
494 (add-timeout (/ mouse-track-scroll-delay 1000.0)
|
|
495 'mouse-track-scroll-undefined
|
|
496 (copy-event event)))))
|
|
497
|
|
498 (defun mouse-track-run-hook (hook event &rest args)
|
223
|
499 ;; ugh, can't use run-hook-with-args-until-success because we have
|
|
500 ;; to get the value using symbol-value-in-buffer. Doing a
|
|
501 ;; save-excursion/set-buffer is wrong because the hook might want to
|
|
502 ;; change the buffer, but just doing a set-buffer is wrong because
|
|
503 ;; the hook might not want to change the buffer.
|
|
504 ;; #### What we need here is a Lisp interface to
|
|
505 ;; run_hook_with_args_in_buffer. Here is a poor man's version.
|
209
|
506 (let ((buffer (event-buffer event)))
|
223
|
507 (and mouse-grabbed-buffer (setq buffer mouse-grabbed-buffer))
|
|
508 (when buffer
|
|
509 (let ((value (symbol-value-in-buffer hook buffer nil)))
|
|
510 (if (and (listp value) (not (eq (car value) 'lambda)))
|
|
511 ;; List of functions.
|
|
512 (let (retval)
|
|
513 (while (and value (null retval))
|
|
514 ;; Found `t': should process default value. We could
|
|
515 ;; splice it into the buffer-local value, but that
|
|
516 ;; would cons, which is not a good thing for
|
|
517 ;; mouse-track hooks.
|
|
518 (if (eq (car value) t)
|
|
519 (let ((global (default-value hook)))
|
|
520 (if (and (listp global) (not (eq (car global) 'lambda)))
|
|
521 ;; List of functions.
|
|
522 (while (and global
|
|
523 (null (setq retval
|
|
524 (apply (car global) event args))))
|
|
525 (pop global))
|
|
526 ;; lambda
|
|
527 (setq retval (apply (car global) event args))))
|
|
528 (setq retval (apply (car value) event args)))
|
|
529 (pop value))
|
|
530 retval)
|
|
531 ;; lambda
|
|
532 (apply value event args))))))
|
209
|
533
|
|
534 (defun mouse-track-scroll-undefined (random)
|
|
535 ;; the old implementation didn't actually define this function,
|
|
536 ;; and in normal use it won't ever be called because the timeout
|
|
537 ;; will either be removed before it fires or will be picked off
|
|
538 ;; with next-event and not dispatched. However, if you're
|
|
539 ;; attempting to debug a click-hook (which is pretty damn
|
|
540 ;; difficult to do), this function may get called.
|
|
541 )
|
|
542
|
|
543 (defun mouse-track (event)
|
|
544 "Make a selection with the mouse. This should be bound to a mouse button.
|
|
545 The behavior of XEmacs during mouse selection is customizable using various
|
|
546 hooks and variables: see `mouse-track-click-hook', `mouse-track-drag-hook',
|
|
547 `mouse-track-drag-up-hook', `mouse-track-down-hook', `mouse-track-up-hook',
|
|
548 `mouse-track-cleanup-hook', `mouse-track-multi-click-time',
|
|
549 `mouse-track-scroll-delay', `mouse-track-x-threshold', and
|
|
550 `mouse-track-y-threshold'.
|
|
551
|
|
552 Default handlers are provided to implement standard selecting/positioning
|
|
553 behavior. You can explicitly request this default behavior, and override
|
|
554 any custom-supplied handlers, by using the function `mouse-track-default'
|
|
555 instead of `mouse-track'.
|
|
556
|
272
|
557 Default behavior is as follows:
|
209
|
558
|
|
559 If you click-and-drag, the selection will be set to the region between the
|
|
560 point of the initial click and the point at which you release the button.
|
|
561 These positions need not be ordered.
|
|
562
|
|
563 If you click-and-release without moving the mouse, then the point is moved
|
|
564 and the selection is disowned (there will be no selection owner). The mark
|
|
565 will be set to the previous position of point.
|
|
566
|
|
567 If you double-click, the selection will extend by symbols instead of by
|
|
568 characters. If you triple-click, the selection will extend by lines.
|
|
569
|
|
570 If you drag the mouse off the top or bottom of the window, you can select
|
|
571 pieces of text which are larger than the visible part of the buffer; the
|
|
572 buffer will scroll as necessary.
|
|
573
|
|
574 The selected text becomes the current X Selection. The point will be left
|
|
575 at the position at which you released the button, and the mark will be left
|
|
576 at the initial click position."
|
|
577 (interactive "e")
|
|
578 (let ((mouse-down t)
|
|
579 (xthresh (eval mouse-track-x-threshold))
|
|
580 (ythresh (eval mouse-track-y-threshold))
|
|
581 (orig-x (event-x-pixel event))
|
|
582 (orig-y (event-y-pixel event))
|
|
583 (buffer (event-buffer event))
|
|
584 (mouse-grabbed-buffer (event-buffer event))
|
|
585 mouse-moved)
|
|
586 (if (or (not mouse-track-up-x)
|
|
587 (not mouse-track-up-y)
|
|
588 (not mouse-track-up-time)
|
|
589 (> (- (event-timestamp event) mouse-track-up-time)
|
|
590 mouse-track-multi-click-time)
|
|
591 (> (abs (- mouse-track-up-x orig-x)) xthresh)
|
|
592 (> (abs (- mouse-track-up-y orig-y)) ythresh))
|
|
593 (setq mouse-track-click-count 1)
|
|
594 (setq mouse-track-click-count (1+ mouse-track-click-count)))
|
|
595 (if (not (event-window event))
|
|
596 (error "Not over a window."))
|
|
597 (mouse-track-run-hook 'mouse-track-down-hook
|
|
598 event mouse-track-click-count)
|
|
599 (unwind-protect
|
|
600 (while mouse-down
|
|
601 (setq event (next-event event))
|
|
602 (cond ((motion-event-p event)
|
|
603 (if (and (not mouse-moved)
|
|
604 (or (> (abs (- (event-x-pixel event) orig-x))
|
|
605 xthresh)
|
|
606 (> (abs (- (event-y-pixel event) orig-y))
|
|
607 ythresh)))
|
|
608 (setq mouse-moved t))
|
|
609 (if mouse-moved
|
|
610 (mouse-track-run-hook 'mouse-track-drag-hook
|
|
611 event mouse-track-click-count nil))
|
|
612 (mouse-track-set-timeout event))
|
|
613 ((and (timeout-event-p event)
|
|
614 (eq (event-function event)
|
|
615 'mouse-track-scroll-undefined))
|
|
616 (if mouse-moved
|
|
617 (mouse-track-run-hook 'mouse-track-drag-hook
|
|
618 (event-object event) mouse-track-click-count t))
|
|
619 (mouse-track-set-timeout (event-object event)))
|
|
620 ((button-release-event-p event)
|
|
621 (setq mouse-track-up-time (event-timestamp event))
|
|
622 (setq mouse-track-up-x (event-x-pixel event))
|
|
623 (setq mouse-track-up-y (event-y-pixel event))
|
|
624 (setq mouse-down nil)
|
|
625 (mouse-track-run-hook 'mouse-track-up-hook
|
|
626 event mouse-track-click-count)
|
|
627 (if mouse-moved
|
|
628 (mouse-track-run-hook 'mouse-track-drag-up-hook
|
|
629 event mouse-track-click-count)
|
|
630 (mouse-track-run-hook 'mouse-track-click-hook
|
|
631 event mouse-track-click-count)))
|
|
632 ((key-press-event-p event)
|
|
633 (error "Selection aborted"))
|
|
634 (t
|
|
635 (dispatch-event event))))
|
|
636 ;; protected
|
|
637 (if mouse-track-timeout-id
|
|
638 (disable-timeout mouse-track-timeout-id))
|
|
639 (setq mouse-track-timeout-id nil)
|
|
640 (and buffer
|
|
641 (save-excursion
|
|
642 (set-buffer buffer)
|
|
643 (run-hooks 'mouse-track-cleanup-hook))))))
|
|
644
|
|
645
|
|
646 ;;;;;;;;;;;; default handlers: new version of mouse-track
|
|
647
|
|
648 (defvar default-mouse-track-type nil)
|
|
649 (defvar default-mouse-track-type-list '(char word line))
|
|
650 (defvar default-mouse-track-window nil)
|
|
651 (defvar default-mouse-track-extent nil)
|
|
652 (defvar default-mouse-track-adjust nil)
|
|
653 (defvar default-mouse-track-min-anchor nil)
|
|
654 (defvar default-mouse-track-max-anchor nil)
|
|
655 (defvar default-mouse-track-result nil)
|
|
656 (defvar default-mouse-track-down-event nil)
|
|
657
|
255
|
658 ;; D. Verna Feb. 17 1998
|
272
|
659 ;; This function used to assume that when (event-window event) differs from
|
255
|
660 ;; window, we have to scroll. This is WRONG, for instance when there are
|
|
661 ;; toolbars on the side, in which case window-event returns nil.
|
209
|
662 (defun default-mouse-track-set-point-in-window (event window)
|
255
|
663 (if (event-over-modeline-p event)
|
|
664 nil ;; Scroll
|
|
665 ;; Not over a modeline
|
|
666 (if (eq (event-window event) window)
|
|
667 (let ((p (event-closest-point event)))
|
|
668 (if (or (not p) (not (pos-visible-in-window-p p window)))
|
|
669 nil ;; Scroll
|
|
670 (mouse-set-point event)
|
|
671 t))
|
|
672 ;; Not over a modeline, not the same window. Check if the Y position
|
272
|
673 ;; is still overlapping the original window.
|
255
|
674 (let* ((edges (window-pixel-edges window))
|
|
675 (row (event-y-pixel event))
|
|
676 (text-start (nth 1 edges))
|
|
677 (text-end (+ (nth 3 edges))))
|
272
|
678 (if (or (< row text-start)
|
255
|
679 (> row text-end))
|
|
680 nil ;; Scroll
|
|
681 ;; The Y pos in overlapping the original window. Check however if
|
272
|
682 ;; the position is really visible, because there could be a
|
255
|
683 ;; scrollbar or a modeline at this place.
|
|
684 ;; Find the mean line height (height / lines nb), and approximate
|
|
685 ;; the line number for Y pos.
|
|
686 (select-window window)
|
272
|
687 (let ((line (/ (* (- row text-start) (window-height))
|
255
|
688 (- text-end text-start))))
|
|
689 (if (not (save-excursion
|
|
690 (goto-char (window-start))
|
|
691 (pos-visible-in-window-p
|
|
692 (point-at-bol (+ 1 line)))))
|
|
693 nil ;; Scroll
|
|
694 ;; OK, we can go to that position
|
|
695 (goto-char (window-start))
|
|
696 (forward-line line)
|
|
697 ;; On the right side: go to end-of-line.
|
|
698 (when (>= (event-x-pixel event) (nth 2 edges))
|
|
699 (goto-char (point-at-eol)))
|
|
700 t))))
|
|
701 )))
|
|
702
|
209
|
703
|
|
704 (defun default-mouse-track-scroll-and-set-point (event window)
|
|
705 (select-window window)
|
|
706 (let ((edges (window-pixel-edges window))
|
|
707 (row (event-y-pixel event))
|
|
708 (height (face-height 'default)))
|
|
709 (cond ((< (abs (- row (nth 1 edges))) (abs (- row (nth 3 edges))))
|
|
710 ;; closer to window's top than to bottom, so move up
|
|
711 (let ((delta (max 1 (/ (- (nth 1 edges) row) height))))
|
|
712 (condition-case () (scroll-down delta) (error))
|
|
713 (goto-char (window-start))))
|
|
714 ((>= (point) (point-max)))
|
|
715 (t
|
|
716 ;; scroll by one line if over the modeline or a clipped line
|
|
717 (let ((delta (if (or (event-over-modeline-p event)
|
|
718 (< row (nth 3 edges)))
|
|
719 1
|
|
720 (+ (/ (- row (nth 3 edges)) height) 1)))
|
|
721 (close-pos (event-closest-point event)))
|
|
722 (condition-case () (scroll-up delta) (error))
|
|
723 (if (and close-pos (pos-visible-in-window-p close-pos))
|
|
724 (goto-char close-pos)
|
|
725 (goto-char (window-end))
|
|
726 (vertical-motion delta)
|
|
727 ;; window-end reports the end of the clipped line, even if
|
|
728 ;; scroll-on-clipped-lines is t. compensate.
|
|
729 ;; (If window-end gets fixed this can be removed.)
|
272
|
730 (if (not (pos-visible-in-window-p (max (1- (point))
|
209
|
731 (point-min))))
|
|
732 (vertical-motion -1))
|
272
|
733 (condition-case () (backward-char 1)
|
209
|
734 (error (end-of-line)))))))))
|
|
735
|
|
736
|
|
737 ;; This remembers the last position at which the user clicked, for the
|
|
738 ;; benefit of mouse-track-adjust (for example, button1; scroll until the
|
|
739 ;; position of the click is off the frame; then Sh-button1 to select the
|
|
740 ;; new region.
|
|
741 (defvar default-mouse-track-previous-point nil)
|
|
742
|
|
743 (defun default-mouse-track-set-point (event window)
|
|
744 (if (default-mouse-track-set-point-in-window event window)
|
|
745 nil
|
|
746 (default-mouse-track-scroll-and-set-point event window)))
|
|
747
|
|
748 (defsubst default-mouse-track-beginning-of-word (symbolp)
|
|
749 (let ((word-constituent (cond ((eq symbolp t) "\\w\\|\\s_\\|\\s'")
|
|
750 ((null symbolp) "\\w")
|
|
751 (t "[^ \t\n]")))
|
|
752 (white-space "[ \t]"))
|
|
753 (cond ((bobp) nil)
|
|
754 ((looking-at word-constituent)
|
|
755 (backward-char)
|
|
756 (while (and (not (bobp)) (looking-at word-constituent))
|
|
757 (backward-char))
|
|
758 (if (or (not (bobp)) (not (looking-at word-constituent)))
|
|
759 (forward-char)))
|
|
760 ((looking-at white-space)
|
|
761 (backward-char)
|
|
762 (while (looking-at white-space)
|
|
763 (backward-char))
|
|
764 (forward-char)))))
|
|
765
|
|
766 (defun default-mouse-track-end-of-word (symbolp)
|
|
767 (let ((word-constituent (cond ((eq symbolp t) "\\w\\|\\s_\\|\\s'")
|
|
768 ((null symbolp) "\\w")
|
|
769 (t "[^ \t\n]")))
|
|
770 (white-space "[ \t]"))
|
|
771 (cond ((looking-at word-constituent) ; word or symbol constituent
|
|
772 (while (looking-at word-constituent)
|
|
773 (forward-char)))
|
|
774 ((looking-at white-space) ; word or symbol constituent
|
|
775 (while (looking-at white-space)
|
|
776 (forward-char))))))
|
|
777
|
|
778 ;; Decide what will be the SYMBOLP argument to
|
|
779 ;; default-mouse-track-{beginning,end}-of-word, according to the
|
|
780 ;; syntax of the current character and value of mouse-highlight-text.
|
|
781 (defsubst default-mouse-symbolp (syntax)
|
|
782 (cond ((eq mouse-highlight-text 'context)
|
|
783 (eq syntax ?_))
|
|
784 ((eq mouse-highlight-text 'symbol)
|
|
785 t)
|
|
786 (t
|
|
787 nil)))
|
|
788
|
|
789 (defun default-mouse-track-normalize-point (type forwardp)
|
|
790 (cond ((eq type 'word)
|
|
791 ;; trap the beginning and end of buffer errors
|
|
792 (ignore-errors
|
|
793 (setq type (char-syntax (char-after (point))))
|
|
794 (if forwardp
|
|
795 (if (= type ?\()
|
|
796 (goto-char (scan-sexps (point) 1))
|
|
797 (if (= type ?\))
|
|
798 (forward-char 1)
|
|
799 (default-mouse-track-end-of-word
|
|
800 (default-mouse-symbolp type))))
|
|
801 (if (= type ?\))
|
|
802 (goto-char (scan-sexps (1+ (point)) -1))
|
|
803 (default-mouse-track-beginning-of-word
|
|
804 (default-mouse-symbolp type))))))
|
|
805 ((eq type 'line)
|
|
806 (if forwardp (end-of-line) (beginning-of-line)))
|
|
807 ((eq type 'buffer)
|
|
808 (if forwardp (end-of-buffer) (beginning-of-buffer)))))
|
|
809
|
|
810 (defun default-mouse-track-next-move (min-anchor max-anchor extent)
|
|
811 (let ((anchor (if (<= (point) min-anchor) max-anchor min-anchor)))
|
|
812 (funcall default-mouse-track-normalize-point-function
|
|
813 default-mouse-track-type (> (point) anchor))
|
|
814 (if (consp extent)
|
|
815 (default-mouse-track-next-move-rect anchor (point) extent)
|
|
816 (if extent
|
|
817 (if (<= anchor (point))
|
|
818 (set-extent-endpoints extent anchor (point))
|
|
819 (set-extent-endpoints extent (point) anchor))))))
|
|
820
|
|
821 (defun default-mouse-track-next-move-rect (start end extents &optional pad-p)
|
|
822 (if (< end start)
|
|
823 (let ((tmp start)) (setq start end end tmp)))
|
|
824 (cond
|
|
825 ((= start end) ; never delete the last remaining extent
|
|
826 (mapcar 'delete-extent (cdr extents))
|
|
827 (setcdr extents nil)
|
|
828 (set-extent-endpoints (car extents) start start))
|
|
829 (t
|
|
830 (let ((indent-tabs-mode nil) ; if pad-p, don't use tabs
|
|
831 (rest extents)
|
|
832 left right last p)
|
|
833 (save-excursion
|
|
834 (save-restriction
|
|
835 (goto-char end)
|
|
836 (setq right (current-column))
|
|
837 (goto-char start)
|
|
838 (setq left (current-column))
|
|
839 (if (< right left)
|
|
840 (let ((tmp left))
|
|
841 (setq left right right tmp)
|
|
842 (setq start (- start (- right left))
|
|
843 end (+ end (- right left)))))
|
|
844 ;; End may have been set to a value greater than point-max if drag
|
|
845 ;; or movement extends to end of buffer, so reset it.
|
|
846 (setq end (min end (point-max)))
|
|
847 (beginning-of-line)
|
|
848 (narrow-to-region (point) end)
|
|
849 (goto-char start)
|
|
850 (while (and rest (not (eobp)))
|
|
851 (setq p (point))
|
|
852 (move-to-column right pad-p)
|
|
853 (set-extent-endpoints (car rest) p (point))
|
|
854 ;; this code used to look at the return value
|
|
855 ;; of forward-line, but that doesn't work because
|
|
856 ;; forward-line has bogus behavior: If you're on
|
|
857 ;; the last line of a buffer but not at the very
|
|
858 ;; end, forward-line will move you to the very
|
|
859 ;; end and return 0 instead of 1, like it should.
|
|
860 ;; the result was frequent infinite loops here,
|
|
861 ;; creating very large numbers of extents at
|
|
862 ;; the same position. There was an N^2 sorting
|
|
863 ;; algorithm in extents.c for extents at a
|
|
864 ;; particular position, and the result was very
|
|
865 ;; bad news.
|
|
866 (forward-line 1)
|
|
867 (if (not (eobp))
|
|
868 (move-to-column left pad-p))
|
|
869 (setq last rest
|
|
870 rest (cdr rest)))
|
|
871 (cond (rest
|
|
872 (mapcar 'delete-extent rest)
|
|
873 (setcdr last nil))
|
|
874 ((not (eobp))
|
|
875 (while (not (eobp))
|
|
876 (setq p (point))
|
|
877 (move-to-column right pad-p)
|
|
878 (let ((e (make-extent p (point))))
|
|
879 (set-extent-face e (extent-face (car extents)))
|
|
880 (set-extent-priority e (extent-priority (car extents)))
|
|
881 (setcdr last (cons e nil))
|
|
882 (setq last (cdr last)))
|
|
883 (forward-line 1)
|
|
884 (if (not (eobp))
|
|
885 (move-to-column left pad-p))
|
|
886 )))))
|
|
887 ))))
|
|
888
|
|
889 (defun default-mouse-track-has-selection-p (buffer)
|
280
|
890 (and (selection-owner-p)
|
209
|
891 (extent-live-p primary-selection-extent)
|
|
892 (not (extent-detached-p primary-selection-extent))
|
|
893 (eq buffer (extent-object primary-selection-extent))))
|
|
894
|
|
895 (defun default-mouse-track-anchor (adjust previous-point)
|
|
896 (if adjust
|
|
897 (if (default-mouse-track-has-selection-p (current-buffer))
|
|
898 (let ((start (extent-start-position primary-selection-extent))
|
|
899 (end (extent-end-position primary-selection-extent)))
|
|
900 (cond ((< (point) start) end)
|
|
901 ((> (point) end) start)
|
|
902 ((> (- (point) start) (- end (point))) start)
|
|
903 (t end)))
|
|
904 previous-point)
|
|
905 (point)))
|
|
906
|
|
907 (defun default-mouse-track-maybe-own-selection (pair type)
|
|
908 (let ((start (car pair))
|
|
909 (end (cdr pair)))
|
|
910 (or (= start end) (push-mark (if (= (point) start) end start)))
|
|
911 (cond (zmacs-regions
|
|
912 (if (= start end)
|
|
913 nil
|
|
914 ;; #### UTTER KLUDGE.
|
|
915 ;; If we don't have this sit-for here, then triple-clicking
|
|
916 ;; will result in the line not being highlighted as it
|
|
917 ;; should. What appears to be happening is this:
|
|
918 ;;
|
|
919 ;; -- each time the button goes down, the selection is
|
|
920 ;; disowned (see comment "remove the existing selection
|
|
921 ;; to unclutter the display", below).
|
|
922 ;; -- this causes a SelectionClear event to be sent to
|
|
923 ;; XEmacs.
|
|
924 ;; -- each time the button goes up except the first, the
|
|
925 ;; selection is owned again.
|
|
926 ;; -- later, XEmacs processes the SelectionClear event.
|
|
927 ;; The selection code attempts to keep track of the
|
|
928 ;; time that it last asserted the selection, and
|
|
929 ;; compare it to the time of the SelectionClear event,
|
|
930 ;; to see if it's a bogus notification or not (as
|
|
931 ;; is the case here). However, for some unknown
|
|
932 ;; reason this doesn't work in the triple-clicking
|
|
933 ;; case, and the selection code bogusly thinks this
|
|
934 ;; SelectionClear event is the real thing.
|
|
935 ;; -- putting the sit-for in causes the pending
|
|
936 ;; SelectionClear events to get processed before
|
|
937 ;; the selection is reasserted, so everything works
|
|
938 ;; out OK.
|
|
939 ;;
|
|
940 ;; Presumably(?) this means there is a weird timing bug
|
|
941 ;; in the selection code, but there's not a chance in hell
|
|
942 ;; that I have the patience to track it down. Blame the
|
|
943 ;; designers of X for fucking everything up so badly.
|
|
944 ;;
|
|
945 ;; This was originally a sit-for 0 but that wasn't
|
|
946 ;; sufficient to make things work. Even this isn't
|
|
947 ;; always sufficient but it seems to give something
|
|
948 ;; approaching a 99% success rate. Making it higher yet
|
|
949 ;; would help guarantee success with the price that the
|
|
950 ;; delay would start to become noticable.
|
|
951 ;;
|
286
|
952 (and (eq (console-type) 'x)
|
|
953 (sit-for 0.15 t))
|
209
|
954 (zmacs-activate-region)))
|
286
|
955 ((console-on-window-system-p)
|
209
|
956 (if (= start end)
|
280
|
957 (disown-selection type)
|
209
|
958 (if (consp default-mouse-track-extent)
|
|
959 ;; own the rectangular region
|
|
960 ;; this is a hack
|
|
961 (let ((r default-mouse-track-extent))
|
|
962 (save-excursion
|
|
963 (set-buffer (get-buffer-create " *rect yank temp buf*"))
|
|
964 (while r
|
|
965 (insert (extent-string (car r)) "\n")
|
|
966 (setq r (cdr r)))
|
280
|
967 (own-selection (buffer-substring (point-min) (point-max)))
|
209
|
968 (kill-buffer (current-buffer))))
|
280
|
969 (own-selection (cons (set-marker (make-marker) start)
|
|
970 (set-marker (make-marker) end))
|
|
971 type)))))
|
209
|
972 (if (and (eq 'x (console-type))
|
|
973 (not (= start end)))
|
|
974 ;; I guess cutbuffers should do something with rectangles too.
|
|
975 ;; does anybody use them?
|
|
976 (x-store-cutbuffer (buffer-substring start end)))))
|
|
977
|
|
978 (defun default-mouse-track-deal-with-down-event (click-count)
|
|
979 (let ((event default-mouse-track-down-event))
|
|
980 (if (null event) nil
|
|
981 (select-frame (event-frame event))
|
|
982 (let ((adjust default-mouse-track-adjust)
|
|
983 ;; ####When you click on the splash-screen,
|
|
984 ;; event-{closest-,}point can be out of bounds. Should
|
|
985 ;; event-closest-point really be allowed to return a bad
|
|
986 ;; position like that? Maybe pixel_to_glyph_translation
|
|
987 ;; needs to invalidate its cache when the buffer changes.
|
|
988 ;; -dkindred@cs.cmu.edu
|
|
989 (close-pos (save-excursion
|
|
990 (set-buffer (event-buffer event))
|
|
991 (let ((p (event-closest-point event)))
|
|
992 (and p (min (max p (point-min)) (point-max))))))
|
|
993 extent previous-point)
|
272
|
994
|
209
|
995 (if (not (event-window event))
|
|
996 (error "not over window?"))
|
|
997 (setq default-mouse-track-type
|
|
998 (nth (mod (1- click-count)
|
|
999 (length default-mouse-track-type-list))
|
|
1000 default-mouse-track-type-list))
|
|
1001 (setq default-mouse-track-window (event-window event))
|
|
1002 ;; Note that the extent used here is NOT the extent which
|
|
1003 ;; ends up as the value of zmacs-region-extent - this one is used
|
|
1004 ;; just during mouse-dragging.
|
|
1005 (setq default-mouse-track-extent
|
|
1006 (make-extent close-pos close-pos (event-buffer event)))
|
|
1007 (setq extent default-mouse-track-extent)
|
|
1008 (set-extent-face extent 'zmacs-region)
|
|
1009 ;; While the selection is being dragged out, give the selection extent
|
|
1010 ;; slightly higher priority than any mouse-highlighted extent, so that
|
|
1011 ;; the exact endpoints of the selection will be visible while the mouse
|
|
1012 ;; is down. Normally, the selection and mouse highlighting have the
|
|
1013 ;; same priority, so that conflicts between the two of them are
|
|
1014 ;; resolved by the usual size-and-endpoint-comparison method.
|
|
1015 (set-extent-priority extent (1+ mouse-highlight-priority))
|
|
1016 (if mouse-track-rectangle-p
|
|
1017 (setq default-mouse-track-extent
|
|
1018 (list default-mouse-track-extent)))
|
272
|
1019
|
209
|
1020 (setq previous-point
|
|
1021 (if (and adjust
|
|
1022 (markerp default-mouse-track-previous-point)
|
|
1023 (eq (current-buffer)
|
|
1024 (marker-buffer default-mouse-track-previous-point)))
|
|
1025 (marker-position default-mouse-track-previous-point)
|
|
1026 (point)))
|
|
1027 (default-mouse-track-set-point event default-mouse-track-window)
|
|
1028 (if (not adjust)
|
|
1029 (if (markerp default-mouse-track-previous-point)
|
|
1030 (set-marker default-mouse-track-previous-point (point))
|
|
1031 (setq default-mouse-track-previous-point (point-marker))))
|
|
1032 ;;
|
|
1033 ;; adjust point to a word or line boundary if appropriate
|
|
1034 (let ((anchor (default-mouse-track-anchor adjust previous-point)))
|
|
1035 (setq default-mouse-track-min-anchor
|
|
1036 (save-excursion (goto-char anchor)
|
|
1037 (funcall
|
|
1038 default-mouse-track-normalize-point-function
|
|
1039 default-mouse-track-type nil)
|
|
1040 (point)))
|
|
1041 (setq default-mouse-track-max-anchor
|
|
1042 (save-excursion (goto-char anchor)
|
|
1043 (funcall
|
|
1044 default-mouse-track-normalize-point-function
|
|
1045 default-mouse-track-type t)
|
|
1046 (point))))
|
|
1047 ;;
|
|
1048 ;; remove the existing selection to unclutter the display
|
|
1049 (if (not adjust)
|
|
1050 (cond (zmacs-regions
|
|
1051 (zmacs-deactivate-region))
|
286
|
1052 ((console-on-window-system-p)
|
|
1053 (disown-selection)))))
|
209
|
1054 (setq default-mouse-track-down-event nil))))
|
|
1055
|
|
1056 (defun default-mouse-track-down-hook (event click-count)
|
|
1057 (setq default-mouse-track-down-event (copy-event event))
|
|
1058 nil)
|
|
1059
|
|
1060 (defun default-mouse-track-cleanup-extents-hook ()
|
|
1061 (remove-hook 'pre-command-hook 'default-mouse-track-cleanup-extents-hook)
|
|
1062 (let ((extent default-mouse-track-extent))
|
|
1063 (if (consp extent) ; rectangle-p
|
|
1064 (mapcar 'delete-extent extent)
|
|
1065 (if extent
|
|
1066 (delete-extent extent)))))
|
|
1067
|
|
1068 (defun default-mouse-track-cleanup-hook ()
|
|
1069 (if zmacs-regions
|
|
1070 (funcall 'default-mouse-track-cleanup-extents-hook)
|
|
1071 (let ((extent default-mouse-track-extent)
|
|
1072 (func #'(lambda (e)
|
|
1073 (and (extent-live-p e)
|
|
1074 (set-extent-face e 'primary-selection)))))
|
|
1075 (add-hook 'pre-command-hook 'default-mouse-track-cleanup-extents-hook)
|
|
1076 (if (consp extent) ; rectangle-p
|
|
1077 (mapcar func extent)
|
|
1078 (if extent
|
|
1079 (funcall func extent))))))
|
|
1080
|
|
1081 (defun default-mouse-track-cleanup-extent ()
|
|
1082 (let ((dead-func
|
|
1083 (function (lambda (x)
|
|
1084 (or (not (extent-live-p x))
|
|
1085 (extent-detached-p x)))))
|
|
1086 (extent default-mouse-track-extent))
|
|
1087 (if (consp extent)
|
|
1088 (if (funcall dead-func extent)
|
|
1089 (let (newval)
|
|
1090 (mapcar (function (lambda (x)
|
|
1091 (if (not (funcall dead-func x))
|
|
1092 (setq newval (cons x newval)))))
|
|
1093 extent)
|
|
1094 (setq default-mouse-track-extent (nreverse newval))))
|
|
1095 (if (funcall dead-func extent)
|
|
1096 (setq default-mouse-track-extent nil)))))
|
|
1097
|
|
1098 (defun default-mouse-track-drag-hook (event click-count was-timeout)
|
|
1099 (default-mouse-track-deal-with-down-event click-count)
|
|
1100 (default-mouse-track-set-point event default-mouse-track-window)
|
|
1101 (default-mouse-track-cleanup-extent)
|
|
1102 (default-mouse-track-next-move default-mouse-track-min-anchor
|
|
1103 default-mouse-track-max-anchor
|
|
1104 default-mouse-track-extent)
|
|
1105 t)
|
|
1106
|
|
1107 (defun default-mouse-track-return-dragged-selection (event)
|
|
1108 (default-mouse-track-cleanup-extent)
|
|
1109 (let ((extent default-mouse-track-extent)
|
|
1110 result)
|
|
1111 (default-mouse-track-set-point-in-window event default-mouse-track-window)
|
|
1112 (default-mouse-track-next-move default-mouse-track-min-anchor
|
|
1113 default-mouse-track-max-anchor
|
|
1114 extent)
|
|
1115 (cond ((consp extent) ; rectangle-p
|
|
1116 (let ((first (car extent))
|
|
1117 (last (car (setq extent (nreverse extent)))))
|
|
1118 ;; nreverse is destructive so we need to reset this
|
|
1119 (setq default-mouse-track-extent extent)
|
|
1120 (setq result (cons (extent-start-position first)
|
|
1121 (extent-end-position last)))
|
|
1122 ;; kludge to fix up region when dragging backwards...
|
|
1123 (if (and (/= (point) (extent-start-position first))
|
|
1124 (/= (point) (extent-end-position last))
|
|
1125 (= (point) (extent-end-position first)))
|
|
1126 (goto-char (car result)))))
|
|
1127 (extent
|
|
1128 (setq result (cons (extent-start-position extent)
|
|
1129 (extent-end-position extent)))))
|
|
1130 ;; Minor kludge: if we're selecting in line-mode, include the
|
|
1131 ;; final newline. It's hard to do this in *-normalize-point.
|
|
1132 (if (and result (eq default-mouse-track-type 'line))
|
|
1133 (let ((end-p (= (point) (cdr result))))
|
|
1134 (goto-char (cdr result))
|
|
1135 (if (not (eobp))
|
|
1136 (setcdr result (1+ (cdr result))))
|
|
1137 (goto-char (if end-p (cdr result) (car result)))))
|
|
1138 ;;; ;; Minor kludge sub 2. If in char mode, and we drag the
|
|
1139 ;;; ;; mouse past EOL, include the newline.
|
|
1140 ;;; ;;
|
|
1141 ;;; ;; Major problem: can't easily distinguish between being
|
|
1142 ;;; ;; just past the last char on a line, and well past it,
|
|
1143 ;;; ;; to determine whether or not to include it in the region
|
|
1144 ;;; ;;
|
|
1145 ;;; (if nil ; (eq default-mouse-track-type 'char)
|
|
1146 ;;; (let ((after-end-p (and (not (eobp))
|
|
1147 ;;; (eolp)
|
|
1148 ;;; (> (point) (car result)))))
|
|
1149 ;;; (if after-end-p
|
|
1150 ;;; (progn
|
|
1151 ;;; (setcdr result (1+ (cdr result)))
|
|
1152 ;;; (goto-char (cdr result))))))
|
|
1153 result))
|
|
1154
|
|
1155 (defun default-mouse-track-drag-up-hook (event click-count)
|
|
1156 (let ((result (default-mouse-track-return-dragged-selection event)))
|
|
1157 (if result
|
|
1158 (default-mouse-track-maybe-own-selection result 'PRIMARY)))
|
|
1159 t)
|
|
1160
|
|
1161 (defun default-mouse-track-click-hook (event click-count)
|
|
1162 (default-mouse-track-drag-hook event click-count nil)
|
|
1163 (default-mouse-track-drag-up-hook event click-count)
|
|
1164 t)
|
|
1165
|
|
1166 (add-hook 'mouse-track-down-hook 'default-mouse-track-down-hook)
|
|
1167 (add-hook 'mouse-track-drag-hook 'default-mouse-track-drag-hook)
|
|
1168 (add-hook 'mouse-track-drag-up-hook 'default-mouse-track-drag-up-hook)
|
|
1169 (add-hook 'mouse-track-click-hook 'default-mouse-track-click-hook)
|
|
1170 (add-hook 'mouse-track-cleanup-hook 'default-mouse-track-cleanup-hook)
|
|
1171
|
|
1172
|
|
1173 ;;;;;;;;;;;; other mouse-track stuff (mostly associated with the
|
|
1174 ;;;;;;;;;;;; default handlers)
|
|
1175
|
|
1176 (defun mouse-track-default (event)
|
|
1177 "Invoke `mouse-track' with only the default handlers active."
|
|
1178 (interactive "e")
|
|
1179 (let ((mouse-track-down-hook 'default-mouse-track-down-hook)
|
|
1180 (mouse-track-drag-hook 'default-mouse-track-drag-hook)
|
|
1181 (mouse-track-drag-up-hook 'default-mouse-track-drag-up-hook)
|
|
1182 (mouse-track-click-hook 'default-mouse-track-click-hook)
|
|
1183 (mouse-track-cleanup-hook 'default-mouse-track-cleanup-hook))
|
|
1184 (mouse-track event)))
|
|
1185
|
|
1186 (defun mouse-track-do-rectangle (event)
|
|
1187 "Like `mouse-track' but selects rectangles instead of regions."
|
|
1188 (interactive "e")
|
|
1189 (let ((mouse-track-rectangle-p t))
|
|
1190 (mouse-track event)))
|
|
1191
|
|
1192 (defun mouse-track-adjust (event)
|
|
1193 "Extend the existing selection. This should be bound to a mouse button.
|
|
1194 The selection will be enlarged or shrunk so that the point of the mouse
|
|
1195 click is one of its endpoints. This function in fact behaves fairly
|
|
1196 similarly to `mouse-track', but begins by extending the existing selection
|
|
1197 (or creating a new selection from the previous text cursor position to
|
|
1198 the current mouse position) instead of creating a new, empty selection.
|
|
1199
|
|
1200 The mouse-track handlers are run from this command just like from
|
|
1201 `mouse-track'. Therefore, do not call this command from a mouse-track
|
|
1202 handler!"
|
|
1203 (interactive "e")
|
|
1204 (let ((default-mouse-track-adjust t))
|
|
1205 (mouse-track event)))
|
|
1206
|
|
1207 (defun mouse-track-adjust-default (event)
|
|
1208 "Extend the existing selection, using only the default handlers.
|
|
1209 This is just like `mouse-track-adjust' but will override any
|
|
1210 custom mouse-track handlers that the user may have installed."
|
|
1211 (interactive "e")
|
|
1212 (let ((default-mouse-track-adjust t))
|
|
1213 (mouse-track-default event)))
|
|
1214
|
|
1215 (defvar mouse-track-insert-selected-region nil)
|
|
1216
|
|
1217 (defun mouse-track-insert-drag-up-hook (event click-count)
|
|
1218 (setq mouse-track-insert-selected-region
|
|
1219 (default-mouse-track-return-dragged-selection event)))
|
272
|
1220
|
209
|
1221 (defun mouse-track-insert (event &optional delete)
|
|
1222 "Make a selection with the mouse and insert it at point.
|
|
1223 This is exactly the same as the `mouse-track' command on \\[mouse-track],
|
|
1224 except that point is not moved; the selected text is immediately inserted
|
|
1225 after being selected\; and the selection is immediately disowned afterwards."
|
|
1226 (interactive "*e")
|
|
1227 (setq mouse-track-insert-selected-region nil)
|
|
1228 (let ((mouse-track-drag-up-hook 'mouse-track-insert-drag-up-hook)
|
|
1229 (mouse-track-click-hook 'mouse-track-insert-click-hook)
|
|
1230 s)
|
|
1231 (save-excursion
|
|
1232 (save-window-excursion
|
|
1233 (mouse-track event)
|
|
1234 (if (consp mouse-track-insert-selected-region)
|
|
1235 (let ((pair mouse-track-insert-selected-region))
|
|
1236 (setq s (prog1
|
|
1237 (buffer-substring (car pair) (cdr pair))
|
|
1238 (if delete
|
|
1239 (kill-region (car pair) (cdr pair)))))))))
|
|
1240 (or (null s) (equal s "") (insert s))))
|
|
1241
|
|
1242 (defun mouse-track-insert-click-hook (event click-count)
|
|
1243 (default-mouse-track-drag-hook event click-count nil)
|
|
1244 (mouse-track-insert-drag-up-hook event click-count)
|
|
1245 t)
|
|
1246
|
|
1247 (defun mouse-track-delete-and-insert (event)
|
|
1248 "Make a selection with the mouse and insert it at point.
|
|
1249 This is exactly the same as the `mouse-track' command on \\[mouse-track],
|
|
1250 except that point is not moved; the selected text is immediately inserted
|
|
1251 after being selected\; and the text of the selection is deleted."
|
|
1252 (interactive "*e")
|
|
1253 (mouse-track-insert event t))
|
|
1254
|
|
1255 ;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1256
|
|
1257
|
|
1258 (defvar inhibit-help-echo nil
|
|
1259 "Inhibits display of `help-echo' extent properties in the minibuffer.")
|
|
1260 (defvar last-help-echo-object nil)
|
|
1261 (defvar help-echo-owns-message nil)
|
|
1262
|
|
1263 (defun clear-help-echo (&optional ignored-frame)
|
|
1264 (if help-echo-owns-message
|
|
1265 (progn
|
|
1266 (setq help-echo-owns-message nil
|
|
1267 last-help-echo-object nil)
|
|
1268 (clear-message 'help-echo))))
|
|
1269
|
|
1270 (defun show-help-echo (mess)
|
|
1271 ;; (clear-help-echo)
|
|
1272 (setq help-echo-owns-message t)
|
|
1273 (display-message 'help-echo mess))
|
|
1274
|
|
1275 (add-hook 'mouse-leave-frame-hook 'clear-help-echo)
|
|
1276
|
|
1277 ;; It may be a good idea to move this to C, for better performance of
|
|
1278 ;; extent highlighting and pointer changes.
|
|
1279 (defun default-mouse-motion-handler (event)
|
|
1280 "For use as the value of `mouse-motion-handler'.
|
|
1281 This implements the various pointer-shape variables,
|
|
1282 as well as extent highlighting, help-echo, toolbar up/down,
|
|
1283 and `mode-motion-hook'."
|
|
1284 (let* ((frame (or (event-frame event) (selected-frame)))
|
|
1285 (window (event-window event))
|
|
1286 (buffer (event-buffer event))
|
|
1287 (modeline-point (and buffer (event-modeline-position event)))
|
|
1288 (modeline-string (and modeline-point
|
|
1289 (symbol-value-in-buffer
|
|
1290 'generated-modeline-string buffer)))
|
|
1291 ;; point must be invalidated by modeline-point.
|
|
1292 (point (and buffer (not modeline-point)
|
|
1293 (event-point event)))
|
|
1294 (extent (or (and point
|
|
1295 (extent-at point buffer 'mouse-face))
|
|
1296 (and modeline-point
|
|
1297 (extent-at modeline-point modeline-string
|
|
1298 ;; Modeline extents don't have a
|
|
1299 ;; mouse-face property set.
|
|
1300 'help-echo))))
|
|
1301 (glyph-extent1 (event-glyph-extent event))
|
|
1302 (glyph-extent (and glyph-extent1
|
|
1303 (extent-live-p glyph-extent1)
|
|
1304 glyph-extent1))
|
|
1305 ;; This is an extent:
|
|
1306 (user-pointer1 (or (and glyph-extent
|
|
1307 (extent-property glyph-extent 'pointer)
|
|
1308 glyph-extent)
|
|
1309 (and point (extent-at point buffer 'pointer))
|
|
1310 (and modeline-point
|
|
1311 (extent-at modeline-point modeline-string
|
|
1312 'pointer))))
|
|
1313 ;; And this should be a glyph:
|
|
1314 (user-pointer (and user-pointer1 (extent-live-p user-pointer1)
|
|
1315 (extent-property user-pointer1 'pointer)))
|
|
1316 (button (event-toolbar-button event))
|
|
1317 (help (or (and glyph-extent (extent-property glyph-extent 'help-echo)
|
|
1318 glyph-extent)
|
|
1319 (and button (not (null (toolbar-button-help-string button)))
|
|
1320 button)
|
|
1321 (and point
|
|
1322 (extent-at point buffer 'help-echo))
|
|
1323 (and modeline-point
|
|
1324 (extent-at modeline-point modeline-string
|
|
1325 'help-echo))))
|
|
1326 ;; vars is a list of glyph variables to check for a pointer
|
|
1327 ;; value.
|
|
1328 (vars (cond
|
|
1329 ;; Checking if button is non-nil is not sufficent
|
|
1330 ;; since the pointer could be over a blank portion
|
|
1331 ;; of the toolbar.
|
|
1332 ((event-over-toolbar-p event)
|
|
1333 '(toolbar-pointer-glyph nontext-pointer-glyph
|
|
1334 text-pointer-glyph))
|
|
1335 ((or extent glyph-extent)
|
|
1336 '(selection-pointer-glyph text-pointer-glyph))
|
|
1337 ((event-over-modeline-p event)
|
|
1338 '(modeline-pointer-glyph nontext-pointer-glyph
|
|
1339 text-pointer-glyph))
|
284
|
1340 ((and (event-over-vertical-divider-p event)
|
|
1341 (specifier-instance vertical-divider-draggable-p
|
|
1342 (event-window event)))
|
|
1343 '(divider-pointer-glyph nontext-pointer-glyph
|
|
1344 text-pointer-glyph))
|
209
|
1345 (point '(text-pointer-glyph))
|
|
1346 (buffer '(nontext-pointer-glyph text-pointer-glyph))
|
|
1347 (t '(nontext-pointer-glyph text-pointer-glyph))))
|
|
1348 pointer)
|
|
1349 (and user-pointer (glyphp user-pointer)
|
|
1350 (push 'user-pointer vars))
|
|
1351 (while (and vars (not (pointer-image-instance-p pointer)))
|
|
1352 (setq pointer (glyph-image-instance (symbol-value (car vars))
|
|
1353 (or window frame))
|
|
1354 vars (cdr vars)))
|
|
1355
|
|
1356 (if (pointer-image-instance-p pointer)
|
|
1357 (set-frame-pointer frame pointer))
|
|
1358
|
|
1359 ;; If last-pressed-toolbar-button is not nil, then check and see
|
|
1360 ;; if we have moved to a new button and adjust the down flags
|
|
1361 ;; accordingly.
|
|
1362 (when (and (featurep 'toolbar) toolbar-active)
|
|
1363 (unless (eq last-pressed-toolbar-button button)
|
|
1364 (release-previous-toolbar-button event)
|
|
1365 (and button (press-toolbar-button event))))
|
|
1366
|
|
1367 (cond (extent (highlight-extent extent t))
|
|
1368 (glyph-extent (highlight-extent glyph-extent t))
|
|
1369 (t (highlight-extent nil nil)))
|
|
1370 (cond ((extentp help)
|
|
1371 (or inhibit-help-echo
|
|
1372 (eq help last-help-echo-object) ;save some time
|
|
1373 (let ((hprop (extent-property help 'help-echo)))
|
|
1374 (setq last-help-echo-object help)
|
|
1375 (or (stringp hprop)
|
|
1376 (setq hprop (funcall hprop help)))
|
|
1377 (and hprop (show-help-echo hprop)))))
|
|
1378 ((and (featurep 'toolbar)
|
|
1379 (toolbar-button-p help)
|
|
1380 (toolbar-button-enabled-p help))
|
|
1381 (or (not toolbar-help-enabled)
|
|
1382 (eq help last-help-echo-object) ;save some time
|
|
1383 (let ((hstring (toolbar-button-help-string button)))
|
|
1384 (setq last-help-echo-object help)
|
|
1385 (or (stringp hstring)
|
|
1386 (setq hstring (funcall hstring help)))
|
|
1387 (show-help-echo hstring))))
|
|
1388 (last-help-echo-object
|
|
1389 (clear-help-echo)))
|
|
1390 (if mouse-grabbed-buffer (setq buffer mouse-grabbed-buffer))
|
|
1391 (if (and buffer (symbol-value-in-buffer 'mode-motion-hook buffer nil))
|
|
1392 (with-current-buffer buffer
|
|
1393 (run-hook-with-args 'mode-motion-hook event)
|
|
1394
|
|
1395 ;; If the mode-motion-hook created a highlightable extent around
|
|
1396 ;; the mouse-point, highlight it right away. Otherwise it wouldn't
|
|
1397 ;; be highlighted until the *next* motion event came in.
|
|
1398 (if (and point
|
|
1399 (null extent)
|
|
1400 (setq extent (extent-at point
|
|
1401 (event-buffer event) ; not buffer
|
|
1402 'mouse-face)))
|
|
1403 (highlight-extent extent t)))))
|
|
1404 nil)
|
|
1405
|
|
1406 (setq mouse-motion-handler 'default-mouse-motion-handler)
|
284
|
1407
|
|
1408 ;;
|
|
1409 ;; Vertical divider dragging
|
|
1410 ;;
|
|
1411 (defun drag-window-divider (event)
|
|
1412 "Handle resizing windows by dragging window dividers.
|
|
1413 This is an intenal function, normally bound to button1 event in
|
|
1414 window-divider-map. You would not call it, but you may bind it to
|
|
1415 other mouse buttons."
|
|
1416 (interactive "e")
|
|
1417 (if (not (specifier-instance vertical-divider-draggable-p
|
|
1418 (event-window event)))
|
|
1419 (error "Not over a window!"))
|
288
|
1420 (let-specifier ((vertical-divider-shadow-thickness
|
|
1421 (- (specifier-instance vertical-divider-shadow-thickness
|
|
1422 (event-window event)))
|
|
1423 (event-window event)))
|
286
|
1424 (let* ((window (event-window event))
|
|
1425 (frame (event-channel event))
|
|
1426 (last-timestamp (event-timestamp event))
|
|
1427 (doit t))
|
|
1428 (while doit
|
|
1429 (let ((old-right (caddr (window-pixel-edges window)))
|
|
1430 (old-left (car (window-pixel-edges window)))
|
|
1431 (backup-conf (current-window-configuration frame))
|
|
1432 (old-edges-all-windows (mapcar 'window-pixel-edges (window-list))))
|
284
|
1433
|
286
|
1434 ;; This is borrowed from modeline.el:
|
|
1435 ;; requeue event and quit if this is a misc-user, eval or
|
|
1436 ;; keypress event.
|
|
1437 ;; quit if this is a button press or release event, or if the event
|
|
1438 ;; occurred in some other frame.
|
|
1439 ;; drag if this is a mouse motion event and the time
|
|
1440 ;; between this event and the last event is greater than
|
|
1441 ;; drag-modeline-event-lag.
|
|
1442 ;; do nothing if this is any other kind of event.
|
|
1443 (setq event (next-event event))
|
|
1444 (cond ((or (misc-user-event-p event)
|
|
1445 (key-press-event-p event))
|
|
1446 (setq unread-command-events (nconc unread-command-events
|
|
1447 (list event))
|
|
1448 doit nil))
|
|
1449 ((button-release-event-p event)
|
|
1450 (setq doit nil))
|
|
1451 ((button-event-p event)
|
|
1452 (setq doit nil))
|
|
1453 ((not (motion-event-p event))
|
|
1454 (dispatch-event event))
|
|
1455 ((not (eq frame (event-frame event)))
|
|
1456 (setq doit nil))
|
|
1457 ((< (abs (- (event-timestamp event) last-timestamp))
|
|
1458 drag-modeline-event-lag))
|
|
1459 (t
|
|
1460 (setq last-timestamp (event-timestamp event))
|
|
1461 ;; Enlarge the window, calculating change in characters
|
|
1462 ;; of default font. Do not let the window to become
|
|
1463 ;; less than alolwed minimum (not because that's critical
|
|
1464 ;; for the code performance, just the visual effect is
|
|
1465 ;; better: when cursor goes to the left of the next left
|
|
1466 ;; divider, the vindow being resized shrinks to minimal
|
|
1467 ;; size.
|
|
1468 (enlarge-window (max (- window-min-width (window-width window))
|
|
1469 (/ (- (event-x-pixel event) old-right)
|
|
1470 (face-width 'default window)))
|
|
1471 t window)
|
|
1472 ;; Backout the change if some windows got deleted, or
|
|
1473 ;; if the change caused more than two windows to resize
|
|
1474 ;; (shifting the whole stack right is ugly), or if the
|
|
1475 ;; left window side has slipped (right side cannot be
|
|
1476 ;; moved any funrther to the right, so enlarge-window
|
|
1477 ;; plays bad games with the left edge.
|
|
1478 (if (or (/= (count-windows) (length old-edges-all-windows))
|
|
1479 (/= old-left (car (window-pixel-edges window)))
|
|
1480 ;; This check is very hairy. We allow any number
|
|
1481 ;; of left edges to change, but only to the same
|
|
1482 ;; new value. Similar procedure is for the right edges.
|
|
1483 (let ((all-that-bad nil)
|
|
1484 (new-left-ok nil)
|
|
1485 (new-right-ok nil))
|
|
1486 (mapcar* (lambda (window old-edges)
|
|
1487 (let ((new (car (window-pixel-edges window))))
|
|
1488 (if (/= new (car old-edges))
|
|
1489 (if (and new-left-ok
|
|
1490 (/= new-left-ok new))
|
|
1491 (setq all-that-bad t)
|
|
1492 (setq new-left-ok new)))))
|
|
1493 (window-list) old-edges-all-windows)
|
|
1494 (mapcar* (lambda (window old-edges)
|
|
1495 (let ((new (caddr (window-pixel-edges window))))
|
|
1496 (if (/= new (caddr old-edges))
|
|
1497 (if (and new-right-ok
|
|
1498 (/= new-right-ok new))
|
|
1499 (setq all-that-bad t)
|
|
1500 (setq new-right-ok new)))))
|
|
1501 (window-list) old-edges-all-windows)
|
|
1502 all-that-bad))
|
288
|
1503 (set-window-configuration backup-conf)))))))))
|
284
|
1504
|
|
1505 (setq vertical-divider-map (make-keymap))
|
|
1506 (define-key vertical-divider-map 'button1 'drag-window-divider)
|
209
|
1507
|
|
1508 ;;; mouse.el ends here
|