2020-06-27 Selective display

A few days ago I was working with some large JSON files. The top level of the file contained a large array, and each of its elements was a large object consisting of numbers, strings and other objects. I needed to work with a few elements at the top level of those objects, and did not want the lower-level objects to get in the way. In other words, I needed to hide them somehow.

Some modes allow for hiding e.g. function bodies, leaving only their headers. (Org-mode is probably the most well-known example.) Unfortunately, JSON mode is not one of them.

Selective display to the rescue. This is a very generic feature of Emacs, rather not known to everyone I suppose, which I find useful on more than one occasion. It hides everything indented more than some level. The UI is not very good – instead of using the point to designate the threshold level, you need to use a numeric prefix argument – but since I use it very rarely anyway, I can live with that. So I just moved the point to the last column I still wanted to see, pressed C-x = to see which column it was (it was the 12th one), and then said C-u 13 C-x $. (Pressing C-x $ with no argument shows everything back again.)

CategoryEnglish, CategoryBlog, CategoryEmacs