Over at the Emacs subreddit, sebhoagie has a short post that some of you may find useful. Sebhoagie really likes narrowing and uses it all the time. Sometimes, though, the narrowed code refers to code outside the narrowed region and he occasionally wants to reference it and then return to the narrowed region.
That’s not a big problem of course. Just widen, search for the referenced code, highlight the original narrowed code, and renarrow. Of course there’s a bit of friction and if you need to do it often it can become a burden.
Sebhoagie has a writeup that explains his solution. The TL;DR is that he wrote a function that narrows to a region but when you widen, it remembers the narrowed region. If you narrow again (using his function) it will renarrow to the previous region and forget the saved region parameters. If you think it through, that does exactly what you want. When you’re finished with the narrowed region you simply widen in the normal way (with widen
) and everything is reset.
My solution is to use Artur Malabarba’s narrow-or-widen-dwim
that almost always does exactly what I want. Take a look at Malabarba’s post to see how it works. If you’re not using it, you’re definitely working too hard. Still, you may find sebhoagie’s useful. If you have a similar need, his code is a nice companion to Malabarba’s.
Narrowing really can be a superpower as sebhoagie says and it’s worthwhile making its use as easy as possible.