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