New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interoperate better with kill-ring #1133
Conversation
Make counsel-yank-pop inter-operate better with the existing variable kill-ring-yank-pointer * Don't let delete leave kill-ring-yank-pointer dangling * Add action to set kill-ring-yank-pointer to selection
(setq kill-ring (delete s kill-ring))) | ||
(let ((next-ptr (cdr (member s kill-ring)))) | ||
(setq kill-ring (delete s kill-ring)) | ||
(setq kill-ring-yank-pointer (or next-ptr kill-ring)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's sufficient to write
(setq kill-ring (delete s kill-ring))
(setq kill-ring-yank-pointer (delete s kill-ring-yank-pointer))
The docstring should also read "Remove all occurences of S from the kill ring."
|
||
(defun counsel-yank-pop-action-position (s) | ||
"Set yank position to S." | ||
(setq kill-ring-yank-pointer (member s kill-ring))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Emacs this is called "rotating" the yank pointer, so I think we should also say "rotate" instead of "position".
Modifying the kill ring and its pointer directly is not usually kosher, as killing and yanking are very central, configurable and flexible features of Emacs. We should, therefore, delegate as much as possible to internal functions:
(defun counsel--yank-pop-position (s)
"Return position of S in `kill-ring' relative to last yank.
S must exist in `kill-ring'."
(or (cl-position s kill-ring-yank-pointer :test #'equal-including-properties)
(+ (cl-position s kill-ring :test #'equal-including-properties)
(- (length kill-ring-yank-pointer)
(length kill-ring)))))
(defun counsel-yank-pop-action-rotate (s)
"Rotate the yanking point to S in the kill ring.
See `current-kill' for how this interacts with the window system
selection."
(current-kill (counsel--yank-pop-position s)))
Adding counsel--yank-pop-position
would make this PR a borderline non-trivial contribution (right @abo-abo ?), so you may need to assign your copyright to the FSF first. Otherwise you can hope that and wait until my next PR lands which needs to define counsel--yank-pop-position
anyway. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any great desire to do that paperwork, otherwise I'd probably contribute more to this project, in fact I cut this PR down to make it fit under the total limit. So, anything you can do first I'm OK with. I'll examine your suggestions later, I'm preoccupied atm. But you are probably right that it could be simpler. I'm fairly new to writing [e]lisp code.
@@ -2814,7 +2820,8 @@ A is the left hand side, B the right hand side." | |||
|
|||
(ivy-set-actions | |||
'counsel-yank-pop | |||
'(("d" counsel-yank-pop-action-remove "delete"))) | |||
'(("d" counsel-yank-pop-action-remove "delete") | |||
("p" counsel-yank-pop-action-position "position"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto re: saying "rotate" instead of "position". It would then follow that a more intuitive key should be "r" instead of "p".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rotate makes sense.
@abo-abo Both of the |
Possible, but a bit hacky, see M-o k for |
@ambihelical Thanks. |
Is it just a matter of updating and refreshing the
How would it do that for static collections? |
(counsel-yank-pop-action-remove): Simplify logic. (counsel-yank-pop-action-rotate): Use current-kill. Re: abo-abo#1133
Done: #1359 |
(counsel--yank-pop-kills): New function. (counsel-yank-pop): Use it. (counsel-yank-pop-action-remove, counsel-yank-pop-action-rotate): Use it. Update collection and preselect for next ivy-call. Re: abo-abo#1133
Make counsel-yank-pop inter-operate better with the
existing variable kill-ring-yank-pointer