Subject: bug#31209: 27.0.50; current-kill calls interprogram-paste-function more than once

From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 18 Apr 2018 18:47:04 +0100

Under lexical-binding, I expect the following:

(let* ((i 0)
       (kill-ring ())
       (kill-ring-yank-pointer ())
       (save-interprogram-paste-before-kill t)
       (interprogram-paste-function
        (lambda ()
          (setq i (1+ i))
          (list "a" "b" "c"))))
  (current-kill 0)
  (message "\
`interprogram-paste-function' called %d time(s)
`kill-ring' = %s"
           i kill-ring))

to evaluate to:

‘interprogram-paste-function’ called 1 time(s)
‘kill-ring’ = (a b c)

but the actual result is:

‘interprogram-paste-function’ called 4 time(s)
‘kill-ring’ = (a a b c b a b c c a b c)

This behaviour is due to current-kill passing each string returned by
interprogram-paste-function to kill-new, which in turn calls
interprogram-paste-function when save-interprogram-paste-before-kill is
non-nil, and was introduced along with
save-interprogram-paste-before-kill [1: 4ed8c7aadb].

[1: 4ed8c7aadb]: 2009-08-26 20:55:39 +0000
  (save-interprogram-paste-before-kill): New user option.
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=4ed8c7aadb59c8ae75641710e3d9ff5bddbbd952

Patch addressing this to follow.

Thanks,

-- 
Basil

In GNU Emacs 27.0.50 (build 6, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2018-04-18 built on thunk
Repository revision: 5dff4905d73d0d42447ff4b114d1af726a689c6a
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: Debian GNU/Linux buster/sid