Emacs Redux: Dedicate Windows with toggle-window-dedicated

Wait 5 sec.

You’ve carefully arranged your windows just the way you want them - source codeon the left, tests on the right, maybe a shell at the bottom. Then you run somecommand that calls display-buffer, and suddenly one of your carefully placedwindows gets hijacked to show a *Help* buffer or a compilation log. We’ve allbeen there.The display-buffer machinery is one of Emacs’s most powerful features, but alsoone of its most frustrating. Emacs 30 adds a simple, practical tool to help tameit: toggle-window-dedicated.How it worksThe concept of “dedicated” windows has existed in Emacs for a long time - adedicated window tells display-buffer “don’t touch me, display your buffersomewhere else.” But setting this up required Elisp:(set-window-dedicated-p (selected-window) t)Not exactly something you’d do interactively in the middle of a coding session.Emacs 30 changes this with a simple keybinding - C-x w d toggles the currentwindow’s dedicated status.That’s it. Press it once, and the window is dedicated. Press it again, and it’sback to normal.Here’s the whole thing in action. I dedicate the code window on the left (watchthe d appear in its mode line), then ask for help with C-h f - and instead ofhijacking my code window, the *Help* buffer politely opens on the right:Mode line indicatorWhen a window is dedicated, you’ll see a small indicator in the mode line: d - the window is dedicated (soft dedication) D - the window is strongly dedicatedThe indicator appears before the buffer name, right after the modificationindicators (the usual --- area).Practical uses Lock your source code windows so that help buffers, grep results, orcompilation output land in other windows instead. Protect your shell or REPL window from being taken over. Stabilize complex window layouts when running commands that spawn newbuffers.A workflow tipA nice pattern is to set up your window layout, then quickly dedicate the windowsyou want to protect: Arrange your windows In each window you want to lock, press C-x w d Go about your work - display-buffer will respect your dedicated windowsWhen you’re done and want to return to a more flexible layout, just toggle themoff again.I put off learning the display-buffer machinery for years - it’s famouslyfiddly - so having a one-keystroke escape hatch for the most common annoyance isa real relief. It won’t replace a properly tuned display-buffer-alist, but forquickly protecting a window in the middle of a session it’s hard to beat.How do you keep display-buffer from scribbling over your carefully arrangedlayout - dedicated windows, a hand-tuned display-buffer-alist, or somethingelse entirely? I’d love to hear about it in the comments!That’s all I have for you today. Keep your windows in their place!