Skip to content
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

Counsel yank pop: paste after point #884

Closed
dieggsy opened this issue Feb 11, 2017 · 4 comments
Closed

Counsel yank pop: paste after point #884

dieggsy opened this issue Feb 11, 2017 · 4 comments

Comments

@dieggsy
Copy link
Contributor

@dieggsy dieggsy commented Feb 11, 2017

Currently, counsel-yank-pop seems to insert text before point. Is there a way to have it inserted after instead?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Feb 11, 2017

That's how yank (C-y) works. I suggest to get used to it. Or you can re-define this function in your config:

(defun counsel-yank-pop-action (s)
  "Insert S into the buffer, overwriting the previous yank."
  (with-ivy-window
    (delete-region ivy-completion-beg
                   ivy-completion-end)
    (insert (substring-no-properties s))
    (setq ivy-completion-end (point))))

Just add a save-excursion to the above function.

@dieggsy
Copy link
Contributor Author

@dieggsy dieggsy commented Feb 11, 2017

Thanks! The reason is I'm an evil user, and would like to make counsel-yank-pop-action more like evil-paste-after. I've redefined the function to this, which is close:

(defun counsel-yank-pop-action (s)
  "Insert S into the buffer, overwriting the previous yank." 
  (save-excursion
    (forward-char)
    (with-ivy-window
      (delete-region ivy-completion-beg
                     ivy-completion-end)
      (insert (substring-no-properties s))
      (setq ivy-completion-end (point))))
  (forward-char (length s)))

But on undo I get placed one char after original point. Do you know of a way to fix that?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Feb 11, 2017

Try (undo-boundary).

@dieggsy
Copy link
Contributor Author

@dieggsy dieggsy commented Feb 11, 2017

Great! Thanks again!

The final function:

(defun counsel-yank-pop-action (s)
  "Insert S into the buffer, overwriting the previous yank."
  (save-excursion
    (undo-boundary)
    (forward-char)
    (with-ivy-window
      (delete-region ivy-completion-beg
                     ivy-completion-end)
      (insert (substring-no-properties s))
      (setq ivy-completion-end (point))))
  (forward-char (length s)))

@dieggsy dieggsy closed this Feb 11, 2017
basil-conto added a commit to basil-conto/swiper that referenced this issue Sep 20, 2018
(counsel-yank-pop-after-point): New user option.
(counsel-yank-pop-action):
Use it to determine whether to exchange point and mark.
(counsel-yank-pop): Repurpose plain prefix arguments like C-u for
temporarily toggling the new counsel-yank-pop-after-point.

Re: abo-abo#884
Closes abo-abo#1761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants