Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add vim's ]p and ]P commands #896
Conversation
|
olmokramer
commented
Aug 8, 2017
I hope I can find some time tonight to update. |
VanLaser
commented
Aug 8, 2017
•
|
@olmokramer - sorry for putting you to such trouble! I'm not very familiar with github's workflow, nor with evil's tests (if I understand well, one could inspire from something like this test: evil-test-paste-after - maybe just a few, well-chosen, more difficult tests would do? E.g. pasting directly with a count, from a register) BTW, in the quest for perfection, there's also another improvement that can be made - after a paste operation, (evil-define-command evil-paste-before-and-indent (count &optional register yank-handler)
"Paste text with `evil-paste-before' and re-indent it so it has the
same indentation as the surrounding code."
:supress-operator t
(interactive "P<x>")
(evil-with-single-undo
(let ((text (evil-paste-before count register yank-handler)))
(evil-indent (evil-get-marker ?\[) (evil-get-marker ?\]))
(setq this-command #'evil-paste-before) ;; for `evil-paste-pop' (C-p)
text)))... although, ideally, Maybe if |
olmokramer
commented
Aug 8, 2017
|
@VanLaser That's alright, it's a good learning experience :) And thanks for yet another tip about |
olmokramer
commented
Aug 9, 2017
•
|
Ok, I've been trying to work on this for a few hours but made 0 progress (except that I found a bug in |
|
The return value is a string, I'll keep this one open as the only thing missing here are tests. Figuring them out takes like half an hour of staring at existing tests and another to write and test your own. |
olmokramer
commented
Aug 10, 2017
•
|
Well, wouldn't you want Then there's another issue: in vim, if the pasted text spans less than a line (e.g. EDIT: I got close to solving the problem by storing I did figure out the tests, they are quite easy indeed. I'll await your response and then write some if this is going to be mergeerd. |
VanLaser
commented
Aug 10, 2017
•
|
Because string properties just got discussed, in relation to that returned text, I just got the idea and checked, so ... if I'm not mistaken, the yanked text itself stores the type of the fetching operation (line, block or none - aka char) used when it got copied (and this is the text (evil-define-command evil-paste-after-and-indent (count &optional register yank-handler)
"Paste text with `evil-paste-after' and re-indent it so it has the
same indentation as the surrounding code."
:supress-operator t
(interactive "P<x>")
(evil-with-single-undo
(let* ((text (evil-paste-after count register yank-handler))
(paste-type (when (stringp text)
(car-safe (get-text-property 0 'yank-handler text)))))
;; paste-type -> evil-yank-line-handler, evil-yank-block-handler or nil
(message "%s" paste-type)
(evil-indent (evil-get-marker ?\[) (evil-get-marker ?\]))
(setq this-command #'evil-paste-after) ;; for `evil-paste-pop' (C-p)
text)))So, in this case, one could place the cursor differently, based on the value of BTW, small thing, I suggest using |
olmokramer commentedAug 8, 2017
]pand]Pbehave just likepandP, except that they re-indent the text that was pasted so it has the same indentation as the surrounding code.Lots of credits to https://reddit.com/u/VanLaser
Known issues:
evil-paste-afterandevil-paste-before) but I couldn't figure out how to do this, as the the call toevil-paste-*isn't the last function call in the function body...