25 ms·
I don't think it's quite what you're talking about, but I have an Emacs function that runs the current region through Python and replaces it with the stdout fro
by jlarocco 15y ago
I don't think it's quite what you're talking about, but I have an Emacs function that runs the current region through Python and replaces it with the stdout from running it.
For your example, I write this:
vars = list('abcdefghijklm')
for v,i in zip(vars, range(len(vars))):
print("#define {} {}".format(v, i))
Select it and press Ctrl+Alt+p and have it replaced by:
#define a 0
#define b 1
#define c 2
#define d 3
#define e 4
#define f 5
#define g 6
#define h 7
#define i 8
#define j 9
#define k 10
#define l 11
#define m 12
https://gist.github.com/1355548 https://gist.github.com/1355548
- yuan 15y agoOr just learn a little bit of Elisp, and do this: M-: (loop for i from ?a for j below 12 do (insert (format "#define %c %d\n" i j)))
- jlarocco 15y agoYeah, I considered that, but the situation comes up so infrequently I'd never remember the syntax. I use Python everyday anyway, so it almost comes naturally.