emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs hanging after M-w and C-k


From: Stefan Monnier
Subject: Re: Emacs hanging after M-w and C-k
Date: Mon, 07 Nov 2005 16:28:03 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>> Every once in a while Emacs gets into a strange mood where any text killing
>> (C-k, C-w, M-w, mouse selection, ...) causes it to hang (breakable with
>> C-g, thank god).
>> 
>> It turns out that it's due to some other app being stuck (probably while
>> holding the X selection, tho my understanding of the X protocol is too
>> flakey to be sure).  So maybe it's not strictly speaking an Emacs bug, but
>> I wish Emacs could grab the X selection asynchronously, so it wouldn't
>> get stuck.
>> 
>> Does anybody know how feasible this is?

> If it get stuck in XSetSelectionOwner it is not feasible, as this is
> a synchronous call in X.  Can you verify that it is there it is stuck?

Hmm.... OK it turns out that it's a problem due to my own local hacks (see
the patch below).  So in a vanilla Emacs, the way to reproduce a similar
problem is to do C-y when another app has the selection and is frozen.
But unless we add a timeout, there is little we can do about it in the case
of C-y.  In the case of the patch below, I'd want to run
interprogram-paste-function asynchronously, but it's not clear how to do.
That's too bad: I was planning to submit the patch below for inclusion.


        Stefan


--- orig/lisp/simple.el
+++ mod/lisp/simple.el
@@ -2382,6 +2428,21 @@
 argument is not used by `insert-for-yank'.  However, since Lisp code
 may access and use elements from the kill ring directly, the STRING
 argument should still be a \"useful\" string for such uses."
+  ;; To better pretend that X-selection = head-of-kill-ring, we copy other
+  ;; application's X-selection to the kill-ring.  This comes in handy when
+  ;; you do something like:
+  ;; - copy a piece of text in your web-browser.
+  ;; - have to do some editing (including killing) before you can yank
+  ;;   that text.
+  ;; Note: this piece of code inspired from current-kill.
+  (let ((paste (and interprogram-paste-function
+                    (funcall interprogram-paste-function))))
+    (when paste
+      (let ((interprogram-cut-function nil)
+            (interprogram-paste-function nil))
+        (kill-new paste))))
+  ;; The actual kill-new functionality.
+  (when (equal string (car kill-ring)) (setq replace t))
   (if (> (length string) 0)
       (if yank-handler
          (put-text-property 0 (length string)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]