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

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

bug#29323: kill-do-not-save-duplicate, FR


From: Andreas Röhler
Subject: bug#29323: kill-do-not-save-duplicate, FR
Date: Sun, 19 Nov 2017 19:42:27 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0



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))))

reply via email to

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