help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: how to get subsequent text copies to emacs kill ring?


From: Drew Adams
Subject: RE: how to get subsequent text copies to emacs kill ring?
Date: Thu, 16 May 2013 22:00:34 -0700

> (setq save-interprogram-paste-before-kill t)

Thanks for pointing this out, Samuel!  It seems to do just what I requested.
Dunno how I missed it.

Stefan, what does your local patch do differently from what this option does?

---

I think the option name and doc for this are a bit misleading, however.

The Emacs manual, at (emacs) `Clipboard', is almost OK about this. But it
suggests that the problem, in which copied text gets "lost" or "replaced", is
that the clipboard text is overwritten by a kill or a copy to the kill ring:

 When an Emacs kill command puts text in the clipboard, the
 existing clipboard contents are normally lost.
          ^^^^^^^^^

The problem is not that the _clipboard_ gets overwritten by a kill.  It is that
the Emacs `current-kill', copied automatically from the clipboard (good), is
overwritten (replaced) by an Emacs kill or copy to the kill ring.  (When you
yank (`C-y') you get the `current-kill'.)

IOW, the problem is about the opposite of what the doc says.  It does not matter
to Emacs behavior that the clipboard gets overwritten.  What matters here is
that the "current kill", which came from the clipboard, gets replaced when you
kill text.

This problem has to do with the fact that the clipboard text was never copied to
the `kill-ring' (the list variable).  It gets treated as the (zeroth)
`current-kill', so an immediate `C-y' yanks it, but though it is called "current
kill" and it can be yanked it is not really on the `kill-ring'.

That is quite different from the behavior provided by `kill-ring-save' or
`copy-region-as-kill' - they add the text to `kill-ring', as well as making it
the `current-kill'.

A non-nil value of this option effectively copies the clipboard text to the
`kill-ring', just as `kill-ring-save' and `copy-region-as-kill' do.  And that's
all it does, I think.

The option should perhaps have been called something like
`clipboard-to-kill-ring', `copy-clipboard-as-kill', `copy-clipboard-before-kill'
or `kill-copies-clipboard-first'.  The name should, above all, say that it
causes the clipboard text to be copied to the kill ring.

A problem with such a (better) name could be that some people might think that
the clipboard text already gets copied to the kill ring anyway, without the
option, because of the curious behavior of `current-kill'.  You can yank the
clipboard text (provided you do so immediately), but it is not on the
`kill-ring'.

IOW, it might not be clear to everyone that what `C-y' yanks is the
`current-kill', which is not necessarily the first item (or any item) in the
`kill-ring'.

The Emacs doc, at (emacs) `Yanking', makes that clear:

 Emacs effectively treats "cut" or "copy" clipboard operations
 performed in other applications like Emacs kills, except that
                                 ^^^^^^^^^^^^^^^^
 they are not recorded in the kill ring.
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Regardless of this possible confusion, the most important thing the option name
could suggest is that it causes the clipboard text to be added to the
`kill-ring'.  Currently, the name does not convey that.

The current option name is also misleading because it can suggest that it
controls "pasting" in Emacs.  I'm guessing the name was taken from "interprogram
paste function", but as used here the word "paste" is misleading, even for those
who might happen to know about "interprogram paste function".

The name can unfortunately suggest that this is about saving a _paste_ from
another program (before a kill).  There is no such paste here.  And even if
there were, what does it mean to save a paste?

What happens is that before a kill (and before a copy to the kill ring, which is
also important), the clipboard text is copied to the `kill-ring'.  The doc
string should just say that:

 Non-nil means copy clipboard text to kill ring before text you kill.
 That is, when you kill or copy text to the kill ring, as its first
 item, the clipboard text is put on the ring as the second (older)
 item.  You can thus yank it using `C-y M-y'.

It could also say this, which might not be obvious though it follows from what
has already been said:

 Whatever is on the clipboard when you kill or copy in Emacs gets added
 to the kill ring.  It does not matter how long ago it was cut or
 copied to the clipboard or by which program.

The doc string can go on to point out what happens if the value is nil, and that
you can always yank the clipboard text immediately:

 If nil, clipboard text is not added to the kill ring.  Whether nil or
 non-nil, you can yank the text using `C-y' immediately after it is
 added to the clipboard.  But if nil then a subsequent kill or copy to
 the kill ring overwrites the text as the current kill, so it is no
 longer available to be yanked.

The doc string should also, like Emacs doc generally, speak of yanking, not
pasting, when it talks about yanking text in Emacs.  And whatever this doc
string says about yanking text (i.e., `C-y M-y') should be only secondary.

The point of the option is to make sure that the clipboard text gets copied
(really) to the kill ring.  What you do with text on the kill ring is secondary
here to the effect of the option.




reply via email to

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