Like most Emacsers, I very seldom restart Emacs. When I do it’s usually because I just finished my weekly ELPA update. Despite my extensive configuration, Emacs starts up reasonably quickly for me but I still hate restarting it. The major reason is Magit. I love Magit but the first time I open the status page, the “Untracked Files” and “Unmerged Info” sections are expanded. For various reasons, these sections are fairly large in some of my repositories so I always have to close them. If I don’t do that, disaster is only a keystroke away when I accidental stage a large collection of untracked files and freeze Emacs for a minute or two and then another long wait when I undo the erroneous staging.
Obviously, this is a situation crying out for a remedy. The obvious approach is to look for some variables controlling which sections are displayed initially. It’s not hard to find it. The magit-section-initial-visibility-alist
variable is an alist that controls whether a section is shown or hidden. That seems straightforward but the problem is discovering the names of the sections. They’re not the labels shown on the status page. I checked the source code but couldn’t find a list of the names. Finally, I dropped back to basics and RTFM. The manual has a section on matching section names. There I found the magit-describe-section-briefly
function that displays information about the section under the point. The information is meant to help maintainers with debugging so it’s not very end-user friendly. However, part of the output is [XXX status]
and the XXX is the name we’re after.
With that information at hand, I solved my problem by adding
(setq magit-section-initial-visibility-alist
'((stashes . hide) (untracked . hide) (unpushed . hide)))
to my init.el
. If you have other sections you’d like to control, you can use magit-describe-section-briefly
to discover their names and add them to the alist. The available options are show
and hide
.