Overhaul counsel-yank-pop #1356
Conversation
- Hoist common branch code. - Heed carriage returns. - Consolidate nested lets.
Do not unnecessarily modify kill-ring structure and elements.
(setq ivy-completion-end (point)) | ||
(ivy-read "kill-ring: " cands | ||
:require-match t | ||
:preselect (nth (or arg 1) kill-ring-yank-pointer) |
basil-conto
Dec 8, 2017
Author
Collaborator
Woops, this is wrong for negative ARGs; I'll fix it later today.
Woops, this is wrong for negative ARGs; I'll fix it later today.
(ivy-read "kill-ring: " candidates | ||
:action 'counsel-yank-pop-action | ||
:caller 'counsel-yank-pop)))) | ||
(string-match "\\`[\n\r[:blank:]]*\\'" s)) |
ambihelical
Dec 8, 2017
Contributor
Potentially replaceable with string-blank-p
Potentially replaceable with string-blank-p
(delete-dups kill-ring)))) | ||
(let ((cands (delete-dups | ||
(cl-mapcan (lambda (s) | ||
(unless (string-match-p "\\`[\n\r[:blank:]]*\\'" s) |
ambihelical
Dec 8, 2017
Contributor
potentially use string-blank-p here.
potentially use string-blank-p here.
@ambihelical I would have used I'm more concerned about whether we should unconditionally be removing all blank kills from the candidates offered. |
While trying to fix the Nevertheless, I understand why users may want to ignore certain 1. Leave the kill ring alone
Pros:
Cons:
2. Modify the kill ring; long live the kill ring!If Pros:
Cons:
3. All of the aboveProvide a toggle between leaving the kill ring untouched and destructively filtering it. Pros:
Cons:
My personal favorite is 3, for which I'd be happy to provide the code. Thoughts? |
I've fixed the |
The command yank-pop does too much under the bonnet to ever hope to emulate, so use it directly. This respects and updates various internals, most noticeably kill-ring-yank-pointer, thus allowing consecutive calls to yank to work. See https://emacs.stackexchange.com/q/37351/15748. (counsel--yank-pop-position): New function. (counsel-yank-pop-action): Use yank-pop. (counsel-yank-pop): Do The Right Thing w.r.t. point and mark regardless of whether last-command was a yank. Adopt interactive-spec of yank-pop and preselect candidate accordingly. Abort on empty/blank kill-ring. Fixes #1190
Thanks.
You mean deleting blanks from the |
Not exactly. What I think is The Wrong Thing is a) not giving users the choice to complete Point (a) is simply about user preference. Point (b), on the other hand, is a more subtle problem because many kill/yank commands operate in terms of relative offsets of This is why I think it is important to accompany filtering of If that sounds good to you I'll submit another PR to allow toggling |
Thanks for the explanation. Please PR, with deletion on by default. |
(counsel-string-non-blank-p): New function. (counsel-yank-pop-filter): New defcustom defaulting to it. (counsel--yank-pop-kills): Use it to destructively filter and uniquify kill-ring and kill-ring-yank-pointer elements. (counsel-yank-pop-action-remove, counsel-yank-pop): Consistently test equivalence with equal-including-properties. Re: abo-abo#1356
(counsel-string-non-blank-p): New function. (counsel-yank-pop-filter): New defcustom defaulting to it. (counsel--yank-pop-kills): Use it to destructively filter and uniquify kill-ring and kill-ring-yank-pointer elements. (counsel-yank-pop-action-remove, counsel-yank-pop): Consistently test equivalence with equal-including-properties. Re: #1356 Fixes #1367
Changelog
Please see each commit message in order. The last and most significant commit in particular addresses this Emacs SE question and closes #1190.
Before merging
The function
counsel--yank-pop-position
is also useful in #1133. If that PR lands first, the function should be removed from this PR. Conversely, if this PR lands first, then #1133 should be rebased to avail of the function.Question
Is completely ignoring blank kills really that useful? Thoughts on lifting this restriction or making it configurable?