annotate lisp/mouse-sel.el @ 11704:6c9716b7a23d

(string_display_width): Renamed from string_width. (vmotion): Use new name.
author Richard M. Stallman <rms@gnu.org>
date Fri, 05 May 1995 03:04:06 +0000
parents 01f5b6e9c234
children efb59db39da7
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
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995 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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
7942
bc5dccc5375f Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7644
diff changeset
20 ;;; Commentary:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; This module provides multi-click mouse support for GNU Emacs versions
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; 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
24 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Basically:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; * Clicking or dragging mouse-3 extends the selection as well.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; * Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Triple-clicking selects lines.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
36 ;; Quad-clicking selects paragraphs.
4934
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 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
43 ;; * Clicking mouse-2 inserts the contents of the primary selection at
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
44 ;; the mouse position (or point, if mouse-yank-at-point is non-nil).
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
50 ;;
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
51 ;; * M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
52 ;; & mouse-3, but operate on the X secondary selection rather than the
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
53 ;; primary selection and region.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
55 ;; 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
56 ;; bounds of words, lines, sexps, etc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
60 ;;--- Customisation -------------------------------------------------------
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
61 ;;
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
62 ;; * You may want to use none or more of following:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; ;; Enable region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; (transient-mark-mode 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; ;; But only in the selected window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; (setq highlight-nonselected-windows nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; ;; Enable pending-delete
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; (delete-selection-mode 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;
8766
116e1882576b Fix typo in comment.
Karl Heuer <kwzh@gnu.org>
parents: 8608
diff changeset
73 ;; * You can control the way mouse-sel binds its keys by setting the value
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; of mouse-sel-default-bindings before loading mouse-sel.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; (a) If mouse-sel-default-bindings = t (the default)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
78 ;; Mouse sets and insert selection
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; mouse-2 mouse-insert-selection
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
81 ;; mouse-3 mouse-extend
4934
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 ;; Selection/kill-ring interaction is disabled
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; interprogram-cut-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; interprogram-paste-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; Mouse sets selection, and pastes from kill-ring
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
90 ;; mouse-1 mouse-select
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
91 ;; mouse-2 mouse-yank-at-click
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
92 ;; mouse-3 mouse-extend
4934
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 ;; Selection/kill-ring interaction is retained
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; interprogram-cut-function = x-select-text
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; interprogram-paste-function = x-cut-buffer-or-selection-value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; What you lose is the ability to select some text in
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; delete-selection-mode and yank over the top of it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;;
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
103 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
104 ;; 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
105 ;;
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
106 ;; (setq mouse-yank-at-point t)
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
107 ;;
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; * 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
109 ;; mouse was, even though this makes region highlighting mis-leading (the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; cursor makes it look like one extra character is selected). You can
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;; disable this behaviour with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; (setq mouse-sel-leave-point-near-mouse nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
115 ;; * By default, mouse-select cycles the click count after 4 clicks. That
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
116 ;; is, clicking mouse-1 five times has the same effect as clicking it
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
117 ;; once, clicking six times has the same effect as clicking twice, etc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; Disable this behaviour with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; (setq mouse-sel-cycle-clicks nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;;
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
122 ;; * The variables mouse-sel-{set,get}-selection-function control how the
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
123 ;; selection is handled. Under X Windows, these variables default so
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; that the X primary selection is used. Under other windowing systems,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; alternate functions are used, which simply store the selection value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; in a variable.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; * You can change the selection highlight face by altering the properties
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; of mouse-drag-overlay, eg.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; (overlay-put mouse-drag-overlay 'face 'bold)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
5750
e1153522d5f1 (mouse-sel-version): Don't base version number on
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
133 ;;; Code: =================================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (provide 'mouse-sel)
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 (require 'mouse)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (require 'thingatpt)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
139 (require 'backquote)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;;=== User Variables ======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defvar mouse-sel-leave-point-near-mouse t
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 "*Leave point near last mouse position.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
145 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 of the region nearest to where the mouse last was.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
147 If nil, point will always be placed at the beginning of the region.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (defvar mouse-sel-cycle-clicks t
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
150 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (defvar mouse-sel-default-bindings t
6228
116607f5ce37 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 5750
diff changeset
153 "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
154
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
155 ;;=== Internal Variables/Constants ========================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
156
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
157 (defvar mouse-sel-primary-thing nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
158 "Type of PRIMARY selection in current buffer.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
159 (make-variable-buffer-local 'mouse-sel-primary-thing)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
160
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
161 (defvar mouse-sel-secondary-thing nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
162 "Type of SECONDARY selection in current buffer.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
163 (make-variable-buffer-local 'mouse-sel-secondary-thing)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
165 ;; Ensure that secondary overlay is defined
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
166 (if (overlayp mouse-secondary-overlay) nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
167 (setq mouse-secondary-overlay (make-overlay 1 1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
168 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
170 (defconst mouse-sel-selection-alist
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
171 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
172 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
173 "Alist associating selections with variables. Each element is of
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
174 the form:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
176 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
177
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
178 where SELECTION-NAME = name of selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
179 OVERLAY-SYMBOL = name of variable containing overlay to use
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
180 SELECTION-THING-SYMBOL = name of variable where the current selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
181 type for this selection should be stored.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
182
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (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
184 (if (fboundp 'x-set-selection)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
185 'x-set-selection)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "Function to call to set selection.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
187 Called with two arguments:
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
188
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
189 SELECTION, the name of the selection concerned, and
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
190 VALUE, the text to store.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (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
193 (if (fboundp 'x-get-selection)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
194 'x-get-selection)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 "Function to call to get the selection.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
196 Called with one argument:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
198 SELECTION: the name of the selection concerned.")
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
200 (defvar mouse-sel-selection-owner-p-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
201 (if (fboundp 'x-selection-owner-p)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
202 'x-selection-owner-p)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
203 "Function to check whether Emacs still owns the selection.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
204 Called with one argument:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
206 SELECTION: the name of the selection concerned.")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
207
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
208 ;;=== Support/access functions ============================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
210 (defun mouse-sel-determine-selection-thing (nclicks)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
211 "Determine what `thing' `mouse-sel' should operate on.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
212 The first argument is NCLICKS, is the number of consecutive
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
213 mouse clicks at the same position.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 Triple-clicking selects lines.
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
220 Quad-clicking selects paragraphs.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
222 Feel free to re-define this function to support your own desired
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
223 multi-click semantics."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
224 (let* ((next-char (char-after (point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
225 (char-syntax (if next-char (char-syntax next-char))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
226 (if mouse-sel-cycle-clicks
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
227 (setq nclicks (1+ (% (1- nclicks) 4))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
228 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
229 ((= nclicks 1) nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
230 ((= nclicks 3) 'line)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
231 ((>= nclicks 4) 'paragraph)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
232 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
233 ((memq next-char '(? ?\t ?\n)) 'whitespace)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
234 ((eq char-syntax ?_) 'symbol)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
235 ((eq char-syntax ?w) 'word))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
236
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
237 (defun mouse-sel-set-selection (selection value)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
238 "Set the specified SELECTION to VALUE."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
239 (if mouse-sel-set-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
240 (funcall mouse-sel-set-selection-function selection value)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
241 (put 'mouse-sel-internal-selection selection value)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
242
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
243 (defun mouse-sel-get-selection (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
244 "Get the value of the specified SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
245 (if mouse-sel-get-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
246 (funcall mouse-sel-get-selection-function selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
247 (get 'mouse-sel-internal-selection selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
248
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
249 (defun mouse-sel-selection-owner-p (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
250 "Determine whether Emacs owns the specified SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
251 (if mouse-sel-selection-owner-p-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
252 (funcall mouse-sel-selection-owner-p-function selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
253 t))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
254
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
255 (defun mouse-sel-selection-overlay (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
256 "Return overlay corresponding to SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
257 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
258 (or symbol (error "No overlay corresponding to %s selection" selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
259 (symbol-value symbol)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
260
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
261 (defun mouse-sel-selection-thing (selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
262 "Return overlay corresponding to SELECTION."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
263 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
264 (or symbol (error "No symbol corresponding to %s selection" selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
265 symbol))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
266
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
267 (defun mouse-sel-region-to-primary (orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
268 "Convert region to PRIMARY overlay and deactivate region.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
269 Argument ORIG-WINDOW specifies the window the cursor was in when the
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
270 originating command was issued, and is used to determine whether the
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
271 region was visible or not."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
272 (if transient-mark-mode
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
273 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
274 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
275 ((and mark-active
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
276 (or highlight-nonselected-windows
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
277 (eq orig-window (selected-window))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
278 ;; Region was visible, so convert region to overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
279 (move-overlay overlay (region-beginning) (region-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
280 (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
281 ((eq orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
282 ;; Point was visible, so set overlay at point
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
283 (move-overlay overlay (point) (point) (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
284 (t
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
285 ;; Nothing was visible, so remove overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
286 (delete-overlay overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
287 (setq mark-active nil))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
288
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
289 (defun mouse-sel-primary-to-region (&optional direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
290 "Convert PRIMARY overlay to region.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
291 Optional argument DIRECTION specifies the mouse drag direction: a value of
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
292 1 indicates that the mouse was dragged left-to-right, otherwise it was
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
293 dragged right-to-left."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
294 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
295 (start (overlay-start overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
296 (end (overlay-end overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
297 (if (eq start end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
298 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
299 (if start (goto-char start))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
300 (deactivate-mark))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
301 (if (and mouse-sel-leave-point-near-mouse (eq direction 1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
302 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
303 (goto-char end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
304 (push-mark start 'nomsg 'active))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
305 (goto-char start)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
306 (push-mark end 'nomsg 'active)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
307 (if transient-mark-mode (delete-overlay overlay))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
308
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
309 (defmacro mouse-sel-eval-at-event-end (event &rest forms)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
310 "Evaluate forms at mouse position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
311 Move to the end position of EVENT, execute FORMS, and restore original
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
312 point and window."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
313 (`
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
314 (let ((posn (event-end (, event))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
315 (if posn (mouse-minibuffer-check (, event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
316 (if (and posn (not (windowp (posn-window posn))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
317 (error "Cursor not in text area of window"))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
318 (let (orig-window orig-point-marker)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
319 (setq orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
320 (if posn (select-window (posn-window posn)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
321 (setq orig-point-marker (point-marker))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
322 (if (and posn (numberp (posn-point posn)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
323 (goto-char (posn-point posn)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
324 (unwind-protect
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
325 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
326 (,@ forms))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
327 (goto-char (marker-position orig-point-marker))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
328 (move-marker orig-point-marker nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
329 (select-window orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
330 )))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
331
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
332 (put 'mouse-sel-eval-at-event-end 'lisp-indent-hook 1)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
333
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
334 ;;=== Select ==============================================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
335
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
336 (defun mouse-select (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
337 "Set region/selection using the mouse.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
338
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
339 Click sets point & mark to click position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
340 Dragging extends region/selection.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
341
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
342 Multi-clicking selects word/lines/paragraphs, as determined by
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
343 'mouse-sel-determine-selection-thing.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
344
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
345 Clicking mouse-2 while selecting copies selected text to the kill-ring.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
346 Clicking mouse-1 or mouse-3 kills the selected text.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 This should be bound to a down-mouse event."
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
349 (interactive "@e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
350 (let (direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
351 (unwind-protect
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
352 (setq direction (mouse-select-internal 'PRIMARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
353 (mouse-sel-primary-to-region direction))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
354
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
355 (defun mouse-select-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
356 "Set secondary selection using the mouse.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
358 Click sets the start of the secondary selection to click position.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
359 Dragging extends the secondary selection.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
361 Multi-clicking selects word/lines/paragraphs, as determined by
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
362 'mouse-sel-determine-selection-thing.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
363
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
364 Clicking mouse-2 while selecting copies selected text to the kill-ring.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
365 Clicking mouse-1 or mouse-3 kills the selected text.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 This should be bound to a down-mouse event."
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
368 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
369 (mouse-select-internal 'SECONDARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
370
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
371 (defun mouse-select-internal (selection event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
372 "Set SELECTION using the mouse."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
373 (mouse-sel-eval-at-event-end event
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
374 (let ((thing-symbol (mouse-sel-selection-thing selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
375 (overlay (mouse-sel-selection-overlay selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
376 (set thing-symbol
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
377 (mouse-sel-determine-selection-thing (event-click-count event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
378 (let ((object-bounds (bounds-of-thing-at-point
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
379 (symbol-value thing-symbol))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
380 (if object-bounds
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
381 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
382 (move-overlay overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
383 (car object-bounds) (cdr object-bounds)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
384 (current-buffer)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
385 (move-overlay overlay (point) (point) (current-buffer)))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
386 (mouse-extend-internal selection)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
387
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
388 ;;=== Extend ==============================================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
389
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
390 (defun mouse-extend (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
391 "Extend region/selection using the mouse."
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
393 (let ((orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
394 direction)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
395 (select-window (posn-window (event-end event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
396 (unwind-protect
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
397 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
398 (mouse-sel-region-to-primary orig-window)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
399 (setq direction (mouse-extend-internal 'PRIMARY event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
400 (mouse-sel-primary-to-region direction))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
401
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
402 (defun mouse-extend-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
403 "Extend secondary selection using the mouse."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
404 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
405 (save-window-excursion
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
406 (mouse-extend-internal 'SECONDARY event)))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
408 (defun mouse-extend-internal (selection &optional initial-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
409 "Extend specified SELECTION using the mouse.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
410 Track mouse-motion events, adjusting the SELECTION appropriately.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
411 Optional argument INITIAL-EVENT specifies an initial down-mouse event to
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
412 process.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
414 See documentation for mouse-select-internal for more details."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
415 (mouse-sel-eval-at-event-end initial-event
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
416 (let ((orig-cursor-type
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
417 (cdr (assoc 'cursor-type (frame-parameters (selected-frame))))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
418 (unwind-protect
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
420 (let* ((thing-symbol (mouse-sel-selection-thing selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
421 (overlay (mouse-sel-selection-overlay selection))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
422 (orig-window (selected-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
423 (orig-window-frame (window-frame orig-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
424 (top (nth 1 (window-edges orig-window)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
425 (bottom (nth 3 (window-edges orig-window)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
426 (mark-active nil) ; inhibit normal region highlight
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
427 (echo-keystrokes 0) ; don't echo mouse events
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
428 min max
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
429 direction
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
430 event)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
432 ;; Get current bounds of overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
433 (if (eq (overlay-buffer overlay) (current-buffer))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
434 (setq min (overlay-start overlay)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
435 max (overlay-end overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
436 (setq min (point)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
437 max min)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
438 (set thing-symbol nil))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
439
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
440
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
441 ;; Bar cursor
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
442 (if (fboundp 'modify-frame-parameters)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
443 (modify-frame-parameters (selected-frame)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
444 '((cursor-type . bar))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
445
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
446 ;; Handle dragging
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
447 (track-mouse
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
449 (while (if initial-event ; Use initial event
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
450 (prog1
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
451 (setq event initial-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
452 (setq initial-event nil))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
453 (setq event (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
454 (and (consp event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
455 (memq (car event) '(mouse-movement switch-frame))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
456
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
457 (let ((selection-thing (symbol-value thing-symbol))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
458 (end (event-end event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
459
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
460 (cond
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
462 ;; Ignore any movement outside the frame
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
463 ((eq (car-safe event) 'switch-frame) nil)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
464 ((and (posn-window end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
465 (not (eq (let ((posn-w (posn-window end)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
466 (if (windowp posn-w)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
467 (window-frame posn-w)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
468 posn-w))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
469 (window-frame orig-window)))) nil)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
471 ;; Different window, same frame
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
472 ((not (eq (posn-window end) orig-window))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
473 (let ((end-row (cdr (cdr (mouse-position)))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
474 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
475 ((and end-row (not (bobp)) (< end-row top))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
476 (mouse-scroll-subr orig-window (- end-row top)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
477 overlay max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
478 ((and end-row (not (eobp)) (>= end-row bottom))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
479 (mouse-scroll-subr orig-window (1+ (- end-row bottom))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
480 overlay min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
481 )))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
482
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
483 ;; On the mode line
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
484 ((eq (posn-point end) 'mode-line)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
485 (mouse-scroll-subr orig-window 1 overlay min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
486
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
487 ;; In original window
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
488 (t (goto-char (posn-point end)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
489
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
490 )
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
491
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
492 ;; Determine direction of drag
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
493 (cond
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
494 ((and (not direction) (not (eq min max)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
495 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
496 ((and (not (eq direction -1)) (<= (point) min))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
497 (setq direction -1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
498 ((and (not (eq direction 1)) (>= (point) max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
499 (setq direction 1)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
500
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
501 (if (not selection-thing) nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
502
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
503 ;; If dragging forward, goal is next character
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
504 (if (and (eq direction 1) (not (eobp))) (forward-char 1))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
505
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
506 ;; Move to start/end of selected thing
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
507 (let ((goal (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
508 last)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
509 (goto-char (if (eq 1 direction) min max))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
510 (condition-case nil
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
511 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
512 (while (> (* direction (- goal (point))) 0)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
513 (setq last (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
514 (forward-thing selection-thing direction))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
515 (let ((end (point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
516 (forward-thing selection-thing (- direction))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
517 (goto-char
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
518 (if (> (* direction (- goal (point))) 0)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
519 end last))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
520 (error))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
521
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
522 ;; Move overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
523 (move-overlay overlay
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
524 (if (eq 1 direction) min (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
525 (if (eq -1 direction) max (point))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
526 (current-buffer))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
527
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
528 ))) ; end track-mouse
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
530 ;; Finish up after dragging
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
531 (let ((overlay-start (overlay-start overlay))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
532 (overlay-end (overlay-end overlay)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
533
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
534 ;; Set selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
535 (if (not (eq overlay-start overlay-end))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
536 (mouse-sel-set-selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
537 selection
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
538 (buffer-substring overlay-start overlay-end)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
539
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
540 ;; Handle copy/kill
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
541 (let (this-command)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (cond
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
543 ((eq (event-basic-type last-input-event) 'mouse-2)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
544 (copy-region-as-kill overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
545 (read-event) (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
546 ((and (memq (event-basic-type last-input-event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
547 '(mouse-1 mouse-3))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
548 (memq 'down (event-modifiers last-input-event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
549 (kill-region overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
550 (move-overlay overlay overlay-start overlay-start)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
551 (read-event) (read-event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
552 ((and (eq (event-basic-type last-input-event) 'mouse-3)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
553 (memq 'double (event-modifiers last-input-event)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
554 (kill-region overlay-start overlay-end)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
555 (move-overlay overlay overlay-start overlay-start)))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
557 direction)
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
559 ;; Restore cursor
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
560 (if (fboundp 'modify-frame-parameters)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
561 (modify-frame-parameters
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
562 (selected-frame) (list (cons 'cursor-type orig-cursor-type))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
563
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
564 ))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
566 ;;=== Paste ===============================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
568 (defun mouse-insert-selection (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
569 "Insert the contents of the PRIMARY selection at mouse click.
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
570 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
571 (interactive "e")
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
572 (mouse-insert-selection-internal 'PRIMARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
573
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
574 (defun mouse-insert-secondary (event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
575 "Insert the contents of the SECONDARY selection at mouse click.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
576 If `mouse-yank-at-point' is non-nil, insert at point instead."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
577 (interactive "e")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
578 (mouse-insert-selection-internal 'SECONDARY event))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
579
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
580 (defun mouse-insert-selection-internal (selection event)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
581 "Insert the contents of the named SELECTION at mouse click.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
582 If `mouse-yank-at-point' is non-nil, insert at point instead."
7644
d50f6828a89d (mouse-insert-selection): Test mouse-yank-at-point.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
583 (or mouse-yank-at-point
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
584 (mouse-set-point event))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (if mouse-sel-get-selection-function
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
586 (progn
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
587 (push-mark (point) 'nomsg)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
588 (insert (or (funcall mouse-sel-get-selection-function selection) "")))))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
589
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
590 ;;=== Validate selection ==================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (defun mouse-sel-validate-selection ()
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
593 "Validate selections in mouse-sel-selection-alist.
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
594 For each listed selection, remove the selection overlay if Emacs no longer
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
595 owns the selection."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
596 (let ((owner-p-function mouse-sel-selection-owner-p-function)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
597 (alist mouse-sel-selection-alist)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
598 selection overlay)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
599 (if owner-p-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
600 (while alist
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
601 (setq selection (car (car alist))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
602 overlay (symbol-value (nth 1 (car alist)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
603 alist (cdr alist))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
604 (or (funcall owner-p-function selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
605 (delete-overlay overlay))))))
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (add-hook 'pre-command-hook 'mouse-sel-validate-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 ;;=== Key bindings ========================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (if (not mouse-sel-default-bindings) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (global-unset-key [mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (global-unset-key [drag-mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (global-unset-key [mouse-3])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 (global-set-key [down-mouse-1] 'mouse-select)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (global-set-key [down-mouse-3] 'mouse-extend)
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
619
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
620 (global-unset-key [M-mouse-1])
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
621 (global-unset-key [M-drag-mouse-1])
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
622 (global-unset-key [M-mouse-3])
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
624 (global-set-key [M-down-mouse-1] 'mouse-select-secondary)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
625 (global-set-key [M-down-mouse-3] 'mouse-extend-secondary)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
626
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
629 (global-set-key [mouse-2] 'mouse-insert-selection)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
630
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (setq interprogram-cut-function nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 interprogram-paste-function nil))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
634 (global-set-key [M-mouse-2] 'mouse-insert-secondary)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
635
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 )
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
11490
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
638 ;;=== Bug reporting =======================================================
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
639
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
640 (defconst mouse-sel-maintainer-address "mikew@gopher.dosli.govt.nz")
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
641
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
642 (defun mouse-sel-submit-bug-report ()
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
643 "Submit a bug report on mouse-sel.el via mail."
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
644 (interactive)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
645 (require 'reporter)
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
646 (reporter-submit-bug-report
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
647 mouse-sel-maintainer-address
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
648 (concat "mouse-sel.el "
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
649 (or (condition-case nil mouse-sel-version (error))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
650 "(distributed with Emacs)"))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
651 (list 'transient-mark-mode
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
652 'delete-selection-mode
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
653 'mouse-sel-default-bindings
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
654 'mouse-sel-leave-point-near-mouse
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
655 'mouse-sel-cycle-clicks
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
656 'mouse-sel-selection-alist
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
657 'mouse-sel-set-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
658 'mouse-sel-get-selection-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
659 'mouse-sel-selection-owner-p-function
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
660 'mouse-yank-at-point)))
01f5b6e9c234 Downcase function parameters.
Richard M. Stallman <rms@gnu.org>
parents: 9427
diff changeset
661
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 ;; mouse-sel.el ends here.