annotate lisp/mouse-sel.el @ 5494:1ea2b4351945

[MSDOS]: #include "msdos.h" and <sys/param.h> needed for the following changes. (Ffile_name_directory, Fexpand_file_name) [FILE_SYSTEM_CASE]: Apply case conversion if defined. (Ffile_name_directory, Ffile_name_nondirectory, file_name_as_directory, directory_file_name, Fexpand_file_name, Fsubstitute_in_file_name, expand_and_dir_to_file) [MSDOS]: Drive letter support. (Fexpand_file_name) [MSDOS]: Support for multiple default directories. (Ffile_writeable_p) [MSDOS]: Don't call access with file name ending in slash. (Finsert_file_contents) [MSDOS]: Determine file type by name (call find-buffer-file-type) and change CR+LF to LF if it is a text file. (Fwrite_region) [MSDOS]: Use text/binary mode as specified by buffer_file_type. (syms_of_fileio) [MSDOS]: Set Qfind_buffer_file_type. (Fsubstitute_in_file_name) [MSDOS]: Ignore case in environtment variable.
author Richard M. Stallman <rms@gnu.org>
date Sat, 08 Jan 1994 09:15:49 +0000
parents a8b355b89859
children e1153522d5f1
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
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 ;; Version: $Revision: 1.20 $
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;;; Commentary:
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 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; * Clicking mouse-2 pastes contents of primary selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; * Pressing mouse-2 while selecting or extending copies selected text
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; to the kill ring. Pressing mouse-1 or mouse-3 kills it.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; This module requires my thingatpt.el module, version 1.14 or later, which
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; it uses to find the bounds of words, lines, sexps, etc.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; You may also want to use one or more of following:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; ;; Enable region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; (transient-mark-mode 1)
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 ;; ;; But only in the selected window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; (setq highlight-nonselected-windows nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; ;; Enable pending-delete
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; (delete-selection-mode 1)
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 ;;--- Customisation -------------------------------------------------------
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 ;; * 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
67 ;; of mouse-sel-default-bindings before loading mouse-sel.
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 ;; (a) If mouse-sel-default-bindings = t (the default)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; Mouse sets and pastes selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; mouse-2 mouse-insert-selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; mouse-3 mouse-extend
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 ;; Selection/kill-ring interaction is disabled
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; interprogram-cut-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; interprogram-paste-function = nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; Mouse sets selection, and pastes from kill-ring
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; mouse-1 mouse-select
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; mouse-2 mouse-yank-at-click
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; mouse-3 mouse-extend
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; Selection/kill-ring interaction is retained
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; interprogram-cut-function = x-select-text
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; interprogram-paste-function = x-cut-buffer-or-selection-value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; What you lose is the ability to select some text in
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; delete-selection-mode and yank over the top of it.
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 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; * 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
97 ;; mouse was, even though this makes region highlighting mis-leading (the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; cursor makes it look like one extra character is selected). You can
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; disable this behaviour with:
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 ;; (setq mouse-sel-leave-point-near-mouse nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; * Normally, the selection highlight will be removed when the mouse is
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; lifted. You can tell mouse-sel to retain the selection highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; (useful if you don't use transient-mark-mode) with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;; (setq mouse-sel-retain-highlight t)
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 ;; * By default, mouse-select cycles the click count after 3 clicks. That
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; 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
111 ;; once, clicking five times has the same effect as clicking twice, etc.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; Disable this behaviour with:
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; (setq mouse-sel-cycle-clicks nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;; * The variables mouse-sel-{set,get,check}-selection-function control how
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; the selection is handled. Under X Windows, these variables default so
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; that the X primary selection is used. Under other windowing systems,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; alternate functions are used, which simply store the selection value
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; in a variable.
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 ;;--- Hints ---------------------------------------------------------------
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 ;; * You can change the selection highlight face by altering the properties
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; of mouse-drag-overlay, eg.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; (overlay-put mouse-drag-overlay 'face 'bold)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; * 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
130 ;; 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
131 ;; the cut buffer rather than the primary selection. However, be aware
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; that cut buffers are OBSOLETE, and some X applications may not support
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; them.
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 ;; (setq mouse-sel-set-selection-function 'x-select-text
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; mouse-sel-get-selection-function 'x-get-cut-buffer)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;;--- Warnings ------------------------------------------------------------
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; * When selecting sexps, the selection extends by sexps at the same
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;; nesting level. This also means the selection cannot be extended out
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;; of the enclosing nesting level. This is INTENTIONAL.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;;; Code:
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 (provide 'mouse-sel)
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 (require 'mouse)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (require 'thingatpt)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;;=== Version =============================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (defconst mouse-sel-version (substring "$Revision: 1.20 $" 11 -2)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 "The revision number of mouse-sel (as string). The complete RCS id is:
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 $Id: mouse-sel.el,v 1.20 1993/09/30 23:57:32 mike Exp $")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;;=== User Variables ======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defvar mouse-sel-leave-point-near-mouse t
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 "*Leave point near last mouse position.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 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
163 of the region nearest to where the mouse last was.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 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
165
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (defvar mouse-sel-retain-highlight nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 "*Retain highlight on mouse-drag-overlay.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 If non-nil, regions selected using \\[mouse-select] and \\[mouse-extend] will
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 remain highlighted.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 If nil, highlighting will be turned off when the mouse is lifted.")
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-cycle-clicks t
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 "*If non-nil, \\[mouse-select] cycles the click-counts after 3 clicks.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 Ie. 4 clicks = 1 click, 5 clicks = 2 clicks, etc.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (defvar mouse-sel-default-bindings t
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 "Set to nil before loading mouse-sel to prevent default mouse bindings.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;;=== Selection ===========================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (defvar mouse-sel-selection-type nil "Type of current selection")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (make-variable-buffer-local 'mouse-sel-selection-type)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (defvar mouse-sel-selection ""
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 "This variable is used to store the selection value when mouse-sel is
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 used on windowing systems other than X Windows.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defvar mouse-sel-set-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (if (eq window-system 'x)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (function (lambda (s) (x-set-selection 'PRIMARY s)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (function (lambda (s) (setq mouse-sel-selection s))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 "Function to call to set selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 Called with one argument, the text to select.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (defvar mouse-sel-get-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (if (eq window-system 'x)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 'x-get-selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (function (lambda () mouse-sel-selection)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 "Function to call to get the selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 Called with no argument, it should return the selected text.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (defvar mouse-sel-check-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (if (eq window-system 'x)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 'x-selection-owner-p
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 "Function to check whether emacs still owns the selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 Called with no arguments.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (defun mouse-sel-determine-selection-type (NCLICKS)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 "Determine what `thing' \\[mouse-select] and \\[mouse-extend] should
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 select by. The first argument is NCLICKS, is the number of consecutive
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 mouse clicks at the same position."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (let* ((next-char (char-after (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (char-syntax (if next-char (char-syntax next-char)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (nclicks (if mouse-sel-cycle-clicks (1+ (% (1- NCLICKS) 3)) NCLICKS)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ((= nclicks 1) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ((>= nclicks 3) 'line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ((memq char-syntax '(?\( ?\) ?\" ?')) 'sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ((memq next-char '(? ?\t ?\n)) 'whitespace)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ((eq char-syntax ?_) 'symbol)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ((eq char-syntax ?w) 'word))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (defun mouse-select (EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 "Set region/selection using the mouse.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 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
228 Dragging extends region/selection.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 Double-clicking on word constituents selects words.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 Double-clicking on symbol constituents selects symbols.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 Double-clicking on quotes or parentheses selects sexps.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 Double-clicking on whitespace selects whitespace.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 Triple-clicking selects lines.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 Clicking mouse-2 while selecting copies the region to the kill-ring.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 Clicking mouse-1 or mouse-3 kills the region.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 This should be bound to a down-mouse event."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (mouse-set-point EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (setq mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (mouse-sel-determine-selection-type (event-click-count EVENT)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (let ((object-bounds (bounds-of-thing-at-point mouse-sel-selection-type)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (if object-bounds
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (setq mark-active t)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (goto-char (car object-bounds))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (set-mark (cdr object-bounds)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (deactivate-mark)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (mouse-extend))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (defun mouse-extend (&optional EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "Extend region/selection using the mouse.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 See documentation for mouse-select for more details.
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 This should be bound to a down-mouse event."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (if EVENT (select-window (posn-window (event-end EVENT))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (let* ((min (if mark-active (region-beginning) (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (max (if mark-active (region-end) (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (orig-window (selected-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (orig-window-frame (window-frame orig-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (top (nth 1 (window-edges orig-window)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (bottom (nth 3 (window-edges orig-window)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (orig-cursor-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (cdr (assoc 'cursor-type (frame-parameters (selected-frame)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 direction
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 event)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ;; Inhibit normal region highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (setq mark-active nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 ;; Highlight region (forcing re-highlight)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (move-overlay mouse-drag-overlay min max (current-buffer))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (overlay-put mouse-drag-overlay 'face
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (overlay-get mouse-drag-overlay 'face))
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 ;; Bar cursor
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (modify-frame-parameters (selected-frame) '((cursor-type . bar)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 ;; Handle dragging
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (unwind-protect
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (track-mouse
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (while (if EVENT ; Use initial event
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (prog1
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (setq event EVENT)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (setq EVENT nil))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (setq event (read-event))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (and (consp event)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (memq (car event) '(mouse-movement switch-frame))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (let ((end (event-end event)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 ;; Ignore any movement outside the frame
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 ((eq (car-safe event) 'switch-frame) nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ((and (posn-window end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (not (eq (window-frame (posn-window end))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (window-frame orig-window)))) nil)
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 ;; Different window, same frame
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ((not (eq (posn-window end) orig-window))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (let ((end-row (cdr (cdr (mouse-position)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ((and end-row (not (bobp)) (< end-row top))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (mouse-scroll-subr (- end-row top)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 mouse-drag-overlay max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ((and end-row (not (eobp)) (>= end-row bottom))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (mouse-scroll-subr (1+ (- end-row bottom))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 mouse-drag-overlay min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 )))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ;; On the mode line
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ((eq (posn-point end) 'mode-line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (mouse-scroll-subr 1 mouse-drag-overlay min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ;; In original window
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (t (goto-char (posn-point end)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
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 ;; Determine direction of drag
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 ((and (not direction) (not (eq min max)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (setq direction (if (< (point) (/ (+ min max) 2)) -1 1)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ((and (not (eq direction -1)) (<= (point) min))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (setq direction -1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ((and (not (eq direction 1)) (>= (point) max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (setq direction 1)))
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 (if (not mouse-sel-selection-type) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 ;; If dragging forward, goal is next character
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (if (and (eq direction 1) (not (eobp))) (forward-char 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 ;; Move to start/end of selected thing
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (let ((goal (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 last)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (goto-char (if (eq 1 direction) min max))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (while (> (* direction (- goal (point))) 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (setq last (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (forward-thing mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 direction))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (let ((end (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (forward-thing mouse-sel-selection-type
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (- direction))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (goto-char
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (if (> (* direction (- goal (point))) 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 end last))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (error))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 ;; Move overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (move-overlay mouse-drag-overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (if (eq 1 direction) min (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (if (eq -1 direction) max (point))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (current-buffer))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 ))) ; end track-mouse
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 (let ((overlay-start (overlay-start mouse-drag-overlay))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (overlay-end (overlay-end mouse-drag-overlay)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 ;; Set region
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (if (eq overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (if (and mouse-sel-leave-point-near-mouse (eq direction 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (set-mark overlay-start)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (goto-char overlay-end))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (set-mark overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (goto-char overlay-start)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 ;; Set selection
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (if (and mark-active mouse-sel-set-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (funcall mouse-sel-set-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (buffer-substring overlay-start overlay-end)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 ;; Handle copy/kill
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (cond
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 ((eq (car-safe last-input-event) 'down-mouse-2)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (copy-region-as-kill overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (read-event) (read-event))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 ((memq (car-safe last-input-event) '(down-mouse-1 down-mouse-3))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (kill-region overlay-start overlay-end)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (read-event) (read-event)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 ;; Restore cursor
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (modify-frame-parameters (selected-frame)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (list (cons 'cursor-type orig-cursor-type)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 ;; Remove overlay
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (or mouse-sel-retain-highlight
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (delete-overlay mouse-drag-overlay)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (defun mouse-insert-selection (click)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 "Insert the contents of the selection at mouse click."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (interactive "e")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (mouse-set-point click)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (deactivate-mark)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (if mouse-sel-get-selection-function
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (insert (or (funcall mouse-sel-get-selection-function) ""))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (defun mouse-sel-validate-selection ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 "Remove selection highlight if emacs no longer owns the primary selection."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (or (not mouse-sel-check-selection-function)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (funcall mouse-sel-check-selection-function)
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 (add-hook 'pre-command-hook 'mouse-sel-validate-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 ;;=== Key bindings ========================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (if (not mouse-sel-default-bindings) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (global-unset-key [mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (global-unset-key [drag-mouse-1])
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (global-unset-key [mouse-3])
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 (global-set-key [down-mouse-1] 'mouse-select)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (global-set-key [down-mouse-3] 'mouse-extend)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste) nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (global-set-key [mouse-2] 'mouse-insert-selection)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (setq interprogram-cut-function nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 interprogram-paste-function nil))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434
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
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 ;; mouse-sel.el ends here.