From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#29323: kill-do-not-save-duplicate, FR Date: Sun, 19 Nov 2017 19:42:27 +0100 Message-ID: <0c96aedc-36e2-2bbd-8672-0008dbbfd7d5@easy-emacs.de> References: <389775cc-0e7b-ec2b-37d3-176516fc0786@easy-emacs.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------3C9FFDBF81A3A2AF80D33943" X-Trace: blaine.gmane.org 1511115922 26905 195.159.176.226 (19 Nov 2017 18:25:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Nov 2017 18:25:22 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 To: 29323@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 19 19:25:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGUHG-00065H-Tv for geb-bug-gnu-emacs@m.gmane.org; Sun, 19 Nov 2017 19:25:11 +0100 Original-Received: from localhost ([::1]:54001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGUHK-00052y-UV for geb-bug-gnu-emacs@m.gmane.org; Sun, 19 Nov 2017 13:25:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGUHD-00050a-4R for bug-gnu-emacs@gnu.org; Sun, 19 Nov 2017 13:25:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGUH8-0007ce-5K for bug-gnu-emacs@gnu.org; Sun, 19 Nov 2017 13:25:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39231) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eGUH8-0007cZ-0J for bug-gnu-emacs@gnu.org; Sun, 19 Nov 2017 13:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eGUH7-0006xe-Qc for bug-gnu-emacs@gnu.org; Sun, 19 Nov 2017 13:25:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Nov 2017 18:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29323 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 29323-submit@debbugs.gnu.org id=B29323.151111587126720 (code B ref 29323); Sun, 19 Nov 2017 18:25:01 +0000 Original-Received: (at 29323) by debbugs.gnu.org; 19 Nov 2017 18:24:31 +0000 Original-Received: from localhost ([127.0.0.1]:47912 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGUGd-0006wu-8G for submit@debbugs.gnu.org; Sun, 19 Nov 2017 13:24:31 -0500 Original-Received: from mout.kundenserver.de ([212.227.126.134]:58960) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGUGb-0006wh-MR for 29323@debbugs.gnu.org; Sun, 19 Nov 2017 13:24:30 -0500 Original-Received: from [192.168.178.35] ([77.12.48.49]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.167]) with ESMTPSA (Nemesis) id 0Ljxqo-1esI7o4Atm-00cAm2 for <29323@debbugs.gnu.org>; Sun, 19 Nov 2017 19:24:23 +0100 In-Reply-To: <389775cc-0e7b-ec2b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U+mitz1a30MPTZCWAe4d3BBc0Ft/ERI0hQic5mKcI/AqJSVdcj7yk= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:140112 Archived-At: This is a multi-part message in MIME format. --------------3C9FFDBF81A3A2AF80D33943 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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)))) --------------3C9FFDBF81A3A2AF80D33943 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit



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