💾 Archived View for idiomdrottning.org › emacs-basics captured on 2024-08-25 at 00:50:18. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-03-21)
-=-=-=-=-=-=-
Emacs is a Lisp machine. Lisp is a programming language from the 1950s but it’s good. It looks different from C or JavaScript or shell scripts but just like them, you can make functions, and functions can be marked as interactive so they can be called as commands. Don’t worry, it comes with a huge amount of ready-made commands.
Commands can be bound to keyboard shortcuts, and many are, by default.
Emacs nerds write about keyboard shortcuts in an unusual way. Where a Windows user would write Ctrl+G, an Emacs nerd would express that as C-g. C is control, S is shift (does not work very well over Blink/Mosh), M is meta or alt or escape.
Keyboard bindings can be long chains, like the ESC ESC ESC example here. (Important to remember when you’re using describe-key, which can get confusing on such a “prefix key”.)
You can put stuff in init.el and it’ll get run when you start Emacs (and when you eval it). A great place to make your own commands and to set options.
For example, you can put
(setq backup-by-copying t)
This literally sets a variable named backup-by-copying to t, in Lisp code, to set an option.
There’s also a settings GUI and it adds stuff to this file for you, it’s called customize.
Modes are like apps in Emacs. Each buffer can have one major mode and any number of minor modes. I am typing this post in markdown-mode with a bunch of minor modes on.
There are modes for Vim nerds (evil-mode, see Packages, below) and for Windows nerds (cua-mode) and many others, so you can use the keyboard bindings you’re used to.
There are competing package managers in Emacs because of course there is.
I dislike the default one in favor of one called straight.el, because of two reasons:
1. It makes it easy to make and maintain local changes to Emacs packages, while you’re waiting for them to accept your patches
2. It makes it easy to use packages from the big repos (ELPA and MELPA) but also from any repository out there.
Another alternative package managing system, quelpa, share that second quality but straight.el is the best because of the first.
Other popular package systems include Doom (which is based on straight.el, and, Doom Emacs is like it’s own ready-made distro made by a Vim user. I haven’t tried it personally because get off my lawn I’m old but it looks good) and Spacemacs, another Vim-centric system that I don’t understand (something something layers?).
Installing straight.el and getting started
Emacs undo system works very differently than the modern undo/redo setup, but there’s a package that makes it work normal. I don’t use it because I got used to the weird Emacs way. Which I can’t explain or barely even consciously understand. Some deep part of my psyche learned it by trial and brutal error.
One thing I wish I had learned earlier is that the keyboard bindings F5 through F8, in addition to commands that start with C-c and a letter, are reserved for your own custom stuff and won’t get clobbered by well-behaved modes. C-c followed by Control combos aren’t reserved for you, but loose letter combos are, like C-c a and C-c A (which can be different).
Of course you can also override other keyboard bindings too, I do that all the time, but it’s nice to know that there are some that are reserved for your own stuff that packages aren’t really supposed to clobber.
What makes Emacs so much better than any other OS is how you can mix and match stuff from different “apps” on the function level. I’ve set it up so I can use the block quote formatter from markdown-mode when I’m writing emails in notmuch-message-mode.