annotate lisp/mouse-sel.el @ 7694:92a4522c37fc

Make previous change limited to HPUX.
author Richard M. Stallman <rms@gnu.org>
date Thu, 26 May 1994 22:15:23 +0000
parents d50f6828a89d
children bc5dccc5375f
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 ;;
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
102 ;; (setq mouse-yank-at-point t)
6228
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (defvar mouse-sel-default-bindings t
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
183 "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
184
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;;=== Selection ===========================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (defvar mouse-sel-selection-type nil "Type of current selection")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (make-variable-buffer-local 'mouse-sel-selection-type)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (defvar mouse-sel-selection ""
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
191 "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
192
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (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
194 (if (fboundp 'x-set-selection)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (function (lambda (s) (x-set-selection 'PRIMARY s)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (function (lambda (s) (setq mouse-sel-selection s))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 "Function to call to set selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 Called with one argument, the text to select.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (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
201 (if (fboundp 'x-get-selection)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 'x-get-selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (function (lambda () mouse-sel-selection)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 "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
205 Called with no argument.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (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
208 (if (fboundp 'x-selection-owner-p)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 'x-selection-owner-p
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 "Function to check whether emacs still owns the selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 Called with no arguments.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (defun mouse-sel-determine-selection-type (NCLICKS)
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
215 "Determine what `thing' `mouse-sel' should operate on.
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
216 The first argument is NCLICKS, is the number of consecutive
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 mouse clicks at the same position."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (let* ((next-char (char-after (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (char-syntax (if next-char (char-syntax next-char)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (nclicks (if mouse-sel-cycle-clicks (1+ (% (1- NCLICKS) 3)) NCLICKS)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ((= nclicks 1) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ((>= nclicks 3) 'line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ((memq next-char '(? ?\t ?\n)) 'whitespace)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ((eq char-syntax ?_) 'symbol)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ((eq char-syntax ?w) 'word))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (defun mouse-select (EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 "Set region/selection using the mouse.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 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
233 Dragging extends region/selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 Triple-clicking selects lines.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 Clicking mouse-2 while selecting copies the region to the kill-ring.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 Clicking mouse-1 or mouse-3 kills the region.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 This should be bound to a down-mouse event."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (mouse-set-point EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (setq mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (mouse-sel-determine-selection-type (event-click-count EVENT)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (let ((object-bounds (bounds-of-thing-at-point mouse-sel-selection-type)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (if object-bounds
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (setq mark-active t)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (goto-char (car object-bounds))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (set-mark (cdr object-bounds)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (deactivate-mark)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (mouse-extend))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun mouse-extend (&optional EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "Extend region/selection using the mouse.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 See documentation for mouse-select for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 This should be bound to a down-mouse event."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (if EVENT (select-window (posn-window (event-end EVENT))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (let* ((min (if mark-active (region-beginning) (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (max (if mark-active (region-end) (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (orig-window (selected-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (orig-window-frame (window-frame orig-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (top (nth 1 (window-edges orig-window)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (bottom (nth 3 (window-edges orig-window)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (orig-cursor-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (cdr (assoc 'cursor-type (frame-parameters (selected-frame)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 direction
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 event)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ;; Inhibit normal region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (setq mark-active nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 ;; Highlight region (forcing re-highlight)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (move-overlay mouse-drag-overlay min max (current-buffer))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (overlay-put mouse-drag-overlay 'face
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (overlay-get mouse-drag-overlay 'face))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 ;; Bar cursor
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
286 (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
287 (modify-frame-parameters (selected-frame) '((cursor-type . bar))))
4934
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 ;; Handle dragging
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (unwind-protect
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (track-mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (while (if EVENT ; Use initial event
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (prog1
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (setq event EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (setq EVENT nil))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (setq event (read-event))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (and (consp event)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (memq (car event) '(mouse-movement switch-frame))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (let ((end (event-end event)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (cond
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 ;; Ignore any movement outside the frame
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ((eq (car-safe event) 'switch-frame) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ((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
309 (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
310 (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
311 (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
312 posn-w))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (window-frame orig-window)))) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ;; Different window, same frame
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ((not (eq (posn-window end) orig-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (let ((end-row (cdr (cdr (mouse-position)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ((and end-row (not (bobp)) (< end-row top))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (mouse-scroll-subr (- end-row top)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 mouse-drag-overlay max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ((and end-row (not (eobp)) (>= end-row bottom))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (mouse-scroll-subr (1+ (- end-row bottom))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 mouse-drag-overlay min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 )))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ;; On the mode line
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ((eq (posn-point end) 'mode-line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (mouse-scroll-subr 1 mouse-drag-overlay min))
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 ;; In original window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (t (goto-char (posn-point end)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 ;; Determine direction of drag
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 ((and (not direction) (not (eq min max)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 ((and (not (eq direction -1)) (<= (point) min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (setq direction -1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 ((and (not (eq direction 1)) (>= (point) max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (setq direction 1)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (if (not mouse-sel-selection-type) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 ;; If dragging forward, goal is next character
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (if (and (eq direction 1) (not (eobp))) (forward-char 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 ;; Move to start/end of selected thing
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (let ((goal (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 last)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (goto-char (if (eq 1 direction) min max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (while (> (* direction (- goal (point))) 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (setq last (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (forward-thing mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 direction))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (let ((end (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (forward-thing mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (- direction))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (goto-char
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (if (> (* direction (- goal (point))) 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 end last))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (error))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ;; Move overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (move-overlay mouse-drag-overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (if (eq 1 direction) min (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (if (eq -1 direction) max (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (current-buffer))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 ))) ; end track-mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (let ((overlay-start (overlay-start mouse-drag-overlay))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (overlay-end (overlay-end mouse-drag-overlay)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 ;; Set region
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (if (eq overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (if (and mouse-sel-leave-point-near-mouse (eq direction 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (set-mark overlay-start)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (goto-char overlay-end))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (set-mark overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (goto-char overlay-start)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 ;; Set selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (if (and mark-active mouse-sel-set-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (funcall mouse-sel-set-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (buffer-substring overlay-start overlay-end)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 ;; Handle copy/kill
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 ((eq (car-safe last-input-event) 'down-mouse-2)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (copy-region-as-kill overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (read-event) (read-event))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 ((memq (car-safe last-input-event) '(down-mouse-1 down-mouse-3))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (kill-region overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (deactivate-mark)
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
402 (read-event) (read-event))
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
403 ((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
404 (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
405 (deactivate-mark)))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 ;; Restore cursor
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
408 (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
409 (modify-frame-parameters
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
410 (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
411
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 ;; Remove overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (or mouse-sel-retain-highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (delete-overlay mouse-drag-overlay)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (defun mouse-insert-selection (click)
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
417 "Insert the contents of the selection at mouse click.
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
418 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
419 (interactive "e")
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
420 (or mouse-yank-at-point
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
421 (mouse-set-point click))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (if mouse-sel-get-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (insert (or (funcall mouse-sel-get-selection-function) ""))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (defun mouse-sel-validate-selection ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 "Remove selection highlight if emacs no longer owns the primary selection."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (or (not mouse-sel-check-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (funcall mouse-sel-check-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (delete-overlay mouse-drag-overlay)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (add-hook 'pre-command-hook 'mouse-sel-validate-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 ;;=== Key bindings ========================================================
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 (if (not mouse-sel-default-bindings) nil
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 (global-unset-key [mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (global-unset-key [drag-mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (global-unset-key [mouse-3])
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-set-key [down-mouse-1] 'mouse-select)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (global-set-key [down-mouse-3] 'mouse-extend)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (global-set-key [mouse-2] 'mouse-insert-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (setq interprogram-cut-function nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 interprogram-paste-function 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 )
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 ;; mouse-sel.el ends here.