reddit / emacs

Run emacs macro on each file then save result as txt

Mamonimoni · 2022-08-28 01:47
I have a bunch of plain text files with a special extension. I also need to do some cleanup on them which I managed to do using flush-lines. I created and saved a macro for this. I can open each file manually and run my macro which is fine. The problem is that I have thousands of them. Here is where I am lost. How do I run my macro on every file with a specific extension and then save the result with the same filename but as a .txt?
Alan_Shutko · 2022-08-28 13:50
Roughly, here is what I do. Use M-x find-name-dired to bring up a dired buffer with the list of files Put cursor on the first one. Edit the macro so that it does the following: * f (to open the file) * Whatever your macro needs to do * C-x C-w to write the file, changing the name. * C-x k to kill the buffer * SPC to move to the next file Then executing the macro should do one file, and you can execute it a lot to do lots of files. If you google "dired macros" there are some hits that show this and slightly different methods.