annotate lisp/mouse-sel.el @ 112438:11f1b4757236

* image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash when calling XpmCreatePixmapFromData.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 22 Jan 2011 20:33:12 -0800
parents 417b1e4d63cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111594
5cacf16597e2 mouse-sel.el comments.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
1 ;;; mouse-sel.el --- multi-click selection support
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
111594
5cacf16597e2 mouse-sel.el comments.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 111594
diff changeset
4 ;; 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
46194
71bf019cb382 Change maintainer email address.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
6 ;; Author: Mike Williams <mdub@bigfoot.com>
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79721
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79721
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79721
diff changeset
14 ;; (at your option) any later version.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79721
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
23
7942
bc5dccc5375f Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7644
diff changeset
24 ;;; Commentary:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
25
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; This module provides multi-click mouse support for GNU Emacs versions
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; 19.18 and later. I've tried to make it behave more like standard X
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Basically:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; * Clicking or dragging mouse-3 extends the selection as well.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; * Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; Triple-clicking selects lines.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
40 ;; Quad-clicking selects paragraphs.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; * Selecting sets the region & X primary selection, but does NOT affect
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; the kill-ring. Because the mouse handlers set the primary selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; directly, mouse-sel sets the variables interprogram-cut-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; and interprogram-paste-function to nil.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
47 ;; * 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
48 ;; the mouse position (or point, if mouse-yank-at-point is non-nil).
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
50 ;; * Pressing mouse-2 while selecting or extending copies selection
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; 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
52 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
53 ;; * Double-clicking mouse-3 also kills selection.
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
54 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
55 ;; * 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
56 ;; & 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
57 ;; primary selection and region.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
59 ;; 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
60 ;; bounds of words, lines, sexps, etc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
64 ;;--- Customisation -------------------------------------------------------
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
65 ;;
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
66 ;; * You may want to use none or more of following:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; ;; Enable region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; (transient-mark-mode 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; ;; But only in the selected window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; (setq highlight-nonselected-windows nil)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
73 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; ;; Enable pending-delete
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; (delete-selection-mode 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;
8766
116e1882576b Fix typo in comment.
Karl Heuer <kwzh@gnu.org>
parents: 8608
diff changeset
77 ;; * You can control the way mouse-sel binds its keys by setting the value
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; of mouse-sel-default-bindings before loading mouse-sel.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; (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
81 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
82 ;; Mouse sets and insert selection
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; mouse-2 mouse-insert-selection
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
85 ;; mouse-3 mouse-extend
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; Selection/kill-ring interaction is disabled
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; interprogram-cut-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; interprogram-paste-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; (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
92 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; Mouse sets selection, and pastes from kill-ring
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
94 ;; mouse-1 mouse-select
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
95 ;; mouse-2 mouse-insert-selection
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
96 ;; mouse-3 mouse-extend
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
97 ;; 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
98 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; Selection/kill-ring interaction is retained
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; interprogram-cut-function = x-select-text
110145
c403c2e0a620 Removed cut-buffer code.
Jan D. <jan.h.d@swipnet.se>
parents: 109112
diff changeset
101 ;; interprogram-paste-function = x-selection-value
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
102 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; What you lose is the ability to select some text in
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; 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
105 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
108 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
109 ;; the mouse position. You can tell it to insert at point instead with:
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
110 ;;
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
111 ;; (setq mouse-yank-at-point t)
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
112 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; * I like to leave point at the end of the region nearest to where the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; mouse was, even though this makes region highlighting mis-leading (the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; cursor makes it look like one extra character is selected). You can
96376
c3309dba6542 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 95841
diff changeset
116 ;; disable this behavior with:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; (setq mouse-sel-leave-point-near-mouse nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
120 ;; * By default, mouse-select cycles the click count after 4 clicks. That
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
121 ;; is, clicking mouse-1 five times has the same effect as clicking it
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
122 ;; once, clicking six times has the same effect as clicking twice, etc.
96376
c3309dba6542 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 95841
diff changeset
123 ;; Disable this behavior with:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; (setq mouse-sel-cycle-clicks nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
127 ;; * The variables mouse-sel-{set,get}-selection-function control how the
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
128 ;; selection is handled. Under X Windows, these variables default so
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; that the X primary selection is used. Under other windowing systems,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; alternate functions are used, which simply store the selection value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; in a variable.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
133 ;;; Code:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (require 'mouse)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (require 'thingatpt)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
138 (eval-when-compile
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
139 (require 'cl))
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
140
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;;=== User Variables ======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
143 (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
144 "Mouse selection enhancement."
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
145 :group 'mouse)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
146
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
147 (defcustom mouse-sel-leave-point-near-mouse t
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 96376
diff changeset
148 "Leave point near last mouse position.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
149 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 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
151 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
152 :type 'boolean
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
153 :group 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
154
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
155 (defcustom mouse-sel-cycle-clicks t
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 96376
diff changeset
156 "If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks."
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
157 :type 'boolean
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
158 :group 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
159
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
160 (defcustom mouse-sel-default-bindings t
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 96376
diff changeset
161 "Control mouse bindings."
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
162 :type '(choice (const :tag "none" nil)
22593
2407b3d241a6 (mouse-sel-default-bindings): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents: 18784
diff changeset
163 (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
164 (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
165 :group 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
166
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
167 ;;=== Key bindings ========================================================
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
168
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
169 (defconst mouse-sel-bound-events
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
170 '(;; Primary selection bindings.
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
171 ;;
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
172 ;; 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
173 ;; 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
174 ;; 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
175 ;; 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
176 ([mouse-1] . ignore)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
177 ([drag-mouse-1] . ignore)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
178 ([mouse-3] . ignore)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
179 ([down-mouse-1] . mouse-select)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
180 ([down-mouse-3] . mouse-extend)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
181 ([mouse-2] . mouse-insert-selection)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
182 ;; Secondary selection bindings.
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
183 ([M-mouse-1] . ignore)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
184 ([M-drag-mouse-1] . ignore)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
185 ([M-mouse-3] . ignore)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
186 ([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
187 ([M-mouse-2] . mouse-insert-secondary)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
188 ([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
189 "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
190
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
191 ;;=== User Command ========================================================
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
192
54257
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
193 (defvar mouse-sel-has-been-enabled nil
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
194 "Non-nil if Mouse Sel mode has been enabled at least once.")
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
195
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
196 (defvar mouse-sel-original-bindings nil)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
197 (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
198 (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
199
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
200 ;;;###autoload
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
201 (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
202 "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
203 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
204 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
205
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
206 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
207
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
208 - 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
209
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
210 - 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
211
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
212 - 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
213 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
214 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
215 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
216 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
217 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
218
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
219 - 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
220 the `kill-ring', nor do the kill-ring functions change the X selection.
30691
eedb47bce69b (mouse-sel-mode): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 24645
diff changeset
221 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
222 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
223 `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
224
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
225 - 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
226 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
227
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
228 - 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
229 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
230
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
231 - Double-clicking mouse-3 also kills selection.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
233 - 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
234 & 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
235 primary selection and region."
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
236 :global t
57687
5a8b58d927d6 (mouse-sel-mode): Specify custom group.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 54258
diff changeset
237 :group 'mouse-sel
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
238 (if mouse-sel-mode
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
239 (progn
74530
b1d0c631bbe2 (mouse-sel-mode): Register mouse-2 as a click type.
Chong Yidong <cyd@stupidchicken.com>
parents: 73272
diff changeset
240 ;; If mouse-2 has never been done by the user, initialize the
b1d0c631bbe2 (mouse-sel-mode): Register mouse-2 as a click type.
Chong Yidong <cyd@stupidchicken.com>
parents: 73272
diff changeset
241 ;; `event-kind' property to ensure that `follow-link' clicks
b1d0c631bbe2 (mouse-sel-mode): Register mouse-2 as a click type.
Chong Yidong <cyd@stupidchicken.com>
parents: 73272
diff changeset
242 ;; are interpreted correctly.
b1d0c631bbe2 (mouse-sel-mode): Register mouse-2 as a click type.
Chong Yidong <cyd@stupidchicken.com>
parents: 73272
diff changeset
243 (put 'mouse-2 'event-kind 'mouse-click)
57781
1d855c5b0242 (mouse-sel-mode): Adjust to new names for x-lost-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57687
diff changeset
244 (add-hook 'x-lost-selection-functions 'mouse-sel-lost-selection-hook)
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
245 (when mouse-sel-default-bindings
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
246 ;; 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
247 (setq mouse-sel-original-bindings
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
248 (mapcar (lambda (binding)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
249 (let ((event (car binding)))
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
250 (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
251 (global-set-key event (cdr binding)))))
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
252 mouse-sel-bound-events))
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
253 ;; Update interprogram functions.
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
254 (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
255 interprogram-cut-function
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
256 mouse-sel-original-interprogram-paste-function
54257
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
257 interprogram-paste-function
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
258 mouse-sel-has-been-enabled t)
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
259 (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
260 (setq interprogram-cut-function nil
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
261 interprogram-paste-function nil))))
38443
643e08c68af9 (mouse-sel-bindings): Instead of unbinding
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
262
46359
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
263 ;; Restore original bindings
57781
1d855c5b0242 (mouse-sel-mode): Adjust to new names for x-lost-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57687
diff changeset
264 (remove-hook 'x-lost-selection-functions 'mouse-sel-lost-selection-hook)
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
265 (dolist (binding mouse-sel-original-bindings)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
266 (global-set-key (car binding) (cdr binding)))
54258
baeae7be621d Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 54257
diff changeset
267 ;; Restore the old values of these variables,
baeae7be621d Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 54257
diff changeset
268 ;; only if they were actually saved previously.
54257
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
269 (if mouse-sel-has-been-enabled
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
270 (setq interprogram-cut-function
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
271 mouse-sel-original-interprogram-cut-function
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
272 interprogram-paste-function
b647c5859635 (mouse-sel-has-been-enabled): New var.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
273 mouse-sel-original-interprogram-paste-function))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
275 ;;=== Internal Variables/Constants ========================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
276
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
277 (defvar mouse-sel-primary-thing nil
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
278 "Type of PRIMARY selection in current buffer.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
279 (make-variable-buffer-local 'mouse-sel-primary-thing)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
280
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
281 (defvar mouse-sel-secondary-thing nil
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
282 "Type of SECONDARY selection in current buffer.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
283 (make-variable-buffer-local 'mouse-sel-secondary-thing)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
285 ;; 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
286 (unless (overlayp mouse-secondary-overlay)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
287 (setq mouse-secondary-overlay (make-overlay 1 1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
288 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
290 (defconst mouse-sel-selection-alist
109112
a46a2b77a8b1 Simplify mouse-dragging implementation.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
291 '((SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing))
38897
f9cec1b1d7ba Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38775
diff changeset
292 "Alist associating selections with variables.
f9cec1b1d7ba Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38775
diff changeset
293 Each element is of the form:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
295 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
296
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
297 where SELECTION-NAME = name of selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
298 OVERLAY-SYMBOL = name of variable containing overlay to use
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
299 SELECTION-THING-SYMBOL = name of variable where the current selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
300 type for this selection should be stored.")
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
301
111299
d1cffc3c49f5 Fix some declarations.
Glenn Morris <rgm@gnu.org>
parents: 110148
diff changeset
302 (declare-function x-select-text "term/common-win" (text))
95841
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
303
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
304 (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
305 (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
306 'x-set-selection
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
307 (lambda (selection value)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
308 (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
309 (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
310 (x-set-selection selection value))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 "Function to call to set selection.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
312 Called with two arguments:
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
313
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
314 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
315 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
316
111299
d1cffc3c49f5 Fix some declarations.
Glenn Morris <rgm@gnu.org>
parents: 110148
diff changeset
317 This sets the selection, unless `mouse-sel-default-bindings'
110148
bcc7c00e9ef4 Remove cut buffer from documentation.
Jan D. <jan.h.d@swipnet.se>
parents: 110145
diff changeset
318 is `interprogram-cut-paste'.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
110145
c403c2e0a620 Removed cut-buffer code.
Jan D. <jan.h.d@swipnet.se>
parents: 109112
diff changeset
320 (declare-function x-selection-value "term/x-win" ())
95841
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
321
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (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
323 (lambda (selection)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
324 (if (eq selection 'PRIMARY)
110145
c403c2e0a620 Removed cut-buffer code.
Jan D. <jan.h.d@swipnet.se>
parents: 109112
diff changeset
325 (or (x-selection-value)
52047
0be309c83b20 (mouse-sel-get-selection-function):
John Paul Wallington <jpw@pobox.com>
parents: 49839
diff changeset
326 (bound-and-true-p x-last-selected-text)
0be309c83b20 (mouse-sel-get-selection-function):
John Paul Wallington <jpw@pobox.com>
parents: 49839
diff changeset
327 (bound-and-true-p x-last-selected-text-primary))
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
328 (x-get-selection selection)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 "Function to call to get the selection.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
330 Called with one argument:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
332 SELECTION: the name of the selection concerned.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
334 ;;=== Support/access functions ============================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
336 (defun mouse-sel-determine-selection-thing (nclicks)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
337 "Determine what `thing' `mouse-sel' should operate on.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
338 The first argument is NCLICKS, is the number of consecutive
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
339 mouse clicks at the same position.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 Triple-clicking selects lines.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
346 Quad-clicking selects paragraphs.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
348 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
349 multi-click semantics."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
350 (let* ((next-char (char-after (point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
351 (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
352 (if mouse-sel-cycle-clicks
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
353 (setq nclicks (1+ (% (1- nclicks) 4))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
354 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
355 ((= nclicks 1) nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
356 ((= nclicks 3) 'line)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
357 ((>= nclicks 4) 'paragraph)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
358 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp)
49839
4398c7a41151 (mouse-sel-determine-selection-thing): Fix character constant.
Juanma Barranquero <lekktu@gmail.com>
parents: 46406
diff changeset
359 ((memq next-char '(?\s ?\t ?\n)) 'whitespace)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
360 ((eq char-syntax ?_) 'symbol)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
361 ((eq char-syntax ?w) 'word))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
362
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
363 (defun mouse-sel-set-selection (selection value)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
364 "Set the specified SELECTION to VALUE."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
365 (if mouse-sel-set-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
366 (funcall mouse-sel-set-selection-function selection value)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
367 (put 'mouse-sel-internal-selection selection value)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
368
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
369 (defun mouse-sel-get-selection (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
370 "Get the value of the specified SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
371 (if mouse-sel-get-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
372 (funcall mouse-sel-get-selection-function selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
373 (get 'mouse-sel-internal-selection selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
374
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
375 (defun mouse-sel-selection-overlay (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
376 "Return overlay corresponding to SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
377 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
378 (or symbol (error "No overlay corresponding to %s selection" selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
379 (symbol-value symbol)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
380
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
381 (defun mouse-sel-selection-thing (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
382 "Return overlay corresponding to SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
383 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
384 (or symbol (error "No symbol corresponding to %s selection" selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
385 symbol))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
386
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
387 (defun mouse-sel-region-to-primary (orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
388 "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
389 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
390 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
391 region was visible or not."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
392 (if transient-mark-mode
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
393 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
394 (cond
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
395 ((and mark-active
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
396 (or highlight-nonselected-windows
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
397 (eq orig-window (selected-window))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
398 ;; 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
399 (move-overlay overlay (region-beginning) (region-end)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
400 (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
401 ((eq orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
402 ;; Point was visible, so set overlay at point
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
403 (move-overlay overlay (point) (point) (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
404 (t
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
405 ;; Nothing was visible, so remove overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
406 (delete-overlay overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
407 (setq mark-active nil))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
408
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
409 (defun mouse-sel-primary-to-region (&optional direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
410 "Convert PRIMARY overlay to region.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
411 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
412 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
413 dragged right-to-left."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
414 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
415 (start (overlay-start overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
416 (end (overlay-end overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
417 (if (eq start end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
418 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
419 (if start (goto-char start))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
420 (deactivate-mark))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
421 (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
422 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
423 (goto-char end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
424 (push-mark start 'nomsg 'active))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
425 (goto-char start)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
426 (push-mark end 'nomsg 'active)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
427 (if transient-mark-mode (delete-overlay overlay))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
428
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
429 (defmacro mouse-sel-eval-at-event-end (event &rest forms)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
430 "Evaluate forms at mouse position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
431 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
432 point and window."
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
433 `(let ((posn (event-end ,event)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
434 (if posn (mouse-minibuffer-check ,event))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
435 (if (and posn (not (windowp (posn-window posn))))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
436 (error "Cursor not in text area of window"))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
437 (let (orig-window orig-point-marker)
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
438 (setq orig-window (selected-window))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
439 (if posn (select-window (posn-window posn)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
440 (setq orig-point-marker (point-marker))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
441 (if (and posn (numberp (posn-point posn)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
442 (goto-char (posn-point posn)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
443 (unwind-protect
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
444 (progn
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
445 ,@forms)
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
446 (goto-char (marker-position orig-point-marker))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
447 (move-marker orig-point-marker nil)
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
448 (select-window orig-window)))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
449
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
450 (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
451
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
452 ;;=== Select ==============================================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
453
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
454 (defun mouse-select (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
455 "Set region/selection using the mouse.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
456
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
457 Click sets point & mark to click position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
458 Dragging extends region/selection.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
459
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
460 Multi-clicking selects word/lines/paragraphs, as determined by
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
461 'mouse-sel-determine-selection-thing.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
462
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
463 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
464 Clicking mouse-1 or mouse-3 kills the selected text.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 This should be bound to a down-mouse event."
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
467 (interactive "@e")
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
468 (let (select)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
469 (unwind-protect
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
470 (setq select (mouse-select-internal 'PRIMARY event))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
471 (if (and select (listp select))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
472 (push (cons 'mouse-2 (cdr event)) unread-command-events)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
473 (mouse-sel-primary-to-region select)))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
474
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
475 (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
476 "Set secondary selection using the mouse.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
478 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
479 Dragging extends the secondary selection.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
481 Multi-clicking selects word/lines/paragraphs, as determined by
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
482 'mouse-sel-determine-selection-thing.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
483
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
484 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
485 Clicking mouse-1 or mouse-3 kills the selected text.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 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
488 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
489 (mouse-select-internal 'SECONDARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
491 (defun mouse-select-internal (selection event)
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
492 "Set SELECTION using the mouse, with EVENT as the initial down-event.
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
493 Normally, this returns the direction in which the selection was
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
494 made: a value of 1 indicates that the mouse was dragged
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
495 left-to-right, otherwise it was dragged right-to-left.
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
496
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
497 However, if `mouse-1-click-follows-link' is non-nil and the
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
498 subsequent mouse events specify following a link, this returns
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
499 the final mouse-event. In that case, the selection is not set."
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
500 (mouse-sel-eval-at-event-end event
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
501 (let ((thing-symbol (mouse-sel-selection-thing selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
502 (overlay (mouse-sel-selection-overlay selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
503 (set thing-symbol
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
504 (mouse-sel-determine-selection-thing (event-click-count event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
505 (let ((object-bounds (bounds-of-thing-at-point
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
506 (symbol-value thing-symbol))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
507 (if object-bounds
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
508 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
509 (move-overlay overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
510 (car object-bounds) (cdr object-bounds)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
511 (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
512 (move-overlay overlay (point) (point) (current-buffer)))))
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
513 (catch 'follow-link
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
514 (mouse-extend-internal selection event t))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
515
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
516 ;;=== Extend ==============================================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
517
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
518 (defun mouse-extend (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
519 "Extend region/selection using the mouse."
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
521 (let ((orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
522 direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
523 (select-window (posn-window (event-end event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
524 (unwind-protect
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
525 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
526 (mouse-sel-region-to-primary orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
527 (setq direction (mouse-extend-internal 'PRIMARY event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
528 (mouse-sel-primary-to-region direction))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
529
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
530 (defun mouse-extend-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
531 "Extend secondary selection using the mouse."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
532 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
533 (save-window-excursion
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
534 (mouse-extend-internal 'SECONDARY event)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
536 (defun mouse-extend-internal (selection &optional initial-event no-process)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
537 "Extend specified SELECTION using the mouse.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
538 Track mouse-motion events, adjusting the SELECTION appropriately.
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
539 Optional argument INITIAL-EVENT specifies an initial down-mouse event.
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
540 Optional argument NO-PROCESS means not to process the initial
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
541 event.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
543 See documentation for mouse-select-internal for more details."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
544 (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
545 (let ((orig-cursor-type
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
546 (cdr (assoc 'cursor-type (frame-parameters (selected-frame))))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
547 (unwind-protect
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
549 (let* ((thing-symbol (mouse-sel-selection-thing selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
550 (overlay (mouse-sel-selection-overlay selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
551 (orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
552 (orig-window-frame (window-frame orig-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
553 (top (nth 1 (window-edges orig-window)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
554 (bottom (nth 3 (window-edges orig-window)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
555 (mark-active nil) ; inhibit normal region highlight
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
556 (echo-keystrokes 0) ; don't echo mouse events
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
557 min max
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
558 direction
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
559 event)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
561 ;; Get current bounds of overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
562 (if (eq (overlay-buffer overlay) (current-buffer))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
563 (setq min (overlay-start overlay)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
564 max (overlay-end overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
565 (setq min (point)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
566 max min)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
567 (set thing-symbol nil))
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
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
570 ;; Bar cursor
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
571 (if (fboundp 'modify-frame-parameters)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
572 (modify-frame-parameters (selected-frame)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
573 '((cursor-type . bar))))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
574
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
575 ;; Handle dragging
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
576 (track-mouse
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
577
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
578 (while (if (and initial-event (not no-process))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
579 ;; Use initial event
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
580 (prog1
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
581 (setq event initial-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
582 (setq initial-event nil))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
583 (setq event (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
584 (and (consp event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
585 (memq (car event) '(mouse-movement switch-frame))))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
586
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
587 (let ((selection-thing (symbol-value thing-symbol))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
588 (end (event-end event)))
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 (cond
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
591
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
592 ;; Ignore any movement outside the frame
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
593 ((eq (car-safe event) 'switch-frame) nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
594 ((and (posn-window end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
595 (not (eq (let ((posn-w (posn-window end)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
596 (if (windowp posn-w)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
597 (window-frame posn-w)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
598 posn-w))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
599 (window-frame orig-window)))) nil)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
600
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
601 ;; Different window, same frame
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
602 ((not (eq (posn-window end) orig-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
603 (let ((end-row (cdr (cdr (mouse-position)))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
604 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
605 ((and end-row (not (bobp)) (< end-row top))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
606 (mouse-scroll-subr orig-window (- end-row top)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
607 overlay max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
608 ((and end-row (not (eobp)) (>= end-row bottom))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
609 (mouse-scroll-subr orig-window (1+ (- end-row bottom))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
610 overlay min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
611 )))
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 ;; On the mode line
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
614 ((eq (posn-point end) 'mode-line)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
615 (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
616
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
617 ;; In original window
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
618 (t (goto-char (posn-point end)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
619
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
620 )
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
621
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
622 ;; Determine direction of drag
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
623 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
624 ((and (not direction) (not (eq min max)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
625 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
626 ((and (not (eq direction -1)) (<= (point) min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
627 (setq direction -1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
628 ((and (not (eq direction 1)) (>= (point) max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
629 (setq direction 1)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
630
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
631 (if (not selection-thing) nil
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 ;; If dragging forward, goal is next character
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
634 (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
635
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
636 ;; Move to start/end of selected thing
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
637 (let ((goal (point)))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
638 (goto-char (if (eq 1 direction) min max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
639 (condition-case nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
640 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
641 (while (> (* direction (- goal (point))) 0)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
642 (forward-thing selection-thing direction))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
643 (let ((end (point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
644 (forward-thing selection-thing (- direction))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
645 (goto-char
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
646 (if (> (* direction (- goal (point))) 0)
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
647 end (point)))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
648 (error))))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
649
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
650 ;; Move overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
651 (move-overlay overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
652 (if (eq 1 direction) min (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
653 (if (eq -1 direction) max (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
654 (current-buffer))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
655
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
656 ))) ; end track-mouse
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
658 ;; Detect follow-link events
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
659 (when (mouse-sel-follow-link-p initial-event event)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
660 (throw 'follow-link event))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
661
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
662 ;; Finish up after dragging
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
663 (let ((overlay-start (overlay-start overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
664 (overlay-end (overlay-end overlay)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
665
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
666 ;; Set selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
667 (if (not (eq overlay-start overlay-end))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
668 (mouse-sel-set-selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
669 selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
670 (buffer-substring overlay-start overlay-end)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
671
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
672 ;; Handle copy/kill
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
673 (let (this-command)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (cond
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
675 ((eq (event-basic-type last-input-event) 'mouse-2)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
676 (copy-region-as-kill overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
677 (read-event) (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
678 ((and (memq (event-basic-type last-input-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
679 '(mouse-1 mouse-3))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
680 (memq 'down (event-modifiers last-input-event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
681 (kill-region overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
682 (move-overlay overlay overlay-start overlay-start)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
683 (read-event) (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
684 ((and (eq (event-basic-type last-input-event) 'mouse-3)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
685 (memq 'double (event-modifiers last-input-event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
686 (kill-region overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
687 (move-overlay overlay overlay-start overlay-start)))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
689 direction)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
691 ;; Restore cursor
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
692 (if (fboundp 'modify-frame-parameters)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
693 (modify-frame-parameters
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
694 (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
695
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
696 ))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
698 (defun mouse-sel-follow-link-p (initial final)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
699 "Return t if we should follow a link, given INITIAL and FINAL mouse events.
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
700 See `mouse-1-click-follows-link' for details. Currently, Mouse
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
701 Sel mode does not support using a `double' value to follow links
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
702 using double-clicks."
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
703 (and initial final mouse-1-click-follows-link
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
704 (eq (car initial) 'down-mouse-1)
72890
5ba1cd1da822 * mouse-sel.el (mouse-sel-follow-link-p): Use event position
David Kastrup <dak@gnu.org>
parents: 68651
diff changeset
705 (mouse-on-link-p (event-start initial))
62228
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
706 (= (posn-point (event-start initial))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
707 (posn-point (event-end final)))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
708 (= (event-click-count initial) 1)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
709 (or (not (integerp mouse-1-click-follows-link))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
710 (let ((t0 (posn-timestamp (event-start initial)))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
711 (t1 (posn-timestamp (event-end final))))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
712 (and (integerp t0) (integerp t1)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
713 (if (> mouse-1-click-follows-link 0)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
714 (<= (- t1 t0) mouse-1-click-follows-link)
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
715 (< (- t0 t1) mouse-1-click-follows-link)))))))
680b3e8df7c5 From Chong Yidong <cyd@stupidchicken.com>
Kim F. Storm <storm@cua.dk>
parents: 57781
diff changeset
716
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
717 ;;=== Paste ===============================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718
46403
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
719 (defun mouse-insert-selection (event arg)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
720 "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
721 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
722 (interactive "e\nP")
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
723 (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
724 (mouse-yank-at-click event arg)
3b394c7ff111 (mouse-sel-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46385
diff changeset
725 (mouse-insert-selection-internal 'PRIMARY event)))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
726
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
727 (defun mouse-insert-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
728 "Insert the contents of the SECONDARY selection at mouse click.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
729 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
730 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
731 (mouse-insert-selection-internal 'SECONDARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
732
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
733 (defun mouse-insert-selection-internal (selection event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
734 "Insert the contents of the named SELECTION at mouse click.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
735 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
736 (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
737 (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
738 (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
739 (push-mark (point) 'nomsg)
73272
a5ea274e14ac (mouse-insert-selection-internal): Use insert-for-yank, so that yank handlers
Eli Zaretskii <eliz@gnu.org>
parents: 72890
diff changeset
740 (insert-for-yank
a5ea274e14ac (mouse-insert-selection-internal): Use insert-for-yank, so that yank handlers
Eli Zaretskii <eliz@gnu.org>
parents: 72890
diff changeset
741 (or (funcall mouse-sel-get-selection-function selection) ""))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
742
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
743 ;;=== Handle loss of selections ===========================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
745 (defun mouse-sel-lost-selection-hook (selection)
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
746 "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
747 (let ((overlay (mouse-sel-selection-overlay selection)))
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
748 (delete-overlay overlay)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
750 (provide 'mouse-sel)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
751
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 30691
diff changeset
752 ;;; mouse-sel.el ends here