From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: 29323@debbugs.gnu.org
Subject: bug#29323: kill-do-not-save-duplicate, FR
Date: Sun, 19 Nov 2017 19:42:27 +0100 [thread overview]
Message-ID: <0c96aedc-36e2-2bbd-8672-0008dbbfd7d5@easy-emacs.de> (raw)
In-Reply-To: <389775cc-0e7b-ec2b-37d3-176516fc0786@easy-emacs.de>
[-- Attachment #1: Type: text/plain, Size: 3362 bytes --]
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))))
[-- Attachment #2: Type: text/html, Size: 4507 bytes --]
next prev parent reply other threads:[~2017-11-19 18:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 19:51 bug#29323: kill-do-not-save-duplicate, FR Andreas Röhler
2017-11-16 22:34 ` Drew Adams
2017-11-18 19:06 ` Andreas Röhler
2017-11-18 19:48 ` Drew Adams
2017-11-19 18:42 ` Andreas Röhler [this message]
2019-11-11 2:14 ` Stefan Kangas
2021-11-30 14:48 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0c96aedc-36e2-2bbd-8672-0008dbbfd7d5@easy-emacs.de \
--to=andreas.roehler@easy-emacs.de \
--cc=29323@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).