aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-07-14 16:58:25 +0000
committerChong Yidong2009-07-14 16:58:25 +0000
commitf470187ffb37a9f917d6a1921804e87d5c3879bb (patch)
treee59d99c49642fb86f74338f7a6cdc306936d32f4
parent72d36834fc488a9c5cf16e043a1ba9124744684f (diff)
downloademacs-f470187ffb37a9f917d6a1921804e87d5c3879bb.tar.gz
emacs-f470187ffb37a9f917d6a1921804e87d5c3879bb.zip
* select.el (x-set-selection): Doc fix.
(x-valid-simple-selection-p): Disallow selection data consisting of a list or cons of integers, since that is not used. (xselect--selection-bounds, xselect--int-to-cons): New functions. (xselect-convert-to-string, xselect-convert-to-length) (xselect-convert-to-filename, xselect-convert-to-charpos) (xselect-convert-to-lineno, xselect-convert-to-colno): Use them.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/select.el218
2 files changed, 90 insertions, 138 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6b1755cc6a2..18a1db7ca68 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12009-07-14 Chong Yidong <cyd@stupidchicken.com>
2
3 * select.el (x-set-selection): Doc fix.
4 (x-valid-simple-selection-p): Disallow selection data consisting
5 of a list or cons of integers, since that is not used.
6 (xselect--selection-bounds, xselect--int-to-cons): New functions.
7 (xselect-convert-to-string, xselect-convert-to-length)
8 (xselect-convert-to-filename, xselect-convert-to-charpos)
9 (xselect-convert-to-lineno, xselect-convert-to-colno): Use them.
10
12009-07-14 Dmitry Dzhus <dima@sphinx.net.ru> 112009-07-14 Dmitry Dzhus <dima@sphinx.net.ru>
2 12
3 * progmodes/gdb-mi.el (json-partial-output): Fix broken GDB/MI 13 * progmodes/gdb-mi.el (json-partial-output): Fix broken GDB/MI
diff --git a/lisp/select.el b/lisp/select.el
index 979189997c3..cc15bed7580 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -116,19 +116,21 @@ in `selection-converter-alist', which see."
116 116
117(defun x-set-selection (type data) 117(defun x-set-selection (type data)
118 "Make an X Windows selection of type TYPE and value DATA. 118 "Make an X Windows selection of type TYPE and value DATA.
119The argument TYPE (nil means `PRIMARY') says which selection, and 119TYPE is a symbol specifying the selection type. This is normally
120DATA specifies the contents. TYPE must be a symbol. \(It can also 120one of `PRIMARY', `SECONDARY', or `CLIPBOARD'; or nil, which is
121be a string, which stands for the symbol with that name, but this 121equivalent to `PRIMARY'. (It can also be a string, which stands
122is considered obsolete.) DATA may be a string, a symbol, an 122for the symbol with that name, but this usage is obsolete.)
123integer (or a cons of two integers or list of two integers). 123
124 124DATA is a selection value. It should be one of the following:
125The selection may also be a cons of two markers pointing to the same buffer, 125 - a vector of non-vector selection values
126or an overlay. In these cases, the selection is considered to be the text 126 - a string
127between the markers *at whatever time the selection is examined*. 127 - an integer
128Thus, editing done in the buffer after you specify the selection 128 - a cons cell of two markers pointing to the same buffer
129can alter the effective value of the selection. 129 - an overlay
130 130In the latter two cases, the selection is considered to be the
131The data may also be a vector of valid non-vector selection values. 131text between the markers at whatever time the selection is
132examined. Thus, editing done in the buffer after you specify the
133selection can alter the effective value of the selection.
132 134
133The return value is DATA. 135The return value is DATA.
134 136
@@ -138,9 +140,7 @@ prefix argument, it uses the text of the region as the selection value ."
138 (interactive (if (not current-prefix-arg) 140 (interactive (if (not current-prefix-arg)
139 (list 'PRIMARY (read-string "Set text for pasting: ")) 141 (list 'PRIMARY (read-string "Set text for pasting: "))
140 (list 'PRIMARY (buffer-substring (region-beginning) (region-end))))) 142 (list 'PRIMARY (buffer-substring (region-beginning) (region-end)))))
141 ;; This is for temporary compatibility with pre-release Emacs 19. 143 (if (stringp type) (setq type (intern type)))
142 (if (stringp type)
143 (setq type (intern type)))
144 (or (x-valid-simple-selection-p data) 144 (or (x-valid-simple-selection-p data)
145 (and (vectorp data) 145 (and (vectorp data)
146 (let ((valid t) 146 (let ((valid t)
@@ -158,24 +158,19 @@ prefix argument, it uses the text of the region as the selection value ."
158 data) 158 data)
159 159
160(defun x-valid-simple-selection-p (data) 160(defun x-valid-simple-selection-p (data)
161 (or (stringp data) 161 (or (and (consp data)
162 (symbolp data)
163 (integerp data)
164 (and (consp data)
165 (integerp (car data))
166 (or (integerp (cdr data))
167 (and (consp (cdr data))
168 (integerp (car (cdr data))))))
169 (overlayp data)
170 (and (consp data)
171 (markerp (car data)) 162 (markerp (car data))
172 (markerp (cdr data)) 163 (markerp (cdr data))
173 (marker-buffer (car data)) 164 (marker-buffer (car data))
174 (marker-buffer (cdr data))
175 (eq (marker-buffer (car data))
176 (marker-buffer (cdr data)))
177 (buffer-name (marker-buffer (car data))) 165 (buffer-name (marker-buffer (car data)))
178 (buffer-name (marker-buffer (cdr data)))))) 166 (eq (marker-buffer (car data))
167 (marker-buffer (cdr data))))
168 (stringp data)
169 (and (overlayp data)
170 (overlay-buffer data)
171 (buffer-name (overlay-buffer data)))
172 (symbolp data)
173 (integerp data)))
179 174
180;;; Cut Buffer support 175;;; Cut Buffer support
181 176
@@ -211,31 +206,38 @@ Cut buffers are considered obsolete; you should use selections instead."
211;; Every selection type that Emacs handles is implemented this way, except 206;; Every selection type that Emacs handles is implemented this way, except
212;; for TIMESTAMP, which is a special case. 207;; for TIMESTAMP, which is a special case.
213 208
209(defun xselect--selection-bounds (value)
210 "Return bounds of X selection value VALUE.
211The return value is a list (BEG END BUF) if VALUE is a cons of
212two markers or an overlay. Otherwise, it is nil."
213 (cond ((and (consp value)
214 (markerp (car value))
215 (markerp (cdr value)))
216 (when (and (marker-buffer (car value))
217 (buffer-name (marker-buffer (car value)))
218 (eq (marker-buffer (car value))
219 (marker-buffer (cdr value))))
220 (list (marker-position (car value))
221 (marker-position (cdr value))
222 (marker-buffer (car value)))))
223 ((overlayp value)
224 (when (overlay-buffer value)
225 (list (overlay-start value)
226 (overlay-end value)
227 (overlay-buffer value))))))
228
229(defun xselect--int-to-cons (n)
230 (cons (ash n -16) (logand n 65535)))
231
214(defun xselect-convert-to-string (selection type value) 232(defun xselect-convert-to-string (selection type value)
215 (let (str coding) 233 (let (str coding)
216 ;; Get the actual string from VALUE. 234 ;; Get the actual string from VALUE.
217 (cond ((stringp value) 235 (cond ((stringp value)
218 (setq str value)) 236 (setq str value))
219 237 ((setq value (xselect--selection-bounds value))
220 ((overlayp value) 238 (with-current-buffer (nth 2 value)
221 (save-excursion 239 (setq str (buffer-substring (nth 0 value)
222 (or (buffer-name (overlay-buffer value)) 240 (nth 1 value))))))
223 (error "selection is in a killed buffer"))
224 (set-buffer (overlay-buffer value))
225 (setq str (buffer-substring (overlay-start value)
226 (overlay-end value)))))
227 ((and (consp value)
228 (markerp (car value))
229 (markerp (cdr value)))
230 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))
231 (signal 'error
232 (list "markers must be in the same buffer"
233 (car value) (cdr value))))
234 (save-excursion
235 (set-buffer (or (marker-buffer (car value))
236 (error "selection is in a killed buffer")))
237 (setq str (buffer-substring (car value) (cdr value))))))
238
239 (when str 241 (when str
240 ;; If TYPE is nil, this is a local request, thus return STR as 242 ;; If TYPE is nil, this is a local request, thus return STR as
241 ;; is. Otherwise, encode STR. 243 ;; is. Otherwise, encode STR.
@@ -288,31 +290,18 @@ Cut buffers are considered obsolete; you should use selections instead."
288 (setq str (string-make-unibyte str))) 290 (setq str (string-make-unibyte str)))
289 291
290 (t 292 (t
291 (error "Unknow selection type: %S" type)) 293 (error "Unknown selection type: %S" type)))))
292 )))
293 294
294 (setq next-selection-coding-system nil) 295 (setq next-selection-coding-system nil)
295 (cons type str)))) 296 (cons type str))))
296 297
297
298(defun xselect-convert-to-length (selection type value) 298(defun xselect-convert-to-length (selection type value)
299 (let ((value 299 (let ((len (cond ((stringp value)
300 (cond ((stringp value) 300 (length value))
301 (length value)) 301 ((setq value (xselect--selection-bounds value))
302 ((overlayp value) 302 (abs (- (nth 0 value) (nth 1 value)))))))
303 (abs (- (overlay-end value) (overlay-start value)))) 303 (if len
304 ((and (consp value) 304 (xselect--int-to-cons len))))
305 (markerp (car value))
306 (markerp (cdr value)))
307 (or (eq (marker-buffer (car value))
308 (marker-buffer (cdr value)))
309 (signal 'error
310 (list "markers must be in the same buffer"
311 (car value) (cdr value))))
312 (abs (- (car value) (cdr value)))))))
313 (if value ; force it to be in 32-bit format.
314 (cons (ash value -16) (logand value 65535))
315 nil)))
316 305
317(defun xselect-convert-to-targets (selection type value) 306(defun xselect-convert-to-targets (selection type value)
318 ;; return a vector of atoms, but remove duplicates first. 307 ;; return a vector of atoms, but remove duplicates first.
@@ -335,77 +324,31 @@ Cut buffers are considered obsolete; you should use selections instead."
335 'NULL) 324 'NULL)
336 325
337(defun xselect-convert-to-filename (selection type value) 326(defun xselect-convert-to-filename (selection type value)
338 (cond ((overlayp value) 327 (when (setq value (xselect--selection-bounds value))
339 (buffer-file-name (or (overlay-buffer value) 328 (buffer-file-name (nth 2 value))))
340 (error "selection is in a killed buffer"))))
341 ((and (consp value)
342 (markerp (car value))
343 (markerp (cdr value)))
344 (buffer-file-name (or (marker-buffer (car value))
345 (error "selection is in a killed buffer"))))
346 (t nil)))
347 329
348(defun xselect-convert-to-charpos (selection type value) 330(defun xselect-convert-to-charpos (selection type value)
349 (let (a b tmp) 331 (when (setq value (xselect--selection-bounds value))
350 (cond ((cond ((overlayp value) 332 (let ((beg (1- (nth 0 value))) ; zero-based
351 (setq a (overlay-start value) 333 (end (1- (nth 1 value))))
352 b (overlay-end value))) 334 (cons 'SPAN (vector (xselect--int-to-cons (min beg end))
353 ((and (consp value) 335 (xselect--int-to-cons (max beg end)))))))
354 (markerp (car value))
355 (markerp (cdr value)))
356 (setq a (car value)
357 b (cdr value))))
358 (setq a (1- a) b (1- b)) ; zero-based
359 (if (< b a) (setq tmp a a b b tmp))
360 (cons 'SPAN
361 (vector (cons (ash a -16) (logand a 65535))
362 (cons (ash b -16) (logand b 65535))))))))
363 336
364(defun xselect-convert-to-lineno (selection type value) 337(defun xselect-convert-to-lineno (selection type value)
365 (let (a b buf tmp) 338 (when (setq value (xselect--selection-bounds value))
366 (cond ((cond ((and (consp value) 339 (with-current-buffer (nth 2 value)
367 (markerp (car value)) 340 (let ((beg (line-number-at-pos (nth 0 value)))
368 (markerp (cdr value))) 341 (end (line-number-at-pos (nth 1 value))))
369 (setq a (marker-position (car value)) 342 (cons 'SPAN (vector (xselect--int-to-cons (min beg end))
370 b (marker-position (cdr value)) 343 (xselect--int-to-cons (max beg end))))))))
371 buf (marker-buffer (car value))))
372 ((overlayp value)
373 (setq buf (overlay-buffer value)
374 a (overlay-start value)
375 b (overlay-end value)))
376 )
377 (save-excursion
378 (set-buffer buf)
379 (setq a (count-lines 1 a)
380 b (count-lines 1 b)))
381 (if (< b a) (setq tmp a a b b tmp))
382 (cons 'SPAN
383 (vector (cons (ash a -16) (logand a 65535))
384 (cons (ash b -16) (logand b 65535))))))))
385 344
386(defun xselect-convert-to-colno (selection type value) 345(defun xselect-convert-to-colno (selection type value)
387 (let (a b buf tmp) 346 (when (setq value (xselect--selection-bounds value))
388 (cond ((cond ((and (consp value) 347 (with-current-buffer (nth 2 value)
389 (markerp (car value)) 348 (let ((beg (progn (goto-char (nth 0 value)) (current-column)))
390 (markerp (cdr value))) 349 (end (progn (goto-char (nth 1 value)) (current-column))))
391 (setq a (car value) 350 (cons 'SPAN (vector (xselect--int-to-cons (min beg end))
392 b (cdr value) 351 (xselect--int-to-cons (max beg end))))))))
393 buf (marker-buffer a)))
394 ((overlayp value)
395 (setq buf (overlay-buffer value)
396 a (overlay-start value)
397 b (overlay-end value)))
398 )
399 (save-excursion
400 (set-buffer buf)
401 (goto-char a)
402 (setq a (current-column))
403 (goto-char b)
404 (setq b (current-column)))
405 (if (< b a) (setq tmp a a b b tmp))
406 (cons 'SPAN
407 (vector (cons (ash a -16) (logand a 65535))
408 (cons (ash b -16) (logand b 65535))))))))
409 352
410(defun xselect-convert-to-os (selection type size) 353(defun xselect-convert-to-os (selection type size)
411 (symbol-name system-type)) 354 (symbol-name system-type))
@@ -430,7 +373,7 @@ This function returns the string \"emacs\"."
430 373
431(defun xselect-convert-to-integer (selection type value) 374(defun xselect-convert-to-integer (selection type value)
432 (and (integerp value) 375 (and (integerp value)
433 (cons (ash value -16) (logand value 65535)))) 376 (xselect--int-to-cons value)))
434 377
435(defun xselect-convert-to-atom (selection type value) 378(defun xselect-convert-to-atom (selection type value)
436 (and (symbolp value) value)) 379 (and (symbolp value) value))
@@ -457,8 +400,7 @@ This function returns the string \"emacs\"."
457 (NAME . xselect-convert-to-name) 400 (NAME . xselect-convert-to-name)
458 (ATOM . xselect-convert-to-atom) 401 (ATOM . xselect-convert-to-atom)
459 (INTEGER . xselect-convert-to-integer) 402 (INTEGER . xselect-convert-to-integer)
460 (_EMACS_INTERNAL . xselect-convert-to-identity) 403 (_EMACS_INTERNAL . xselect-convert-to-identity)))
461 ))
462 404
463(provide 'select) 405(provide 'select)
464 406