Mercurial > emacs
annotate lisp/mouse-sel.el @ 17565:09d1f6578d7f
(rmail-reply): Pass Rmail buffer and msgnum
as arguments within the mail-send action.
(rmail-forward, rmail-retry-failure): Likewise.
(rmail-mark-message): New function.
(rmail-only-expunge): Update the new kind of action.
(rmail-send-actions-rmail-msg-number)
(rmail-send-actions-rmail-buffer): Variables no longer used.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 26 Apr 1997 01:33:18 +0000 |
parents | 51916440738f |
children | 3e65698d4ce9 |
rev | line source |
---|---|
4934 | 1 ;;; mouse-sel.el --- Multi-click selection support for Emacs 19 |
2 | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. |
4934 | 4 |
5 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz> | |
6 ;; Keywords: mouse | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
14169 | 20 ;; You should have received a copy of the GNU General Public License |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
7942 | 25 ;;; Commentary: |
14169 | 26 |
4934 | 27 ;; This module provides multi-click mouse support for GNU Emacs versions |
28 ;; 19.18 and later. I've tried to make it behave more like standard X | |
29 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers. | |
30 ;; Basically: | |
31 ;; | |
32 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it. | |
33 ;; | |
34 ;; * Clicking or dragging mouse-3 extends the selection as well. | |
35 ;; | |
36 ;; * Double-clicking on word constituents selects words. | |
37 ;; Double-clicking on symbol constituents selects symbols. | |
38 ;; Double-clicking on quotes or parentheses selects sexps. | |
39 ;; Double-clicking on whitespace selects whitespace. | |
40 ;; Triple-clicking selects lines. | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
41 ;; Quad-clicking selects paragraphs. |
4934 | 42 ;; |
43 ;; * Selecting sets the region & X primary selection, but does NOT affect | |
44 ;; the kill-ring. Because the mouse handlers set the primary selection | |
45 ;; directly, mouse-sel sets the variables interprogram-cut-function | |
46 ;; and interprogram-paste-function to nil. | |
47 ;; | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
48 ;; * Clicking mouse-2 inserts the contents of the primary selection at |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
49 ;; the mouse position (or point, if mouse-yank-at-point is non-nil). |
4934 | 50 ;; |
5750
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
51 ;; * Pressing mouse-2 while selecting or extending copies selection |
4934 | 52 ;; to the kill ring. Pressing mouse-1 or mouse-3 kills it. |
5750
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
53 ;; |
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
54 ;; * Double-clicking mouse-3 also kills selection. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
55 ;; |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
56 ;; * M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
57 ;; & mouse-3, but operate on the X secondary selection rather than the |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
58 ;; primary selection and region. |
4934 | 59 ;; |
5750
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
60 ;; This module requires my thingatpt.el module, which it uses to find the |
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
61 ;; bounds of words, lines, sexps, etc. |
4934 | 62 ;; |
63 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input. | |
64 ;; | |
5750
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
65 ;;--- Customisation ------------------------------------------------------- |
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
66 ;; |
e1153522d5f1
(mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents:
4934
diff
changeset
|
67 ;; * You may want to use none or more of following: |
4934 | 68 ;; |
69 ;; ;; Enable region highlight | |
70 ;; (transient-mark-mode 1) | |
71 ;; | |
72 ;; ;; But only in the selected window | |
73 ;; (setq highlight-nonselected-windows nil) | |
74 ;; | |
75 ;; ;; Enable pending-delete | |
76 ;; (delete-selection-mode 1) | |
77 ;; | |
8766 | 78 ;; * You can control the way mouse-sel binds its keys by setting the value |
4934 | 79 ;; of mouse-sel-default-bindings before loading mouse-sel. |
80 ;; | |
81 ;; (a) If mouse-sel-default-bindings = t (the default) | |
82 ;; | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
83 ;; Mouse sets and insert selection |
4934 | 84 ;; mouse-1 mouse-select |
85 ;; mouse-2 mouse-insert-selection | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
86 ;; mouse-3 mouse-extend |
4934 | 87 ;; |
88 ;; Selection/kill-ring interaction is disabled | |
89 ;; interprogram-cut-function = nil | |
90 ;; interprogram-paste-function = nil | |
91 ;; | |
92 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste | |
93 ;; | |
94 ;; Mouse sets selection, and pastes from kill-ring | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
95 ;; mouse-1 mouse-select |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
96 ;; mouse-2 mouse-yank-at-click |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
97 ;; mouse-3 mouse-extend |
4934 | 98 ;; |
99 ;; Selection/kill-ring interaction is retained | |
100 ;; interprogram-cut-function = x-select-text | |
101 ;; interprogram-paste-function = x-cut-buffer-or-selection-value | |
102 ;; | |
103 ;; What you lose is the ability to select some text in | |
104 ;; delete-selection-mode and yank over the top of it. | |
105 ;; | |
106 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made. | |
107 ;; | |
6228 | 108 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at |
109 ;; the mouse position. You can tell it to insert at point instead with: | |
110 ;; | |
7644
d50f6828a89d
(mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
111 ;; (setq mouse-yank-at-point t) |
6228 | 112 ;; |
4934 | 113 ;; * I like to leave point at the end of the region nearest to where the |
114 ;; mouse was, even though this makes region highlighting mis-leading (the | |
115 ;; cursor makes it look like one extra character is selected). You can | |
116 ;; disable this behaviour with: | |
117 ;; | |
118 ;; (setq mouse-sel-leave-point-near-mouse nil) | |
119 ;; | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
120 ;; * By default, mouse-select cycles the click count after 4 clicks. That |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
121 ;; is, clicking mouse-1 five times has the same effect as clicking it |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
122 ;; once, clicking six times has the same effect as clicking twice, etc. |
4934 | 123 ;; Disable this behaviour with: |
124 ;; | |
125 ;; (setq mouse-sel-cycle-clicks nil) | |
126 ;; | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
127 ;; * The variables mouse-sel-{set,get}-selection-function control how the |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
128 ;; selection is handled. Under X Windows, these variables default so |
4934 | 129 ;; that the X primary selection is used. Under other windowing systems, |
130 ;; alternate functions are used, which simply store the selection value | |
131 ;; in a variable. | |
132 ;; | |
133 ;; * You can change the selection highlight face by altering the properties | |
134 ;; of mouse-drag-overlay, eg. | |
135 ;; | |
136 ;; (overlay-put mouse-drag-overlay 'face 'bold) | |
137 | |
14169 | 138 ;;; Code: |
4934 | 139 |
140 (provide 'mouse-sel) | |
141 | |
142 (require 'mouse) | |
143 (require 'thingatpt) | |
144 | |
145 ;;=== User Variables ====================================================== | |
146 | |
147 (defvar mouse-sel-leave-point-near-mouse t | |
148 "*Leave point near last mouse position. | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
149 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end |
4934 | 150 of the region nearest to where the mouse last was. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
151 If nil, point will always be placed at the beginning of the region.") |
4934 | 152 |
153 (defvar mouse-sel-cycle-clicks t | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
154 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks.") |
4934 | 155 |
156 (defvar mouse-sel-default-bindings t | |
6228 | 157 "Set to nil before loading `mouse-sel' to prevent default mouse bindings.") |
4934 | 158 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
159 ;;=== Internal Variables/Constants ======================================== |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
160 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
161 (defvar mouse-sel-primary-thing nil |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
162 "Type of PRIMARY selection in current buffer.") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
163 (make-variable-buffer-local 'mouse-sel-primary-thing) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
164 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
165 (defvar mouse-sel-secondary-thing nil |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
166 "Type of SECONDARY selection in current buffer.") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
167 (make-variable-buffer-local 'mouse-sel-secondary-thing) |
4934 | 168 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
169 ;; Ensure that secondary overlay is defined |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
170 (if (overlayp mouse-secondary-overlay) nil |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
171 (setq mouse-secondary-overlay (make-overlay 1 1)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
172 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)) |
4934 | 173 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
174 (defconst mouse-sel-selection-alist |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
175 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
176 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
177 "Alist associating selections with variables. Each element is of |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
178 the form: |
4934 | 179 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
180 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
181 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
182 where SELECTION-NAME = name of selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
183 OVERLAY-SYMBOL = name of variable containing overlay to use |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
184 SELECTION-THING-SYMBOL = name of variable where the current selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
185 type for this selection should be stored.") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
186 |
4934 | 187 (defvar mouse-sel-set-selection-function |
16471
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
188 (function (lambda (selection value) |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
189 (if (eq selection 'PRIMARY) |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
190 (x-select-text value) |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
191 (x-set-selection selection value)))) |
4934 | 192 "Function to call to set selection. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
193 Called with two arguments: |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
194 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
195 SELECTION, the name of the selection concerned, and |
16471
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
196 VALUE, the text to store. |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
197 This sets the selection as well as the cut buffer for the older applications. |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
198 Use (setq mouse-sel-set-selection-function 'x-set-selection) if you don't care |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
199 for them.") |
4934 | 200 |
201 (defvar mouse-sel-get-selection-function | |
16471
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
202 (function (lambda (selection) |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
203 (if (eq selection 'PRIMARY) |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
204 (x-cut-buffer-or-selection-value) |
51916440738f
(mouse-sel-set-selection-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
205 (x-get-selection selection)))) |
4934 | 206 "Function to call to get the selection. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
207 Called with one argument: |
4934 | 208 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
209 SELECTION: the name of the selection concerned.") |
4934 | 210 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
211 ;;=== Support/access functions ============================================ |
4934 | 212 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
213 (defun mouse-sel-determine-selection-thing (nclicks) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
214 "Determine what `thing' `mouse-sel' should operate on. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
215 The first argument is NCLICKS, is the number of consecutive |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
216 mouse clicks at the same position. |
4934 | 217 |
218 Double-clicking on word constituents selects words. | |
219 Double-clicking on symbol constituents selects symbols. | |
220 Double-clicking on quotes or parentheses selects sexps. | |
221 Double-clicking on whitespace selects whitespace. | |
222 Triple-clicking selects lines. | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
223 Quad-clicking selects paragraphs. |
4934 | 224 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
225 Feel free to re-define this function to support your own desired |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
226 multi-click semantics." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
227 (let* ((next-char (char-after (point))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
228 (char-syntax (if next-char (char-syntax next-char)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
229 (if mouse-sel-cycle-clicks |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
230 (setq nclicks (1+ (% (1- nclicks) 4)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
231 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
232 ((= nclicks 1) nil) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
233 ((= nclicks 3) 'line) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
234 ((>= nclicks 4) 'paragraph) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
235 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
236 ((memq next-char '(? ?\t ?\n)) 'whitespace) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
237 ((eq char-syntax ?_) 'symbol) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
238 ((eq char-syntax ?w) 'word)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
239 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
240 (defun mouse-sel-set-selection (selection value) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
241 "Set the specified SELECTION to VALUE." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
242 (if mouse-sel-set-selection-function |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
243 (funcall mouse-sel-set-selection-function selection value) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
244 (put 'mouse-sel-internal-selection selection value))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
245 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
246 (defun mouse-sel-get-selection (selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
247 "Get the value of the specified SELECTION." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
248 (if mouse-sel-get-selection-function |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
249 (funcall mouse-sel-get-selection-function selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
250 (get 'mouse-sel-internal-selection selection))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
251 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
252 (defun mouse-sel-selection-overlay (selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
253 "Return overlay corresponding to SELECTION." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
254 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
255 (or symbol (error "No overlay corresponding to %s selection" selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
256 (symbol-value symbol))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
257 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
258 (defun mouse-sel-selection-thing (selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
259 "Return overlay corresponding to SELECTION." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
260 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
261 (or symbol (error "No symbol corresponding to %s selection" selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
262 symbol)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
263 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
264 (defun mouse-sel-region-to-primary (orig-window) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
265 "Convert region to PRIMARY overlay and deactivate region. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
266 Argument ORIG-WINDOW specifies the window the cursor was in when the |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
267 originating command was issued, and is used to determine whether the |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
268 region was visible or not." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
269 (if transient-mark-mode |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
270 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
271 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
272 ((and mark-active |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
273 (or highlight-nonselected-windows |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
274 (eq orig-window (selected-window)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
275 ;; Region was visible, so convert region to overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
276 (move-overlay overlay (region-beginning) (region-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
277 (current-buffer))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
278 ((eq orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
279 ;; Point was visible, so set overlay at point |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
280 (move-overlay overlay (point) (point) (current-buffer))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
281 (t |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
282 ;; Nothing was visible, so remove overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
283 (delete-overlay overlay))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
284 (setq mark-active nil)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
285 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
286 (defun mouse-sel-primary-to-region (&optional direction) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
287 "Convert PRIMARY overlay to region. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
288 Optional argument DIRECTION specifies the mouse drag direction: a value of |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
289 1 indicates that the mouse was dragged left-to-right, otherwise it was |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
290 dragged right-to-left." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
291 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
292 (start (overlay-start overlay)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
293 (end (overlay-end overlay))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
294 (if (eq start end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
295 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
296 (if start (goto-char start)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
297 (deactivate-mark)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
298 (if (and mouse-sel-leave-point-near-mouse (eq direction 1)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
299 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
300 (goto-char end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
301 (push-mark start 'nomsg 'active)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
302 (goto-char start) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
303 (push-mark end 'nomsg 'active))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
304 (if transient-mark-mode (delete-overlay overlay)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
305 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
306 (defmacro mouse-sel-eval-at-event-end (event &rest forms) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
307 "Evaluate forms at mouse position. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
308 Move to the end position of EVENT, execute FORMS, and restore original |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
309 point and window." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
310 (` |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
311 (let ((posn (event-end (, event)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
312 (if posn (mouse-minibuffer-check (, event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
313 (if (and posn (not (windowp (posn-window posn)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
314 (error "Cursor not in text area of window")) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
315 (let (orig-window orig-point-marker) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
316 (setq orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
317 (if posn (select-window (posn-window posn))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
318 (setq orig-point-marker (point-marker)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
319 (if (and posn (numberp (posn-point posn))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
320 (goto-char (posn-point posn))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
321 (unwind-protect |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
322 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
323 (,@ forms)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
324 (goto-char (marker-position orig-point-marker)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
325 (move-marker orig-point-marker nil) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
326 (select-window orig-window) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
327 ))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
328 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
329 (put 'mouse-sel-eval-at-event-end 'lisp-indent-hook 1) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
330 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
331 ;;=== Select ============================================================== |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
332 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
333 (defun mouse-select (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
334 "Set region/selection using the mouse. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
335 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
336 Click sets point & mark to click position. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
337 Dragging extends region/selection. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
338 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
339 Multi-clicking selects word/lines/paragraphs, as determined by |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
340 'mouse-sel-determine-selection-thing. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
341 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
342 Clicking mouse-2 while selecting copies selected text to the kill-ring. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
343 Clicking mouse-1 or mouse-3 kills the selected text. |
4934 | 344 |
345 This should be bound to a down-mouse event." | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
346 (interactive "@e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
347 (let (direction) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
348 (unwind-protect |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
349 (setq direction (mouse-select-internal 'PRIMARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
350 (mouse-sel-primary-to-region direction)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
351 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
352 (defun mouse-select-secondary (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
353 "Set secondary selection using the mouse. |
4934 | 354 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
355 Click sets the start of the secondary selection to click position. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
356 Dragging extends the secondary selection. |
4934 | 357 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
358 Multi-clicking selects word/lines/paragraphs, as determined by |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
359 'mouse-sel-determine-selection-thing. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
360 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
361 Clicking mouse-2 while selecting copies selected text to the kill-ring. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
362 Clicking mouse-1 or mouse-3 kills the selected text. |
4934 | 363 |
364 This should be bound to a down-mouse event." | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
365 (interactive "e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
366 (mouse-select-internal 'SECONDARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
367 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
368 (defun mouse-select-internal (selection event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
369 "Set SELECTION using the mouse." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
370 (mouse-sel-eval-at-event-end event |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
371 (let ((thing-symbol (mouse-sel-selection-thing selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
372 (overlay (mouse-sel-selection-overlay selection))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
373 (set thing-symbol |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
374 (mouse-sel-determine-selection-thing (event-click-count event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
375 (let ((object-bounds (bounds-of-thing-at-point |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
376 (symbol-value thing-symbol)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
377 (if object-bounds |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
378 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
379 (move-overlay overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
380 (car object-bounds) (cdr object-bounds) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
381 (current-buffer))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
382 (move-overlay overlay (point) (point) (current-buffer))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
383 (mouse-extend-internal selection))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
384 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
385 ;;=== Extend ============================================================== |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
386 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
387 (defun mouse-extend (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
388 "Extend region/selection using the mouse." |
4934 | 389 (interactive "e") |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
390 (let ((orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
391 direction) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
392 (select-window (posn-window (event-end event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
393 (unwind-protect |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
394 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
395 (mouse-sel-region-to-primary orig-window) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
396 (setq direction (mouse-extend-internal 'PRIMARY event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
397 (mouse-sel-primary-to-region direction)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
398 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
399 (defun mouse-extend-secondary (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
400 "Extend secondary selection using the mouse." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
401 (interactive "e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
402 (save-window-excursion |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
403 (mouse-extend-internal 'SECONDARY event))) |
4934 | 404 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
405 (defun mouse-extend-internal (selection &optional initial-event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
406 "Extend specified SELECTION using the mouse. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
407 Track mouse-motion events, adjusting the SELECTION appropriately. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
408 Optional argument INITIAL-EVENT specifies an initial down-mouse event to |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
409 process. |
4934 | 410 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
411 See documentation for mouse-select-internal for more details." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
412 (mouse-sel-eval-at-event-end initial-event |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
413 (let ((orig-cursor-type |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
414 (cdr (assoc 'cursor-type (frame-parameters (selected-frame)))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
415 (unwind-protect |
4934 | 416 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
417 (let* ((thing-symbol (mouse-sel-selection-thing selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
418 (overlay (mouse-sel-selection-overlay selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
419 (orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
420 (orig-window-frame (window-frame orig-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
421 (top (nth 1 (window-edges orig-window))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
422 (bottom (nth 3 (window-edges orig-window))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
423 (mark-active nil) ; inhibit normal region highlight |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
424 (echo-keystrokes 0) ; don't echo mouse events |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
425 min max |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
426 direction |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
427 event) |
4934 | 428 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
429 ;; Get current bounds of overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
430 (if (eq (overlay-buffer overlay) (current-buffer)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
431 (setq min (overlay-start overlay) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
432 max (overlay-end overlay)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
433 (setq min (point) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
434 max min) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
435 (set thing-symbol nil)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
436 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
437 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
438 ;; Bar cursor |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
439 (if (fboundp 'modify-frame-parameters) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
440 (modify-frame-parameters (selected-frame) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
441 '((cursor-type . bar)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
442 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
443 ;; Handle dragging |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
444 (track-mouse |
4934 | 445 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
446 (while (if initial-event ; Use initial event |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
447 (prog1 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
448 (setq event initial-event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
449 (setq initial-event nil)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
450 (setq event (read-event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
451 (and (consp event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
452 (memq (car event) '(mouse-movement switch-frame)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
453 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
454 (let ((selection-thing (symbol-value thing-symbol)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
455 (end (event-end event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
456 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
457 (cond |
4934 | 458 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
459 ;; Ignore any movement outside the frame |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
460 ((eq (car-safe event) 'switch-frame) nil) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
461 ((and (posn-window end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
462 (not (eq (let ((posn-w (posn-window end))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
463 (if (windowp posn-w) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
464 (window-frame posn-w) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
465 posn-w)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
466 (window-frame orig-window)))) nil) |
4934 | 467 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
468 ;; Different window, same frame |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
469 ((not (eq (posn-window end) orig-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
470 (let ((end-row (cdr (cdr (mouse-position))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
471 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
472 ((and end-row (not (bobp)) (< end-row top)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
473 (mouse-scroll-subr orig-window (- end-row top) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
474 overlay max)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
475 ((and end-row (not (eobp)) (>= end-row bottom)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
476 (mouse-scroll-subr orig-window (1+ (- end-row bottom)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
477 overlay min)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
478 ))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
479 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
480 ;; On the mode line |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
481 ((eq (posn-point end) 'mode-line) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
482 (mouse-scroll-subr orig-window 1 overlay min)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
483 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
484 ;; In original window |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
485 (t (goto-char (posn-point end))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
486 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
487 ) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
488 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
489 ;; Determine direction of drag |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
490 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
491 ((and (not direction) (not (eq min max))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
492 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
493 ((and (not (eq direction -1)) (<= (point) min)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
494 (setq direction -1)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
495 ((and (not (eq direction 1)) (>= (point) max)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
496 (setq direction 1))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
497 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
498 (if (not selection-thing) nil |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
499 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
500 ;; If dragging forward, goal is next character |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
501 (if (and (eq direction 1) (not (eobp))) (forward-char 1)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
502 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
503 ;; Move to start/end of selected thing |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
504 (let ((goal (point))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
505 (goto-char (if (eq 1 direction) min max)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
506 (condition-case nil |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
507 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
508 (while (> (* direction (- goal (point))) 0) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
509 (forward-thing selection-thing direction)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
510 (let ((end (point))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
511 (forward-thing selection-thing (- direction)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
512 (goto-char |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
513 (if (> (* direction (- goal (point))) 0) |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
514 end (point))))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
515 (error)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
516 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
517 ;; Move overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
518 (move-overlay overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
519 (if (eq 1 direction) min (point)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
520 (if (eq -1 direction) max (point)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
521 (current-buffer)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
522 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
523 ))) ; end track-mouse |
4934 | 524 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
525 ;; Finish up after dragging |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
526 (let ((overlay-start (overlay-start overlay)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
527 (overlay-end (overlay-end overlay))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
528 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
529 ;; Set selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
530 (if (not (eq overlay-start overlay-end)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
531 (mouse-sel-set-selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
532 selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
533 (buffer-substring overlay-start overlay-end))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
534 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
535 ;; Handle copy/kill |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
536 (let (this-command) |
4934 | 537 (cond |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
538 ((eq (event-basic-type last-input-event) 'mouse-2) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
539 (copy-region-as-kill overlay-start overlay-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
540 (read-event) (read-event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
541 ((and (memq (event-basic-type last-input-event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
542 '(mouse-1 mouse-3)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
543 (memq 'down (event-modifiers last-input-event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
544 (kill-region overlay-start overlay-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
545 (move-overlay overlay overlay-start overlay-start) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
546 (read-event) (read-event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
547 ((and (eq (event-basic-type last-input-event) 'mouse-3) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
548 (memq 'double (event-modifiers last-input-event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
549 (kill-region overlay-start overlay-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
550 (move-overlay overlay overlay-start overlay-start))))) |
4934 | 551 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
552 direction) |
4934 | 553 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
554 ;; Restore cursor |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
555 (if (fboundp 'modify-frame-parameters) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
556 (modify-frame-parameters |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
557 (selected-frame) (list (cons 'cursor-type orig-cursor-type)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
558 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
559 )))) |
4934 | 560 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
561 ;;=== Paste =============================================================== |
4934 | 562 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
563 (defun mouse-insert-selection (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
564 "Insert the contents of the PRIMARY selection at mouse click. |
7644
d50f6828a89d
(mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
565 If `mouse-yank-at-point' is non-nil, insert at point instead." |
4934 | 566 (interactive "e") |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
567 (mouse-insert-selection-internal 'PRIMARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
568 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
569 (defun mouse-insert-secondary (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
570 "Insert the contents of the SECONDARY selection at mouse click. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
571 If `mouse-yank-at-point' is non-nil, insert at point instead." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
572 (interactive "e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
573 (mouse-insert-selection-internal 'SECONDARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
574 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
575 (defun mouse-insert-selection-internal (selection event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
576 "Insert the contents of the named SELECTION at mouse click. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
577 If `mouse-yank-at-point' is non-nil, insert at point instead." |
7644
d50f6828a89d
(mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
578 (or mouse-yank-at-point |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
579 (mouse-set-point event)) |
4934 | 580 (if mouse-sel-get-selection-function |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
581 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
582 (push-mark (point) 'nomsg) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
583 (insert (or (funcall mouse-sel-get-selection-function selection) ""))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
584 |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
585 ;;=== Handle loss of selections =========================================== |
4934 | 586 |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
587 (defun mouse-sel-lost-selection-hook (selection) |
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
588 "Remove the overlay for a lost selection." |
13556
8c181dcb4fdd
(mouse-sel-lost-selection-hook): Undo prev change.
Richard M. Stallman <rms@gnu.org>
parents:
13547
diff
changeset
|
589 (let ((overlay (mouse-sel-selection-overlay selection))) |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
590 (delete-overlay overlay))) |
4934 | 591 |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
592 (add-hook 'x-lost-selection-hooks 'mouse-sel-lost-selection-hook) |
4934 | 593 |
594 ;;=== Key bindings ======================================================== | |
595 | |
596 (if (not mouse-sel-default-bindings) nil | |
597 | |
598 (global-unset-key [mouse-1]) | |
599 (global-unset-key [drag-mouse-1]) | |
600 (global-unset-key [mouse-3]) | |
601 | |
602 (global-set-key [down-mouse-1] 'mouse-select) | |
603 (global-set-key [down-mouse-3] 'mouse-extend) | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
604 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
605 (global-unset-key [M-mouse-1]) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
606 (global-unset-key [M-drag-mouse-1]) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
607 (global-unset-key [M-mouse-3]) |
4934 | 608 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
609 (global-set-key [M-down-mouse-1] 'mouse-select-secondary) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
610 (global-set-key [M-down-mouse-3] 'mouse-extend-secondary) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
611 |
4934 | 612 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) nil |
613 | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
614 (global-set-key [mouse-2] 'mouse-insert-selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
615 |
4934 | 616 (setq interprogram-cut-function nil |
617 interprogram-paste-function nil)) | |
618 | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
619 (global-set-key [M-mouse-2] 'mouse-insert-secondary) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
620 |
4934 | 621 ) |
622 | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
623 ;;=== Bug reporting ======================================================= |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
624 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
625 (defconst mouse-sel-maintainer-address "mikew@gopher.dosli.govt.nz") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
626 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
627 (defun mouse-sel-submit-bug-report () |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
628 "Submit a bug report on mouse-sel.el via mail." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
629 (interactive) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
630 (require 'reporter) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
631 (reporter-submit-bug-report |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
632 mouse-sel-maintainer-address |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
633 (concat "mouse-sel.el " |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
634 (or (condition-case nil mouse-sel-version (error)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
635 "(distributed with Emacs)")) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
636 (list 'transient-mark-mode |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
637 'delete-selection-mode |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
638 'mouse-sel-default-bindings |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
639 'mouse-sel-leave-point-near-mouse |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
640 'mouse-sel-cycle-clicks |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
641 'mouse-sel-selection-alist |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
642 'mouse-sel-set-selection-function |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
643 'mouse-sel-get-selection-function |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
644 'mouse-yank-at-point))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
645 |
4934 | 646 ;; mouse-sel.el ends here. |