annotate lisp/emacs-lisp/lselect.el @ 68192:2cfa649fa39d

* mh-customize.el (mh-index): Rename group to mh-search and sort group definition and options accordingly. (mh-index-program): Rename to mh-search-program. (mh-kill-folder-suppress-prompt-hooks): Rename mh-index-p to mh-search-p. (mh-search-mode-hook): Change group from mh-index to mh-search. (mh-index-folder): Rename to mh-search-folder. Change group from mh-index to mh-search. * mh-e.el (mh-folder-font-lock-keywords): Rename mh-index-folder to mh-search-folder. * mh-search.el (mh-indexer) Rename to mh-searcher. The commands pick and grep are searchers too but aren't indexed. (mh-index-execute-search-function): Rename to mh-search-function. (mh-index-next-result-function): Rename to mh-search-next-result-function. (mh-index-regexp-builder): Rename to mh-search-regexp-builder. (mh-search): Since redo-search-flag defaults to nil and is of lesser importance, make it an optional argument and place it after the folder and search-regexp arguments. Sync docstring with manual. (mh-search-mode-map): Autoload so that keys are shown in help even before mh-search is loaded. (mh-search-mode): Sync docstring with manual. (mh-index-do-search): Rename argument indexer to searcher. Sync docstring with manual. (mh-pick-do-search): Sync docstring with manual. (mh-index-p): Rename to mh-search-p. (mh-indexer-choices): Rename to mh-search-choices. (mh-index-choose): Rename to mh-search-choose. Rename argument indexer to searcher. (mh-swish++-execute-search, mh-swish-execute-search) (mh-mairix-execute-search, mh-namazu-execute-search): Drop "and read the results" from docstring since these functions don't. (mh-pick-execute-search, mh-grep-execute-search): Sync docstring with manual. (mh-index-generate-pretty-name): Prune -search from string so that folder names for pick searches are the same as those of other searches.
author Bill Wohler <wohler@newt.com>
date Sat, 14 Jan 2006 21:17:37 +0000
parents 5d442c673b6b
children 067115a6e738 a3716f7538f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1 ;;; lselect.el --- Lucid interface to X Selections
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
3 ;; Copyright (C) 1990, 1993, 2002, 2003, 2004,
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
4 ;; 2005 Free Software Foundation, Inc.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
5
38961
5b23575286e6 Add the Maintainer keyword. From Pavel Janik.
Eli Zaretskii <eliz@gnu.org>
parents: 38414
diff changeset
6 ;; Maintainer: FSF
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
7 ;; Keywords: emulations
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
8
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
9 ;; This won't completely work until we support or emulate Lucid-style extents.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
10 ;; Based on Lucid's selection code.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
11
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; This file is part of GNU Emacs.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
13
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15 ;; it under the terms of the GNU General Public License as published by
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; any later version.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
18
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; GNU Emacs is distributed in the hope that it will be useful,
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; GNU General Public License for more details.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
23
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 57779
diff changeset
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 57779
diff changeset
27 ;; Boston, MA 02110-1301, USA.
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
29 ;;; Commentary:
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
30
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31 ;;; Code:
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
32
39565
e03e925846db Use facep iso find-face.
Gerd Moellmann <gerd@gnu.org>
parents: 38961
diff changeset
33 ;; The selection code requires us to use certain symbols whose names are
e03e925846db Use facep iso find-face.
Gerd Moellmann <gerd@gnu.org>
parents: 38961
diff changeset
34 ;; all upper-case; this may seem tasteless, but it makes there be a 1:1
e03e925846db Use facep iso find-face.
Gerd Moellmann <gerd@gnu.org>
parents: 38961
diff changeset
35 ;; correspondence between these symbols and X Atoms (which are upcased.)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
36
65192
5d442c673b6b (mouse-highlight-priority, x-lost-selection-functions, zmacs-regions):
Juanma Barranquero <lekktu@gmail.com>
parents: 64751
diff changeset
37 ;; This is Lucid/XEmacs stuff
5d442c673b6b (mouse-highlight-priority, x-lost-selection-functions, zmacs-regions):
Juanma Barranquero <lekktu@gmail.com>
parents: 64751
diff changeset
38 (defvar mouse-highlight-priority)
5d442c673b6b (mouse-highlight-priority, x-lost-selection-functions, zmacs-regions):
Juanma Barranquero <lekktu@gmail.com>
parents: 64751
diff changeset
39 (defvar x-lost-selection-functions)
5d442c673b6b (mouse-highlight-priority, x-lost-selection-functions, zmacs-regions):
Juanma Barranquero <lekktu@gmail.com>
parents: 64751
diff changeset
40 (defvar zmacs-regions)
5d442c673b6b (mouse-highlight-priority, x-lost-selection-functions, zmacs-regions):
Juanma Barranquero <lekktu@gmail.com>
parents: 64751
diff changeset
41
2571
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2234
diff changeset
42 (defalias 'x-get-cutbuffer 'x-get-cut-buffer)
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2234
diff changeset
43 (defalias 'x-store-cutbuffer 'x-set-cut-buffer)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
44
39565
e03e925846db Use facep iso find-face.
Gerd Moellmann <gerd@gnu.org>
parents: 38961
diff changeset
45 (or (facep 'primary-selection)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
46 (make-face 'primary-selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
47
39565
e03e925846db Use facep iso find-face.
Gerd Moellmann <gerd@gnu.org>
parents: 38961
diff changeset
48 (or (facep 'secondary-selection)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49 (make-face 'secondary-selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
50
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51 (defun x-get-secondary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52 "Return text selected from some X window."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53 (x-get-selection-internal 'SECONDARY 'STRING))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
55 (defvar primary-selection-extent nil
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
56 "The extent of the primary selection; don't use this.")
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
57
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
58 (defvar secondary-selection-extent nil
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
59 "The extent of the secondary selection; don't use this.")
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
60
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
61
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
62 (defun x-select-make-extent-for-selection (selection previous-extent face)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
63 ;; Given a selection, this makes an extent in the buffer which holds that
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
64 ;; selection, for highlighting purposes. If the selection isn't associated
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
65 ;; with a buffer, this does nothing.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
66 (let ((buffer nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
67 (valid (and (extentp previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
68 (extent-buffer previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
69 (buffer-name (extent-buffer previous-extent))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
70 start end)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
71 (cond ((stringp selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
72 ;; if we're selecting a string, lose the previous extent used
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
73 ;; to highlight the selection.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
74 (setq valid nil))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
75 ((consp selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
76 (setq start (min (car selection) (cdr selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 end (max (car selection) (cdr selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 valid (and valid
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 (eq (marker-buffer (car selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 (extent-buffer previous-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81 buffer (marker-buffer (car selection))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 ((extentp selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83 (setq start (extent-start-position selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 end (extent-end-position selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 valid (and valid
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 (eq (extent-buffer selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 (extent-buffer previous-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
88 buffer (extent-buffer selection)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 )
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
90 (if (and (not valid)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
91 (extentp previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
92 (extent-buffer previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
93 (buffer-name (extent-buffer previous-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
94 (delete-extent previous-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
95 (if (not buffer)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
96 ;; string case
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 nil
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
98 ;; normal case
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
99 (if valid
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
100 (set-extent-endpoints previous-extent start end)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
101 (setq previous-extent (make-extent start end buffer))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
102 ;; use same priority as mouse-highlighting so that conflicts between
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
103 ;; the selection extent and a mouse-highlighted extent are resolved
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
104 ;; by the usual size-and-endpoint-comparison method.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
105 (set-extent-priority previous-extent mouse-highlight-priority)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
106 (set-extent-face previous-extent face)))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
107
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
108
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
109 (defun x-own-selection (selection &optional type)
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
110 "Make a primary X Selection of the given argument.
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
111 The argument may be a string, a cons of two markers, or an extent.
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
112 In the latter cases the selection is considered to be the text
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
113 between the markers, or the between extents endpoints."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
114 (interactive (if (not current-prefix-arg)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
115 (list (read-string "Store text for pasting: "))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
116 (list (cons ;; these need not be ordered.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
117 (copy-marker (point-marker))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 (copy-marker (mark-marker))))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
119 (or type (setq type 'PRIMARY))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 (x-set-selection selection type)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
121 (cond ((eq type 'PRIMARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122 (setq primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 (x-select-make-extent-for-selection
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 selection primary-selection-extent 'primary-selection)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 ((eq type 'SECONDARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126 (setq secondary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127 (x-select-make-extent-for-selection
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
128 selection secondary-selection-extent 'secondary-selection))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129 selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 (defun x-own-secondary-selection (selection &optional type)
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
133 "Make a secondary X Selection of the given argument. The argument may be a
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
134 string or a cons of two markers (in which case the selection is considered to
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
135 be the text between those markers.)"
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
136 (interactive (if (not current-prefix-arg)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
137 (list (read-string "Store text for pasting: "))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
138 (list (cons ;; these need not be ordered.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
139 (copy-marker (point-marker))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140 (copy-marker (mark-marker))))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 (x-own-selection selection 'SECONDARY))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
142
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
143
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
144 (defun x-own-clipboard (string)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
145 "Paste the given string to the X Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
146 (x-own-selection string 'CLIPBOARD))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
147
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
148
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
149 (defun x-disown-selection (&optional secondary-p)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
150 "Assuming we own the selection, disown it. With an argument, discard the
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
151 secondary selection instead of the primary selection."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 (x-disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154 (defun x-dehilight-selection (selection)
57779
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
155 "for use as a value of `x-lost-selection-functions'."
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
156 (cond ((eq selection 'PRIMARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157 (if primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 (let ((inhibit-quit t))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
159 (delete-extent primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
160 (setq primary-selection-extent nil)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161 (if zmacs-regions (zmacs-deactivate-region)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
162 ((eq selection 'SECONDARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
163 (if secondary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
164 (let ((inhibit-quit t))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
165 (delete-extent secondary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166 (setq secondary-selection-extent nil)))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167 nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
168
57779
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
169 (setq x-lost-selection-functions 'x-dehilight-selection)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
170
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 (defun x-notice-selection-requests (selection type successful)
57779
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
172 "for possible use as the value of `x-sent-selection-functions'."
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 (if (not successful)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
174 (message "Selection request failed to convert %s to %s"
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
175 selection type)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
176 (message "Sent selection %s as %s" selection type)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
177
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
178 (defun x-notice-selection-failures (selection type successful)
57779
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
179 "for possible use as the value of `x-sent-selection-functions'."
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
180 (or successful
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
181 (message "Selection request failed to convert %s to %s"
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
182 selection type)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
183
57779
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
184 ;(setq x-sent-selection-functions 'x-notice-selection-requests)
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
185 ;(setq x-sent-selection-functions 'x-notice-selection-failures)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
186
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
187
39565
e03e925846db Use facep iso find-face.
Gerd Moellmann <gerd@gnu.org>
parents: 38961
diff changeset
188 ;; Random utility functions
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
190 (defun x-kill-primary-selection ()
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
191 "If there is a selection, delete the text it covers, and copy it to
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
192 both the kill ring and the Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
193 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194 (or (x-selection-owner-p) (error "emacs does not own the primary selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
195 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196 (or primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 (error "the primary selection is not an extent?"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
198 (save-excursion
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
199 (set-buffer (extent-buffer primary-selection-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
200 (kill-region (extent-start-position primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201 (extent-end-position primary-selection-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
202 (x-disown-selection nil))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
203
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
204 (defun x-delete-primary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
205 "If there is a selection, delete the text it covers *without* copying it to
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
206 the kill ring or the Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
207 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
208 (or (x-selection-owner-p) (error "emacs does not own the primary selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
209 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
210 (or primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
211 (error "the primary selection is not an extent?"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
212 (save-excursion
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
213 (set-buffer (extent-buffer primary-selection-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
214 (delete-region (extent-start-position primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
215 (extent-end-position primary-selection-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
216 (x-disown-selection nil))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
217
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
218 (defun x-copy-primary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
219 "If there is a selection, copy it to both the kill ring and the Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
220 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
221 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
222 (or (x-selection-owner-p) (error "emacs does not own the primary selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
223 (or primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224 (error "the primary selection is not an extent?"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 (save-excursion
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226 (set-buffer (extent-buffer primary-selection-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
227 (copy-region-as-kill (extent-start-position primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
228 (extent-end-position primary-selection-extent))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
229
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
230 (defun x-yank-clipboard-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
231 "If someone owns a Clipboard selection, insert it at point."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
232 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
233 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
234 (let ((clip (x-get-clipboard)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
235 (or clip (error "there is no clipboard selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
236 (push-mark)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
237 (insert clip)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
238
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
239 (provide 'lselect)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
240
57779
d1c1c0fc40aa Adjust to new names for x-(lost|sent)-selection-functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
241 ;; arch-tag: 92fa54d4-c5d1-4e9b-ad58-cf1e13930556
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
242 ;;; lselect.el ends here