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.

  • fragbot2@alien.topOPB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

    My general thought:

    (defun zzz (elt)
       (let ((file (car elt))
                (repo (cadr elt))
                 (st (caddr elt))
                 (is (cadddr elt))
           (progn (find-file file)
             (search-forward repo)
             (switch-me-to-interactive-node-until-i hit-a-hotkey st is)
             (save-buffer)
             (kill-buffer))))
    

    It’s the switch-me function that I’m not sure how to approach.

  • mmaug@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months 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.