Subject: bug#11394: 24.0.96; Sporadic pasting problem

From: Chong Yidong <[email-masked]>
Date: Thu, 03 May 2012 11:18:06 +0800

> Richard Stanton <[email-masked]> writes:
>
>> I've been using Emacs with org-mode quite a lot over the last 24
>> hours to edit a file that will turn into a Beamer
>> presentation. During the course of this editing, I've several times
>> had the problem that when cutting and pasting text, when I press C-y,
>> instead of doing what I ask, I get a message in the minibuffer
>> telling me something like
>>
>> Quit: pasteboard doesn't contain valid data
>
> My suspicion is the fix for Bug#11315 (revno 107896 on emacs-24 branch).

OK, I think I know where the problem lies.  Here are two things I'd like
you to try before using the patch I posted in my earlier message (which
just reverts select.el to an earlier version).

1. Try a bit to reproduce this (in an unpatched version of the pretest),
   by copying and pasting non-ASCII text like some of the text in the
   HELLO buffer displayed by C-h H.  If you can reproduce the problem,
   that is much more convenient than waiting for the problem to occur
   sporadically.

2. Please apply the following patch and see if the problem goes away.

Please try my earlier patch instead (the one which reverts to an earlier
version) only if the problem still occurs after (2).

Waiting for your reply; thanks in advance!

=== modified file 'lisp/select.el'
*** lisp/select.el	2012-04-24 05:34:50 +0000
--- lisp/select.el	2012-05-03 02:27:09 +0000
***************
*** 228,251 ****
  	  ;; But avoid modifying the string if it's a buffer name etc.
  	  (unless can-modify (setq str (substring str 0)))
  	  (remove-text-properties 0 (length str) '(composition nil) str)
! 	  ;; TEXT is a polymorphic target.  Select the actual type
! 	  ;; from `UTF8_STRING', `COMPOUND_TEXT', `STRING', and
! 	  ;; `C_STRING'.
! 	  (if (eq type 'TEXT)
! 	      (if (not (multibyte-string-p str))
! 		  (setq type 'C_STRING)
! 		(let (non-latin-1 non-unicode eight-bit)
! 		  (mapc #'(lambda (x)
! 			    (if (>= x #x100)
! 				(if (< x #x110000)
! 				    (setq non-latin-1 t)
! 				  (if (< x #x3FFF80)
! 				      (setq non-unicode t)
! 				    (setq eight-bit t)))))
! 			str)
! 		  (setq type (if non-unicode 'COMPOUND_TEXT
! 			       (if non-latin-1 'UTF8_STRING
! 				 (if eight-bit 'C_STRING 'STRING)))))))
  	  (cond
  	   ((eq type 'UTF8_STRING)
  	    (if (or (not coding)
--- 228,256 ----
  	  ;; But avoid modifying the string if it's a buffer name etc.
  	  (unless can-modify (setq str (substring str 0)))
  	  (remove-text-properties 0 (length str) '(composition nil) str)
! 	  ;; For X selections, TEXT is a polymorphic target.  Select
! 	  ;; the actual type from `UTF8_STRING', `COMPOUND_TEXT',
! 	  ;; `STRING', and `C_STRING'.
! 	  (when (eq type 'TEXT)
! 	    (cond
! 	     ((featurep 'ns)
! 	      (setq type 'UTF8_STRING))
! 	     ((not (multibyte-string-p str))
! 	      (setq type 'C_STRING))
! 	     (t
! 	      (let (non-latin-1 non-unicode eight-bit)
! 		(mapc #'(lambda (x)
! 			  (if (>= x #x100)
! 			      (if (< x #x110000)
! 				  (setq non-latin-1 t)
! 				(if (< x #x3FFF80)
! 				    (setq non-unicode t)
! 				  (setq eight-bit t)))))
! 		      str)
! 		(setq type (if non-unicode 'COMPOUND_TEXT
! 			     (if non-latin-1 'UTF8_STRING
! 			       (if eight-bit 'C_STRING
! 				 'STRING))))))))
  	  (cond
  	   ((eq type 'UTF8_STRING)
  	    (if (or (not coding)