Learn Emacs: Keyboard Macros
rawsyntax.com
Learn Emacs: Keyboard Macros
1–10 of 27 posts
Re: Learn Emacs: Keyboard Macros
#2 #define a 0
#define b 1
...
#define l 10
#define m 11
Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way to create a list of sequential things so I don't have to type 1 down 1 down 1 down 1 down 2 down 2 down 2 down...Surely this is a solved problem.
Re: Learn Emacs: Keyboard Macros
#3There have been various times in my programming career that I've wanted an emacs macro with arguments, so that it would do things like concatenate a number in each line. Things like this in C: #define a 0 #define b 1 ... #define l 10 #define m 11 Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way…
My lisp-fu isn't good enough to implement this today, but I would find it really easy to:
* copy `#define a 0` with C-k, M-w, C-y, RET, C-y, RET, C-y, RET, ... (so copy the line and paste N times)
* begin interactive search-and-replace, with usual keybindings (Y for replace, N for skip, . for replace and stop)
* but with additional keybinding, e.g. + for change replacement and apply
Alternatively, the replace argument in M-% would be a [somehow-delimited] list of replacements, and + or capital Y would pop off the next replacement and begin using that.
Re: Learn Emacs: Keyboard Macros
#4There have been various times in my programming career that I've wanted an emacs macro with arguments, so that it would do things like concatenate a number in each line. Things like this in C: #define a 0 #define b 1 ... #define l 10 #define m 11 Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way…
http://www.emacswiki.org/emacs/KeyboardMacrosTricks
From there:
If you want to produce this list:
test1
test2
test3
...
Do like this:
C-x r n q (store the number 1 in register q)
C-x ( (start macro recording)
test C-x r i q (insert contents of register q)
C-x r + q (increment register q by 1)
RET (new line)
C-x ) (stop macro recording)Re: Learn Emacs: Keyboard Macros
#5There have been various times in my programming career that I've wanted an emacs macro with arguments, so that it would do things like concatenate a number in each line. Things like this in C: #define a 0 #define b 1 ... #define l 10 #define m 11 Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way…
You should check out the EmacsWiki macro tricks page: http://www.emacswiki.org/emacs/KeyboardMacrosTricks From there: If you want to produce this list: test1 test2 test3 ... Do like this: C-x r n q (store the number 1 in register q) C-x ( (start macro recording) test C-x r i q (insert contents of register q) C-x r + q (increment register q by 1) RET (new line) C-x ) (stop macro recording)
Re: Learn Emacs: Keyboard Macros
#6There have been various times in my programming career that I've wanted an emacs macro with arguments, so that it would do things like concatenate a number in each line. Things like this in C: #define a 0 #define b 1 ... #define l 10 #define m 11 Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way…
Re: Learn Emacs: Keyboard Macros
#7There have been various times in my programming career that I've wanted an emacs macro with arguments, so that it would do things like concatenate a number in each line. Things like this in C: #define a 0 #define b 1 ... #define l 10 #define m 11 Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way…
I know exactly what you mean -- but perhaps it doesn't even have to be a macro, but a more powerful search-and-replace, with changing replacements. My lisp-fu isn't good enough to implement this today, but I would find it really easy to: * copy `#define a 0` with C-k, M-w, C-y, RET, C-y, RET, C-y, RET, ... (so copy the line and paste N times) * begin interactive search-and-replace, with usual keybindings (Y for repla…
Re: Learn Emacs: Keyboard Macros
#8There have been various times in my programming career that I've wanted an emacs macro with arguments, so that it would do things like concatenate a number in each line. Things like this in C: #define a 0 #define b 1 ... #define l 10 #define m 11 Usually I take that as a sign that I need to write some other program to generate the lines of the C program, but for some tasks that's overkill and I want an automated way…
M-x replace-regexp
Replace regexp: test\(.+\)
Replace regexp with test\#
You can actually drop arbitrary lisp in the middle of search/replace expressions. So, if you'd like to number from 1 instead of 0, M-x replace-regexp
Replace regexp: test\(.+\)
Replace regexp with test\,(1+ \#\)
I'm sure with more lisp tricks, you can get delimited lists: M-x replace-regexp
Replace regexp: test\(.+\)
Replace regexp with test\,(aref ["one", "two", "three"] (mod \# 3))
(Not sure that works, but you get the idea).Anyway, all of this was basically stolen from Steve Yegge. You should totally go read his article if you're interested: http://steve-yegge.blogspot.com/2006/06/shiny-and-new-emacs-...
Re: Learn Emacs: Keyboard Macros
#9Emacs documentation is large and well written, yet we discover features with google, it's not even centralized, let's avoid duplication of efforts and reinforce emacswiki. Maybe integrating emacswiki with the standard emacs distribution in some way ? (if it's not done already.. which would render this little rant finally funny)
Re: Learn Emacs: Keyboard Macros
#10Any suggestions for other emacs topics I should blog about?
Thanks for your interest.