💾 Archived View for idiomdrottning.org › emacs-windows captured on 2024-02-05 at 11:13:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-12-28)

-=-=-=-=-=-=-

Emacs windows

I don’t like using any fancy packages that have it all figured out that I have to learn “on top” of Emacs. Just give me the basics and I have a few small tweaks on top of that.

DWM

First of all, I do sometimes like using several separate frames.

I run emacs --daemon so I can start new ones from the command line with alias ec="emacsclient -t" (opens in the same terminal) or with alias xec="emacsclient -c" (opens as a new X frame). ec is especially good when sshing in.

I also have emacsclient -c mapped to a global shortcut key so I can get to emacs even from other apps. I use dwm, so I have it mapped to s-super-e in dwm’s config.h.

I mean, I’m happy with dwm so I obviously don’t mind managing windows with it. I also use a web browser set to break out every tab into its own window for the same reason.

I close these pretty freely too, since I’m running the daemon I know that I can always reach emacs so there’s no fear of accidentally closing the last window.

These days, when I’m mostly using SSH and more rarely using dwm, I’m still using a couple of different tabs in the SSH apps.

god-mode override

For window splitting and deleting, I use the defaults (C-x 3, C-x 0 etc). I don’t know, I’ve just gotten used to them. I just started using this advice, to get two different buffers when I do split.

As recommended by god-mode, in addition to the defaults I have

(global-set-key (kbd "C-x C-1") 'delete-other-windows)
(global-set-key (kbd "C-x C-o") 'other-window)
(global-set-key (kbd "C-x C-2") 'split-window-vertically); or (split-window-func-with-other-buffer 'split-window-vertically)
(global-set-key (kbd "C-x C-3") 'split-window-horizontally); or (split-window-func-with-other-buffer 'split-window-horizontally)
(global-set-key (kbd "C-x C-0") 'delete-window)

just for when I’m in god-mode and I forget the space.

Splitting vertically, I’m pretty happy with having it split right down the middle but splitting horizontally can feel a li’l cramped on my 11″ screen. I don’t use cozify-window a lot but it’s nice to have:

this advice, to get two different buffers when I do split

god-mode

cozify-window

Finding that particular buffer

I don’t have anything special for finding and killing buffers, I find that C-x C-b, C-x b etc work well. After a while I got really sick of all the fancy icicle, iswitch stuff and just wanted to go back to the basics. The normal switch-to-buffer wasn’t giving me things in a good order with the souped up, Vertico completing-read, so I now use consult-buffer. It has the drawback that buffers are previewed but that’s sometimes a good thing.

The magical shell-key

I have a button that toggles the current window between a shell and itself. Now, I use C-z for this, I get that that overrides suspend-frame in the console (which I can remap, or call via M-x). But that’s why I chose that; I temporarily want to go from emacs to a shell and then back again and my finger was already used to hitting C-z for that.

(global-set-key [(control z)] 'shell)
(eval-after-load 'shell
  '(define-key shell-mode-map [(control z)] 'bury-buffer))

Also since I usually don’t use god-mode in notmuch, outside of composing, I’ve mapped some of my favorite god-mode keys specifically:

(require 'notmuch)
(define-key 'notmuch-show-mode-map (kbd "z") 'shell)
(define-key 'notmuch-search-mode-map (kbd "z") 'shell)
(define-key 'notmuch-search-mode-map (kbd "v") 'scroll-up-command)
(define-key 'notmuch-show-mode-map (kbd "v") 'notmuch-show-advance)
(define-key 'notmuch-show-mode-map (kbd "v") 'notmuch-show-advance)

I have something similar for Scheme and the Scheme REPL at C-c C-z.

Annoying splitting

Some of this breaks down if emacs gets to split the window on its own. You can either prevent specific buffers from splitting the window with

(setq pop-up-windows nil)
(setq split-window-preferred-function #'(lambda () nil))

(dolist
 (reg
  '("\\*shell\\*"
    "\\*Messages\\*"
    "\\*scheme\\*"
    "\\*Buffer List\\*"
    "\\*Help\\*"
    "\\*ag search text.*\\*"
    "\\*cider-repl.*\\*"
    "\\*deadgrep.*\\*"))
 (push (cons reg display-buffer--same-window-action) display-buffer-alist))

And, for Magit:

(defun magit-display-buffer-same-window (buffer)
  "Display BUFFER in the selected window like God intended."
  (display-buffer
   buffer '(display-buffer-same-window)))

(setq magit-display-buffer-function 'magit-display-buffer-same-window)

I love Magit, now that it doesn’t split the window on me anymore. With this code, when I make a commit, the diff comes up first which I can bury with Q. It’s only buried, I can still switch back to it if I need to check it more after I started writing the commit message. The message text is a li’l misleading (it starts talking about how to finish the commit message even though I’m looking at a diff) which is why there’s an official magit tutorial that sets it up so that the diff starts buried and you get the commit message right away. I tried that for a while but I’m pretty happy getting the diff first. I dunno.

I know that there’s alternatively a setting for making the frame “unsplittable” but that hasn’t been working very well, messing with completion buffers for example.