💾 Archived View for idiomdrottning.org › bad-emacs-defaults captured on 2023-04-26 at 13:42:46. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

➡️ Next capture (2023-06-14)

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

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.♥

technomancy — better-defaults.el

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.

fill-sentences-correctly.el

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.

dtrt-indent

EditorConfig plugin for Emacs

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.

frame-inhibit-implied-resize

From Tony Zorman’s Potpourri of Emacs Tweaks there’s a perfect example of an “I can’t believe nil is the default:

(setq frame-inhibit-implied-resize t)

Without this, Emacs will try to resize itself to a specific column size, but like Tony, I’m on a tiling wm, and I change font sizes all the time, so this is no good.

He also suggests

(setq pixel-scroll-precision-mode t)

and his description for why does make sense to me, but my older installation of Emacs doesn’t have that variable yet.

A Potpourri of Emacs Tweaks – Tony Zorman

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.