this post was submitted on 18 Nov 2023
2 points (100.0% liked)

Emacs

313 readers
3 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

I have a number of edits I need to do to yaml files. I'd like to drive emacs in the following way: mapcar over a list calling a function that opens a file, searches for a match, switches to interactive mode so I can adjust point, inserts some pre-formatted data specific to the match, allows me to edit the insertion to fix the inevitable typos that exist and, when I'm ready, saves the file and moves to the next element. I'm automating the file and buffer navigation as well as the content insertion but doing precise placement and editing by hand. Sadly, I did this once previously years ago but I don't remember how.

Relevant rant: this stupidity's only necessary because yaml's flexibility for too many ways to do the same thing so reading the yaml in, adjusting the data structures and writing it back out make pull requests horrific as minute semantic changes can have massive syntactic ones.

you are viewing a single comment's thread
view the rest of the comments
[–] mmaug@alien.top 1 points 1 year ago

My instinct would be to use dired to assemble the list of files and then use the dired open file action, do the simple edit, save and close the buffer, which will return to the dired buffer again and go to the next file name all within an interactive macro. And then repeatedly execute the macro as it steps through each file.

Alternatively, manually assemble the list of files in a text buffer and use M-x ffap to open the file under the cursor, and do the same as above.

If this is something you will be doing frequently, then writing elisp may make sense, but you can get the elisp that a macro represents as well.

Start with an interactive macro.