Idiomdrottning’s homepage

Bad Emacs defaults

Littering backup files all over the place

Emacs by default leaves files~ and #files# all over.

This is annoying because those files may get autoloaded.

A solution is

(make-directory "~/.emacs_backups/" t)
(make-directory "~/.emacs_autosave/" t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs_autosave/" t)))
(setq backup-directory-alist '(("." . "~/.emacs_backups/")))

I was working on a new installation where I didn’t have this in place yet and I kept trying to update a shell function, re-sourcing it but it never changed. Turns out it was loading from a backup~ of the same file.

Thanks to Susam for figuring out a cleaner solution to what I originally had here.

I also found that technomancy has a post similar to this and this is the only overlap we had at first. People really don’t like Emacs’ littering.♥

Backs up by moving the actual file

(setq backup-by-copying t)

The default is nil and that means that every time it makes one of those backups~, it actually moves your file there, copies the backup to the original name, and gives you the copy to work on. This isn’t just a philosophical dilemma (“Am I a butterfly that dreams I am a backup~?”) but actually breaks hardlinks. I can’t believe this is the default.

Sentences have two spaces between them

(setq sentence-end-double-space nil)

The default is t which might’ve made sense in the typewriter era but not only messes up filling paragraphs, it also borks the wonderful family of forward-sentence, kill-sentence, transpose-sentences etc.

If you like the double-spaces between sentences in paragraphs (which I don’t) but want to be able to use the sentence commands on text, a friend of mine has a solution.

Indentation, tabs, and spaces

Emacs famously has its idiosyncratic brace style and indentation style using a mix of tabs and spaces that no-one else uses.

Which would be fine in a vacuum but you end up fighting it when making changes in other people’s projects.

We’re on a super AI Lisp genius pile, can’t it figure it out from the rest of the file or the other files in the directory?

rrthomas and link2xt both wrote in suggesting dtrt-indent which, you’re gonna have to use a package for this one.

If you’re using straight.el:

(straight-use-package 'dtrt-indent)
(require 'dtrt-indent)

If you’re using the default package installer:

(unless (package-installed-p 'dtrt-indent) (package-install 'dtrt-indent)))

Then, to turn it on:

(setq dtrt-indent-global-mode t)

And then, once you’re sure you’ve got it set up the way you want to, and you wanna hide it from the modeline:

(setcar (alist-get 'dtrt-indent-mode minor-mode-alist) "")

Usually, in Emacs, shadowing an alist by pushing to head works but it didn’t for this, hence the setcar shenanigans.

There also Editor Config which you can install and hide (once you know if it works) similarly.

Ctrl-H doesn’t delete backwards

C-h being a convenient, home row way to backspace has been a thing since the original ASCII table was laid out, and is a staple feature whenever you see “Emacs shortcuts supported” like bash or zsh. Except in Emacs itself, where it launches a huge, prompting, window-splitting help affair.

This was the first Emacs setting I ever changed.

Not sure what’s the best way to do it; I use:

(global-set-key [(control h)] 'delete-backward-char)
(keyboard-translate ?\C-h ?\C-?)

require-final-newline

(setq require-final-newline t)

Technomancy’s setup reminded me of this one, which I also use. Not always what you want but most of the time, and, should definitively have been the default especially on bash. Things can get weird when your files don’t end in a newline.

Bonus: Kill whole line

The fact that Emacs just clears the line, not kill it, when there is no prefix arg is maybe not such a bad default. Starting out, I actually liked it, compared to vi. But the more time passes the less I like it. Pretty much all of the time I found myself hitting 1k instead of just k. Thankfully, there is:

(setq kill-whole-line t)

It kills up to newline if I’m not at column zero, but kills the whole line (newline and all) if I am at column zero. Pretty happy with that.