How would one write a function that one could bind to, say, SUPER-f, which inserts the code:
for () {
}
in the buffer with my cursor being moved into the () parens for filling out the loop guard?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityHow would one write a function that one could bind to, say, SUPER-f, which inserts the code:
for () {
}
in the buffer with my cursor being moved into the () parens for filling out the loop guard?
I think I'd do it like this:
(define-skeleton my-for-statement
"Insert a for () {...} skeleton."
nil
\n "for () {" \n > _ "}" \n)
The \n
are for "newlines" (and the ones at beg/end are only added if needed). The _
basically says that if you have selected a region before running the command, then this region will end up right where _
is (IOW, the region will be wrapped by the "for" statement). And the >
in front causes this region (if any) to be re-indented.
You can then do M-x my-for-statement
and that will insert the statement.