comparison lisp/select.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 10a6fd9d8e9c
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; select.el --- lisp portion of standard selection support 1 ;;; select.el --- lisp portion of standard selection support
2 2
3 ;; Maintainer: FSF 3 ;; Maintainer: FSF
4 ;; Keywords: internal 4 ;; Keywords: internal
5 5
6 ;; Copyright (c) 1993, 1994 Free Software Foundation, Inc. 6 ;; Copyright (C) 1993, 1994, 2002, 2003, 2004,
7 ;; 2005 Free Software Foundation, Inc.
7 ;; Based partially on earlier release by Lucid. 8 ;; Based partially on earlier release by Lucid.
8 9
9 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
10 11
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 12 ;; GNU Emacs is free software; you can redistribute it and/or modify
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details. 20 ;; GNU General Public License for more details.
20 21
21 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02110-1301, USA.
25 26
26 ;;; Commentary: 27 ;;; Commentary:
27 28
28 ;;; Code: 29 ;;; Code:
29 30
33 "Return the value of an X Windows selection. 34 "Return the value of an X Windows selection.
34 The argument TYPE (default `PRIMARY') says which selection, 35 The argument TYPE (default `PRIMARY') says which selection,
35 and the argument DATA-TYPE (default `STRING') says 36 and the argument DATA-TYPE (default `STRING') says
36 how to convert the data. 37 how to convert the data.
37 38
38 TYPE may be `SECONDARY' or `CLIPBOARD', in addition to `PRIMARY'. 39 TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
40 only a few symbols are commonly used. They conventionally have
41 all upper-case names. The most often used ones, in addition to
42 `PRIMARY', are `SECONDARY' and `CLIPBOARD'.
43
39 DATA-TYPE is usually `STRING', but can also be one of the symbols 44 DATA-TYPE is usually `STRING', but can also be one of the symbols
40 in `selection-converter-alist', which see." 45 in `selection-converter-alist', which see."
41 (x-get-selection-internal (or type 'PRIMARY) (or data-type 'STRING))) 46 (let ((data (x-get-selection-internal (or type 'PRIMARY)
47 (or data-type 'STRING)))
48 coding)
49 (when (and (stringp data)
50 (setq data-type (get-text-property 0 'foreign-selection data)))
51 (setq coding (if (eq data-type 'UTF8_STRING)
52 'utf-8
53 (or next-selection-coding-system
54 selection-coding-system))
55 data (decode-coding-string data coding))
56 (put-text-property 0 (length data) 'foreign-selection data-type data))
57 data))
42 58
43 (defun x-get-clipboard () 59 (defun x-get-clipboard ()
44 "Return text pasted to the clipboard." 60 "Return text pasted to the clipboard."
45 (x-get-selection-internal 'CLIPBOARD 'STRING)) 61 (x-get-selection-internal 'CLIPBOARD 'STRING))
46 62
47 (defun x-set-selection (type data) 63 (defun x-set-selection (type data)
48 "Make an X Windows selection of type TYPE and value DATA. 64 "Make an X Windows selection of type TYPE and value DATA.
49 The argument TYPE (default `PRIMARY') says which selection, 65 The argument TYPE (nil means `PRIMARY') says which selection, and
50 and DATA specifies the contents. DATA may be a string, 66 DATA specifies the contents. TYPE must be a symbol. \(It can also
51 a symbol, an integer (or a cons of two integers or list of two integers). 67 be a string, which stands for the symbol with that name, but this
68 is considered obsolete.) DATA may be a string, a symbol, an
69 integer (or a cons of two integers or list of two integers).
52 70
53 The selection may also be a cons of two markers pointing to the same buffer, 71 The selection may also be a cons of two markers pointing to the same buffer,
54 or an overlay. In these cases, the selection is considered to be the text 72 or an overlay. In these cases, the selection is considered to be the text
55 between the markers *at whatever time the selection is examined*. 73 between the markers *at whatever time the selection is examined*.
56 Thus, editing done in the buffer after you specify the selection 74 Thus, editing done in the buffer after you specify the selection
57 can alter the effective value of the selection. 75 can alter the effective value of the selection.
58 76
59 The data may also be a vector of valid non-vector selection values. 77 The data may also be a vector of valid non-vector selection values.
60 78
61 Interactively, the text of the region is used as the selection value 79 The return value is DATA.
62 if the prefix arg is set." 80
81 Interactively, this command sets the primary selection. Without
82 prefix argument, it reads the selection in the minibuffer. With
83 prefix argument, it uses the text of the region as the selection value ."
63 (interactive (if (not current-prefix-arg) 84 (interactive (if (not current-prefix-arg)
64 (list 'PRIMARY (read-string "Set text for pasting: ")) 85 (list 'PRIMARY (read-string "Set text for pasting: "))
65 (list 'PRIMARY (buffer-substring (region-beginning) (region-end))))) 86 (list 'PRIMARY (buffer-substring (region-beginning) (region-end)))))
66 ;; This is for temporary compatibility with pre-release Emacs 19. 87 ;; This is for temporary compatibility with pre-release Emacs 19.
67 (if (stringp type) 88 (if (stringp type)
163 str 184 str
164 (setq coding (or next-selection-coding-system selection-coding-system)) 185 (setq coding (or next-selection-coding-system selection-coding-system))
165 (if coding 186 (if coding
166 (setq coding (coding-system-base coding)) 187 (setq coding (coding-system-base coding))
167 (setq coding 'raw-text)) 188 (setq coding 'raw-text))
168 ;; Suppress producing escape sequences for compositions. 189 (let ((inhibit-read-only t))
169 (remove-text-properties 0 (length str) '(composition nil) str) 190 ;; Suppress producing escape sequences for compositions.
170 (cond 191 (remove-text-properties 0 (length str) '(composition nil) str)
171 ((eq type 'TEXT) 192 (cond
172 (if (not (multibyte-string-p str)) 193 ((eq type 'TEXT)
173 ;; Don't have to encode unibyte string. 194 (if (not (multibyte-string-p str))
174 (setq type 'STRING) 195 ;; Don't have to encode unibyte string.
175 ;; If STR contains only ASCII, Latin-1, and raw bytes, 196 (setq type 'STRING)
176 ;; encode STR by iso-latin-1, and return it as type 197 ;; If STR contains only ASCII, Latin-1, and raw bytes,
177 ;; `STRING'. Otherwise, encode STR by CODING. In that 198 ;; encode STR by iso-latin-1, and return it as type
178 ;; case, the returing type depends on CODING. 199 ;; `STRING'. Otherwise, encode STR by CODING. In that
179 (let ((charsets (find-charset-string str))) 200 ;; case, the returing type depends on CODING.
180 (setq charsets 201 (let ((charsets (find-charset-string str)))
181 (delq 'ascii 202 (setq charsets
182 (delq 'latin-iso8859-1 203 (delq 'ascii
183 (delq 'eight-bit-control 204 (delq 'latin-iso8859-1
184 (delq 'eight-bit-graphic charsets))))) 205 (delq 'eight-bit-control
185 (if charsets 206 (delq 'eight-bit-graphic charsets)))))
186 (setq str (encode-coding-string str coding) 207 (if charsets
187 type (if (memq coding '(compound-text 208 (setq str (encode-coding-string str coding)
188 compound-text-with-extensions)) 209 type (if (memq coding '(compound-text
189 'COMPOUND_TEXT 210 compound-text-with-extensions))
190 'STRING)) 211 'COMPOUND_TEXT
191 (setq type 'STRING 212 'STRING))
192 str (encode-coding-string str 'iso-latin-1)))))) 213 (setq type 'STRING
193 214 str (encode-coding-string str 'iso-latin-1))))))
194 ((eq type 'COMPOUND_TEXT) 215
195 (setq str (encode-coding-string str coding))) 216 ((eq type 'COMPOUND_TEXT)
196 217 (setq str (encode-coding-string str coding)))
197 ((eq type 'STRING) 218
198 (if (memq coding '(compound-text 219 ((eq type 'STRING)
199 compound-text-with-extensions)) 220 (if (memq coding '(compound-text
200 (setq str (string-make-unibyte str)) 221 compound-text-with-extensions))
201 (setq str (encode-coding-string str coding)))) 222 (setq str (string-make-unibyte str))
202 223 (setq str (encode-coding-string str coding))))
203 ((eq type 'UTF8_STRING) 224
204 (setq str (encode-coding-string str 'utf-8))) 225 ((eq type 'UTF8_STRING)
205 226 (setq str (encode-coding-string str 'utf-8)))
206 (t 227
207 (error "Unknow selection type: %S" type)) 228 (t
208 )) 229 (error "Unknow selection type: %S" type))
230 )))
209 231
210 (setq next-selection-coding-system nil) 232 (setq next-selection-coding-system nil)
211 (cons type str)))) 233 (cons type str))))
212 234
213 235
376 (_EMACS_INTERNAL . xselect-convert-to-identity) 398 (_EMACS_INTERNAL . xselect-convert-to-identity)
377 )) 399 ))
378 400
379 (provide 'select) 401 (provide 'select)
380 402
403 ;;; arch-tag: bb634f97-8a3b-4b0a-b940-f6e09982328c
381 ;;; select.el ends here 404 ;;; select.el ends here