emacs replace across multiple files - 11-28-21

This week I was making some changes to a hugo shortcode I use on my personal site for videos.

Old one:

{< video-with-caption
    remote_url="https://travisshears.com/image-service/videos/galtenberg-ski-tour/over_the_tree.webm"
    backup_url="https://travisshears.com/image-service/videos/galtenberg-ski-tour/over_the_tree.mp4"
    title="through the woods we go"
>}

New one:

{< video-with-caption
    webm_url="https://travisshears.com/image-service/videos/galtenberg-ski-tour/over_the_tree.webm"
    mp4_url="https://travisshears.com/image-service/videos/galtenberg-ski-tour/over_the_tree.mp4"
    title="through the woods we go"
>}

Problem is this change crosses 50+ files. I knew some ways with sed to regex substitute it across the files but I wanted something more emacs. Eventually found wgrep! Its allows you to search with normal +default/search-project then edit the results.

  • <SPC s p> to search the project
  • type search ex: “remote_url”
  • <C-c C-o> to open the results
  • delete some results with <d>
  • <C-c C-p> to make the results editable
  • make edits example :%s/remote_url/webm_url/g
  • <Z Z> to save changes across all the files
  • lastly review changes via git

final patch: https://git.sr.ht/~travisshears/travisshears.com/commit/71e9c89c32f9b9f362e8e94ca8530530c1418284


In the making of this snippet I had some other fun:

  • this screen recording led me to finding keycastr. A very helpful mac osx program that displays keys as you type them. Great for tutorials.
  • My personal site is not open source because I write lot of drafts that don’t get published for months… For this snippet I wanted to show part of that source code as a patch, decided on hosting it as a sourcehut paste. To create the paste I wrote a sourcehut-paste.
  • Video was created with Quicktime screen recording feature plus my video helper app, ts-video
\- [ emacs ]