Closed KyleBarton closed 3 months ago
I think you'll most likely just need these parts of evil-paste-after
to get what you want:
(defun kjb/evil-insert-content-after (content)
"Insert CONTENT after the cursor."
(unless (eolp) (forward-char))
(insert-for-yank content)
(when (evil-normal-state-p) (evil-move-cursor-back)))
and I expect you can replace insert-for-yank
with insert
because you won't care about yank handlers. lmk if that works for you.
Thanks, yeah that works great! Appreciate your help.
Issue type
Environment
Emacs version: GNU Emacs 29.2 (build 2, aarch64-apple-darwin23.1.0, NS appkit-2487.20 Version 14.1 (Build 23B2073)) of 2024-01-26 Operating System: macOS Sonoma 14.5 Evil version: Evil version 1.15.0 Evil installation type: MELPA Graphical/Terminal: graphical Tested in a
make emacs
session (see CONTRIBUTING.md): NoProblem
I have a few use-cases where I'd like to "insert" a value while in normal mode, in such a way that mimics the behavior of
evil-paste-after
-- that is, after the "normal-mode" cursor, rather than before the cursor as in when usinginsert
. For instance, I have a quick function that pastes the current date into the buffer. I solve with a function that uses a register I don't normally use in combination withevil-paste-after
:Hence, instead of
(insert "foo")
, I can call(kjb/evil-paste-content-after "foo")
and text is pasted after the cursor.Question
So my question is, is there a way to do this without using a register? Ultimately it's kind of a hack because I just want to paste content programmatically in these use cases, so using the register is kind of a leaky abstraction. Really the only part of
evil-paste-after
that I'm looking to leverage is the logic that inserts into the active buffer after the normal-mode cursor, rather than before. However, I'm not sure how feasible it is to extract that logic in a way that's similar toinsert
.