quark-emacs icon indicating copy to clipboard operation
quark-emacs copied to clipboard

Don't hang when interacting with the kill-ring after an image has been copied

Open PythonNut opened this issue 3 years ago • 1 comments

Recipe:

  1. Take a large screenshot
  2. Try to kill something to the kill ring

PythonNut avatar Feb 13 '21 23:02 PythonNut

It is unclear if this was really the issue I was seeing earlier.

Anyway, here is a patch for it:

(el-patch-defun kill-new (string &optional replace)
  "Make STRING the latest kill in the kill ring.
Set `kill-ring-yank-pointer' to point to it.
If `interprogram-cut-function' is non-nil, apply it to STRING.
Optional second argument REPLACE non-nil means that STRING will replace
the front of the kill ring, rather than being added to the list.

When `save-interprogram-paste-before-kill' and `interprogram-paste-function'
are non-nil, save the interprogram paste string(s) into `kill-ring' before
STRING.

When the yank handler has a non-nil PARAM element, the original STRING
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."
  (unless (and kill-do-not-save-duplicates
               ;; Due to text properties such as 'yank-handler that
               ;; can alter the contents to yank, comparison using
               ;; `equal' is unsafe.
               (equal-including-properties string (car kill-ring)))
    (if (fboundp 'menu-bar-update-yank-menu)
        (menu-bar-update-yank-menu string (and replace (car kill-ring)))))
  (when save-interprogram-paste-before-kill
    (let ((interprogram-paste (and interprogram-paste-function
                                   (funcall interprogram-paste-function))))
      (when (el-patch-wrap 1 1
              (and interprogram-paste
                   (< (length interprogram-paste) 100000)))
        (dolist (s (if (listp interprogram-paste)
                       ;; Use `reverse' to avoid modifying external data.
                       (reverse interprogram-paste)
                     (list interprogram-paste)))
          (unless (and kill-do-not-save-duplicates
                       (equal-including-properties s (car kill-ring)))
            (push s kill-ring))))))
  (unless (and kill-do-not-save-duplicates
               (equal-including-properties string (car kill-ring)))
    (if (and replace kill-ring)
        (setcar kill-ring string)
      (let ((history-delete-duplicates nil))
        (add-to-history 'kill-ring string kill-ring-max t))))
  (setq kill-ring-yank-pointer kill-ring)
  (if interprogram-cut-function
      (funcall interprogram-cut-function string)))

PythonNut avatar Feb 16 '21 01:02 PythonNut