bburns / clipmon

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keeping save highlighted region to kill ring

tomhk215 opened this issue · comments

I just have this configuration.

(add-to-list 'after-init-hook 'clipmon-mode-start)

Upon highlighting a region, no matter in emacs or in other applications, it keeps pushing the highlighted text to the kill ring. Can it be configured so that text only push to kill ring when I copy it?

Hmm, it's not supposed to do that - I think you found a bug -

I'm on Windows, where there is just the clipboard - you have to explicitly copy things to it, whereas on Linux, you can just select text and it will be added to the primary selection, which is separate from the clipboard - I hadn't understood that when I wrote this, and just did some cursory tests on a Linux VM, which seemed to check out.

So there should be a way to distinguish those in Emacs - I'll take a look at it.

Thanks for the report!

Finally, I figure out the solution. Under the GNU Emacs Manual:

Under X, whenever the region is active (see Chapter 8 [Mark], page 45), the text in the
region is saved in the primary selection. This applies regardless of whether the region was
made by dragging or clicking the mouse (see Section 18.1 [Mouse Commands], page 162),
or by keyboard commands (e.g., by typing C-SPC and moving point; see Section 8.1 [Setting
Mark], page 45).
If you change the variable select-active-regions to only, Emacs saves only temporar-
ily active regions to the primary selection, i.e., those made with the mouse or with shift
selection (see Section 8.6 [Shift Selection], page 49). If you change select-active-regions
to nil, Emacs avoids saving active regions to the primary selection entirely.

So, I just do (setq select-active-regions nil)
I think this may also be related to the gui hanging issue. Still trying.

That's great, thanks for finding that! I'll put out an update later
tonight.

Brian

On Mon, Jan 18, 2016 at 4:30 AM, tomhk215 notifications@github.com wrote:

Finally, I figure out the solution. Under the GNU Emacs Manual:

Under X, whenever the region is active (see Chapter 8 [Mark], page 45),
the text in the
region is saved in the primary selection. This applies regardless of
whether the region was
made by dragging or clicking the mouse (see Section 18.1 [Mouse Commands],
page 162),
or by keyboard commands (e.g., by typing C-SPC and moving point; see
Section 8.1 [Setting
Mark], page 45).
If you change the variable select-active-regions to only, Emacs saves only
temporar-
ily active regions to the primary selection, i.e., those made with the
mouse or with shift
selection (see Section 8.6 [Shift Selection], page 49). If you change
select-active-regions
to nil, Emacs avoids saving active regions to the primary selection
entirely.

So, I just do (setq select-active-regions nil)


Reply to this email directly or view it on GitHub
#4 (comment).

Well this seems to have fixed it -
(ignore-errors (x-get-selection 'CLIPBOARD)))
instead of
(ignore-errors (x-get-selection-value)))

the latter defaults to using the primary selection. Unfortunately it didn't help with the gui bug - I'll have to keep working on that one.

Uploading to Melpa soon - might take a while for it to show up.

Thanks again,
Brian

Actually I think I'll make it an option to use the primary selection instead of the clipboard, as some people might prefer to use it that way - then they could just select text in the browser to copy it to Emacs, for instance. Will try to get it to cooperate for both Windows and Linux.

Okay, I finally fixed the problem with the duplicates in the kill-ring - it needed to check if Emacs was the owner of the selection with x-selection-owner-p.

And I initially added an option clipmon-use-primary-selection, which worked - you could select some text in Firefox, and it would be added to the kill-ring. But if the timer happened to fire when you were in the midst of making a selection, it would add the partial text to the kill-ring, or insert it if autoinsert was on. So I just removed that option. Now to get something added to the kill-ring from an external application the user will need to copy it to the clipboard, which was the original intent of the program.