3

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?

eof
  • 91
  • 1

1 Answers1

3

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.

Stefan
  • 26,404
  • 3
  • 48
  • 85