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