Mercurial > emacs
annotate lisp/mouse-sel.el @ 49171:e0c2ecbf4fc5
(Commentary): Use command remapping instead of
substitute-key-definition.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Sun, 12 Jan 2003 20:48:49 +0000 |
parents | 72f4c4b10835 |
children | 4398c7a41151 d7ddb3e565de |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
30691
diff
changeset
|
1 ;;; mouse-sel.el --- multi-click selection support for Emacs 19 |
4934 | 2 |
46359
186ccb97f37d
(mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents:
46194
diff
changeset
|
3 ;; Copyright (C) 1993,1994,1995,2001,2002 Free Software Foundation, Inc. |
4934 | 4 |
46194
71bf019cb382
Change maintainer email address.
Richard M. Stallman <rms@gnu.org>
parents:
41608
diff
changeset
|
5 ;; Author: Mike Williams <mdub@bigfoot.com> |
4934 | 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. |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
53 ;; |
5750
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. |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
55 ;; |
11490
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) | |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
74 ;; |
4934 | 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) | |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
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 | |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
93 ;; |
4934 | 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 |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
96 ;; mouse-2 mouse-insert-selection |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
97 ;; mouse-3 mouse-extend |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
98 ;; In this mode, mouse-insert-selection just calls mouse-yank-at-click. |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
99 ;; |
4934 | 100 ;; Selection/kill-ring interaction is retained |
101 ;; interprogram-cut-function = x-select-text | |
102 ;; interprogram-paste-function = x-cut-buffer-or-selection-value | |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
103 ;; |
4934 | 104 ;; What you lose is the ability to select some text in |
105 ;; delete-selection-mode and yank over the top of it. | |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
106 ;; |
4934 | 107 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made. |
108 ;; | |
6228 | 109 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at |
110 ;; the mouse position. You can tell it to insert at point instead with: | |
111 ;; | |
7644
d50f6828a89d
(mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
112 ;; (setq mouse-yank-at-point t) |
6228 | 113 ;; |
4934 | 114 ;; * I like to leave point at the end of the region nearest to where the |
115 ;; mouse was, even though this makes region highlighting mis-leading (the | |
116 ;; cursor makes it look like one extra character is selected). You can | |
117 ;; disable this behaviour with: | |
118 ;; | |
119 ;; (setq mouse-sel-leave-point-near-mouse nil) | |
120 ;; | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
121 ;; * 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
|
122 ;; 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
|
123 ;; once, clicking six times has the same effect as clicking twice, etc. |
4934 | 124 ;; Disable this behaviour with: |
125 ;; | |
126 ;; (setq mouse-sel-cycle-clicks nil) | |
127 ;; | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
128 ;; * 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
|
129 ;; selection is handled. Under X Windows, these variables default so |
4934 | 130 ;; that the X primary selection is used. Under other windowing systems, |
131 ;; alternate functions are used, which simply store the selection value | |
132 ;; in a variable. | |
133 ;; | |
134 ;; * You can change the selection highlight face by altering the properties | |
135 ;; of mouse-drag-overlay, eg. | |
136 ;; | |
137 ;; (overlay-put mouse-drag-overlay 'face 'bold) | |
138 | |
14169 | 139 ;;; Code: |
4934 | 140 |
141 (require 'mouse) | |
142 (require 'thingatpt) | |
143 | |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
144 (eval-when-compile |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
145 (require 'cl)) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
146 |
4934 | 147 ;;=== User Variables ====================================================== |
148 | |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
149 (defgroup mouse-sel nil |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
150 "Mouse selection enhancement." |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
151 :group 'mouse) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
152 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
153 (defcustom mouse-sel-leave-point-near-mouse t |
4934 | 154 "*Leave point near last mouse position. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
155 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end |
4934 | 156 of the region nearest to where the mouse last was. |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
157 If nil, point will always be placed at the beginning of the region." |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
158 :type 'boolean |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
159 :group 'mouse-sel) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
160 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
161 (defcustom mouse-sel-cycle-clicks t |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
162 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks." |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
163 :type 'boolean |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
164 :group 'mouse-sel) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
165 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
166 (defcustom mouse-sel-default-bindings t |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
167 "*Control mouse bindings." |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
168 :type '(choice (const :tag "none" nil) |
22593
2407b3d241a6
(mouse-sel-default-bindings): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
18784
diff
changeset
|
169 (const :tag "cut and paste" interprogram-cut-paste) |
2407b3d241a6
(mouse-sel-default-bindings): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
18784
diff
changeset
|
170 (other :tag "default bindings" t)) |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
171 :group 'mouse-sel) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
172 |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
173 ;;=== Key bindings ======================================================== |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
174 |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
175 (defconst mouse-sel-bound-events |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
176 '(;; Primary selection bindings. |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
177 ;; |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
178 ;; Bind keys to `ignore' instead of unsetting them because modes may |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
179 ;; bind `down-mouse-1', for instance, without binding `mouse-1'. |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
180 ;; If we unset `mouse-1', this leads to a bitch_at_user when the |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
181 ;; mouse goes up because no matching binding is found for that. |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
182 ([mouse-1] . ignore) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
183 ([drag-mouse-1] . ignore) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
184 ([mouse-3] . ignore) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
185 ([down-mouse-1] . mouse-select) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
186 ([down-mouse-3] . mouse-extend) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
187 ([mouse-2] . mouse-insert-selection) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
188 ;; Secondary selection bindings. |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
189 ([M-mouse-1] . ignore) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
190 ([M-drag-mouse-1] . ignore) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
191 ([M-mouse-3] . ignore) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
192 ([M-down-mouse-1] . mouse-select-secondary) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
193 ([M-mouse-2] . mouse-insert-secondary) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
194 ([M-down-mouse-3] . mouse-extend-secondary)) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
195 "An alist of events that `mouse-sel-mode' binds.") |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
196 |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
197 ;;=== User Command ======================================================== |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
198 |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
199 (defvar mouse-sel-original-bindings nil) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
200 (defvar mouse-sel-original-interprogram-cut-function nil) |
46406
72f4c4b10835
(mouse-sel-original-interprogram-paste-function): Defvar it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46403
diff
changeset
|
201 (defvar mouse-sel-original-interprogram-paste-function nil) |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
202 |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
203 ;;;###autoload |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
204 (define-minor-mode mouse-sel-mode |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
205 "Toggle Mouse Sel mode. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
206 With prefix ARG, turn Mouse Sel mode on if and only if ARG is positive. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
207 Returns the new status of Mouse Sel mode (non-nil means on). |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
208 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
209 When Mouse Sel mode is enabled, mouse selection is enhanced in various ways: |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
210 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
211 - Clicking mouse-1 starts (cancels) selection, dragging extends it. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
212 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
213 - Clicking or dragging mouse-3 extends the selection as well. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
214 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
215 - Double-clicking on word constituents selects words. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
216 Double-clicking on symbol constituents selects symbols. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
217 Double-clicking on quotes or parentheses selects sexps. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
218 Double-clicking on whitespace selects whitespace. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
219 Triple-clicking selects lines. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
220 Quad-clicking selects paragraphs. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
221 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
222 - Selecting sets the region & X primary selection, but does NOT affect |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
223 the `kill-ring', nor do the kill-ring functions change the X selection. |
30691 | 224 Because the mouse handlers set the primary selection directly, |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
225 mouse-sel sets the variables `interprogram-cut-function' and |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
226 `interprogram-paste-function' to nil. |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
227 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
228 - Clicking mouse-2 inserts the contents of the primary selection at |
38897
f9cec1b1d7ba
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38775
diff
changeset
|
229 the mouse position (or point, if `mouse-yank-at-point' is non-nil). |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
230 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
231 - Pressing mouse-2 while selecting or extending copies selection |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
232 to the kill ring. Pressing mouse-1 or mouse-3 kills it. |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
233 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
234 - Double-clicking mouse-3 also kills selection. |
4934 | 235 |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
236 - M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
237 & mouse-3, but operate on the X secondary selection rather than the |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
238 primary selection and region." |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
239 :global t |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
240 (if mouse-sel-mode |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
241 (progn |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
242 (add-hook 'x-lost-selection-hooks 'mouse-sel-lost-selection-hook) |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
243 (when mouse-sel-default-bindings |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
244 ;; Save original bindings and replace them with new ones. |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
245 (setq mouse-sel-original-bindings |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
246 (mapcar (lambda (binding) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
247 (let ((event (car binding))) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
248 (prog1 (cons event (lookup-key global-map event)) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
249 (global-set-key event (cdr binding))))) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
250 mouse-sel-bound-events)) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
251 ;; Update interprogram functions. |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
252 (setq mouse-sel-original-interprogram-cut-function |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
253 interprogram-cut-function |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
254 mouse-sel-original-interprogram-paste-function |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
255 interprogram-paste-function) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
256 (unless (eq mouse-sel-default-bindings 'interprogram-cut-paste) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
257 (setq interprogram-cut-function nil |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
258 interprogram-paste-function nil)))) |
38443
643e08c68af9
(mouse-sel-bindings): Instead of unbinding
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
259 |
46359
186ccb97f37d
(mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents:
46194
diff
changeset
|
260 ;; Restore original bindings |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
261 (remove-hook 'x-lost-selection-hooks 'mouse-sel-lost-selection-hook) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
262 (dolist (binding mouse-sel-original-bindings) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
263 (global-set-key (car binding) (cdr binding))) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
264 (setq interprogram-cut-function |
46385
9ef1f4b9623a
(mouse-sel-bindings): Save/restore interprogram cut/paste functions.
Mike Williams <mdub@bigfoot.com>
parents:
46359
diff
changeset
|
265 mouse-sel-original-interprogram-cut-function |
9ef1f4b9623a
(mouse-sel-bindings): Save/restore interprogram cut/paste functions.
Mike Williams <mdub@bigfoot.com>
parents:
46359
diff
changeset
|
266 interprogram-paste-function |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
267 mouse-sel-original-interprogram-paste-function))) |
4934 | 268 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
269 ;;=== Internal Variables/Constants ======================================== |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
270 |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
271 (defvar mouse-sel-primary-thing nil |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
272 "Type of PRIMARY selection in current buffer.") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
273 (make-variable-buffer-local 'mouse-sel-primary-thing) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
274 |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
275 (defvar mouse-sel-secondary-thing nil |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
276 "Type of SECONDARY selection in current buffer.") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
277 (make-variable-buffer-local 'mouse-sel-secondary-thing) |
4934 | 278 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
279 ;; Ensure that secondary overlay is defined |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
280 (unless (overlayp mouse-secondary-overlay) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
281 (setq mouse-secondary-overlay (make-overlay 1 1)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
282 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)) |
4934 | 283 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
284 (defconst mouse-sel-selection-alist |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
285 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
286 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing)) |
38897
f9cec1b1d7ba
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38775
diff
changeset
|
287 "Alist associating selections with variables. |
f9cec1b1d7ba
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38775
diff
changeset
|
288 Each element is of the form: |
4934 | 289 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
290 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
291 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
292 where SELECTION-NAME = name of selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
293 OVERLAY-SYMBOL = name of variable containing overlay to use |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
294 SELECTION-THING-SYMBOL = name of variable where the current selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
295 type for this selection should be stored.") |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
296 |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
297 (defvar mouse-sel-set-selection-function |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
298 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
299 'x-set-selection |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
300 (lambda (selection value) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
301 (if (eq selection 'PRIMARY) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
302 (x-select-text value) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
303 (x-set-selection selection value)))) |
4934 | 304 "Function to call to set selection. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
305 Called with two arguments: |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
306 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
307 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
|
308 VALUE, the text to store. |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
309 |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
310 This sets the selection as well as the cut buffer for the older applications, |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
311 unless `mouse-sel-default-bindings' is `interprogram-cut-paste'.") |
4934 | 312 |
313 (defvar mouse-sel-get-selection-function | |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
314 (lambda (selection) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
315 (if (eq selection 'PRIMARY) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
316 (or (x-cut-buffer-or-selection-value) x-last-selected-text) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
317 (x-get-selection selection))) |
4934 | 318 "Function to call to get the selection. |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
319 Called with one argument: |
4934 | 320 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
321 SELECTION: the name of the selection concerned.") |
4934 | 322 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
323 ;;=== Support/access functions ============================================ |
4934 | 324 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
325 (defun mouse-sel-determine-selection-thing (nclicks) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
326 "Determine what `thing' `mouse-sel' should operate on. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
327 The first argument is NCLICKS, is the number of consecutive |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
328 mouse clicks at the same position. |
4934 | 329 |
330 Double-clicking on word constituents selects words. | |
331 Double-clicking on symbol constituents selects symbols. | |
332 Double-clicking on quotes or parentheses selects sexps. | |
333 Double-clicking on whitespace selects whitespace. | |
334 Triple-clicking selects lines. | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
335 Quad-clicking selects paragraphs. |
4934 | 336 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
337 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
|
338 multi-click semantics." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
339 (let* ((next-char (char-after (point))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
340 (char-syntax (if next-char (char-syntax next-char)))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
341 (if mouse-sel-cycle-clicks |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
342 (setq nclicks (1+ (% (1- nclicks) 4)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
343 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
344 ((= nclicks 1) nil) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
345 ((= nclicks 3) 'line) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
346 ((>= nclicks 4) 'paragraph) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
347 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
348 ((memq next-char '(? ?\t ?\n)) 'whitespace) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
349 ((eq char-syntax ?_) 'symbol) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
350 ((eq char-syntax ?w) 'word)))) |
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-sel-set-selection (selection value) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
353 "Set the specified SELECTION to VALUE." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
354 (if mouse-sel-set-selection-function |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
355 (funcall mouse-sel-set-selection-function selection value) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
356 (put 'mouse-sel-internal-selection selection value))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
357 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
358 (defun mouse-sel-get-selection (selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
359 "Get the value of the specified SELECTION." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
360 (if mouse-sel-get-selection-function |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
361 (funcall mouse-sel-get-selection-function selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
362 (get 'mouse-sel-internal-selection selection))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
363 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
364 (defun mouse-sel-selection-overlay (selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
365 "Return overlay corresponding to SELECTION." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
366 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
367 (or symbol (error "No overlay corresponding to %s selection" selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
368 (symbol-value symbol))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
369 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
370 (defun mouse-sel-selection-thing (selection) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
371 "Return overlay corresponding to SELECTION." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
372 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
373 (or symbol (error "No symbol corresponding to %s selection" selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
374 symbol)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
375 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
376 (defun mouse-sel-region-to-primary (orig-window) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
377 "Convert region to PRIMARY overlay and deactivate region. |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
378 Argument ORIG-WINDOW specifies the window the cursor was in when the |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
379 originating command was issued, and is used to determine whether the |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
380 region was visible or not." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
381 (if transient-mark-mode |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
382 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
383 (cond |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
384 ((and mark-active |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
385 (or highlight-nonselected-windows |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
386 (eq orig-window (selected-window)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
387 ;; Region was visible, so convert region to overlay |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
388 (move-overlay overlay (region-beginning) (region-end) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
389 (current-buffer))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
390 ((eq orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
391 ;; Point was visible, so set overlay at point |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
392 (move-overlay overlay (point) (point) (current-buffer))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
393 (t |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
394 ;; Nothing was visible, so remove overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
395 (delete-overlay overlay))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
396 (setq mark-active nil)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
397 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
398 (defun mouse-sel-primary-to-region (&optional direction) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
399 "Convert PRIMARY overlay to region. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
400 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
|
401 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
|
402 dragged right-to-left." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
403 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
404 (start (overlay-start overlay)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
405 (end (overlay-end overlay))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
406 (if (eq start end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
407 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
408 (if start (goto-char start)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
409 (deactivate-mark)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
410 (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
|
411 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
412 (goto-char end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
413 (push-mark start 'nomsg 'active)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
414 (goto-char start) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
415 (push-mark end 'nomsg 'active))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
416 (if transient-mark-mode (delete-overlay overlay)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
417 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
418 (defmacro mouse-sel-eval-at-event-end (event &rest forms) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
419 "Evaluate forms at mouse position. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
420 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
|
421 point and window." |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
422 `(let ((posn (event-end ,event))) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
423 (if posn (mouse-minibuffer-check ,event)) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
424 (if (and posn (not (windowp (posn-window posn)))) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
425 (error "Cursor not in text area of window")) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
426 (let (orig-window orig-point-marker) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
427 (setq orig-window (selected-window)) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
428 (if posn (select-window (posn-window posn))) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
429 (setq orig-point-marker (point-marker)) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
430 (if (and posn (numberp (posn-point posn))) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
431 (goto-char (posn-point posn))) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
432 (unwind-protect |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
433 (progn |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
434 ,@forms) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
435 (goto-char (marker-position orig-point-marker)) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
436 (move-marker orig-point-marker nil) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
437 (select-window orig-window))))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
438 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
439 (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
|
440 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
441 ;;=== Select ============================================================== |
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 (defun mouse-select (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
444 "Set region/selection using the mouse. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
445 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
446 Click sets point & mark to click position. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
447 Dragging extends region/selection. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
448 |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
449 Multi-clicking selects word/lines/paragraphs, as determined by |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
450 'mouse-sel-determine-selection-thing. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
451 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
452 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
|
453 Clicking mouse-1 or mouse-3 kills the selected text. |
4934 | 454 |
455 This should be bound to a down-mouse event." | |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
456 (interactive "@e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
457 (let (direction) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
458 (unwind-protect |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
459 (setq direction (mouse-select-internal 'PRIMARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
460 (mouse-sel-primary-to-region direction)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
461 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
462 (defun mouse-select-secondary (event) |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
463 "Set secondary selection using the mouse. |
4934 | 464 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
465 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
|
466 Dragging extends the secondary selection. |
4934 | 467 |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
468 Multi-clicking selects word/lines/paragraphs, as determined by |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
469 'mouse-sel-determine-selection-thing. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
470 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
471 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
|
472 Clicking mouse-1 or mouse-3 kills the selected text. |
4934 | 473 |
474 This should be bound to a down-mouse event." | |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
475 (interactive "e") |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
476 (mouse-select-internal 'SECONDARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
477 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
478 (defun mouse-select-internal (selection event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
479 "Set SELECTION using the mouse." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
480 (mouse-sel-eval-at-event-end event |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
481 (let ((thing-symbol (mouse-sel-selection-thing selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
482 (overlay (mouse-sel-selection-overlay selection))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
483 (set thing-symbol |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
484 (mouse-sel-determine-selection-thing (event-click-count event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
485 (let ((object-bounds (bounds-of-thing-at-point |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
486 (symbol-value thing-symbol)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
487 (if object-bounds |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
488 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
489 (move-overlay overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
490 (car object-bounds) (cdr object-bounds) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
491 (current-buffer))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
492 (move-overlay overlay (point) (point) (current-buffer))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
493 (mouse-extend-internal selection))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
494 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
495 ;;=== Extend ============================================================== |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
496 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
497 (defun mouse-extend (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
498 "Extend region/selection using the mouse." |
4934 | 499 (interactive "e") |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
500 (let ((orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
501 direction) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
502 (select-window (posn-window (event-end event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
503 (unwind-protect |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
504 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
505 (mouse-sel-region-to-primary orig-window) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
506 (setq direction (mouse-extend-internal 'PRIMARY event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
507 (mouse-sel-primary-to-region direction)))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
508 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
509 (defun mouse-extend-secondary (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
510 "Extend secondary selection using the mouse." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
511 (interactive "e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
512 (save-window-excursion |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
513 (mouse-extend-internal 'SECONDARY event))) |
4934 | 514 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
515 (defun mouse-extend-internal (selection &optional initial-event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
516 "Extend specified SELECTION using the mouse. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
517 Track mouse-motion events, adjusting the SELECTION appropriately. |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
518 Optional argument INITIAL-EVENT specifies an initial down-mouse event to |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
519 process. |
4934 | 520 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
521 See documentation for mouse-select-internal for more details." |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
522 (mouse-sel-eval-at-event-end initial-event |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
523 (let ((orig-cursor-type |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
524 (cdr (assoc 'cursor-type (frame-parameters (selected-frame)))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
525 (unwind-protect |
4934 | 526 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
527 (let* ((thing-symbol (mouse-sel-selection-thing selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
528 (overlay (mouse-sel-selection-overlay selection)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
529 (orig-window (selected-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
530 (orig-window-frame (window-frame orig-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
531 (top (nth 1 (window-edges orig-window))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
532 (bottom (nth 3 (window-edges orig-window))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
533 (mark-active nil) ; inhibit normal region highlight |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
534 (echo-keystrokes 0) ; don't echo mouse events |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
535 min max |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
536 direction |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
537 event) |
4934 | 538 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
539 ;; Get current bounds of overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
540 (if (eq (overlay-buffer overlay) (current-buffer)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
541 (setq min (overlay-start overlay) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
542 max (overlay-end overlay)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
543 (setq min (point) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
544 max min) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
545 (set thing-symbol nil)) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
546 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
547 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
548 ;; Bar cursor |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
549 (if (fboundp 'modify-frame-parameters) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
550 (modify-frame-parameters (selected-frame) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
551 '((cursor-type . bar)))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
552 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
553 ;; Handle dragging |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
554 (track-mouse |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
555 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
556 (while (if initial-event ; Use initial event |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
557 (prog1 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
558 (setq event initial-event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
559 (setq initial-event nil)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
560 (setq event (read-event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
561 (and (consp event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
562 (memq (car event) '(mouse-movement switch-frame)))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
563 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
564 (let ((selection-thing (symbol-value thing-symbol)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
565 (end (event-end event))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
566 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
567 (cond |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
568 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
569 ;; Ignore any movement outside the frame |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
570 ((eq (car-safe event) 'switch-frame) nil) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
571 ((and (posn-window end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
572 (not (eq (let ((posn-w (posn-window end))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
573 (if (windowp posn-w) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
574 (window-frame posn-w) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
575 posn-w)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
576 (window-frame orig-window)))) nil) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
577 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
578 ;; Different window, same frame |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
579 ((not (eq (posn-window end) orig-window)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
580 (let ((end-row (cdr (cdr (mouse-position))))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
581 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
582 ((and end-row (not (bobp)) (< end-row top)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
583 (mouse-scroll-subr orig-window (- end-row top) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
584 overlay max)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
585 ((and end-row (not (eobp)) (>= end-row bottom)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
586 (mouse-scroll-subr orig-window (1+ (- end-row bottom)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
587 overlay min)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
588 ))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
589 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
590 ;; On the mode line |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
591 ((eq (posn-point end) 'mode-line) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
592 (mouse-scroll-subr orig-window 1 overlay min)) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
593 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
594 ;; In original window |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
595 (t (goto-char (posn-point end))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
596 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
597 ) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
598 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
599 ;; Determine direction of drag |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
600 (cond |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
601 ((and (not direction) (not (eq min max))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
602 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
603 ((and (not (eq direction -1)) (<= (point) min)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
604 (setq direction -1)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
605 ((and (not (eq direction 1)) (>= (point) max)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
606 (setq direction 1))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
607 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
608 (if (not selection-thing) nil |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
609 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
610 ;; If dragging forward, goal is next character |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
611 (if (and (eq direction 1) (not (eobp))) (forward-char 1)) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
612 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
613 ;; Move to start/end of selected thing |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
614 (let ((goal (point))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
615 (goto-char (if (eq 1 direction) min max)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
616 (condition-case nil |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
617 (progn |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
618 (while (> (* direction (- goal (point))) 0) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
619 (forward-thing selection-thing direction)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
620 (let ((end (point))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
621 (forward-thing selection-thing (- direction)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
622 (goto-char |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
623 (if (> (* direction (- goal (point))) 0) |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
624 end (point))))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
625 (error)))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
626 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
627 ;; Move overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
628 (move-overlay overlay |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
629 (if (eq 1 direction) min (point)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
630 (if (eq -1 direction) max (point)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
631 (current-buffer)) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
632 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
633 ))) ; end track-mouse |
4934 | 634 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
635 ;; Finish up after dragging |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
636 (let ((overlay-start (overlay-start overlay)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
637 (overlay-end (overlay-end overlay))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
638 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
639 ;; Set selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
640 (if (not (eq overlay-start overlay-end)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
641 (mouse-sel-set-selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
642 selection |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
643 (buffer-substring overlay-start overlay-end))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
644 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
645 ;; Handle copy/kill |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
646 (let (this-command) |
4934 | 647 (cond |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
648 ((eq (event-basic-type last-input-event) 'mouse-2) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
649 (copy-region-as-kill overlay-start overlay-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
650 (read-event) (read-event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
651 ((and (memq (event-basic-type last-input-event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
652 '(mouse-1 mouse-3)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
653 (memq 'down (event-modifiers last-input-event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
654 (kill-region overlay-start overlay-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
655 (move-overlay overlay overlay-start overlay-start) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
656 (read-event) (read-event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
657 ((and (eq (event-basic-type last-input-event) 'mouse-3) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
658 (memq 'double (event-modifiers last-input-event))) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
659 (kill-region overlay-start overlay-end) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
660 (move-overlay overlay overlay-start overlay-start))))) |
4934 | 661 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
662 direction) |
4934 | 663 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
664 ;; Restore cursor |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
665 (if (fboundp 'modify-frame-parameters) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
666 (modify-frame-parameters |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
667 (selected-frame) (list (cons 'cursor-type orig-cursor-type)))) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
668 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
669 )))) |
4934 | 670 |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
671 ;;=== Paste =============================================================== |
4934 | 672 |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
673 (defun mouse-insert-selection (event arg) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
674 "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
|
675 If `mouse-yank-at-point' is non-nil, insert at point instead." |
46403
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
676 (interactive "e\nP") |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
677 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
678 (mouse-yank-at-click event arg) |
3b394c7ff111
(mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46385
diff
changeset
|
679 (mouse-insert-selection-internal 'PRIMARY event))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
680 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
681 (defun mouse-insert-secondary (event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
682 "Insert the contents of the SECONDARY selection at mouse click. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
683 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
|
684 (interactive "e") |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
685 (mouse-insert-selection-internal 'SECONDARY event)) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
686 |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
687 (defun mouse-insert-selection-internal (selection event) |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
688 "Insert the contents of the named SELECTION at mouse click. |
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
689 If `mouse-yank-at-point' is non-nil, insert at point instead." |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38897
diff
changeset
|
690 (unless mouse-yank-at-point |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
691 (mouse-set-point event)) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
692 (when mouse-sel-get-selection-function |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
693 (push-mark (point) 'nomsg) |
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
694 (insert (or (funcall mouse-sel-get-selection-function selection) "")))) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
695 |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
696 ;;=== Handle loss of selections =========================================== |
4934 | 697 |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
698 (defun mouse-sel-lost-selection-hook (selection) |
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
699 "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
|
700 (let ((overlay (mouse-sel-selection-overlay selection))) |
12592
efb59db39da7
Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents:
11490
diff
changeset
|
701 (delete-overlay overlay))) |
4934 | 702 |
18784
5e56fda13c2f
Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents:
17671
diff
changeset
|
703 (provide 'mouse-sel) |
11490
01f5b6e9c234
Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents:
9427
diff
changeset
|
704 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
30691
diff
changeset
|
705 ;;; mouse-sel.el ends here |