annotate lisp/mouse-sel.el @ 46359:186ccb97f37d

(mouse-sel-bound-events): New constant. (mouse-sel-save-original-bindings): New function. (mouse-sel-restore-original-bindings): New function. (mouse-sel-bindings): Save/restore original mouse-bindings.
author Mike Williams <mdub@bigfoot.com>
date Sun, 14 Jul 2002 10:13:27 +0000
parents 71bf019cb382
children 9ef1f4b9623a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 30691
diff changeset
1 ;;; mouse-sel.el --- multi-click selection support for Emacs 19
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
46359
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
3 ;; Copyright (C) 1993,1994,1995,2001,2002 Free Software Foundation, Inc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
46194
71bf019cb382 Change maintainer email address.
Richard M. Stallman <rms@gnu.org>
parents: 41608
diff changeset
5 ;; Author: Mike Williams <mdub@bigfoot.com>
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
20 ;; You should have received a copy of the GNU General Public License
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
23 ;; Boston, MA 02111-1307, USA.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
24
7942
bc5dccc5375f Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7644
diff changeset
25 ;;; Commentary:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
26
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; This module provides multi-click mouse support for GNU Emacs versions
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; 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
29 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Basically:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; * Clicking or dragging mouse-3 extends the selection as well.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; * Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; Triple-clicking selects lines.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
41 ;; Quad-clicking selects paragraphs.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; * Selecting sets the region & X primary selection, but does NOT affect
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; the kill-ring. Because the mouse handlers set the primary selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; directly, mouse-sel sets the variables interprogram-cut-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; and interprogram-paste-function to nil.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
48 ;; * Clicking mouse-2 inserts the contents of the primary selection at
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
49 ;; the mouse position (or point, if mouse-yank-at-point is non-nil).
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
51 ;; * Pressing mouse-2 while selecting or extending copies selection
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; to the kill ring. Pressing mouse-1 or mouse-3 kills it.
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
53 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
54 ;; * Double-clicking mouse-3 also kills selection.
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
55 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
56 ;; * M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
57 ;; & mouse-3, but operate on the X secondary selection rather than the
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
58 ;; primary selection and region.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
60 ;; This module requires my thingatpt.el module, which it uses to find the
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
61 ;; bounds of words, lines, sexps, etc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
65 ;;--- Customisation -------------------------------------------------------
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
66 ;;
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
67 ;; * You may want to use none or more of following:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; ;; Enable region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; (transient-mark-mode 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; ;; But only in the selected window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; (setq highlight-nonselected-windows nil)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
74 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; ;; Enable pending-delete
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; (delete-selection-mode 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;
8766
116e1882576b Fix typo in comment.
Karl Heuer <kwzh@gnu.org>
parents: 8608
diff changeset
78 ;; * 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
79 ;; of mouse-sel-default-bindings before loading mouse-sel.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; (a) If mouse-sel-default-bindings = t (the default)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
82 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
83 ;; Mouse sets and insert selection
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; mouse-2 mouse-insert-selection
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
86 ;; mouse-3 mouse-extend
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; Selection/kill-ring interaction is disabled
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; interprogram-cut-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; interprogram-paste-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
93 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; Mouse sets selection, and pastes from kill-ring
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
95 ;; mouse-1 mouse-select
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
96 ;; mouse-2 mouse-yank-at-click
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
97 ;; mouse-3 mouse-extend
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; interprogram-paste-function = x-cut-buffer-or-selection-value
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;; disable this behaviour with:
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.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;; Disable this behaviour with:
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 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; * You can change the selection highlight face by altering the properties
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;; of mouse-drag-overlay, eg.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; (overlay-put mouse-drag-overlay 'face 'bold)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13556
diff changeset
138 ;;; Code:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (require 'mouse)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (require 'thingatpt)
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 (eval-when-compile
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
144 (require 'cl))
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
145
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;;=== User Variables ======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
148 (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
149 "Mouse selection enhancement."
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
150 :group 'mouse)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
151
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
152 (defcustom mouse-sel-mode nil
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
153 "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
154 When Mouse Sel mode is enabled, mouse selection is enhanced in various ways.
24645
ba928fb691dc (mouse-sel-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24550
diff changeset
155 Setting this variable directly does not take effect;
ba928fb691dc (mouse-sel-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24550
diff changeset
156 use either \\[customize] or the function `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
157 :set (lambda (symbol value)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
158 (mouse-sel-mode (or value 0)))
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
159 :initialize 'custom-initialize-default
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
160 :type 'boolean
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
161 :group 'mouse-sel
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
162 :require 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
163
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
164 (defcustom mouse-sel-leave-point-near-mouse t
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 "*Leave point near last mouse position.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
166 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
167 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
168 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
169 :type 'boolean
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
170 :group 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
171
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
172 (defcustom mouse-sel-cycle-clicks t
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
173 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks."
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
174 :type 'boolean
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
175 :group 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
176
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
177 (defcustom mouse-sel-default-bindings t
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
178 "*Control mouse bindings."
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
179 :type '(choice (const :tag "none" nil)
22593
2407b3d241a6 (mouse-sel-default-bindings): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents: 18784
diff changeset
180 (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
181 (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
182 :group 'mouse-sel)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
183
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
184 ;;=== User Command ========================================================
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
185
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
186 ;;;###autoload
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
187 (defun mouse-sel-mode (&optional arg)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
188 "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
189 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
190 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
191
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
192 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
193
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
194 - 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
195
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
196 - 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
197
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
198 - 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
199 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
200 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
201 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
202 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
203 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
204
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
205 - Selecting sets the region & X primary selection, but does NOT affect
30691
eedb47bce69b (mouse-sel-mode): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 24645
diff changeset
206 the kill-ring, nor do the kill-ring function change the X selection.
eedb47bce69b (mouse-sel-mode): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 24645
diff changeset
207 Because the mouse handlers set the primary selection directly,
eedb47bce69b (mouse-sel-mode): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 24645
diff changeset
208 mouse-sel sets the variables interprogram-cut-function and
eedb47bce69b (mouse-sel-mode): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 24645
diff changeset
209 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
210
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
211 - Clicking mouse-2 inserts the contents of the primary selection at
38897
f9cec1b1d7ba Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38775
diff changeset
212 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
213
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
214 - 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
215 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
216
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
217 - Double-clicking mouse-3 also kills selection.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
219 - 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
220 & 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
221 primary selection and region."
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
222 (interactive "P")
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
223 (let ((on-p (if arg
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
224 (> (prefix-numeric-value arg) 0)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
225 (not mouse-sel-mode))))
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
226 (if on-p
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
227 (add-hook 'x-lost-selection-hooks 'mouse-sel-lost-selection-hook)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
228 (remove-hook 'x-lost-selection-hooks 'mouse-sel-lost-selection-hook))
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
229 (mouse-sel-bindings on-p)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
230 (setq mouse-sel-mode on-p)))
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
231
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
232 ;;=== Key bindings ========================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
46359
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
234 (defconst mouse-sel-bound-events
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
235 '([down-mouse-1] [mouse-1] [drag-mouse-1]
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
236 [mouse-2]
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
237 [down-mouse-3] [mouse-3]
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
238 [M-mouse-2]
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
239 [M-down-mouse-1] [M-mouse-1] [M-drag-mouse-1]
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
240 [M-down-mouse-3] [M-mouse-3])
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
241 "A list of events that mouse-sel binds.")
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
242
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
243 (defun mouse-sel-save-original-bindings ()
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
244 "Save the current bindings for `mouse-sel-bound-events'."
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
245 (setq mouse-sel-original-bindings nil)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
246 (mapc (function
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
247 (lambda (event)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
248 (setq mouse-sel-original-bindings
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
249 (cons (cons event (lookup-key global-map event))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
250 mouse-sel-original-bindings))))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
251 mouse-sel-bound-events))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
252
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
253 (defun mouse-sel-restore-original-bindings ()
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
254 "Restore the original bindings for `mouse-sel-bound-events'."
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
255 (mapc (function
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
256 (lambda (binding)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
257 (if (cdr binding)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
258 (global-set-key (car binding) (cdr binding))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
259 (global-unset-key (car binding)))))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
260 mouse-sel-original-bindings))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
261
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
262 (defun mouse-sel-bindings (bind)
46359
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
263 (cond
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
264
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
265 ;; Default mouse-sel bindings
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
266 ((and bind mouse-sel-default-bindings)
38443
643e08c68af9 (mouse-sel-bindings): Instead of unbinding
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
267
46359
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
268 ;; Save original bindings
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
269 (mouse-sel-save-original-bindings)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
270
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
271 ;; Primary selection bindings.
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
272 ;;
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
273 ;; Bind keys to `ignore' instead of unsetting them because
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
274 ;; modes may bind `down-mouse-1', for instance, without
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
275 ;; binding other `up-mouse-1' or `mouse-1'. If we unset
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
276 ;; `mouse-1', this leads to a bitch_at_user when the mouse
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
277 ;; goes up because no matching binding is found for that.
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
278 (global-set-key [mouse-1] 'ignore)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
279 (global-set-key [drag-mouse-1] 'ignore)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
280 (global-set-key [mouse-3] 'ignore)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
281 (global-set-key [down-mouse-1] 'mouse-select)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
282 (unless (eq mouse-sel-default-bindings 'interprogram-cut-paste)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
283 (global-set-key [mouse-2] 'mouse-insert-selection)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
284 (setq interprogram-cut-function nil
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
285 interprogram-paste-function nil))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
286 (global-set-key [down-mouse-3] 'mouse-extend)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
287
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
288 ;; Secondary selection bindings.
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
289 (global-set-key [M-mouse-1] 'ignore)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
290 (global-set-key [M-drag-mouse-1] 'ignore)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
291 (global-set-key [M-mouse-3] 'ignore)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
292 (global-set-key [M-down-mouse-1] 'mouse-select-secondary)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
293 (global-set-key [M-mouse-2] 'mouse-insert-secondary)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
294 (global-set-key [M-down-mouse-3] 'mouse-extend-secondary))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
295
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
296 ((not bind)
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
297 ;; Restore original bindings
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
298 (mouse-sel-restore-original-bindings))
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
299
186ccb97f37d (mouse-sel-bound-events): New constant.
Mike Williams <mdub@bigfoot.com>
parents: 46194
diff changeset
300 ))
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
301
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
302 ;;=== Command Variable ====================================================
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
303
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
304 ;; This has to come after the function `mouse-sel-mode' and its callee.
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
305 ;; An alternative is to put the option `mouse-sel-mode' here and remove its
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
306 ;; `:initialize' keyword.
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
307 (when mouse-sel-mode
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
308 (mouse-sel-mode t))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
310 ;;=== Internal Variables/Constants ========================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
311
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
312 (defvar mouse-sel-primary-thing nil
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
313 "Type of PRIMARY selection in current buffer.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
314 (make-variable-buffer-local 'mouse-sel-primary-thing)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
315
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
316 (defvar mouse-sel-secondary-thing nil
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
317 "Type of SECONDARY selection in current buffer.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
318 (make-variable-buffer-local 'mouse-sel-secondary-thing)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
320 ;; 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
321 (unless (overlayp mouse-secondary-overlay)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
322 (setq mouse-secondary-overlay (make-overlay 1 1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
323 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
325 (defconst mouse-sel-selection-alist
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
326 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
327 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing))
38897
f9cec1b1d7ba Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38775
diff changeset
328 "Alist associating selections with variables.
f9cec1b1d7ba Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38775
diff changeset
329 Each element is of the form:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
331 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
332
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
333 where SELECTION-NAME = name of selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
334 OVERLAY-SYMBOL = name of variable containing overlay to use
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
335 SELECTION-THING-SYMBOL = name of variable where the current selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
336 type for this selection should be stored.")
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
337
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
338 (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
339 (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
340 'x-set-selection
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
341 (lambda (selection value)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
342 (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
343 (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
344 (x-set-selection selection value))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 "Function to call to set selection.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
346 Called with two arguments:
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
347
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
348 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
349 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
350
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
351 This sets the selection as well as the cut buffer for the older applications,
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
352 unless `mouse-sel-default-bindings' is `interprogram-cut-paste'.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (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
355 (lambda (selection)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
356 (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
357 (or (x-cut-buffer-or-selection-value) x-last-selected-text)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
358 (x-get-selection selection)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 "Function to call to get the selection.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
360 Called with one argument:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
362 SELECTION: the name of the selection concerned.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
364 ;;=== Support/access functions ============================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
366 (defun mouse-sel-determine-selection-thing (nclicks)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
367 "Determine what `thing' `mouse-sel' should operate on.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
368 The first argument is NCLICKS, is the number of consecutive
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
369 mouse clicks at the same position.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 Triple-clicking selects lines.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
376 Quad-clicking selects paragraphs.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
378 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
379 multi-click semantics."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
380 (let* ((next-char (char-after (point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
381 (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
382 (if mouse-sel-cycle-clicks
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
383 (setq nclicks (1+ (% (1- nclicks) 4))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
384 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
385 ((= nclicks 1) nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
386 ((= nclicks 3) 'line)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
387 ((>= nclicks 4) 'paragraph)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
388 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
389 ((memq next-char '(? ?\t ?\n)) 'whitespace)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
390 ((eq char-syntax ?_) 'symbol)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
391 ((eq char-syntax ?w) 'word))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
392
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
393 (defun mouse-sel-set-selection (selection value)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
394 "Set the specified SELECTION to VALUE."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
395 (if mouse-sel-set-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
396 (funcall mouse-sel-set-selection-function selection value)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
397 (put 'mouse-sel-internal-selection selection value)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
398
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
399 (defun mouse-sel-get-selection (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
400 "Get the value of the specified SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
401 (if mouse-sel-get-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
402 (funcall mouse-sel-get-selection-function selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
403 (get 'mouse-sel-internal-selection selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
404
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
405 (defun mouse-sel-selection-overlay (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
406 "Return overlay corresponding to SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
407 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
408 (or symbol (error "No overlay corresponding to %s selection" selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
409 (symbol-value symbol)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
410
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
411 (defun mouse-sel-selection-thing (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
412 "Return overlay corresponding to SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
413 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
414 (or symbol (error "No symbol corresponding to %s selection" selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
415 symbol))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
416
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
417 (defun mouse-sel-region-to-primary (orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
418 "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
419 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
420 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
421 region was visible or not."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
422 (if transient-mark-mode
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
423 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
424 (cond
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
425 ((and mark-active
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
426 (or highlight-nonselected-windows
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
427 (eq orig-window (selected-window))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
428 ;; 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
429 (move-overlay overlay (region-beginning) (region-end)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
430 (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
431 ((eq orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
432 ;; Point was visible, so set overlay at point
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
433 (move-overlay overlay (point) (point) (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
434 (t
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
435 ;; Nothing was visible, so remove overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
436 (delete-overlay overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
437 (setq mark-active nil))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
438
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
439 (defun mouse-sel-primary-to-region (&optional direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
440 "Convert PRIMARY overlay to region.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
441 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
442 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
443 dragged right-to-left."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
444 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
445 (start (overlay-start overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
446 (end (overlay-end overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
447 (if (eq start end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
448 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
449 (if start (goto-char start))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
450 (deactivate-mark))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
451 (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
452 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
453 (goto-char end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
454 (push-mark start 'nomsg 'active))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
455 (goto-char start)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
456 (push-mark end 'nomsg 'active)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
457 (if transient-mark-mode (delete-overlay overlay))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
458
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
459 (defmacro mouse-sel-eval-at-event-end (event &rest forms)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
460 "Evaluate forms at mouse position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
461 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
462 point and window."
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
463 `(let ((posn (event-end ,event)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
464 (if posn (mouse-minibuffer-check ,event))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
465 (if (and posn (not (windowp (posn-window posn))))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
466 (error "Cursor not in text area of window"))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
467 (let (orig-window orig-point-marker)
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
468 (setq orig-window (selected-window))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
469 (if posn (select-window (posn-window posn)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
470 (setq orig-point-marker (point-marker))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
471 (if (and posn (numberp (posn-point posn)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
472 (goto-char (posn-point posn)))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
473 (unwind-protect
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
474 (progn
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
475 ,@forms)
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
476 (goto-char (marker-position orig-point-marker))
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
477 (move-marker orig-point-marker nil)
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
478 (select-window orig-window)))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
479
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
480 (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
481
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
482 ;;=== Select ==============================================================
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 (defun mouse-select (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
485 "Set region/selection using the mouse.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
486
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
487 Click sets point & mark to click position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
488 Dragging extends region/selection.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
489
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
490 Multi-clicking selects word/lines/paragraphs, as determined by
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
491 'mouse-sel-determine-selection-thing.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
492
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
493 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
494 Clicking mouse-1 or mouse-3 kills the selected text.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 This should be bound to a down-mouse event."
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
497 (interactive "@e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
498 (let (direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
499 (unwind-protect
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
500 (setq direction (mouse-select-internal 'PRIMARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
501 (mouse-sel-primary-to-region direction))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
502
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
503 (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
504 "Set secondary selection using the mouse.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
506 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
507 Dragging extends the secondary selection.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
509 Multi-clicking selects word/lines/paragraphs, as determined by
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
510 'mouse-sel-determine-selection-thing.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
511
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
512 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
513 Clicking mouse-1 or mouse-3 kills the selected text.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 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
516 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
517 (mouse-select-internal 'SECONDARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
518
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
519 (defun mouse-select-internal (selection event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
520 "Set SELECTION using the mouse."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
521 (mouse-sel-eval-at-event-end event
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
522 (let ((thing-symbol (mouse-sel-selection-thing selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
523 (overlay (mouse-sel-selection-overlay selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
524 (set thing-symbol
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
525 (mouse-sel-determine-selection-thing (event-click-count event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
526 (let ((object-bounds (bounds-of-thing-at-point
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
527 (symbol-value thing-symbol))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
528 (if object-bounds
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
529 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
530 (move-overlay overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
531 (car object-bounds) (cdr object-bounds)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
532 (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
533 (move-overlay overlay (point) (point) (current-buffer)))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
534 (mouse-extend-internal selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
535
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
536 ;;=== Extend ==============================================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
537
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
538 (defun mouse-extend (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
539 "Extend region/selection using the mouse."
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
541 (let ((orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
542 direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
543 (select-window (posn-window (event-end event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
544 (unwind-protect
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
545 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
546 (mouse-sel-region-to-primary orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
547 (setq direction (mouse-extend-internal 'PRIMARY event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
548 (mouse-sel-primary-to-region direction))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
549
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
550 (defun mouse-extend-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
551 "Extend secondary selection using the mouse."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
552 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
553 (save-window-excursion
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
554 (mouse-extend-internal 'SECONDARY event)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
556 (defun mouse-extend-internal (selection &optional initial-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
557 "Extend specified SELECTION using the mouse.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
558 Track mouse-motion events, adjusting the SELECTION appropriately.
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
559 Optional argument INITIAL-EVENT specifies an initial down-mouse event to
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
560 process.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
562 See documentation for mouse-select-internal for more details."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
563 (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
564 (let ((orig-cursor-type
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
565 (cdr (assoc 'cursor-type (frame-parameters (selected-frame))))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
566 (unwind-protect
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
568 (let* ((thing-symbol (mouse-sel-selection-thing selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
569 (overlay (mouse-sel-selection-overlay selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
570 (orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
571 (orig-window-frame (window-frame orig-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
572 (top (nth 1 (window-edges orig-window)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
573 (bottom (nth 3 (window-edges orig-window)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
574 (mark-active nil) ; inhibit normal region highlight
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
575 (echo-keystrokes 0) ; don't echo mouse events
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
576 min max
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
577 direction
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
578 event)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
580 ;; Get current bounds of overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
581 (if (eq (overlay-buffer overlay) (current-buffer))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
582 (setq min (overlay-start overlay)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
583 max (overlay-end overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
584 (setq min (point)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
585 max min)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
586 (set thing-symbol nil))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
587
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
588
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
589 ;; Bar cursor
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
590 (if (fboundp 'modify-frame-parameters)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
591 (modify-frame-parameters (selected-frame)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
592 '((cursor-type . bar))))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
593
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
594 ;; Handle dragging
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
595 (track-mouse
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
596
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
597 (while (if initial-event ; Use initial event
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
598 (prog1
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
599 (setq event initial-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
600 (setq initial-event nil))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
601 (setq event (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
602 (and (consp event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
603 (memq (car event) '(mouse-movement switch-frame))))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
604
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
605 (let ((selection-thing (symbol-value thing-symbol))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
606 (end (event-end event)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
607
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
608 (cond
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
609
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
610 ;; Ignore any movement outside the frame
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
611 ((eq (car-safe event) 'switch-frame) nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
612 ((and (posn-window end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
613 (not (eq (let ((posn-w (posn-window end)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
614 (if (windowp posn-w)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
615 (window-frame posn-w)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
616 posn-w))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
617 (window-frame orig-window)))) nil)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
618
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
619 ;; Different window, same frame
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
620 ((not (eq (posn-window end) orig-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
621 (let ((end-row (cdr (cdr (mouse-position)))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
622 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
623 ((and end-row (not (bobp)) (< end-row top))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
624 (mouse-scroll-subr orig-window (- end-row top)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
625 overlay max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
626 ((and end-row (not (eobp)) (>= end-row bottom))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
627 (mouse-scroll-subr orig-window (1+ (- end-row bottom))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
628 overlay min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
629 )))
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 ;; On the mode line
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
632 ((eq (posn-point end) 'mode-line)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
633 (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
634
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
635 ;; In original window
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
636 (t (goto-char (posn-point end)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
637
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
638 )
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
639
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
640 ;; Determine direction of drag
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
641 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
642 ((and (not direction) (not (eq min max)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
643 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
644 ((and (not (eq direction -1)) (<= (point) min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
645 (setq direction -1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
646 ((and (not (eq direction 1)) (>= (point) max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
647 (setq direction 1)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
648
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
649 (if (not selection-thing) nil
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
650
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
651 ;; If dragging forward, goal is next character
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
652 (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
653
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
654 ;; Move to start/end of selected thing
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
655 (let ((goal (point)))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
656 (goto-char (if (eq 1 direction) min max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
657 (condition-case nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
658 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
659 (while (> (* direction (- goal (point))) 0)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
660 (forward-thing selection-thing direction))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
661 (let ((end (point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
662 (forward-thing selection-thing (- direction))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
663 (goto-char
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
664 (if (> (* direction (- goal (point))) 0)
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
665 end (point)))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
666 (error))))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
667
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
668 ;; Move overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
669 (move-overlay overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
670 (if (eq 1 direction) min (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
671 (if (eq -1 direction) max (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
672 (current-buffer))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
673
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
674 ))) ; end track-mouse
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
676 ;; Finish up after dragging
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
677 (let ((overlay-start (overlay-start overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
678 (overlay-end (overlay-end overlay)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
679
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
680 ;; Set selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
681 (if (not (eq overlay-start overlay-end))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
682 (mouse-sel-set-selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
683 selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
684 (buffer-substring overlay-start overlay-end)))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
685
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
686 ;; Handle copy/kill
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
687 (let (this-command)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (cond
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
689 ((eq (event-basic-type last-input-event) 'mouse-2)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
690 (copy-region-as-kill overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
691 (read-event) (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
692 ((and (memq (event-basic-type last-input-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
693 '(mouse-1 mouse-3))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
694 (memq 'down (event-modifiers last-input-event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
695 (kill-region overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
696 (move-overlay overlay overlay-start overlay-start)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
697 (read-event) (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
698 ((and (eq (event-basic-type last-input-event) 'mouse-3)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
699 (memq 'double (event-modifiers last-input-event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
700 (kill-region overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
701 (move-overlay overlay overlay-start overlay-start)))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
703 direction)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
705 ;; Restore cursor
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
706 (if (fboundp 'modify-frame-parameters)
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38897
diff changeset
707 (modify-frame-parameters
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
708 (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
709
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
710 ))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
712 ;;=== Paste ===============================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
714 (defun mouse-insert-selection (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
715 "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
716 If `mouse-yank-at-point' is non-nil, insert at point instead."
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
718 (mouse-insert-selection-internal 'PRIMARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
719
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
720 (defun mouse-insert-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
721 "Insert the contents of the SECONDARY selection at mouse click.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
722 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
723 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
724 (mouse-insert-selection-internal 'SECONDARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
725
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
726 (defun mouse-insert-selection-internal (selection event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
727 "Insert the contents of the named SELECTION at mouse click.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
728 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
729 (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
730 (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
731 (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
732 (push-mark (point) 'nomsg)
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
733 (insert (or (funcall mouse-sel-get-selection-function selection) ""))))
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
734
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
735 ;;=== Handle loss of selections ===========================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
737 (defun mouse-sel-lost-selection-hook (selection)
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
738 "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
739 (let ((overlay (mouse-sel-selection-overlay selection)))
12592
efb59db39da7 Don't (require 'backquote).
Richard M. Stallman <rms@gnu.org>
parents: 11490
diff changeset
740 (delete-overlay overlay)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741
18784
5e56fda13c2f Customise. Don't install bindings on file load; use a fn.
Simon Marshall <simon@gnu.org>
parents: 17671
diff changeset
742 (provide 'mouse-sel)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
743
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 30691
diff changeset
744 ;;; mouse-sel.el ends here