annotate lisp/mouse-sel.el @ 7456:493a32789e7d

(update-file-autoloads): Delete leftover variable.
author Karl Heuer <kwzh@gnu.org>
date Wed, 11 May 1994 04:40:25 +0000
parents 4fd40bd394fe
children d50f6828a89d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; mouse-sel.el --- Multi-click selection support for Emacs 19
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
7298
4fd40bd394fe Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 7023
diff changeset
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz>
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mouse
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
7 ;; Version: 2.1
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
21 ;;; Commentary: ===========================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; This module provides multi-click mouse support for GNU Emacs versions
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; 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
25 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; Basically:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; * Clicking or dragging mouse-3 extends the selection as well.
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 ;; * Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Triple-clicking selects lines.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; * Selecting sets the region & X primary selection, but does NOT affect
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; the kill-ring. Because the mouse handlers set the primary selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; directly, mouse-sel sets the variables interprogram-cut-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; and interprogram-paste-function to nil.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
43 ;; * Clicking mouse-2 pastes contents of primary selection at the mouse
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
44 ;; position.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
46 ;; * Pressing mouse-2 while selecting or extending copies selection
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; to the kill ring. Pressing mouse-1 or mouse-3 kills it.
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
48 ;;
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
49 ;; * Double-clicking mouse-3 also kills selection.
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 ;; 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
52 ;; bounds of words, lines, sexps, etc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
56 ;;--- Customisation -------------------------------------------------------
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
57 ;;
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
58 ;; * You may want to use none or more of following:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; ;; Enable region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; (transient-mark-mode 1)
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 ;; ;; But only in the selected window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; (setq highlight-nonselected-windows nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; ;; Enable pending-delete
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; (delete-selection-mode 1)
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 ;; * You can control the way mouse-sel binds it's keys by setting the value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; of mouse-sel-default-bindings before loading mouse-sel.
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 ;; (a) If mouse-sel-default-bindings = t (the default)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; Mouse sets and pastes selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; mouse-2 mouse-insert-selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; mouse-3 mouse-extend
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; Selection/kill-ring interaction is disabled
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; interprogram-cut-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; interprogram-paste-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; Mouse sets selection, and pastes from kill-ring
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; mouse-2 mouse-yank-at-click
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; mouse-3 mouse-extend
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; Selection/kill-ring interaction is retained
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; interprogram-cut-function = x-select-text
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; interprogram-paste-function = x-cut-buffer-or-selection-value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; What you lose is the ability to select some text in
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; delete-selection-mode and yank over the top of it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
99 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
100 ;; 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
101 ;;
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
102 ;; (setq mouse-sel-insert-at-point t)
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
103 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; * 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
105 ;; mouse was, even though this makes region highlighting mis-leading (the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; cursor makes it look like one extra character is selected). You can
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;; disable this behaviour with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; (setq mouse-sel-leave-point-near-mouse nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;; * Normally, the selection highlight will be removed when the mouse is
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; lifted. You can tell mouse-sel to retain the selection highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; (useful if you don't use transient-mark-mode) with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; (setq mouse-sel-retain-highlight t)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; * By default, mouse-select cycles the click count after 3 clicks. That
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; is, clicking mouse-1 four times has the same effect as clicking it
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; once, clicking five times has the same effect as clicking twice, etc.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; Disable this behaviour with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;; (setq mouse-sel-cycle-clicks nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; * The variables mouse-sel-{set,get,check}-selection-function control how
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; the selection is handled. Under X Windows, these variables default so
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; that the X primary selection is used. Under other windowing systems,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; alternate functions are used, which simply store the selection value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; in a variable.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;;--- Hints ---------------------------------------------------------------
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; * You can change the selection highlight face by altering the properties
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; of mouse-drag-overlay, eg.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;; (overlay-put mouse-drag-overlay 'face 'bold)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; * Pasting from the primary selection under emacs 19.19 is SLOW (there's
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;; a two second delay). The following code will cause mouse-sel to use
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; the cut buffer rather than the primary selection. However, be aware
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; that cut buffers are OBSOLETE, and some X applications may not support
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;; them.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;; (setq mouse-sel-set-selection-function 'x-select-text
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; mouse-sel-get-selection-function 'x-get-cut-buffer)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;;--- Warnings ------------------------------------------------------------
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; * When selecting sexps, the selection extends by sexps at the same
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; nesting level. This also means the selection cannot be extended out
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; of the enclosing nesting level. This is INTENTIONAL.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
152 ;;; Code: =================================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (provide 'mouse-sel)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (require 'mouse)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (require 'thingatpt)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;;=== Version =============================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
161 (defconst mouse-sel-version "2.1"
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
162 "The version number of mouse-sel (as string).")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;;=== User Variables ======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (defvar mouse-sel-leave-point-near-mouse t
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 "*Leave point near last mouse position.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 of the region nearest to where the mouse last was.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 If nil, point will always be placed at the beginning of the region.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defvar mouse-sel-retain-highlight nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 "*Retain highlight on mouse-drag-overlay.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 If non-nil, regions selected using \\[mouse-select] and \\[mouse-extend] will
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 remain highlighted.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 If nil, highlighting will be turned off when the mouse is lifted.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (defvar mouse-sel-cycle-clicks t
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 "*If non-nil, \\[mouse-select] cycles the click-counts after 3 clicks.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 Ie. 4 clicks = 1 click, 5 clicks = 2 clicks, etc.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
182 (defvar mouse-sel-insert-at-point nil
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
183 "*If non-nil, \\[mouse-insert-selection] inserts at point.
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
184 Normally, \\[mouse-insert-selection] inserts at the mouse position.")
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
185
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defvar mouse-sel-default-bindings t
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
187 "Set to nil before loading `mouse-sel' to prevent default mouse bindings.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;;=== Selection ===========================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defvar mouse-sel-selection-type nil "Type of current selection")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (make-variable-buffer-local 'mouse-sel-selection-type)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defvar mouse-sel-selection ""
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
195 "Store the selection value when using a window systems other than X.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (defvar mouse-sel-set-selection-function
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
198 (if (fboundp 'x-set-selection)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (function (lambda (s) (x-set-selection 'PRIMARY s)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (function (lambda (s) (setq mouse-sel-selection s))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 "Function to call to set selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 Called with one argument, the text to select.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defvar mouse-sel-get-selection-function
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
205 (if (fboundp 'x-get-selection)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 'x-get-selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (function (lambda () mouse-sel-selection)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 "Function to call to get the selection.
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
209 Called with no argument.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (defvar mouse-sel-check-selection-function
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
212 (if (fboundp 'x-selection-owner-p)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 'x-selection-owner-p
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 "Function to check whether emacs still owns the selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 Called with no arguments.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (defun mouse-sel-determine-selection-type (NCLICKS)
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
219 "Determine what `thing' `mouse-sel' should operate on.
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
220 The first argument is NCLICKS, is the number of consecutive
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 mouse clicks at the same position."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (let* ((next-char (char-after (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (char-syntax (if next-char (char-syntax next-char)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (nclicks (if mouse-sel-cycle-clicks (1+ (% (1- NCLICKS) 3)) NCLICKS)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ((= nclicks 1) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ((>= nclicks 3) 'line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ((memq next-char '(? ?\t ?\n)) 'whitespace)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ((eq char-syntax ?_) 'symbol)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ((eq char-syntax ?w) 'word))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (defun mouse-select (EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 "Set region/selection using the mouse.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 On click, point & mark are set to click position, and mark is disabled.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 Dragging extends region/selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 Triple-clicking selects lines.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 Clicking mouse-2 while selecting copies the region to the kill-ring.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 Clicking mouse-1 or mouse-3 kills the region.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 This should be bound to a down-mouse event."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (mouse-set-point EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (setq mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (mouse-sel-determine-selection-type (event-click-count EVENT)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (let ((object-bounds (bounds-of-thing-at-point mouse-sel-selection-type)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (if object-bounds
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (setq mark-active t)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (goto-char (car object-bounds))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (set-mark (cdr object-bounds)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (deactivate-mark)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (mouse-extend))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun mouse-extend (&optional EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 "Extend region/selection using the mouse.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 See documentation for mouse-select for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 This should be bound to a down-mouse event."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (if EVENT (select-window (posn-window (event-end EVENT))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (let* ((min (if mark-active (region-beginning) (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (max (if mark-active (region-end) (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (orig-window (selected-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (orig-window-frame (window-frame orig-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (top (nth 1 (window-edges orig-window)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (bottom (nth 3 (window-edges orig-window)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (orig-cursor-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (cdr (assoc 'cursor-type (frame-parameters (selected-frame)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 direction
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 event)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 ;; Inhibit normal region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (setq mark-active nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 ;; Highlight region (forcing re-highlight)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (move-overlay mouse-drag-overlay min max (current-buffer))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (overlay-put mouse-drag-overlay 'face
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (overlay-get mouse-drag-overlay 'face))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 ;; Bar cursor
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
290 (if (fboundp 'modify-frame-parameters)
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
291 (modify-frame-parameters (selected-frame) '((cursor-type . bar))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 ;; Handle dragging
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (unwind-protect
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (track-mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (while (if EVENT ; Use initial event
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (prog1
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (setq event EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (setq EVENT nil))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (setq event (read-event))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (and (consp event)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (memq (car event) '(mouse-movement switch-frame))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (let ((end (event-end event)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;; Ignore any movement outside the frame
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ((eq (car-safe event) 'switch-frame) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ((and (posn-window end)
7023
a326806e4752 (mouse-extend): Handle case where posn-window is a frame.
Richard M. Stallman <rms@gnu.org>
parents: 6228
diff changeset
313 (not (eq (let ((posn-w (posn-window end)))
a326806e4752 (mouse-extend): Handle case where posn-window is a frame.
Richard M. Stallman <rms@gnu.org>
parents: 6228
diff changeset
314 (if (windowp posn-w)
a326806e4752 (mouse-extend): Handle case where posn-window is a frame.
Richard M. Stallman <rms@gnu.org>
parents: 6228
diff changeset
315 (window-frame posn-w)
a326806e4752 (mouse-extend): Handle case where posn-window is a frame.
Richard M. Stallman <rms@gnu.org>
parents: 6228
diff changeset
316 posn-w))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (window-frame orig-window)))) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ;; Different window, same frame
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ((not (eq (posn-window end) orig-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (let ((end-row (cdr (cdr (mouse-position)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ((and end-row (not (bobp)) (< end-row top))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (mouse-scroll-subr (- end-row top)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 mouse-drag-overlay max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 ((and end-row (not (eobp)) (>= end-row bottom))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (mouse-scroll-subr (1+ (- end-row bottom))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 mouse-drag-overlay min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 )))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ;; On the mode line
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 ((eq (posn-point end) 'mode-line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (mouse-scroll-subr 1 mouse-drag-overlay min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ;; In original window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (t (goto-char (posn-point end)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 )
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 ;; Determine direction of drag
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 ((and (not direction) (not (eq min max)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 ((and (not (eq direction -1)) (<= (point) min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (setq direction -1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ((and (not (eq direction 1)) (>= (point) max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (setq direction 1)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (if (not mouse-sel-selection-type) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 ;; If dragging forward, goal is next character
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (if (and (eq direction 1) (not (eobp))) (forward-char 1))
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 ;; Move to start/end of selected thing
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (let ((goal (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 last)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (goto-char (if (eq 1 direction) min max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (while (> (* direction (- goal (point))) 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (setq last (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (forward-thing mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 direction))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (let ((end (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (forward-thing mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (- direction))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (goto-char
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (if (> (* direction (- goal (point))) 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 end last))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (error))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 ;; Move overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (move-overlay mouse-drag-overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (if (eq 1 direction) min (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (if (eq -1 direction) max (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (current-buffer))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 ))) ; end track-mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (let ((overlay-start (overlay-start mouse-drag-overlay))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (overlay-end (overlay-end mouse-drag-overlay)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 ;; Set region
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (if (eq overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (if (and mouse-sel-leave-point-near-mouse (eq direction 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (set-mark overlay-start)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (goto-char overlay-end))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (set-mark overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (goto-char overlay-start)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 ;; Set selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (if (and mark-active mouse-sel-set-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (funcall mouse-sel-set-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (buffer-substring overlay-start overlay-end)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 ;; Handle copy/kill
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 ((eq (car-safe last-input-event) 'down-mouse-2)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (copy-region-as-kill overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (read-event) (read-event))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 ((memq (car-safe last-input-event) '(down-mouse-1 down-mouse-3))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (kill-region overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (deactivate-mark)
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
406 (read-event) (read-event))
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
407 ((eq (car-safe last-input-event) 'double-mouse-3)
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
408 (kill-region overlay-start overlay-end)
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
409 (deactivate-mark)))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 ;; Restore cursor
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
412 (if (fboundp 'modify-frame-parameters)
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
413 (modify-frame-parameters
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
414 (selected-frame) (list (cons 'cursor-type orig-cursor-type))))
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
415
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 ;; Remove overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (or mouse-sel-retain-highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (delete-overlay mouse-drag-overlay)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (defun mouse-insert-selection (click)
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
421 "Insert the contents of the selection at mouse click.
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
422 If `mouse-sel-insert-at-point' is non-nil, insert at point instead."
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (interactive "e")
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
424 (or mouse-sel-insert-at-point
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
425 (mouse-set-point click))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (if mouse-sel-get-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (insert (or (funcall mouse-sel-get-selection-function) ""))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (defun mouse-sel-validate-selection ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 "Remove selection highlight if emacs no longer owns the primary selection."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (or (not mouse-sel-check-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (funcall mouse-sel-check-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (delete-overlay mouse-drag-overlay)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (add-hook 'pre-command-hook 'mouse-sel-validate-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 ;;=== Key bindings ========================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (if (not mouse-sel-default-bindings) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (global-unset-key [mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (global-unset-key [drag-mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (global-unset-key [mouse-3])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (global-set-key [down-mouse-1] 'mouse-select)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (global-set-key [down-mouse-3] 'mouse-extend)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (global-set-key [mouse-2] 'mouse-insert-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (setq interprogram-cut-function nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 interprogram-paste-function nil))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 )
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 ;; mouse-sel.el ends here.