bburns / clipmon

Clipboard monitor for Emacs - monitors clipboard and pastes contents on change

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clipmon adding text selected in Emacs to the killring/autoinserting for Win/Emacs25, Linux

bburns opened this issue · comments

Not supposed to do that. The text is also doubled inside the kill ring.

Works alright on Windows/Emacs24.5.
Fails on Linux/Emacs24.5 and 25.1.

I think I found the problem - in Emacs24/Windows it checks if the clipboard contents are equal to the previous value - other implementations don't. Presumably they've standardized Emacs25 on this behavior, so clipmon will need to handle it.

For reference, the calling sequences are -

on windows/emacs24

(clipmon--clipboard-contents)
(clipmon--get-selection)
(x-get-selection-value) ; this checks if it's equal to last selected value, returns nil if so
(w32-get-clipboard-data)

on windows/emacs25

(clipmon--clipboard-contents)
(clipmon--get-selection)
(gui-get-selection 'CLIPBOARD)
(gui-backend-get-selection 'CLIPBOARD 'STRING)
(w32--get-selection 'CLIPBOARD 'STRING)
(w32-get-clipboard-data)

And the functions that differ are -

windows/emacs24

(defun x-get-selection-value ()
  "Return the value of the current selection.
Consult the selection.  Treat empty strings as if they were unset."
  (if x-select-enable-clipboard
      (let (text)
    ;; Don't die if x-get-selection signals an error.
    (with-demoted-errors "w32-get-clipboard-data:%s"
      (setq text (w32-get-clipboard-data)))
    (if (string= text "") (setq text nil))
    (cond
     ((not text) nil)
     ((eq text x-last-selected-text) nil)
     ((string= text x-last-selected-text) ; <<<<<<<<<<<<<<<<<<<<<<<<< note this <<<<<<<<<
      ;; Record the newer string, so subsequent calls can use the 'eq' test.
      (setq x-last-selected-text text)
      nil)
     (t
      (setq x-last-selected-text text))))))

vs windows/emacs25

(defun w32--get-selection  (&optional type data-type)
  (if (and (eq type 'CLIPBOARD)
           (eq data-type 'STRING))
      (with-demoted-errors "w32-get-clipboard-data:%S"
        (w32-get-clipboard-data))
    (get 'x-selections (or type 'PRIMARY))))

Fixed this by comparing clipboard text with top of kill-ring - returns nil if equal. So if user just copied/cut something from Emacs clipmon will ignore it.