diff options
| author | Kenichi Handa | 2002-08-14 00:57:55 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2002-08-14 00:57:55 +0000 |
| commit | eb1416b9bcf82289fd2ad9389bafe135da9483db (patch) | |
| tree | b218e0ab290d5498e242a99d1b8c53c2d99a062e | |
| parent | 79fab26b4fcbb64d4f6e79cb4abb852b65b94ea2 (diff) | |
| download | emacs-eb1416b9bcf82289fd2ad9389bafe135da9483db.tar.gz emacs-eb1416b9bcf82289fd2ad9389bafe135da9483db.zip | |
(xselect-convert-to-string): If TYPE is non-nil,
encode the selection data string. Always return cons of type and
string.
(selection-converter-alist): Add (UTF8_STRING .
xselect-convert-to-string).
| -rw-r--r-- | lisp/select.el | 102 |
1 files changed, 79 insertions, 23 deletions
diff --git a/lisp/select.el b/lisp/select.el index 801db31cb61..6f9fa1fd042 100644 --- a/lisp/select.el +++ b/lisp/select.el | |||
| @@ -133,29 +133,84 @@ Cut buffers are considered obsolete; you should use selections instead." | |||
| 133 | ;;; for TIMESTAMP, which is a special case. | 133 | ;;; for TIMESTAMP, which is a special case. |
| 134 | 134 | ||
| 135 | (defun xselect-convert-to-string (selection type value) | 135 | (defun xselect-convert-to-string (selection type value) |
| 136 | (cond ((stringp value) | 136 | (let (str coding) |
| 137 | ;; Return the type as well, so that xselect.c could honor | 137 | ;; Get the actual string from VALUE. |
| 138 | ;; requests whose type is STRING. | 138 | (cond ((stringp value) |
| 139 | (cons type value)) | 139 | (setq str value)) |
| 140 | ((overlayp value) | 140 | |
| 141 | (save-excursion | 141 | ((overlayp value) |
| 142 | (or (buffer-name (overlay-buffer value)) | 142 | (save-excursion |
| 143 | (error "selection is in a killed buffer")) | 143 | (or (buffer-name (overlay-buffer value)) |
| 144 | (set-buffer (overlay-buffer value)) | 144 | (error "selection is in a killed buffer")) |
| 145 | (buffer-substring (overlay-start value) | 145 | (set-buffer (overlay-buffer value)) |
| 146 | (overlay-end value)))) | 146 | (setq str (buffer-substring (overlay-start value) |
| 147 | ((and (consp value) | 147 | (overlay-end value))))) |
| 148 | (markerp (car value)) | 148 | ((and (consp value) |
| 149 | (markerp (cdr value))) | 149 | (markerp (car value)) |
| 150 | (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) | 150 | (markerp (cdr value))) |
| 151 | (signal 'error | 151 | (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) |
| 152 | (list "markers must be in the same buffer" | 152 | (signal 'error |
| 153 | (car value) (cdr value)))) | 153 | (list "markers must be in the same buffer" |
| 154 | (save-excursion | 154 | (car value) (cdr value)))) |
| 155 | (set-buffer (or (marker-buffer (car value)) | 155 | (save-excursion |
| 156 | (error "selection is in a killed buffer"))) | 156 | (set-buffer (or (marker-buffer (car value)) |
| 157 | (buffer-substring (car value) (cdr value)))) | 157 | (error "selection is in a killed buffer"))) |
| 158 | (t nil))) | 158 | (setq str (buffer-substring (car value) (cdr value)))))) |
| 159 | |||
| 160 | (when str | ||
| 161 | ;; If TYPE is nil, this is a local request, thus return STR as | ||
| 162 | ;; is. Otherwise, encode STR. | ||
| 163 | (if (not type) | ||
| 164 | str | ||
| 165 | (setq coding (or next-selection-coding-system selection-coding-system)) | ||
| 166 | (if coding | ||
| 167 | (setq coding (coding-system-base coding)) | ||
| 168 | (setq coding 'raw-text)) | ||
| 169 | ;; Suppress producing escape sequences for compositions. | ||
| 170 | (remove-text-properties 0 (length str) '(composition nil) str) | ||
| 171 | (cond | ||
| 172 | ((eq type 'TEXT) | ||
| 173 | (if (not (multibyte-string-p str)) | ||
| 174 | ;; Don't have to encode unibyte string. | ||
| 175 | (setq type 'STRING) | ||
| 176 | ;; If STR contains only ASCII, Latin-1, and raw bytes, | ||
| 177 | ;; encode STR by iso-latin-1, and return it as type | ||
| 178 | ;; `STRING'. Otherwise, encode STR by CODING. In that | ||
| 179 | ;; case, the returing type depends on CODING. | ||
| 180 | (let ((charsets (find-charset-string str))) | ||
| 181 | (setq charsets | ||
| 182 | (delq 'ascii | ||
| 183 | (delq 'latin-iso8859-1 | ||
| 184 | (delq 'eight-bit-control | ||
| 185 | (delq 'eight-bit-graphic charsets))))) | ||
| 186 | (if charsets | ||
| 187 | (setq str (encode-coding-string str coding) | ||
| 188 | type (if (memq coding '(compound-text | ||
| 189 | compound-text-with-extensions)) | ||
| 190 | 'COMPOUND_TEXT | ||
| 191 | 'STRING)) | ||
| 192 | (setq type 'STRING | ||
| 193 | str (encode-coding-string str 'iso-latin-1)))))) | ||
| 194 | |||
| 195 | ((eq type 'COMPOUND_TEXT) | ||
| 196 | (setq str (encode-coding-string str coding))) | ||
| 197 | |||
| 198 | ((eq type 'STRING) | ||
| 199 | (if (memq coding '(compound-text | ||
| 200 | compound-text-with-extensions)) | ||
| 201 | (setq str (string-make-unibyte str)) | ||
| 202 | (setq str (encode-coding-string str coding)))) | ||
| 203 | |||
| 204 | ((eq type 'UTF8_STRING) | ||
| 205 | (setq str (encode-coding-string str 'utf-8))) | ||
| 206 | |||
| 207 | (t | ||
| 208 | (error "Unknow selection type: %S" type)) | ||
| 209 | )) | ||
| 210 | |||
| 211 | (setq next-selection-coding-system nil) | ||
| 212 | (cons type str)))) | ||
| 213 | |||
| 159 | 214 | ||
| 160 | (defun xselect-convert-to-length (selection type value) | 215 | (defun xselect-convert-to-length (selection type value) |
| 161 | (let ((value | 216 | (let ((value |
| @@ -304,6 +359,7 @@ This function returns the string \"emacs\"." | |||
| 304 | '((TEXT . xselect-convert-to-string) | 359 | '((TEXT . xselect-convert-to-string) |
| 305 | (COMPOUND_TEXT . xselect-convert-to-string) | 360 | (COMPOUND_TEXT . xselect-convert-to-string) |
| 306 | (STRING . xselect-convert-to-string) | 361 | (STRING . xselect-convert-to-string) |
| 362 | (UTF8_STRING . xselect-convert-to-string) | ||
| 307 | (TARGETS . xselect-convert-to-targets) | 363 | (TARGETS . xselect-convert-to-targets) |
| 308 | (LENGTH . xselect-convert-to-length) | 364 | (LENGTH . xselect-convert-to-length) |
| 309 | (DELETE . xselect-convert-to-delete) | 365 | (DELETE . xselect-convert-to-delete) |