annotate lisp/mouse.el @ 4792:95b04754ea8c

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