GNU bug report logs - #29323
kill-do-not-save-duplicate, FR

Previous Next

Package: emacs;

Reported by: Andreas Röhler <andreas.roehler <at> easy-emacs.de>

Date: Thu, 16 Nov 2017 19:35:02 UTC

Severity: wishlist

Tags: wontfix

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #17 received at 29323 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: 29323 <at> debbugs.gnu.org
Subject: Re: bug#29323: kill-do-not-save-duplicate, FR
Date: Sun, 19 Nov 2017 19:42:27 +0100
[Message part 1 (text/plain, inline)]

On 16.11.2017 20:51, Andreas Röhler wrote:
> Feature request:
>
> Currently variable kill-do-not-save-duplicates checks only the (car 
> kill-ring) as docu explains:
>
> Do not add a new string to ‘kill-ring’ if it duplicates the last one.
> The comparison is done using ‘equal-including-properties’.
>
> AFAIU it would be trivial replace this check by a call of "member", 
> thus checking the whole kill-ring.
>
> Thanks,
>
> Andreas
>
>

This variant of kill-new should do it. Diff basically at comment " ;; 
delete string from kill-ring"

(defun ar-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, saves 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."
  (let (newring)
    (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 interprogram-paste
          (dolist (s (if (listp interprogram-paste)
                         (nreverse interprogram-paste)
                       (list interprogram-paste)))
            (unless (and kill-do-not-save-duplicates
                         (equal-including-properties s (car kill-ring)))
              (push s kill-ring))))))
    (if (and kill-do-not-save-duplicates
         (member string kill-ring))
    (progn
      ;; delete string from kill-ring
      (dolist (ele kill-ring)
        (unless (equal-including-properties string ele)
          (push ele newring)))
      ;; push the match at top
      (push string newring)
      (setq kill-ring newring))
      (if (and replace kill-ring)
          (setcar kill-ring string)
        (push string kill-ring)
        (if (> (length kill-ring) kill-ring-max)
            (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))))
    (setq kill-ring-yank-pointer kill-ring)
    (if interprogram-cut-function
        (funcall interprogram-cut-function string))))
[Message part 2 (text/html, inline)]

This bug report was last modified 3 years and 233 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.