💾 Archived View for idiomdrottning.org › emacs-windows captured on 2023-04-26 at 14:00:19. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-03)
➡️ Next capture (2023-12-28)
-=-=-=-=-=-=-
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.
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.
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.
this advice, to get two different buffers when I do split
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 does what I want 99.99999% of the time.
This is something I cooked up today and I’ll try to get used to it over the good old C-x o which I’ve been using for 20 years. I’m not gonna remove my old binding but if this shaves a couple of millis off every day it might be worth it.
(defun dwim-next-buffer () (interactive) (if (= 1 (count-windows)) (switch-to-next-buffer) (other-window 1))) (defun dwim-prev-buffer () (interactive) (if (= 1 (count-windows)) (switch-to-prev-buffer) (other-window -1))) (global-set-key (kbd "<C-tab>") 'dwim-prev-buffer) (global-set-key (kbd "<M-C-tab>") 'switch-to-prev-buffer) (global-set-key (if (featurep 'xemacs) (kbd "<C-iso-lefttab>") (kbd "<C-S-iso-lefttab>")) 'dwim-next-buffer) (global-set-key (if (featurep 'xemacs) (kbd "<M-C-iso-lefttab>") (kbd "<M-C-S-iso-lefttab>")) 'switch-to-next-buffer)
If I’m on a frame with multiple windows, C-tab and C-S-tab cycles backwards and forwards between those windows (without messing with what buffers those windows are showing). But when I’m on a frame with just a single window, C-tab and C-S-tab cycles between the buffers instead. When I hold down meta I unambiguously get buffer switching within the current window. I originally had next and prev in the opposite directions but this matches more what I want.
I also want this to override whatever org-mode was doing with C-tab, so:
(define-key org-mode-map (kbd "<C-tab>") nil)
Sometimes I’m really done with a buffer for a while, so let’s bury it:
(global-set-key (kbd "C-S-q") 'bury-buffer)
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)
Some of this, especially the shell-key (and its scheme counterpart, which is C-c C-z), breaks down if emacs gets to split the window on its own. You can either prevent specific buffers from splitting the window with
(push (cons "\\*shell\\*" display-buffer--same-window-action) display-buffer-alist) (push (cons "\\*scheme\\*" display-buffer--same-window-action) display-buffer-alist) (push (cons "\\*Help\\*" display-buffer--same-window-action) display-buffer-alist) (push (cons "\\*Buffer List\\*" display-buffer--same-window-action) display-buffer-alist)
Or, instead of doing that, you can make the frame “unsplittable”, which, weird name for it, because you can still use C-x 3 and C-x 2 etc.
(add-to-list 'default-frame-alist '(unsplittable . t))
I prefer the first, more specific solution because there are some things that get weird in unsplittable frames, like completion buffers for example.