How to create an emacs macro for text templates
I am new to lisp and I am having trouble figuring out how to create a
macro in emacs with the following functionality: Say I am tired of writing
out the pattern in c++ for a for loop:
for (int i = 0; i < N; i++) {
}
Call this macro "forloop" then I would like to do the following: when I
type "M-x forloop" the macro prints out
for (int
in the buffer and waits for an input. Then I type "i" and hit return after
which the macro continues and prints
for (int i = 0; i <
And again waits for input. Finally after I type "N" and hit return the
macro finishes by printing the rest:
for (int i = 0; i < N; i++) {
}
After some extensive reading and testing, I was able to write simple lisp
functions, create my own macros, save them and call them and so on... but
I still can't quite figure out how to make a macro that does something
like I have described above. Any thoughts would be much appreciated!
Thanks in advance!
Macros like this could be really nice for speeding up coding in any
language. I would prefer the macro to be dynamic in the way described so
that you don't have to remember how many arguments it needs and in which
order they go when calling it.
No comments:
Post a Comment