ResultsMotivated.com

An Introduction to Emacs for Noobs

<2023-02-19>

Here's some Emacs tips intended for people who are absolute wet-behind-the-ears Emacs noobs.

1. What's Emacs?

Emacs is a great operating system, but it's a shame it doesn't have a decent text editor. – George Washington

Emacs is a text editor used primarily by programmers. Emacs can be set-up as a first-rate IDE for any programming language, but using it at that level requires a lot of skill. You probably won't be able to do it on the first day or even the first week. The main obstacle that new users face is that Emacs requires a lot of 3rd party packages and configuration to work. In practical terms, this means reading blog posts and documentation, shopping for packages, debugging, and editing your init file.

The good news is that it only takes a minimal amount of effort to get Emacs to a state where it is a viable light-duty text editor without IDE features. Emacs is definitely a better tool than Notepad++ or Gedit for simple text editing. For a long time, I used Emacs to edit code while knowing practically nothing about configuring it. The M-q autoindentation feature alone saved me a lot of time.

2. What to do first

Here's a bare minimum Emacs init file:

;; -----------------------------------------------------------------
;; MELPA
;; -----------------------------------------------------------------
(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("melpa-stable" . "https://stable.melpa.org/packages/")
                         ))


(package-initialize)

;; install use-package if it isn't installed already
(unless (package-installed-p 'use-package)
  (package-install 'use-package))
(require 'use-package)

;; -----------------------------------------------------------------
;; If you see `:straight t` in a `use-package` block, it's using `straight.el` (gets the package "straight from Git.")
;; If you see `:ensure t` in a `use-package` block, it's using MELPA. (technically, it's using `package.el`.)
;; If you see `:ensure nil`, that means don't use `package.el`. Makes sense when you want to use the built-in version
;; of a package, or if the package isn't on MELPA (e.g., personal packages that only exist locally.)
;; -----------------------------------------------------------------

;; Enable cua-mode (i.e., use "normal" copy-and-paste commands.)
(cua-mode)

The first thing we do is set-up a package manager. Put this in your ~/.emacs file, restart Emacs, and now you can do M-x package-install RET or M-x package-list-packages to install packages.

3. Editing your init file

Emacs has no "settings" screen. Instead, the way you change the behavior of Emacs is by editing the file ~/.init. The most important commands for this are:

  • C-M-x - Evaluate lisp at the point (i.e., the cursor.)
  • C-h o - Open documentation for the symbol under the point
  • C-h f - Open documentation for the function under the point

4. Emacs terminology

Emacs has a lot of unusual lingo. For example, a "window" in Emacs has a special meaning which is completely different from the usual meaning in the context of computing. The glossary of Emacs Wiki is an indispensable reference for this:

https://www.emacswiki.org/emacs/Glossary

5. Key bindings

Some people think of a key binding as a set of keys that you press all at once. For example, people think Ctrl-Alt-Delete means press all three buttons at the same time rather than Control, Alt and then Delete. In Emacs, shortcuts don't work that way. Emacs commands are more nuanced in that they have order. Failure to realize this will result in frustration.

6. Using Emacs self-help features

A few basic commands for viewing documentation, presented in order of importance:

  • C-h o - Open documentation for the symbol under the point. Works for most things, including functions and symbols.
  • C-h f - Open documentation for the function under the point. Works for functions that aren't interactive.
  • C-h P - Open documentation for a package.
  • C-h p - The main help screen. Most likely, this is not the quickest way to get what you want.

7. Themes

For me, feeling like I'm using a computer from an anime is not a priority. I did not change the default Emacs theme for a long time because I simply didn't care. That said, the default Emacs theme has some practical issues and it's not a bad idea to change it. One issue that comes to mind is that in tab-bar-mode, the color of the active tab is almost the same as the color of the inactive tab. There are better themes out there, but there are also a lot of terrible ones. It's easy to get lost in the sauce.

The themes from the package modus-themes stand out in terms of their level of quality. Use one of the modus themes if you want to avoid a whole category of UI bugs.

(use-package modus-themes
  :ensure t
  :config
  (load-theme 'modus-vivendi)
  (tool-bar-mode -1))

Keywords: emacs

Modified: 2024-09-10 10:10:00 EDT

Emacs 29.1.50 (Org mode 9.7.6)