Mercurial > hg > xemacs-beta
annotate lisp/select.el @ 5368:ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
2011-03-10 Aidan Kehoe <kehoea@parhasard.net>
* cmdloop.el (yes-or-no-p):
* cmdloop.el (y-or-n-p):
* descr-text.el (describe-char):
* diagnose.el (show-memory-usage):
* diagnose.el (show-object-memory-usage-stats):
* diagnose.el (show-mc-alloc-memory-usage):
* diagnose.el (show-gc-stats):
* faces.el (face-font-instance):
* gtk-font-menu.el (gtk-reset-device-font-menus):
* help.el (help-symbol-function-context-menu):
* help.el (help-symbol-variable-context-menu):
* help.el (help-symbol-function-and-variable-context-menu):
* help.el (help-find-source-or-scroll-up):
* help.el (help-mouse-find-source-or-track):
* help.el (temp-buffer-resize-mode):
* minibuf.el (mouse-read-file-name-1):
* obsolete.el (find-non-ascii-charset-string):
* obsolete.el (find-non-ascii-charset-region):
* occur.el (occur-engine):
* paragraphs.el (forward-paragraph):
* paragraphs.el (forward-sentence):
* select.el (activate-region-as-selection):
* select.el (select-make-extent-for-selection):
* simple.el (zmacs-make-extent-for-region):
Use quote, not function, for quoting symbols that may not be
fboundp at the point they are read (again, a style issue, since
Common Lisp throws an error on this, but we don't, and have no
plans to.)
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 10 Mar 2011 18:51:15 +0000 |
parents | 0f9aa4eb4bec |
children | ac37a5f7e5be |
rev | line source |
---|---|
428 | 1 ;;; select.el --- Lisp interface to windows selections. |
2 | |
3 ;; Copyright (C) 1998 Andy Piper. | |
4 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc. | |
5 ;; Copyright (C) 1995 Sun Microsystems. | |
851 | 6 ;; Copyright (C) 2002 Ben Wing. |
428 | 7 |
8 ;; Maintainer: XEmacs Development Team | |
9 ;; Keywords: extensions, dumped | |
10 | |
11 ;; This file is part of XEmacs. | |
12 | |
13 ;; XEmacs is free software; you can redistribute it and/or modify it | |
14 ;; under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
18 ;; XEmacs is distributed in the hope that it will be useful, but | |
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 ;; General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
444 | 24 ;; along with XEmacs; see the file COPYING. If not, write to the |
428 | 25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
26 ;; Boston, MA 02111-1307, USA. | |
27 | |
28 ;;; Synched up with: Not in FSF | |
29 | |
30 ;;; Commentary: | |
31 | |
444 | 32 ;; This file is dumped with XEmacs |
428 | 33 |
34 ;;; Code: | |
35 | |
2624 | 36 ;; We prefer UTF8_STRING to COMPOUND_TEXT because, even though the latter |
37 ;; gives us more information when taking data from other XEmacs invocations, | |
38 ;; Mozilla will happily give us broken COMPOUND_TEXT where a non-broken | |
39 ;; UTF8_STRING is available. | |
40 (defvar selection-preferred-types | |
5364
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
41 `(UTF8_STRING ,@(and (featurep 'mule) '(COMPOUND_TEXT)) STRING |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
42 ,@(mapcan #'(lambda (format) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
43 (and (featurep format) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
44 (list (intern (format "image/%s" format))))) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
45 '(png gif jpeg tiff xpm xbm))) |
2624 | 46 "An ordered list of X11 type atoms for selections we want to receive. |
47 We prefer UTF8_STRING over COMPOUND_TEXT, for compatibility with a certain | |
48 widely-used browser suite, and COMPOUND_TEXT over STRING. (COMPOUND_TEXT | |
49 isn't available on non-Mule.) We also accept several image types. | |
50 | |
51 For compatibility, this can be a single atom. ") | |
52 | |
53 ;; Renamed because it was just ridiculous for it to be mostly image formats | |
54 ;; and named selected-text-type. | |
55 (define-obsolete-variable-alias 'selected-text-type 'selection-preferred-types) | |
428 | 56 |
444 | 57 (defvar selection-sets-clipboard nil |
428 | 58 "Controls the selection's relationship to the clipboard. |
59 When non-nil, any operation that sets the primary selection will also | |
60 set the clipboard.") | |
61 | |
62 (defun copy-primary-selection () | |
851 | 63 "Copy the selection to the Clipboard and the kill ring. |
64 This is similar to the command \\[kill-ring-save] except that it will | |
65 save to the Clipboard even if that command doesn't, and it handles rectangles | |
66 properly." | |
428 | 67 (interactive) |
68 (and (console-on-window-system-p) | |
69 (cut-copy-clear-internal 'copy))) | |
70 | |
71 (defun kill-primary-selection () | |
2624 | 72 "Copy the selection to the Clipboard and the kill ring, then delete it. |
851 | 73 This is similar to the command \\[kill-region] except that it will |
74 save to the Clipboard even if that command doesn't, and it handles rectangles | |
75 properly." | |
428 | 76 (interactive "*") |
77 (and (console-on-window-system-p) | |
78 (cut-copy-clear-internal 'cut))) | |
79 | |
80 (defun delete-primary-selection () | |
81 "Delete the selection without copying it to the Clipboard or the kill ring." | |
82 (interactive "*") | |
83 (and (console-on-window-system-p) | |
84 (cut-copy-clear-internal 'clear))) | |
85 | |
86 (defun yank-clipboard-selection () | |
87 "Insert the current Clipboard selection at point." | |
88 (interactive "*") | |
89 (when (console-on-window-system-p) | |
90 (setq last-command nil) | |
91 (setq this-command 'yank) ; so that yank-pop works. | |
92 (let ((clip (get-clipboard))) | |
93 (or clip (error "there is no clipboard selection")) | |
94 (push-mark) | |
95 (insert clip)))) | |
96 | |
97 (defun get-clipboard () | |
829 | 98 "Return text pasted to the clipboard. |
843 | 99 Not suitable for `interprogram-paste-function', use `get-clipboard-foreign'." |
100 (get-selection 'CLIPBOARD)) | |
101 | |
102 (defun get-clipboard-foreign () | |
103 "Return text pasted to the clipboard by another program. | |
829 | 104 See `interprogram-paste-function' for more information." |
843 | 105 (get-selection-foreign 'CLIPBOARD)) |
428 | 106 |
107 (define-device-method get-cutbuffer | |
108 "Return the value of one of the cut buffers. | |
109 This will do nothing under anything other than X.") | |
110 | |
111 (defun get-selection-no-error (&optional type data-type) | |
442 | 112 "Return the value of a window-system selection. |
2624 | 113 The argument TYPE (default `PRIMARY') says which selection, and the argument |
114 DATA-TYPE (defaulting to the value of `selection-preferred-types'), says how | |
115 to convert the data. Returns NIL if there is no selection." | |
442 | 116 (condition-case nil (get-selection type data-type) (t nil))) |
428 | 117 |
118 (defun get-selection (&optional type data-type) | |
843 | 119 "Return the value of a window-system selection. |
2624 | 120 The argument TYPE (default `PRIMARY') says which selection, and the argument |
121 DATA-TYPE (defaulting to the value of, and compatible with, | |
122 `selection-preferred-types') says how to convert the data. If | |
123 there is no selection an error is signalled. Not suitable in a | |
124 `interprogram-paste-function', q.v." | |
428 | 125 (or type (setq type 'PRIMARY)) |
2624 | 126 (or data-type (setq data-type selection-preferred-types)) |
829 | 127 (if (consp data-type) |
2624 | 128 ;; TARGETS is a vector; we want a list so we can memq --> append it to |
129 ;; nil. | |
130 (let ((targets (append (get-selection-internal type 'TARGETS) nil)) | |
131 res) | |
132 (catch 'converted | |
133 (if targets | |
134 (dolist (current-preference data-type) | |
3072 | 135 (condition-case nil |
2624 | 136 (if (and (memq current-preference targets) |
137 (setq res (get-selection-internal | |
138 type current-preference))) | |
139 (throw 'converted res)) | |
140 (selection-conversion-error | |
141 nil)))) | |
142 ;; The source app didn't offer us anything compatible in TARGETS, | |
143 ;; or they're not negotiating at all. (That is, we're probably not | |
144 ;; on X11.) Try to convert to the types specified by our caller, | |
145 ;; and throw an error if the last one of those fails. | |
146 (while data-type | |
147 (condition-case err | |
148 (progn | |
149 (setq res (get-selection-internal type (car data-type))) | |
2656 | 150 (if res (throw 'converted res) |
151 (signal 'selection-conversion-error nil))) | |
2624 | 152 (selection-conversion-error |
153 (if (cdr data-type) | |
2656 | 154 (setq data-type (cdr data-type)) |
2624 | 155 (signal (car err) (cdr err)))))))) |
829 | 156 (get-selection-internal type data-type))) |
428 | 157 |
847 | 158 (defun get-selection-foreign (&optional type data-type) |
159 "Return the value of a window-system selection, or nil if XEmacs owns it. | |
2624 | 160 The argument TYPE (default `PRIMARY') says which selection, and the argument |
161 DATA-TYPE (defaulting to the value of `selection-preferred-types' which see) | |
162 says how to convert the data. If there is no selection an error is | |
163 signalled. See `interprogram-paste-function' for more information." | |
847 | 164 (unless (selection-owner-p type) |
165 (get-selection type data-type))) | |
166 | |
428 | 167 ;; FSFmacs calls this `x-set-selection', and reverses the |
442 | 168 ;; first two arguments (duh ...). This order is more logical. |
169 (defun own-selection (data &optional type how-to-add data-type) | |
170 "Make a window-system selection of type TYPE and value DATA. | |
428 | 171 The argument TYPE (default `PRIMARY') says which selection, |
442 | 172 and DATA specifies the contents. DATA may be any lisp data type |
173 that can be converted using the function corresponding to DATA-TYPE | |
174 in `select-converter-alist'---strings are the usual choice, but | |
175 other types may be permissible depending on the DATA-TYPE parameter | |
851 | 176 \(if DATA-TYPE is not supplied, the default behavior is window |
442 | 177 system specific, but strings are always accepted). |
178 HOW-TO-ADD may be any of the following: | |
179 | |
180 'replace-all or nil -- replace all data in the selection. | |
181 'replace-existing -- replace data for specified DATA-TYPE only. | |
182 'append or t -- append data to existing DATA-TYPE data. | |
183 | |
184 DATA-TYPE is the window-system specific data type identifier | |
851 | 185 \(see `register-selection-data-type' for more information). |
428 | 186 |
187 The selection may also be a cons of two markers pointing to the same buffer, | |
188 or an overlay. In these cases, the selection is considered to be the text | |
442 | 189 between the markers *at whatever time the selection is examined* (note |
190 that the window system clipboard does not necessarily duplicate this | |
191 behavior - it doesn't on mswindows for example). | |
428 | 192 Thus, editing done in the buffer after you specify the selection |
193 can alter the effective value of the selection. | |
194 | |
195 The data may also be a vector of valid non-vector selection values. | |
196 | |
197 Interactively, the text of the region is used as the selection value." | |
198 (interactive (if (not current-prefix-arg) | |
199 (list (read-string "Store text for pasting: ")) | |
200 (list (substring (region-beginning) (region-end))))) | |
442 | 201 ;; calling own-selection-internal will mess this up, so preserve it. |
202 (let ((zmacs-region-stays zmacs-region-stays)) | |
203 ;FSFmacs huh?? It says: | |
204 ;; "This is for temporary compatibility with pre-release Emacs 19." | |
205 ;(if (stringp type) | |
206 ; (setq type (intern type))) | |
207 (or type (setq type 'PRIMARY)) | |
208 (if (null data) | |
209 (disown-selection-internal type) | |
210 (own-selection-internal type data how-to-add data-type) | |
211 (when (and (eq type 'PRIMARY) | |
212 selection-sets-clipboard) | |
213 (own-selection-internal 'CLIPBOARD data how-to-add data-type))) | |
214 (cond ((eq type 'PRIMARY) | |
215 (setq primary-selection-extent | |
216 (select-make-extent-for-selection | |
217 data primary-selection-extent))) | |
218 ((eq type 'SECONDARY) | |
219 (setq secondary-selection-extent | |
220 (select-make-extent-for-selection | |
221 data secondary-selection-extent))))) | |
222 ;; zmacs-region-stays is for commands, not low-level functions. | |
223 ;; when behaving as the latter, we better not set it, or we will | |
224 ;; cause unwanted sticky-region behavior in kill-region and friends. | |
225 (if (interactive-p) | |
226 (setq zmacs-region-stays t)) | |
428 | 227 data) |
228 | |
229 (defun dehilight-selection (selection) | |
230 "for use as a value of `lost-selection-hooks'." | |
231 (cond ((eq selection 'PRIMARY) | |
232 (if primary-selection-extent | |
233 (let ((inhibit-quit t)) | |
234 (if (consp primary-selection-extent) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
235 (mapc 'delete-extent primary-selection-extent) |
428 | 236 (delete-extent primary-selection-extent)) |
237 (setq primary-selection-extent nil))) | |
238 (if zmacs-regions (zmacs-deactivate-region))) | |
239 ((eq selection 'SECONDARY) | |
240 (if secondary-selection-extent | |
241 (let ((inhibit-quit t)) | |
242 (if (consp secondary-selection-extent) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
243 (mapc 'delete-extent secondary-selection-extent) |
428 | 244 (delete-extent secondary-selection-extent)) |
245 (setq secondary-selection-extent nil))))) | |
246 nil) | |
247 | |
248 (setq lost-selection-hooks 'dehilight-selection) | |
249 | |
442 | 250 (defun own-clipboard (string &optional push) |
251 "Paste the given string to the window system Clipboard. | |
252 See `interprogram-cut-function' for more information." | |
428 | 253 (own-selection string 'CLIPBOARD)) |
254 | |
255 (defun disown-selection (&optional secondary-p) | |
487 | 256 "Assuming we own the selection, disown it. |
257 With an argument, discard the secondary selection instead of the | |
258 primary selection." | |
428 | 259 (disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY)) |
260 (when (and selection-sets-clipboard | |
261 (or (not secondary-p) | |
262 (eq secondary-p 'PRIMARY) | |
263 (eq secondary-p 'CLIPBOARD))) | |
264 (disown-selection-internal 'CLIPBOARD))) | |
265 | |
266 ;; selections and active regions | |
267 | |
268 ;; If and only if zmacs-regions is true: | |
269 | |
270 ;; When a mark is pushed and the region goes into the "active" state, we | |
271 ;; assert it as the Primary selection. This causes it to be hilighted. | |
272 ;; When the region goes into the "inactive" state, we disown the Primary | |
273 ;; selection, causing the region to be dehilighted. | |
274 | |
275 ;; Note that it is possible for the region to be in the "active" state | |
276 ;; and not be hilighted, if it is in the active state and then some other | |
277 ;; application asserts the selection. This is probably not a big deal. | |
278 | |
279 (defun activate-region-as-selection () | |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5364
diff
changeset
|
280 (cond ((and-fboundp 'mouse-track-rectangle-p |
4222 | 281 (mouse-track-rectangle-p |
282 (mouse-track-activate-rectangular-selection)))) | |
487 | 283 ((marker-buffer (mark-marker t)) |
284 (own-selection (cons (point-marker t) (mark-marker t)))))) | |
428 | 285 |
286 (defvar primary-selection-extent nil | |
287 "The extent of the primary selection; don't use this.") | |
288 | |
289 (defvar secondary-selection-extent nil | |
290 "The extent of the secondary selection; don't use this.") | |
291 | |
292 (defun select-make-extent-for-selection (selection previous-extent) | |
293 ;; Given a selection, this makes an extent in the buffer which holds that | |
294 ;; selection, for highlighting purposes. If the selection isn't associated | |
295 ;; with a buffer, this does nothing. | |
2624 | 296 ;; |
297 ;; Something similar needs to be hooked into the rectangle functions. | |
428 | 298 (let ((buffer nil) |
299 (valid (and (extentp previous-extent) | |
300 (extent-object previous-extent) | |
301 (buffer-live-p (extent-object previous-extent)))) | |
302 start end) | |
303 (cond ((stringp selection) | |
304 ;; if we're selecting a string, lose the previous extent used | |
305 ;; to highlight the selection. | |
306 (setq valid nil)) | |
307 ((consp selection) | |
308 (setq start (min (car selection) (cdr selection)) | |
309 end (max (car selection) (cdr selection)) | |
310 valid (and valid | |
311 (eq (marker-buffer (car selection)) | |
312 (extent-object previous-extent))) | |
313 buffer (marker-buffer (car selection)))) | |
314 ((extentp selection) | |
315 (setq start (extent-start-position selection) | |
316 end (extent-end-position selection) | |
317 valid (and valid | |
318 (eq (extent-object selection) | |
319 (extent-object previous-extent))) | |
320 buffer (extent-object selection))) | |
321 (t | |
322 (signal 'error (list "invalid selection" selection)))) | |
323 | |
324 (if valid | |
325 nil | |
326 (condition-case () | |
327 (if (listp previous-extent) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
328 (mapc 'delete-extent previous-extent) |
428 | 329 (delete-extent previous-extent)) |
330 (error nil))) | |
331 | |
332 (if (not buffer) | |
333 ;; string case | |
334 nil | |
335 ;; normal case | |
336 (if valid | |
337 (set-extent-endpoints previous-extent start end) | |
338 (setq previous-extent (make-extent start end buffer)) | |
339 | |
340 ;; Make the extent be closed on the right, which means that if | |
341 ;; characters are inserted exactly at the end of the extent, the | |
342 ;; extent will grow to cover them. This is important for shell | |
343 ;; buffers - suppose one makes a selection, and one end is at | |
344 ;; point-max. If the shell produces output, that marker will remain | |
345 ;; at point-max (its position will increase). So it's important that | |
346 ;; the extent exhibit the same behavior, lest the region covered by | |
347 ;; the extent (the visual indication), and the region between point | |
348 ;; and mark (the actual selection value) become different! | |
349 (set-extent-property previous-extent 'end-open nil) | |
350 | |
351 (cond | |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5364
diff
changeset
|
352 ((and-fboundp 'mouse-track-rectangle-p |
4222 | 353 (mouse-track-rectangle-p |
354 (setq previous-extent (list previous-extent)) | |
355 (default-mouse-track-next-move-rect start end previous-extent) | |
356 )))) | |
428 | 357 previous-extent)))) |
358 | |
359 (defun valid-simple-selection-p (data) | |
442 | 360 "An obsolete function that tests whether something was a valid simple |
361 selection using the old XEmacs selection support. You shouldn't use this | |
362 any more, because just about anything could be a valid selection now." | |
428 | 363 (or (stringp data) |
364 ;FSFmacs huh?? (symbolp data) | |
365 (integerp data) | |
366 (and (consp data) | |
367 (integerp (car data)) | |
368 (or (integerp (cdr data)) | |
369 (and (consp (cdr data)) | |
370 (integerp (car (cdr data)))))) | |
371 (extentp data) | |
372 (and (consp data) | |
373 (markerp (car data)) | |
374 (markerp (cdr data)) | |
375 (marker-buffer (car data)) | |
376 (marker-buffer (cdr data)) | |
377 (eq (marker-buffer (car data)) | |
378 (marker-buffer (cdr data))) | |
379 (buffer-live-p (marker-buffer (car data))) | |
380 (buffer-live-p (marker-buffer (cdr data)))))) | |
381 | |
382 (defun cut-copy-clear-internal (mode) | |
5364
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
383 (or (memq mode '(cut copy clear)) (error "unknown mode %S" mode)) |
428 | 384 (or (selection-owner-p) |
385 (error "XEmacs does not own the primary selection")) | |
386 (setq last-command nil) | |
387 (or primary-selection-extent | |
388 (error "the primary selection is not an extent?")) | |
389 (save-excursion | |
390 (let (rect-p b s e) | |
391 (cond | |
392 ((consp primary-selection-extent) | |
393 (setq rect-p t | |
394 b (extent-object (car primary-selection-extent)) | |
395 s (extent-start-position (car primary-selection-extent)) | |
396 e (extent-end-position (car (reverse primary-selection-extent))))) | |
397 (t | |
398 (setq rect-p nil | |
399 b (extent-object primary-selection-extent) | |
400 s (extent-start-position primary-selection-extent) | |
401 e (extent-end-position primary-selection-extent)))) | |
402 (set-buffer b) | |
403 (cond ((memq mode '(cut copy)) | |
404 (if rect-p | |
405 (progn | |
851 | 406 ;; killed-rectangle is defvarred in rect.el |
428 | 407 (setq killed-rectangle (extract-rectangle s e)) |
408 (kill-new (mapconcat #'identity killed-rectangle "\n"))) | |
409 (copy-region-as-kill s e)) | |
410 ;; Maybe killing doesn't own clipboard. Make sure it happens. | |
411 ;; This memq is kind of grody, because they might have done it | |
412 ;; some other way, but owning the clipboard twice in that case | |
413 ;; wouldn't actually hurt anything. | |
414 (or (and (consp kill-hooks) (memq 'own-clipboard kill-hooks)) | |
851 | 415 (eq 'own-clipboard interprogram-cut-function) |
428 | 416 (own-clipboard (car kill-ring))))) |
417 (cond ((memq mode '(cut clear)) | |
418 (if rect-p | |
419 (delete-rectangle s e) | |
420 (delete-region s e)))) | |
421 (disown-selection nil) | |
422 ))) | |
423 | |
442 | 424 |
428 | 425 ;;; Functions to convert the selection into various other selection |
442 | 426 ;;; types. |
427 | |
428 ;; These next three functions get called by C code... | |
429 (defun select-convert-in (selection type value) | |
430 "Attempt to convert the specified external VALUE to the specified DATA-TYPE, | |
431 for the specified SELECTION. Return nil if this is impossible, or a | |
432 suitable internal representation otherwise." | |
433 (when value | |
434 (let ((handler-fn (cdr (assq type selection-converter-in-alist)))) | |
2624 | 435 (if handler-fn |
436 (apply handler-fn (list selection type value)) | |
437 value)))) | |
428 | 438 |
442 | 439 (defun select-convert-out (selection type value) |
440 "Attempt to convert the specified internal VALUE for the specified DATA-TYPE | |
441 and SELECTION. Return nil if this is impossible, or a suitable external | |
442 representation otherwise." | |
443 (when value | |
444 (let ((handler-fn (cdr (assq type selection-converter-out-alist)))) | |
445 (when handler-fn | |
446 (apply handler-fn (list selection type value)))))) | |
447 | |
448 (defun select-coerce (selection type value) | |
449 "Attempt to convert the specified internal VALUE to a representation | |
450 suitable for return from `get-selection' in the specified DATA-TYPE. Return | |
451 nil if this is impossible, or a suitable representation otherwise." | |
452 (when value | |
453 (let ((handler-fn (cdr (assq type selection-coercion-alist)))) | |
454 (when handler-fn | |
455 (apply handler-fn (list selection type value)))))) | |
456 | |
457 ;; The rest of the functions on this "page" are conversion handlers, | |
458 ;; append handlers and buffer-kill handlers. | |
428 | 459 (defun select-convert-to-text (selection type value) |
460 (cond ((stringp value) | |
461 value) | |
462 ((extentp value) | |
463 (save-excursion | |
464 (set-buffer (extent-object value)) | |
465 (save-restriction | |
466 (widen) | |
467 (buffer-substring (extent-start-position value) | |
468 (extent-end-position value))))) | |
469 ((and (consp value) | |
470 (markerp (car value)) | |
471 (markerp (cdr value))) | |
472 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) | |
473 (signal 'error | |
474 (list "markers must be in the same buffer" | |
475 (car value) (cdr value)))) | |
476 (save-excursion | |
477 (set-buffer (or (marker-buffer (car value)) | |
478 (error "selection is in a killed buffer"))) | |
479 (save-restriction | |
480 (widen) | |
481 (buffer-substring (car value) (cdr value))))) | |
482 (t nil))) | |
483 | |
2624 | 484 (defun select-convert-to-timestamp (selection type value) |
485 (let ((ts (get-xemacs-selection-timestamp selection))) | |
486 (if ts (cons 'TIMESTAMP ts)))) | |
487 | |
488 (defun select-convert-to-utf-8-text (selection type value) | |
489 (cond ((stringp value) | |
490 (cons 'UTF8_STRING (encode-coding-string value 'utf-8))) | |
491 ((extentp value) | |
492 (save-excursion | |
493 (set-buffer (extent-object value)) | |
494 (save-restriction | |
495 (widen) | |
496 (cons 'UTF8_STRING | |
497 (encode-coding-string | |
498 (buffer-substring (extent-start-position value) | |
499 (extent-end-position value)) 'utf-8))))) | |
500 ((and (consp value) | |
501 (markerp (car value)) | |
502 (markerp (cdr value))) | |
503 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) | |
504 (signal 'error | |
505 (list "markers must be in the same buffer" | |
506 (car value) (cdr value)))) | |
507 (save-excursion | |
508 (set-buffer (or (marker-buffer (car value)) | |
509 (error "selection is in a killed buffer"))) | |
510 (save-restriction | |
511 (widen) | |
512 (cons 'UTF8_STRING (encode-coding-string | |
513 (buffer-substring (car value) (cdr value)) | |
514 'utf-8))))) | |
515 (t nil))) | |
516 | |
442 | 517 (defun select-coerce-to-text (selection type value) |
518 (select-convert-to-text selection type value)) | |
519 | |
428 | 520 (defun select-convert-to-string (selection type value) |
521 (let ((outval (select-convert-to-text selection type value))) | |
442 | 522 ;; force the string to be not in Compound Text format. This grubby |
523 ;; hack will go soon, to be replaced by a more general mechanism. | |
428 | 524 (if (stringp outval) |
525 (cons 'STRING outval) | |
526 outval))) | |
527 | |
528 (defun select-convert-to-compound-text (selection type value) | |
529 ;; converts to compound text automatically | |
530 (select-convert-to-text selection type value)) | |
531 | |
532 (defun select-convert-to-length (selection type value) | |
533 (let ((value | |
534 (cond ((stringp value) | |
535 (length value)) | |
536 ((extentp value) | |
537 (extent-length value)) | |
538 ((and (consp value) | |
539 (markerp (car value)) | |
540 (markerp (cdr value))) | |
541 (or (eq (marker-buffer (car value)) | |
542 (marker-buffer (cdr value))) | |
543 (signal 'error | |
544 (list "markers must be in the same buffer" | |
545 (car value) (cdr value)))) | |
546 (abs (- (car value) (cdr value))))))) | |
547 (if value ; force it to be in 32-bit format. | |
548 (cons (ash value -16) (logand value 65535)) | |
549 nil))) | |
550 | |
551 (defun select-convert-to-targets (selection type value) | |
552 ;; return a vector of atoms, but remove duplicates first. | |
553 (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist))) | |
554 (rest all)) | |
555 (while rest | |
556 (cond ((memq (car rest) (cdr rest)) | |
557 (setcdr rest (delq (car rest) (cdr rest)))) | |
558 (t | |
559 (setq rest (cdr rest))))) | |
560 (apply 'vector all))) | |
561 | |
562 (defun select-convert-to-delete (selection type value) | |
563 (disown-selection-internal selection) | |
564 ;; A return value of nil means that we do not know how to do this conversion, | |
565 ;; and replies with an "error". A return value of NULL means that we have | |
566 ;; done the conversion (and any side-effects) but have no value to return. | |
567 'NULL) | |
568 | |
569 (defun select-convert-to-filename (selection type value) | |
570 (cond ((extentp value) | |
571 (buffer-file-name (or (extent-object value) | |
572 (error "selection is in a killed buffer")))) | |
573 ((and (consp value) | |
574 (markerp (car value)) | |
575 (markerp (cdr value))) | |
576 (buffer-file-name (or (marker-buffer (car value)) | |
577 (error "selection is in a killed buffer")))) | |
578 (t nil))) | |
579 | |
580 (defun select-convert-to-charpos (selection type value) | |
581 (let (a b tmp) | |
582 (cond ((cond ((extentp value) | |
583 (setq a (extent-start-position value) | |
584 b (extent-end-position value))) | |
585 ((and (consp value) | |
586 (markerp (car value)) | |
587 (markerp (cdr value))) | |
588 (setq a (car value) | |
589 b (cdr value)))) | |
590 (setq a (1- a) b (1- b)) ; zero-based | |
591 (if (< b a) (setq tmp a a b b tmp)) | |
592 (cons 'SPAN | |
593 (vector (cons (ash a -16) (logand a 65535)) | |
594 (cons (ash b -16) (logand b 65535)))))))) | |
595 | |
596 (defun select-convert-to-lineno (selection type value) | |
597 (let (a b buf tmp) | |
598 (cond ((cond ((extentp value) | |
599 (setq buf (extent-object value) | |
600 a (extent-start-position value) | |
601 b (extent-end-position value))) | |
602 ((and (consp value) | |
603 (markerp (car value)) | |
604 (markerp (cdr value))) | |
605 (setq a (marker-position (car value)) | |
606 b (marker-position (cdr value)) | |
607 buf (marker-buffer (car value))))) | |
608 (save-excursion | |
609 (set-buffer buf) | |
610 (save-restriction | |
611 (widen) | |
612 (goto-char a) | |
613 (beginning-of-line) | |
614 (setq a (1+ (count-lines 1 (point)))) | |
615 (goto-char b) | |
616 (beginning-of-line) | |
617 (setq b (1+ (count-lines 1 (point)))))) | |
618 (if (< b a) (setq tmp a a b b tmp)) | |
619 (cons 'SPAN | |
620 (vector (cons (ash a -16) (logand a 65535)) | |
621 (cons (ash b -16) (logand b 65535)))))))) | |
622 | |
623 (defun select-convert-to-colno (selection type value) | |
624 (let (a b buf tmp) | |
625 (cond ((cond ((extentp value) | |
626 (setq buf (extent-object value) | |
627 a (extent-start-position value) | |
628 b (extent-end-position value))) | |
629 ((and (consp value) | |
630 (markerp (car value)) | |
631 (markerp (cdr value))) | |
632 (setq a (car value) | |
633 b (cdr value) | |
634 buf (marker-buffer a)))) | |
635 (save-excursion | |
636 (set-buffer buf) | |
637 (goto-char a) | |
638 (setq a (current-column)) | |
639 (goto-char b) | |
640 (setq b (current-column))) | |
641 (if (< b a) (setq tmp a a b b tmp)) | |
642 (cons 'SPAN | |
643 (vector (cons (ash a -16) (logand a 65535)) | |
644 (cons (ash b -16) (logand b 65535)))))))) | |
645 | |
646 (defun select-convert-to-sourceloc (selection type value) | |
647 (let (a b buf file-name tmp) | |
648 (cond ((cond ((extentp value) | |
649 (setq buf (or (extent-object value) | |
650 (error "selection is in a killed buffer")) | |
651 a (extent-start-position value) | |
652 b (extent-end-position value) | |
653 file-name (buffer-file-name buf))) | |
654 ((and (consp value) | |
655 (markerp (car value)) | |
656 (markerp (cdr value))) | |
657 (setq a (marker-position (car value)) | |
658 b (marker-position (cdr value)) | |
659 buf (or (marker-buffer (car value)) | |
660 (error "selection is in a killed buffer")) | |
661 file-name (buffer-file-name buf)))) | |
662 (save-excursion | |
663 (set-buffer buf) | |
664 (save-restriction | |
665 (widen) | |
666 (goto-char a) | |
667 (beginning-of-line) | |
668 (setq a (1+ (count-lines 1 (point)))) | |
669 (goto-char b) | |
670 (beginning-of-line) | |
671 (setq b (1+ (count-lines 1 (point)))))) | |
672 (if (< b a) (setq tmp a a b b tmp)) | |
673 (format "%s:%d" file-name a))))) | |
674 | |
675 (defun select-convert-to-os (selection type size) | |
676 (symbol-name system-type)) | |
677 | |
678 (defun select-convert-to-host (selection type size) | |
679 (system-name)) | |
680 | |
681 (defun select-convert-to-user (selection type size) | |
682 (user-full-name)) | |
683 | |
684 (defun select-convert-to-class (selection type size) | |
442 | 685 (symbol-value 'x-emacs-application-class)) |
428 | 686 |
687 ;; We do not try to determine the name Emacs was invoked with, | |
688 ;; because it is not clean for a program's behavior to depend on that. | |
689 (defun select-convert-to-name (selection type size) | |
690 ;invocation-name | |
691 "xemacs") | |
692 | |
693 (defun select-convert-to-integer (selection type value) | |
694 (and (integerp value) | |
695 (cons (ash value -16) (logand value 65535)))) | |
696 | |
442 | 697 ;; Can convert from the following integer representations |
698 ;; | |
699 ;; integer | |
700 ;; (integer . integer) | |
701 ;; (integer integer) | |
702 ;; (list [integer|(integer . integer)]*) | |
703 ;; (vector [integer|(integer . integer)]*) | |
704 ;; | |
705 ;; Cons'd integers get cleaned up a little. | |
706 | |
707 (defun select-convert-from-integer (selection type value) | |
708 (cond ((integerp value) ; Integer | |
709 value) | |
444 | 710 |
442 | 711 ((and (consp value) ; (integer . integer) |
712 (integerp (car value)) | |
713 (integerp (cdr value))) | |
714 (if (eq (car value) 0) | |
715 (cdr value) | |
716 (if (and (eq (car value) -1) | |
717 (< (cdr value) 0)) | |
718 (cdr value) | |
719 value))) | |
444 | 720 |
442 | 721 ((and (listp value) ; (integer integer) |
722 (eq (length value) 2) | |
723 (integerp (car value)) | |
724 (integerp (cadr value))) | |
725 (if (eq (car value) 0) | |
726 (cadr value) | |
727 (if (and (eq (car value) -1) | |
728 (< (cdr value) 0)) | |
729 (- (cadr value)) | |
730 (cons (car value) (cadr value))))) | |
444 | 731 |
442 | 732 ((listp value) ; list |
733 (if (cdr value) | |
4021 | 734 (mapcar #'(lambda (x) |
735 (select-convert-from-integer selection type x)) | |
442 | 736 value) |
737 (select-convert-from-integer selection type (car value)))) | |
444 | 738 |
442 | 739 ((vectorp value) ; vector |
740 (if (eq (length value) 1) | |
741 (select-convert-from-integer selection type (aref value 0)) | |
4021 | 742 (mapvector #'(lambda (x) |
743 (select-convert-from-integer selection type x)) | |
744 value))) | |
444 | 745 |
442 | 746 (t nil) |
747 )) | |
748 | |
2624 | 749 (defun select-convert-from-ip-address (selection type value) |
750 (if (and (stringp value) | |
751 (= (length value) 4)) | |
752 (format "%d.%d.%d.%d" | |
753 (aref value 0) (aref value 1) (aref value 2) (aref value 3)))) | |
754 | |
428 | 755 (defun select-convert-to-atom (selection type value) |
756 (and (symbolp value) value)) | |
757 | |
2624 | 758 (defun select-convert-from-utf-8-text (selection type value) |
759 (decode-coding-string value 'utf-8)) | |
760 | |
761 (defun select-convert-from-utf-16-le-text (selection type value) | |
762 (decode-coding-string value 'utf-16-le)) | |
763 | |
764 ;; Image conversion. | |
765 (defun select-convert-from-image-data (image-type value) | |
766 "Take an image type specification--one of the image types this XEmacs | |
767 supports--and some data in that format, return a space, with a glyph | |
768 corresponding to that data as an end-glyph extent property of that space. " | |
769 (let* ((str (make-string 1 ?\ )) | |
770 (extent (make-extent 0 1 str)) | |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
771 (glyph (make-glyph (vector image-type :data value)))) |
2624 | 772 (when glyph |
773 (set-extent-property extent 'invisible t) | |
774 (set-extent-property extent 'start-open t) | |
775 (set-extent-property extent 'end-open t) | |
776 (set-extent-property extent 'duplicable t) | |
777 (set-extent-property extent 'atomic t) | |
778 (set-extent-end-glyph extent glyph) | |
779 str))) | |
780 | |
5364
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
781 (macrolet |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
782 ((create-image-functions (&rest formats) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
783 (cons |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
784 'progn |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
785 (mapcar |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
786 #'(lambda (format) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
787 `(if (featurep ',format) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
788 (defalias (intern (concat "select-convert-from-image/" |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
789 ,(symbol-name format))) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
790 #'(lambda (selection type value) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
791 (select-convert-from-image-data ',format |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
792 value))))) formats)))) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
793 (create-image-functions gif jpeg png tiff xpm xbm)) |
2624 | 794 |
442 | 795 ;;; CF_xxx conversions |
796 (defun select-convert-from-cf-text (selection type value) | |
2624 | 797 (if (find-coding-system 'mswindows-multibyte) |
798 (let ((value (decode-coding-string value 'mswindows-multibyte))) | |
799 (replace-in-string (if (string-match "\0" value) | |
800 (substring value 0 (match-beginning 0)) | |
801 value) | |
802 "\\(\r\n\\|\n\r\\)" "\n" t)))) | |
771 | 803 |
804 (defun select-convert-from-cf-unicodetext (selection type value) | |
2624 | 805 (if (find-coding-system 'mswindows-unicode) |
806 (let ((value (decode-coding-string value 'mswindows-unicode))) | |
807 (replace-in-string (if (string-match "\0" value) | |
808 (substring value 0 (match-beginning 0)) | |
809 value) | |
810 "\\(\r\n\\|\n\r\\)" "\n" t)))) | |
442 | 811 |
812 (defun select-convert-to-cf-text (selection type value) | |
2624 | 813 (if (find-coding-system 'mswindows-multibyte) |
814 (let ((text (select-convert-to-text selection type value))) | |
815 (encode-coding-string | |
816 (concat (replace-in-string text "\n" "\r\n" t) "\0") | |
817 'mswindows-multibyte)))) | |
771 | 818 |
819 (defun select-convert-to-cf-unicodetext (selection type value) | |
2624 | 820 (if (find-coding-system 'mswindows-unicode) |
821 (let ((text (select-convert-to-text selection type value))) | |
822 (encode-coding-string | |
823 (concat (replace-in-string text "\n" "\r\n" t) "\0") | |
824 'mswindows-unicode)))) | |
442 | 825 |
826 ;;; Appenders | |
827 (defun select-append-to-text (selection type value1 value2) | |
828 (let ((text1 (select-convert-to-text selection 'STRING value1)) | |
829 (text2 (select-convert-to-text selection 'STRING value2))) | |
830 (if (and text1 text2) | |
831 (concat text1 text2) | |
832 nil))) | |
833 | |
834 (defun select-append-to-string (selection type value1 value2) | |
835 (select-append-to-text selection type value1 value2)) | |
836 | |
837 (defun select-append-to-compound-text (selection type value1 value2) | |
838 (select-append-to-text selection type value1 value2)) | |
839 | |
840 (defun select-append-to-cf-text (selection type value1 value2) | |
841 (let ((text1 (select-convert-from-cf-text selection 'CF_TEXT value1)) | |
842 (text2 (select-convert-from-cf-text selection 'CF_TEXT value2))) | |
843 (if (and text1 text2) | |
844 (select-convert-to-cf-text selection type (concat text1 text2)) | |
845 nil))) | |
428 | 846 |
771 | 847 (defun select-append-to-cf-unicodetext (selection type value1 value2) |
848 (let ((text1 (select-convert-from-cf-unicodetext selection | |
849 'CF_UNICODETEXT value1)) | |
850 (text2 (select-convert-from-cf-unicodetext selection | |
851 'CF_UNICODETEXT value2))) | |
852 (if (and text1 text2) | |
853 (select-convert-to-cf-unicodetext selection type (concat text1 text2)) | |
854 nil))) | |
855 | |
442 | 856 (defun select-append-default (selection type value1 value2) |
857 ;; This appender gets used if the type is "nil" - i.e. default. | |
858 ;; It should probably have more cases implemented than it does - e.g. | |
859 ;; appending numbers to strings, etc... | |
860 (cond ((and (stringp value1) (stringp value2)) | |
861 (select-append-to-string selection 'STRING value1 value2)) | |
862 (t nil))) | |
863 | |
864 ;;; Buffer kill handlers | |
865 | |
866 (defun select-buffer-killed-default (selection type value buffer) | |
867 ;; This handler gets used if the type is "nil". | |
868 (cond ((extentp value) | |
869 (if (eq (extent-object value) buffer) | |
870 ; If this selection is on the clipboard, grab it quick | |
871 (when (eq selection 'CLIPBOARD) | |
872 (save-excursion | |
873 (set-buffer (extent-object value)) | |
874 (save-restriction | |
875 (widen) | |
876 (buffer-substring (extent-start-position value) | |
877 (extent-end-position value))))) | |
878 value)) | |
879 ((markerp value) | |
880 (unless (eq (marker-buffer value) buffer) | |
881 value)) | |
882 ((and (consp value) | |
883 (markerp (car value)) | |
884 (markerp (cdr value))) | |
885 (if (or (eq (marker-buffer (car value)) buffer) | |
886 (eq (marker-buffer (cdr value)) buffer)) | |
887 ; If this selection is on the clipboard, grab it quick | |
888 (when (eq selection 'CLIPBOARD) | |
889 (save-excursion | |
890 (set-buffer (marker-buffer (car value))) | |
891 (save-restriction | |
892 (widen) | |
893 (buffer-substring (car value) (cdr value))))) | |
894 value)) | |
895 (t value))) | |
896 | |
897 (defun select-buffer-killed-text (selection type value buffer) | |
898 (select-buffer-killed-default selection type value buffer)) | |
444 | 899 |
442 | 900 ;; Types listed in here can be selections of XEmacs |
901 (setq selection-converter-out-alist | |
2624 | 902 '((TIMESTAMP . select-convert-to-timestamp) |
903 (UTF8_STRING . select-convert-to-utf-8-text) | |
904 (TEXT . select-convert-to-text) | |
428 | 905 (STRING . select-convert-to-string) |
906 (COMPOUND_TEXT . select-convert-to-compound-text) | |
907 (TARGETS . select-convert-to-targets) | |
908 (LENGTH . select-convert-to-length) | |
909 (DELETE . select-convert-to-delete) | |
910 (FILE_NAME . select-convert-to-filename) | |
911 (CHARACTER_POSITION . select-convert-to-charpos) | |
912 (SOURCE_LOC . select-convert-to-sourceloc) | |
913 (LINE_NUMBER . select-convert-to-lineno) | |
914 (COLUMN_NUMBER . select-convert-to-colno) | |
915 (OWNER_OS . select-convert-to-os) | |
916 (HOST_NAME . select-convert-to-host) | |
917 (USER . select-convert-to-user) | |
918 (CLASS . select-convert-to-class) | |
919 (NAME . select-convert-to-name) | |
920 (ATOM . select-convert-to-atom) | |
921 (INTEGER . select-convert-to-integer) | |
442 | 922 (CF_TEXT . select-convert-to-cf-text) |
771 | 923 (CF_UNICODETEXT . select-convert-to-cf-unicodetext) |
442 | 924 )) |
925 | |
926 ;; Types listed here can be selections foreign to XEmacs | |
927 (setq selection-converter-in-alist | |
5364
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
928 `(; Specific types that get handled by generic converters |
442 | 929 (INTEGER . select-convert-from-integer) |
2624 | 930 (TIMESTAMP . select-convert-from-integer) |
931 (LENGTH . select-convert-from-integer) | |
932 (LIST_LENGTH . select-convert-from-integer) | |
933 (CLIENT_WINDOW . select-convert-from-integer) | |
934 (PROCESS . select-convert-from-integer) | |
935 (IP_ADDRESS . select-convert-from-ip-address) | |
936 ;; We go after UTF8_STRING in preference to STRING because Mozilla, | |
937 ;; at least, does bad things with non-Latin-1 Unicode characters in | |
938 ;; STRING. | |
939 (UTF8_STRING . select-convert-from-utf-8-text) | |
442 | 940 (CF_TEXT . select-convert-from-cf-text) |
771 | 941 (CF_UNICODETEXT . select-convert-from-cf-unicodetext) |
2624 | 942 (text/html . select-convert-from-utf-16-le-text) ; Mozilla |
943 (text/_moz_htmlcontext . select-convert-from-utf-16-le-text) | |
944 (text/_moz_htmlinfo . select-convert-from-utf-16-le-text) | |
5364
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
945 ,@(loop |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
946 for format in '(gif jpeg png tiff xpm xbm) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
947 nconc (if (featurep format) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
948 (list (cons (intern (format "image/%s" format)) |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
949 (intern (format "select-convert-from-image/%s" |
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
950 format)))))))) |
428 | 951 |
442 | 952 ;; Types listed here have special coercion functions that can munge |
953 ;; other types. This can also be used to add special features - e.g. | |
954 ;; being able to pass a region or a cons of markers to own-selection, | |
955 ;; but getting the *current* text in the region back when calling | |
956 ;; get-selection. | |
957 ;; | |
958 ;; Any function listed in here *will be called* whenever a value of | |
959 ;; its type is retrieved from the internal selection cache, or when | |
960 ;; no suitable values could be found in which case XEmacs looks for | |
961 ;; values with types listed in selection-coercible-types. | |
962 (setq selection-coercion-alist | |
963 '((TEXT . select-coerce-to-text) | |
964 (STRING . select-coerce-to-text) | |
965 (COMPOUND_TEXT . select-coerce-to-text) | |
771 | 966 (CF_TEXT . select-coerce-to-text) |
967 (CF_UNICODETEXT . select-coerce-to-text) | |
968 )) | |
442 | 969 |
970 ;; Types listed here can be appended by own-selection | |
971 (setq selection-appender-alist | |
972 '((nil . select-append-default) | |
973 (TEXT . select-append-to-text) | |
974 (STRING . select-append-to-string) | |
975 (COMPOUND_TEXT . select-append-to-compound-text) | |
976 (CF_TEXT . select-append-to-cf-text) | |
771 | 977 (CF_UNICODETEXT . select-append-to-cf-unicodetext) |
442 | 978 )) |
979 | |
980 ;; Types listed here have buffer-kill handlers | |
981 (setq selection-buffer-killed-alist | |
982 '((nil . select-buffer-killed-default) | |
983 (TEXT . select-buffer-killed-text) | |
984 (STRING . select-buffer-killed-text) | |
985 (COMPOUND_TEXT . select-buffer-killed-text) | |
771 | 986 (CF_TEXT . select-buffer-killed-text) |
987 (CF_UNICODETEXT . select-buffer-killed-text) | |
988 )) | |
442 | 989 |
990 ;; Lists of types that are coercible (can be converted to other types) | |
771 | 991 (setq selection-coercible-types '(TEXT STRING COMPOUND_TEXT CF_TEXT CF_UNICODETEXT)) |
442 | 992 |
428 | 993 ;;; select.el ends here |