/[emacs]/emacs/lisp/select.el
ViewVC logotype

Diff of /emacs/lisp/select.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by eliz, Wed Jun 5 17:14:16 2002 UTC revision 1.18 by handa, Wed Aug 14 00:57:55 2002 UTC
# Line 133  Cut buffers are considered obsolete; you Line 133  Cut buffers are considered obsolete; you
133  ;;; for TIMESTAMP, which is a special case.  ;;; for TIMESTAMP, which is a special case.
134    
135  (defun xselect-convert-to-string (selection type value)  (defun xselect-convert-to-string (selection type value)
136    (cond ((stringp value)    (let (str coding)
137           ;; Return the type as well, so that xselect.c could honor      ;; Get the actual string from VALUE.
138           ;; requests whose type is STRING.      (cond ((stringp value)
139           (cons type value))             (setq str value))
140          ((overlayp value)  
141           (save-excursion            ((overlayp value)
142             (or (buffer-name (overlay-buffer value))             (save-excursion
143                 (error "selection is in a killed buffer"))               (or (buffer-name (overlay-buffer value))
144             (set-buffer (overlay-buffer value))                   (error "selection is in a killed buffer"))
145             (buffer-substring (overlay-start value)               (set-buffer (overlay-buffer value))
146                               (overlay-end value))))               (setq str (buffer-substring (overlay-start value)
147          ((and (consp value)                                           (overlay-end value)))))
148                (markerp (car value))            ((and (consp value)
149                (markerp (cdr value)))                  (markerp (car value))
150           (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))                  (markerp (cdr value)))
151               (signal 'error             (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))
152                       (list "markers must be in the same buffer"                 (signal 'error
153                             (car value) (cdr value))))                         (list "markers must be in the same buffer"
154           (save-excursion                               (car value) (cdr value))))
155             (set-buffer (or (marker-buffer (car value))             (save-excursion
156                             (error "selection is in a killed buffer")))               (set-buffer (or (marker-buffer (car value))
157             (buffer-substring (car value) (cdr value))))                               (error "selection is in a killed buffer")))
158          (t nil)))               (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    
214    
215  (defun xselect-convert-to-length (selection type value)  (defun xselect-convert-to-length (selection type value)
216    (let ((value    (let ((value
# Line 304  This function returns the string \"emacs Line 359  This function returns the string \"emacs
359        '((TEXT . xselect-convert-to-string)        '((TEXT . xselect-convert-to-string)
360          (COMPOUND_TEXT . xselect-convert-to-string)          (COMPOUND_TEXT . xselect-convert-to-string)
361          (STRING . xselect-convert-to-string)          (STRING . xselect-convert-to-string)
362            (UTF8_STRING . xselect-convert-to-string)
363          (TARGETS . xselect-convert-to-targets)          (TARGETS . xselect-convert-to-targets)
364          (LENGTH . xselect-convert-to-length)          (LENGTH . xselect-convert-to-length)
365          (DELETE . xselect-convert-to-delete)          (DELETE . xselect-convert-to-delete)

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26