Mike Zamansky has another great video up in his Using Emacs Series. This time it’s about using ripgrep to do some refactoring of his blog. The problem is that for reasons explained in the video, he upgraded Hugo—his blog software—and installed a new theme. The new Hugo broke the embedding of his videos and tweets and to fix things he needed to wrap the HTML code for the embeddings in a #+begin_export html
, #+end_export
pair. Further complicating things is that the Org sources for the posts were scattered across multiple directories.
Ripgrep to the rescue. It will search recursively into all subdirectories looking for matches to the regex that you give it. The results, of course, are gathered in an output buffer that can be made editable. Once the changes are made to the ripgrep output buffer, they will be saved to the original files. Zamansky chose to make the changes with a keyboard macro, which worked out well. Once he saved the buffer, his blog posts with embedded videos or tweets started working again.
Zamansky installed the rg.el
package to act as his Emacs interface to ripgrep. I prefer to use the Ivy/Counsel interface, council-rg
. It has nice integration with Ivy and is essentially the only grep-like tool I use. It’s built into Ivy/Swiper/Counsel, so if you’re using Swiper, you already have it installed. I have it bound to Ctrl+c k because I use it so often. It has the other nice feature that if a file is a member of Git repository, it will begin the search at the repository root. That turns out to be very handy.
The video is 13 minutes, 40 seconds long so you’ll need to schedule some time. As usual with Zamansky’s videos, it’s well worth your time. And you’ll get to see his nifty new theme.