I recently added a modification to my Enter keybinding based on an answer (if you can't see it, this is a link) on this SE. It was good and I liked it. So of course...
Now I want to add MORE dwim behavior. Specifically, while programming, if I'm typing a comment, I'd like to press the Enter key and the next line automatically also be a comment. E.g. in Ruby, if I have # blah blah|
where |
is the cursor, I want to press Enter and see
# blah blah
# |
So the question - what is preferred / philosophically correct with emacs?
Do I:
- Expand my
enter-key-dwim
function to just check for more things? - Do I switch to two small functions that work as a local-buffer
post-command-hook
and only run if the last command was the Enter key? - Put an advice around the Enter key behavior?
- Something else?
One comment says that I generally want to avoid post-command-hook
because it gets run after every keystroke as well, which seems to be a vote against option 2.
post-command-hook
if you reasonably can. Anything in that hook will run after every single command you enter. Doing so is probably going to be overkill, and depending on what you're asking Emacs to do, could be a big performance issue as well.enter-key-dwim
does? Maybe just edit a link to the Emacs SE answer you mentioned into your question...