Mercurial > hg > xemacs-beta
annotate lisp/select.el @ 5839:d139eb1fead8
Check return value of fseek.
| author | Marcus Crestani <marcus@crestani.de> |
|---|---|
| date | Sat, 13 Dec 2014 14:09:33 +0100 |
| parents | 0df3cedee9ac |
| children | bbe4146603db |
| 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 | |
|
5618
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
259 (memq secondary-p '(nil PRIMARY CLIPBOARD))) |
| 428 | 260 (disown-selection-internal 'CLIPBOARD))) |
| 261 | |
| 262 ;; selections and active regions | |
| 263 | |
| 264 ;; If and only if zmacs-regions is true: | |
| 265 | |
| 266 ;; When a mark is pushed and the region goes into the "active" state, we | |
| 267 ;; assert it as the Primary selection. This causes it to be hilighted. | |
| 268 ;; When the region goes into the "inactive" state, we disown the Primary | |
| 269 ;; selection, causing the region to be dehilighted. | |
| 270 | |
| 271 ;; Note that it is possible for the region to be in the "active" state | |
| 272 ;; and not be hilighted, if it is in the active state and then some other | |
| 273 ;; application asserts the selection. This is probably not a big deal. | |
| 274 | |
| 275 (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
|
276 (cond ((and-fboundp 'mouse-track-rectangle-p |
| 4222 | 277 (mouse-track-rectangle-p |
| 278 (mouse-track-activate-rectangular-selection)))) | |
| 487 | 279 ((marker-buffer (mark-marker t)) |
| 280 (own-selection (cons (point-marker t) (mark-marker t)))))) | |
| 428 | 281 |
| 282 (defvar primary-selection-extent nil | |
| 283 "The extent of the primary selection; don't use this.") | |
| 284 | |
| 285 (defvar secondary-selection-extent nil | |
| 286 "The extent of the secondary selection; don't use this.") | |
| 287 | |
| 288 (defun select-make-extent-for-selection (selection previous-extent) | |
| 289 ;; Given a selection, this makes an extent in the buffer which holds that | |
| 290 ;; selection, for highlighting purposes. If the selection isn't associated | |
| 291 ;; with a buffer, this does nothing. | |
| 2624 | 292 ;; |
| 293 ;; Something similar needs to be hooked into the rectangle functions. | |
| 428 | 294 (let ((buffer nil) |
| 295 (valid (and (extentp previous-extent) | |
| 296 (extent-object previous-extent) | |
| 297 (buffer-live-p (extent-object previous-extent)))) | |
| 298 start end) | |
| 299 (cond ((stringp selection) | |
| 300 ;; if we're selecting a string, lose the previous extent used | |
| 301 ;; to highlight the selection. | |
| 302 (setq valid nil)) | |
| 303 ((consp selection) | |
| 304 (setq start (min (car selection) (cdr selection)) | |
| 305 end (max (car selection) (cdr selection)) | |
| 306 valid (and valid | |
| 307 (eq (marker-buffer (car selection)) | |
| 308 (extent-object previous-extent))) | |
| 309 buffer (marker-buffer (car selection)))) | |
| 310 ((extentp selection) | |
| 311 (setq start (extent-start-position selection) | |
| 312 end (extent-end-position selection) | |
| 313 valid (and valid | |
| 314 (eq (extent-object selection) | |
| 315 (extent-object previous-extent))) | |
| 316 buffer (extent-object selection))) | |
| 317 (t | |
| 318 (signal 'error (list "invalid selection" selection)))) | |
| 319 | |
| 320 (if valid | |
| 321 nil | |
| 322 (condition-case () | |
| 323 (if (listp previous-extent) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
324 (mapc 'delete-extent previous-extent) |
| 428 | 325 (delete-extent previous-extent)) |
| 326 (error nil))) | |
| 327 | |
| 328 (if (not buffer) | |
| 329 ;; string case | |
| 330 nil | |
| 331 ;; normal case | |
| 332 (if valid | |
| 333 (set-extent-endpoints previous-extent start end) | |
| 334 (setq previous-extent (make-extent start end buffer)) | |
| 335 | |
| 336 ;; Make the extent be closed on the right, which means that if | |
| 337 ;; characters are inserted exactly at the end of the extent, the | |
| 338 ;; extent will grow to cover them. This is important for shell | |
| 339 ;; buffers - suppose one makes a selection, and one end is at | |
| 340 ;; point-max. If the shell produces output, that marker will remain | |
| 341 ;; at point-max (its position will increase). So it's important that | |
| 342 ;; the extent exhibit the same behavior, lest the region covered by | |
| 343 ;; the extent (the visual indication), and the region between point | |
| 344 ;; and mark (the actual selection value) become different! | |
| 345 (set-extent-property previous-extent 'end-open nil) | |
| 346 | |
| 347 (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
|
348 ((and-fboundp 'mouse-track-rectangle-p |
| 4222 | 349 (mouse-track-rectangle-p |
| 350 (setq previous-extent (list previous-extent)) | |
| 351 (default-mouse-track-next-move-rect start end previous-extent) | |
| 352 )))) | |
| 428 | 353 previous-extent)))) |
| 354 | |
| 355 (defun valid-simple-selection-p (data) | |
| 442 | 356 "An obsolete function that tests whether something was a valid simple |
| 357 selection using the old XEmacs selection support. You shouldn't use this | |
| 358 any more, because just about anything could be a valid selection now." | |
| 428 | 359 (or (stringp data) |
| 360 ;FSFmacs huh?? (symbolp data) | |
| 361 (integerp data) | |
| 362 (and (consp data) | |
| 363 (integerp (car data)) | |
| 364 (or (integerp (cdr data)) | |
| 365 (and (consp (cdr data)) | |
| 366 (integerp (car (cdr data)))))) | |
| 367 (extentp data) | |
| 368 (and (consp data) | |
| 369 (markerp (car data)) | |
| 370 (markerp (cdr data)) | |
| 371 (marker-buffer (car data)) | |
| 372 (marker-buffer (cdr data)) | |
| 373 (eq (marker-buffer (car data)) | |
| 374 (marker-buffer (cdr data))) | |
| 375 (buffer-live-p (marker-buffer (car data))) | |
| 376 (buffer-live-p (marker-buffer (cdr data)))))) | |
| 377 | |
| 378 (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
|
379 (or (memq mode '(cut copy clear)) (error "unknown mode %S" mode)) |
| 428 | 380 (or (selection-owner-p) |
| 381 (error "XEmacs does not own the primary selection")) | |
| 382 (setq last-command nil) | |
| 383 (or primary-selection-extent | |
| 384 (error "the primary selection is not an extent?")) | |
| 385 (save-excursion | |
| 386 (let (rect-p b s e) | |
| 387 (cond | |
| 388 ((consp primary-selection-extent) | |
| 389 (setq rect-p t | |
| 390 b (extent-object (car primary-selection-extent)) | |
| 391 s (extent-start-position (car primary-selection-extent)) | |
| 392 e (extent-end-position (car (reverse primary-selection-extent))))) | |
| 393 (t | |
| 394 (setq rect-p nil | |
| 395 b (extent-object primary-selection-extent) | |
| 396 s (extent-start-position primary-selection-extent) | |
| 397 e (extent-end-position primary-selection-extent)))) | |
| 398 (set-buffer b) | |
| 399 (cond ((memq mode '(cut copy)) | |
| 400 (if rect-p | |
| 401 (progn | |
| 851 | 402 ;; killed-rectangle is defvarred in rect.el |
| 428 | 403 (setq killed-rectangle (extract-rectangle s e)) |
| 404 (kill-new (mapconcat #'identity killed-rectangle "\n"))) | |
| 405 (copy-region-as-kill s e)) | |
| 406 ;; Maybe killing doesn't own clipboard. Make sure it happens. | |
| 407 ;; This memq is kind of grody, because they might have done it | |
| 408 ;; some other way, but owning the clipboard twice in that case | |
| 409 ;; wouldn't actually hurt anything. | |
| 410 (or (and (consp kill-hooks) (memq 'own-clipboard kill-hooks)) | |
| 851 | 411 (eq 'own-clipboard interprogram-cut-function) |
| 428 | 412 (own-clipboard (car kill-ring))))) |
| 413 (cond ((memq mode '(cut clear)) | |
| 414 (if rect-p | |
| 415 (delete-rectangle s e) | |
| 416 (delete-region s e)))) | |
| 417 (disown-selection nil) | |
| 418 ))) | |
| 419 | |
| 442 | 420 |
| 428 | 421 ;;; Functions to convert the selection into various other selection |
| 442 | 422 ;;; types. |
| 423 | |
| 424 ;; These next three functions get called by C code... | |
| 425 (defun select-convert-in (selection type value) | |
| 426 "Attempt to convert the specified external VALUE to the specified DATA-TYPE, | |
| 427 for the specified SELECTION. Return nil if this is impossible, or a | |
| 428 suitable internal representation otherwise." | |
|
5618
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
429 (and value |
|
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
430 (funcall (or (cdr (assq type selection-converter-in-alist)) #'ignore) |
|
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
431 selection type value))) |
| 428 | 432 |
| 442 | 433 (defun select-convert-out (selection type value) |
| 434 "Attempt to convert the specified internal VALUE for the specified DATA-TYPE | |
| 435 and SELECTION. Return nil if this is impossible, or a suitable external | |
| 436 representation otherwise." | |
|
5618
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
437 (and value |
|
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
438 (funcall (or (cdr (assq type selection-converter-out-alist)) #'ignore) |
|
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
439 selection type value))) |
| 442 | 440 |
| 441 (defun select-coerce (selection type value) | |
| 442 "Attempt to convert the specified internal VALUE to a representation | |
| 443 suitable for return from `get-selection' in the specified DATA-TYPE. Return | |
| 444 nil if this is impossible, or a suitable representation otherwise." | |
|
5618
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
445 (and value |
|
5644
0df3cedee9ac
select-coercion-alist, not select-conversion-alist, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5618
diff
changeset
|
446 (funcall (or (cdr (assq type selection-coercion-alist)) #'ignore) |
|
5618
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
447 selection type value))) |
| 442 | 448 |
| 449 ;; The rest of the functions on this "page" are conversion handlers, | |
| 450 ;; append handlers and buffer-kill handlers. | |
| 428 | 451 (defun select-convert-to-text (selection type value) |
| 452 (cond ((stringp value) | |
|
5571
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
453 (substring-no-properties value)) |
| 428 | 454 ((extentp value) |
| 455 (save-excursion | |
| 456 (set-buffer (extent-object value)) | |
| 457 (save-restriction | |
| 458 (widen) | |
|
5571
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
459 (buffer-substring-no-properties (extent-start-position value) |
|
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
460 (extent-end-position value))))) |
| 428 | 461 ((and (consp value) |
| 462 (markerp (car value)) | |
| 463 (markerp (cdr value))) | |
| 464 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) | |
| 465 (signal 'error | |
| 466 (list "markers must be in the same buffer" | |
| 467 (car value) (cdr value)))) | |
| 468 (save-excursion | |
| 469 (set-buffer (or (marker-buffer (car value)) | |
| 470 (error "selection is in a killed buffer"))) | |
| 471 (save-restriction | |
| 472 (widen) | |
|
5571
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
473 (buffer-substring-no-properties (car value) (cdr value))))) |
| 428 | 474 (t nil))) |
| 475 | |
| 2624 | 476 (defun select-convert-to-timestamp (selection type value) |
| 477 (let ((ts (get-xemacs-selection-timestamp selection))) | |
| 478 (if ts (cons 'TIMESTAMP ts)))) | |
| 479 | |
| 480 (defun select-convert-to-utf-8-text (selection type value) | |
| 481 (cond ((stringp value) | |
|
5571
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
482 (cons 'UTF8_STRING (encode-coding-string |
|
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
483 (substring-no-properties value) 'utf-8))) |
| 2624 | 484 ((extentp value) |
| 485 (save-excursion | |
| 486 (set-buffer (extent-object value)) | |
| 487 (save-restriction | |
| 488 (widen) | |
| 489 (cons 'UTF8_STRING | |
|
5571
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
490 (encode-coding-string (buffer-substring-no-properties |
|
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
491 (extent-start-position value) |
|
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
492 (extent-end-position value)) |
|
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
493 'utf-8))))) |
| 2624 | 494 ((and (consp value) |
| 495 (markerp (car value)) | |
| 496 (markerp (cdr value))) | |
| 497 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) | |
| 498 (signal 'error | |
| 499 (list "markers must be in the same buffer" | |
| 500 (car value) (cdr value)))) | |
| 501 (save-excursion | |
| 502 (set-buffer (or (marker-buffer (car value)) | |
| 503 (error "selection is in a killed buffer"))) | |
| 504 (save-restriction | |
| 505 (widen) | |
| 506 (cons 'UTF8_STRING (encode-coding-string | |
|
5571
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
507 (buffer-substring-no-properties |
|
5273dd66a1ba
Strip extent information when passing text to external programs, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
508 (car value) (cdr value)) 'utf-8))))) |
| 2624 | 509 (t nil))) |
| 510 | |
| 442 | 511 (defun select-coerce-to-text (selection type value) |
| 512 (select-convert-to-text selection type value)) | |
| 513 | |
| 428 | 514 (defun select-convert-to-string (selection type value) |
| 515 (let ((outval (select-convert-to-text selection type value))) | |
| 442 | 516 ;; force the string to be not in Compound Text format. This grubby |
| 517 ;; hack will go soon, to be replaced by a more general mechanism. | |
| 428 | 518 (if (stringp outval) |
| 519 (cons 'STRING outval) | |
| 520 outval))) | |
| 521 | |
| 522 (defun select-convert-to-compound-text (selection type value) | |
| 523 ;; converts to compound text automatically | |
| 524 (select-convert-to-text selection type value)) | |
| 525 | |
| 526 (defun select-convert-to-length (selection type value) | |
| 527 (let ((value | |
| 528 (cond ((stringp value) | |
| 529 (length value)) | |
| 530 ((extentp value) | |
| 531 (extent-length value)) | |
| 532 ((and (consp value) | |
| 533 (markerp (car value)) | |
| 534 (markerp (cdr value))) | |
| 535 (or (eq (marker-buffer (car value)) | |
| 536 (marker-buffer (cdr value))) | |
| 537 (signal 'error | |
| 538 (list "markers must be in the same buffer" | |
| 539 (car value) (cdr value)))) | |
| 540 (abs (- (car value) (cdr value))))))) | |
| 541 (if value ; force it to be in 32-bit format. | |
| 542 (cons (ash value -16) (logand value 65535)) | |
| 543 nil))) | |
| 544 | |
| 545 (defun select-convert-to-targets (selection type value) | |
| 546 ;; return a vector of atoms, but remove duplicates first. | |
|
5618
cc1ec4c93a67
Improve Lisp style in a few places, select.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5571
diff
changeset
|
547 (delete-duplicates (map 'vector #'car selection-converter-out-alist))) |
| 428 | 548 |
| 549 (defun select-convert-to-delete (selection type value) | |
| 550 (disown-selection-internal selection) | |
| 551 ;; A return value of nil means that we do not know how to do this conversion, | |
| 552 ;; and replies with an "error". A return value of NULL means that we have | |
| 553 ;; done the conversion (and any side-effects) but have no value to return. | |
| 554 'NULL) | |
| 555 | |
| 556 (defun select-convert-to-filename (selection type value) | |
| 557 (cond ((extentp value) | |
| 558 (buffer-file-name (or (extent-object value) | |
| 559 (error "selection is in a killed buffer")))) | |
| 560 ((and (consp value) | |
| 561 (markerp (car value)) | |
| 562 (markerp (cdr value))) | |
| 563 (buffer-file-name (or (marker-buffer (car value)) | |
| 564 (error "selection is in a killed buffer")))) | |
| 565 (t nil))) | |
| 566 | |
| 567 (defun select-convert-to-charpos (selection type value) | |
| 568 (let (a b tmp) | |
| 569 (cond ((cond ((extentp value) | |
| 570 (setq a (extent-start-position value) | |
| 571 b (extent-end-position value))) | |
| 572 ((and (consp value) | |
| 573 (markerp (car value)) | |
| 574 (markerp (cdr value))) | |
| 575 (setq a (car value) | |
| 576 b (cdr value)))) | |
| 577 (setq a (1- a) b (1- b)) ; zero-based | |
| 578 (if (< b a) (setq tmp a a b b tmp)) | |
| 579 (cons 'SPAN | |
| 580 (vector (cons (ash a -16) (logand a 65535)) | |
| 581 (cons (ash b -16) (logand b 65535)))))))) | |
| 582 | |
| 583 (defun select-convert-to-lineno (selection type value) | |
| 584 (let (a b buf tmp) | |
| 585 (cond ((cond ((extentp value) | |
| 586 (setq buf (extent-object value) | |
| 587 a (extent-start-position value) | |
| 588 b (extent-end-position value))) | |
| 589 ((and (consp value) | |
| 590 (markerp (car value)) | |
| 591 (markerp (cdr value))) | |
| 592 (setq a (marker-position (car value)) | |
| 593 b (marker-position (cdr value)) | |
| 594 buf (marker-buffer (car value))))) | |
| 595 (save-excursion | |
| 596 (set-buffer buf) | |
| 597 (save-restriction | |
| 598 (widen) | |
| 599 (goto-char a) | |
| 600 (beginning-of-line) | |
| 601 (setq a (1+ (count-lines 1 (point)))) | |
| 602 (goto-char b) | |
| 603 (beginning-of-line) | |
| 604 (setq b (1+ (count-lines 1 (point)))))) | |
| 605 (if (< b a) (setq tmp a a b b tmp)) | |
| 606 (cons 'SPAN | |
| 607 (vector (cons (ash a -16) (logand a 65535)) | |
| 608 (cons (ash b -16) (logand b 65535)))))))) | |
| 609 | |
| 610 (defun select-convert-to-colno (selection type value) | |
| 611 (let (a b buf tmp) | |
| 612 (cond ((cond ((extentp value) | |
| 613 (setq buf (extent-object value) | |
| 614 a (extent-start-position value) | |
| 615 b (extent-end-position value))) | |
| 616 ((and (consp value) | |
| 617 (markerp (car value)) | |
| 618 (markerp (cdr value))) | |
| 619 (setq a (car value) | |
| 620 b (cdr value) | |
| 621 buf (marker-buffer a)))) | |
| 622 (save-excursion | |
| 623 (set-buffer buf) | |
| 624 (goto-char a) | |
| 625 (setq a (current-column)) | |
| 626 (goto-char b) | |
| 627 (setq b (current-column))) | |
| 628 (if (< b a) (setq tmp a a b b tmp)) | |
| 629 (cons 'SPAN | |
| 630 (vector (cons (ash a -16) (logand a 65535)) | |
| 631 (cons (ash b -16) (logand b 65535)))))))) | |
| 632 | |
| 633 (defun select-convert-to-sourceloc (selection type value) | |
| 634 (let (a b buf file-name tmp) | |
| 635 (cond ((cond ((extentp value) | |
| 636 (setq buf (or (extent-object value) | |
| 637 (error "selection is in a killed buffer")) | |
| 638 a (extent-start-position value) | |
| 639 b (extent-end-position value) | |
| 640 file-name (buffer-file-name buf))) | |
| 641 ((and (consp value) | |
| 642 (markerp (car value)) | |
| 643 (markerp (cdr value))) | |
| 644 (setq a (marker-position (car value)) | |
| 645 b (marker-position (cdr value)) | |
| 646 buf (or (marker-buffer (car value)) | |
| 647 (error "selection is in a killed buffer")) | |
| 648 file-name (buffer-file-name buf)))) | |
| 649 (save-excursion | |
| 650 (set-buffer buf) | |
| 651 (save-restriction | |
| 652 (widen) | |
| 653 (goto-char a) | |
| 654 (beginning-of-line) | |
| 655 (setq a (1+ (count-lines 1 (point)))) | |
| 656 (goto-char b) | |
| 657 (beginning-of-line) | |
| 658 (setq b (1+ (count-lines 1 (point)))))) | |
| 659 (if (< b a) (setq tmp a a b b tmp)) | |
| 660 (format "%s:%d" file-name a))))) | |
| 661 | |
| 662 (defun select-convert-to-os (selection type size) | |
| 663 (symbol-name system-type)) | |
| 664 | |
| 665 (defun select-convert-to-host (selection type size) | |
| 666 (system-name)) | |
| 667 | |
| 668 (defun select-convert-to-user (selection type size) | |
| 669 (user-full-name)) | |
| 670 | |
| 671 (defun select-convert-to-class (selection type size) | |
| 442 | 672 (symbol-value 'x-emacs-application-class)) |
| 428 | 673 |
| 674 ;; We do not try to determine the name Emacs was invoked with, | |
| 675 ;; because it is not clean for a program's behavior to depend on that. | |
| 676 (defun select-convert-to-name (selection type size) | |
| 677 ;invocation-name | |
| 678 "xemacs") | |
| 679 | |
| 680 (defun select-convert-to-integer (selection type value) | |
| 681 (and (integerp value) | |
| 682 (cons (ash value -16) (logand value 65535)))) | |
| 683 | |
| 442 | 684 ;; Can convert from the following integer representations |
| 685 ;; | |
| 686 ;; integer | |
| 687 ;; (integer . integer) | |
| 688 ;; (integer integer) | |
| 689 ;; (list [integer|(integer . integer)]*) | |
| 690 ;; (vector [integer|(integer . integer)]*) | |
| 691 ;; | |
| 692 ;; Cons'd integers get cleaned up a little. | |
| 693 | |
| 694 (defun select-convert-from-integer (selection type value) | |
| 695 (cond ((integerp value) ; Integer | |
| 696 value) | |
| 444 | 697 |
| 442 | 698 ((and (consp value) ; (integer . integer) |
| 699 (integerp (car value)) | |
| 700 (integerp (cdr value))) | |
| 701 (if (eq (car value) 0) | |
| 702 (cdr value) | |
| 703 (if (and (eq (car value) -1) | |
| 704 (< (cdr value) 0)) | |
| 705 (cdr value) | |
| 706 value))) | |
| 444 | 707 |
| 442 | 708 ((and (listp value) ; (integer integer) |
| 709 (eq (length value) 2) | |
| 710 (integerp (car value)) | |
| 711 (integerp (cadr value))) | |
| 712 (if (eq (car value) 0) | |
| 713 (cadr value) | |
| 714 (if (and (eq (car value) -1) | |
| 715 (< (cdr value) 0)) | |
| 716 (- (cadr value)) | |
| 717 (cons (car value) (cadr value))))) | |
| 444 | 718 |
| 442 | 719 ((listp value) ; list |
| 720 (if (cdr value) | |
| 4021 | 721 (mapcar #'(lambda (x) |
| 722 (select-convert-from-integer selection type x)) | |
| 442 | 723 value) |
| 724 (select-convert-from-integer selection type (car value)))) | |
| 444 | 725 |
| 442 | 726 ((vectorp value) ; vector |
| 727 (if (eq (length value) 1) | |
| 728 (select-convert-from-integer selection type (aref value 0)) | |
| 4021 | 729 (mapvector #'(lambda (x) |
| 730 (select-convert-from-integer selection type x)) | |
| 731 value))) | |
| 444 | 732 |
| 442 | 733 (t nil) |
| 734 )) | |
| 735 | |
| 2624 | 736 (defun select-convert-from-ip-address (selection type value) |
| 737 (if (and (stringp value) | |
| 738 (= (length value) 4)) | |
| 739 (format "%d.%d.%d.%d" | |
| 740 (aref value 0) (aref value 1) (aref value 2) (aref value 3)))) | |
| 741 | |
| 428 | 742 (defun select-convert-to-atom (selection type value) |
| 743 (and (symbolp value) value)) | |
| 744 | |
| 2624 | 745 (defun select-convert-from-utf-8-text (selection type value) |
| 746 (decode-coding-string value 'utf-8)) | |
| 747 | |
| 748 (defun select-convert-from-utf-16-le-text (selection type value) | |
| 749 (decode-coding-string value 'utf-16-le)) | |
| 750 | |
| 751 ;; Image conversion. | |
| 752 (defun select-convert-from-image-data (image-type value) | |
| 753 "Take an image type specification--one of the image types this XEmacs | |
| 754 supports--and some data in that format, return a space, with a glyph | |
| 755 corresponding to that data as an end-glyph extent property of that space. " | |
| 756 (let* ((str (make-string 1 ?\ )) | |
| 757 (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
|
758 (glyph (make-glyph (vector image-type :data value)))) |
| 2624 | 759 (when glyph |
| 760 (set-extent-property extent 'invisible t) | |
| 761 (set-extent-property extent 'start-open t) | |
| 762 (set-extent-property extent 'end-open t) | |
| 763 (set-extent-property extent 'duplicable t) | |
| 764 (set-extent-property extent 'atomic t) | |
| 765 (set-extent-end-glyph extent glyph) | |
| 766 str))) | |
| 767 | |
|
5364
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
768 (macrolet |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
769 ((create-image-functions (&rest formats) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
770 (cons |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
771 'progn |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
772 (mapcar |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
773 #'(lambda (format) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
774 `(if (featurep ',format) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
775 (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
|
776 ,(symbol-name format))) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
777 #'(lambda (selection type value) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
778 (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
|
779 value))))) formats)))) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
780 (create-image-functions gif jpeg png tiff xpm xbm)) |
| 2624 | 781 |
| 442 | 782 ;;; CF_xxx conversions |
| 783 (defun select-convert-from-cf-text (selection type value) | |
| 2624 | 784 (if (find-coding-system 'mswindows-multibyte) |
| 785 (let ((value (decode-coding-string value 'mswindows-multibyte))) | |
| 786 (replace-in-string (if (string-match "\0" value) | |
| 787 (substring value 0 (match-beginning 0)) | |
| 788 value) | |
| 789 "\\(\r\n\\|\n\r\\)" "\n" t)))) | |
| 771 | 790 |
| 791 (defun select-convert-from-cf-unicodetext (selection type value) | |
| 2624 | 792 (if (find-coding-system 'mswindows-unicode) |
| 793 (let ((value (decode-coding-string value 'mswindows-unicode))) | |
| 794 (replace-in-string (if (string-match "\0" value) | |
| 795 (substring value 0 (match-beginning 0)) | |
| 796 value) | |
| 797 "\\(\r\n\\|\n\r\\)" "\n" t)))) | |
| 442 | 798 |
| 799 (defun select-convert-to-cf-text (selection type value) | |
| 2624 | 800 (if (find-coding-system 'mswindows-multibyte) |
| 801 (let ((text (select-convert-to-text selection type value))) | |
| 802 (encode-coding-string | |
| 803 (concat (replace-in-string text "\n" "\r\n" t) "\0") | |
| 804 'mswindows-multibyte)))) | |
| 771 | 805 |
| 806 (defun select-convert-to-cf-unicodetext (selection type value) | |
| 2624 | 807 (if (find-coding-system 'mswindows-unicode) |
| 808 (let ((text (select-convert-to-text selection type value))) | |
| 809 (encode-coding-string | |
| 810 (concat (replace-in-string text "\n" "\r\n" t) "\0") | |
| 811 'mswindows-unicode)))) | |
| 442 | 812 |
| 813 ;;; Appenders | |
| 814 (defun select-append-to-text (selection type value1 value2) | |
| 815 (let ((text1 (select-convert-to-text selection 'STRING value1)) | |
| 816 (text2 (select-convert-to-text selection 'STRING value2))) | |
| 817 (if (and text1 text2) | |
| 818 (concat text1 text2) | |
| 819 nil))) | |
| 820 | |
| 821 (defun select-append-to-string (selection type value1 value2) | |
| 822 (select-append-to-text selection type value1 value2)) | |
| 823 | |
| 824 (defun select-append-to-compound-text (selection type value1 value2) | |
| 825 (select-append-to-text selection type value1 value2)) | |
| 826 | |
| 827 (defun select-append-to-cf-text (selection type value1 value2) | |
| 828 (let ((text1 (select-convert-from-cf-text selection 'CF_TEXT value1)) | |
| 829 (text2 (select-convert-from-cf-text selection 'CF_TEXT value2))) | |
| 830 (if (and text1 text2) | |
| 831 (select-convert-to-cf-text selection type (concat text1 text2)) | |
| 832 nil))) | |
| 428 | 833 |
| 771 | 834 (defun select-append-to-cf-unicodetext (selection type value1 value2) |
| 835 (let ((text1 (select-convert-from-cf-unicodetext selection | |
| 836 'CF_UNICODETEXT value1)) | |
| 837 (text2 (select-convert-from-cf-unicodetext selection | |
| 838 'CF_UNICODETEXT value2))) | |
| 839 (if (and text1 text2) | |
| 840 (select-convert-to-cf-unicodetext selection type (concat text1 text2)) | |
| 841 nil))) | |
| 842 | |
| 442 | 843 (defun select-append-default (selection type value1 value2) |
| 844 ;; This appender gets used if the type is "nil" - i.e. default. | |
| 845 ;; It should probably have more cases implemented than it does - e.g. | |
| 846 ;; appending numbers to strings, etc... | |
| 847 (cond ((and (stringp value1) (stringp value2)) | |
| 848 (select-append-to-string selection 'STRING value1 value2)) | |
| 849 (t nil))) | |
| 850 | |
| 851 ;;; Buffer kill handlers | |
| 852 | |
| 853 (defun select-buffer-killed-default (selection type value buffer) | |
| 854 ;; This handler gets used if the type is "nil". | |
| 855 (cond ((extentp value) | |
| 856 (if (eq (extent-object value) buffer) | |
| 857 ; If this selection is on the clipboard, grab it quick | |
| 858 (when (eq selection 'CLIPBOARD) | |
| 859 (save-excursion | |
| 860 (set-buffer (extent-object value)) | |
| 861 (save-restriction | |
| 862 (widen) | |
| 863 (buffer-substring (extent-start-position value) | |
| 864 (extent-end-position value))))) | |
| 865 value)) | |
| 866 ((markerp value) | |
| 867 (unless (eq (marker-buffer value) buffer) | |
| 868 value)) | |
| 869 ((and (consp value) | |
| 870 (markerp (car value)) | |
| 871 (markerp (cdr value))) | |
| 872 (if (or (eq (marker-buffer (car value)) buffer) | |
| 873 (eq (marker-buffer (cdr value)) buffer)) | |
| 874 ; If this selection is on the clipboard, grab it quick | |
| 875 (when (eq selection 'CLIPBOARD) | |
| 876 (save-excursion | |
| 877 (set-buffer (marker-buffer (car value))) | |
| 878 (save-restriction | |
| 879 (widen) | |
| 880 (buffer-substring (car value) (cdr value))))) | |
| 881 value)) | |
| 882 (t value))) | |
| 883 | |
| 884 (defun select-buffer-killed-text (selection type value buffer) | |
| 885 (select-buffer-killed-default selection type value buffer)) | |
| 444 | 886 |
| 442 | 887 ;; Types listed in here can be selections of XEmacs |
| 888 (setq selection-converter-out-alist | |
| 2624 | 889 '((TIMESTAMP . select-convert-to-timestamp) |
| 890 (UTF8_STRING . select-convert-to-utf-8-text) | |
| 891 (TEXT . select-convert-to-text) | |
| 428 | 892 (STRING . select-convert-to-string) |
| 893 (COMPOUND_TEXT . select-convert-to-compound-text) | |
| 894 (TARGETS . select-convert-to-targets) | |
| 895 (LENGTH . select-convert-to-length) | |
| 896 (DELETE . select-convert-to-delete) | |
| 897 (FILE_NAME . select-convert-to-filename) | |
| 898 (CHARACTER_POSITION . select-convert-to-charpos) | |
| 899 (SOURCE_LOC . select-convert-to-sourceloc) | |
| 900 (LINE_NUMBER . select-convert-to-lineno) | |
| 901 (COLUMN_NUMBER . select-convert-to-colno) | |
| 902 (OWNER_OS . select-convert-to-os) | |
| 903 (HOST_NAME . select-convert-to-host) | |
| 904 (USER . select-convert-to-user) | |
| 905 (CLASS . select-convert-to-class) | |
| 906 (NAME . select-convert-to-name) | |
| 907 (ATOM . select-convert-to-atom) | |
| 908 (INTEGER . select-convert-to-integer) | |
| 442 | 909 (CF_TEXT . select-convert-to-cf-text) |
| 771 | 910 (CF_UNICODETEXT . select-convert-to-cf-unicodetext) |
| 442 | 911 )) |
| 912 | |
| 913 ;; Types listed here can be selections foreign to XEmacs | |
| 914 (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
|
915 `(; Specific types that get handled by generic converters |
| 442 | 916 (INTEGER . select-convert-from-integer) |
| 2624 | 917 (TIMESTAMP . select-convert-from-integer) |
| 918 (LENGTH . select-convert-from-integer) | |
| 919 (LIST_LENGTH . select-convert-from-integer) | |
| 920 (CLIENT_WINDOW . select-convert-from-integer) | |
| 921 (PROCESS . select-convert-from-integer) | |
| 922 (IP_ADDRESS . select-convert-from-ip-address) | |
| 923 ;; We go after UTF8_STRING in preference to STRING because Mozilla, | |
| 924 ;; at least, does bad things with non-Latin-1 Unicode characters in | |
| 925 ;; STRING. | |
| 926 (UTF8_STRING . select-convert-from-utf-8-text) | |
| 442 | 927 (CF_TEXT . select-convert-from-cf-text) |
| 771 | 928 (CF_UNICODETEXT . select-convert-from-cf-unicodetext) |
| 2624 | 929 (text/html . select-convert-from-utf-16-le-text) ; Mozilla |
| 930 (text/_moz_htmlcontext . select-convert-from-utf-16-le-text) | |
| 931 (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
|
932 ,@(loop |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
933 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
|
934 nconc (if (featurep format) |
|
0f9aa4eb4bec
Make my Lisp a little more sophisticated, select.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
935 (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
|
936 (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
|
937 format)))))))) |
| 428 | 938 |
| 442 | 939 ;; Types listed here have special coercion functions that can munge |
| 940 ;; other types. This can also be used to add special features - e.g. | |
| 941 ;; being able to pass a region or a cons of markers to own-selection, | |
| 942 ;; but getting the *current* text in the region back when calling | |
| 943 ;; get-selection. | |
| 944 ;; | |
| 945 ;; Any function listed in here *will be called* whenever a value of | |
| 946 ;; its type is retrieved from the internal selection cache, or when | |
| 947 ;; no suitable values could be found in which case XEmacs looks for | |
| 948 ;; values with types listed in selection-coercible-types. | |
| 949 (setq selection-coercion-alist | |
| 950 '((TEXT . select-coerce-to-text) | |
| 951 (STRING . select-coerce-to-text) | |
| 952 (COMPOUND_TEXT . select-coerce-to-text) | |
| 771 | 953 (CF_TEXT . select-coerce-to-text) |
| 954 (CF_UNICODETEXT . select-coerce-to-text) | |
| 955 )) | |
| 442 | 956 |
| 957 ;; Types listed here can be appended by own-selection | |
| 958 (setq selection-appender-alist | |
| 959 '((nil . select-append-default) | |
| 960 (TEXT . select-append-to-text) | |
| 961 (STRING . select-append-to-string) | |
| 962 (COMPOUND_TEXT . select-append-to-compound-text) | |
| 963 (CF_TEXT . select-append-to-cf-text) | |
| 771 | 964 (CF_UNICODETEXT . select-append-to-cf-unicodetext) |
| 442 | 965 )) |
| 966 | |
| 967 ;; Types listed here have buffer-kill handlers | |
| 968 (setq selection-buffer-killed-alist | |
| 969 '((nil . select-buffer-killed-default) | |
| 970 (TEXT . select-buffer-killed-text) | |
| 971 (STRING . select-buffer-killed-text) | |
| 972 (COMPOUND_TEXT . select-buffer-killed-text) | |
| 771 | 973 (CF_TEXT . select-buffer-killed-text) |
| 974 (CF_UNICODETEXT . select-buffer-killed-text) | |
| 975 )) | |
| 442 | 976 |
| 977 ;; Lists of types that are coercible (can be converted to other types) | |
| 771 | 978 (setq selection-coercible-types '(TEXT STRING COMPOUND_TEXT CF_TEXT CF_UNICODETEXT)) |
| 442 | 979 |
| 428 | 980 ;;; select.el ends here |
