UNSOLVED: emacs becomes sluggish & unusable unto hanging

Problem

Emacs becomes unuseable

  • General sluggishness.
    • Hanging permanently with probability 1 as usage time goes to several hours
    • Upon hanging “permanently”, it requires to be killed. It takes multiple SIGTERM to get it to die.
  • Hanging for seconds-to-minutes at a time when cutting, yanking.
  • Hanging for seconds-to-minutes at a time when running the keyboard macro M-x e.
  • Inserting characters out of order when typing fast.

Remediation

Just grasping at straws. No idea what’s wrong with the X clipboard manager.

(setq x-select-enable-clipboard-manager nil)
(setq interprogram-cut-function nil)

Indications

In the *Message* buffrer:

X clipboard manager error: Timed out waiting for reply from selection owner
If the problem persists, set `x-select-enable-clipboard-manager' to nil.

Context

$ rpm -q emacs gnome-shell
emacs-24.3-11.fc19.x86_64
gnome-shell-3.8.4-3.fc19.x86_64

Documentation

x-select-enable-clipboard‘s value is t(true).Documentation:
Non-nil means cutting and pasting uses the clipboard. This is in addition to, but in preference to, the primary selection.
Note that MS-Windows does not support selection types other than the clipboard. (The primary selection that is set by Emacs is not accessible to other programs on MS-Windows.)
This variable is not used by the Nextstep port.
You can customize this variable.
This variable was introduced, or its default value was changed, in version 24.1 of Emacs.
interprogram-cut-function‘s value is x-select-textThis variable may be risky if used as a file-local variable.Documentation:
Function to call to make a killed region available to other programs. Most window systems provide a facility for cutting and pasting text between different programs, such as the clipboard on X and MS-Windows, or the pasteboard on Nextstep/Mac OS.
This variable holds a function that Emacs calls whenever text is put in the kill ring, to make the new kill available to other programs. The function takes one argument, TEXT, which is a string containing the text which should be made available.

Workarounds

Via: Make emacs explicitly copy to/from the X11 selection and clipboard buffers?; Some dude using the self-asserted identity token bstpierre; In Superuser; 2012-05-02 2012-05-03

(defun my-yank (&optional arg)
  "Yank from the clipboard, not the primary selection."
  (interactive "*P")
  (let ((x-select-enable-clipboard t)
        (x-select-enable-primary nil))
    (yank arg)))

(defun my-kill-region (beg end)
  "Kill to the clipboard, not the primary selection."
  (interactive "r")
  (let ((x-select-enable-clipboard t)
        (x-select-enable-primary nil))
    (kill-region beg end)))

(defun my-kill-ring-save (beg end)
  "Save to the clipboard, not the primary selection."
  (interactive "*r")
  (let ((x-select-enable-clipboard t)
        (x-select-enable-primary nil))
    (kill-ring-save beg end)))

(define-key global-map (kbd "C-S-w") 'my-kill-region)
(define-key global-map (kbd "C-M-S-w") 'my-kill-ring-save)
(define-key global-map (kbd "C-S-y") 'my-yank)

Folklore

Based on information & belief, maybe these are relevant

Via /etc/PROBLEMS
Member “emacs-24.5/etc/PROBLEMS” (2 Apr 2015, 123908 Bytes) of archive /linux/misc/emacs-24.5.tar.gz

  920 *** Gnome: Emacs receives input directly from the keyboard, bypassing XIM.
  921 
  922 This seems to happen when gnome-settings-daemon version 2.12 or later
  923 is running.  If gnome-settings-daemon is not running, Emacs receives
  924 input through XIM without any problem.  Furthermore, this seems only
  925 to happen in *.UTF-8 locales; zh_CN.GB2312 and zh_CN.GBK locales, for
  926 example, work fine.  A bug report has been filed in the Gnome
  927 bugzilla: http://bugzilla.gnome.org/show_bug.cgi?id=357032
  928 
  929 *** Gnome: Emacs's xterm-mouse-mode doesn't work on the Gnome terminal.
  930 
  931 A symptom of this bug is that double-clicks insert a control sequence
  932 into the buffer.  The reason this happens is an apparent
  933 incompatibility of the Gnome terminal with Xterm, which also affects
  934 other programs using the Xterm mouse interface.  A problem report has
  935 been filed.
  936 
<snip/>
  966 *** KDE: Emacs hangs on KDE when a large portion of text is killed.
  967 
  968 This is caused by a bug in the KDE applet `klipper' which periodically
  969 requests the X clipboard contents from applications.  Early versions
  970 of klipper don't implement the ICCCM protocol for large selections,
  971 which leads to Emacs being flooded with selection requests.  After a
  972 while, Emacs may print a message:
  973 
  974   Timed out waiting for property-notify event
  975 
  976 A workaround is to not use `klipper'.  An upgrade to the `klipper' that
  977 comes with KDE 3.3 or later also solves the problem.