Skip to content

Commit

Permalink
Update emacs tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Oct 1, 2024
1 parent c88a543 commit 9597f10
Showing 1 changed file with 83 additions and 15 deletions.
98 changes: 83 additions & 15 deletions content/emacs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ There are many tutorials, but this one is mine.
To put things into perspective, Emacs started in 1976 as a set of macros for the Tape Editor and Corrector (TECO).
GNU Emacs began in 1984 as a true Lisp interpreter, and it is among the oldest free and open source projects still under development.

## Start
## First contact

In this first session you learn the most basic usage.

### Start

Start Emacs in the terminal like this: `emacs -nw [file]`.
You can ensure a clean start using the `-Q` option.
Expand All @@ -31,13 +35,14 @@ After starting Emacs, run the `help-quick` command by pressing `C-h C-q`, your t
At the bottom you now have a helpful quick help window that shows you the essential commands.
Once you are comfortable, close the help window by running the same command again.

## Cursor movements
### Cursor movements

In this section I introduce how to move the cursor, also called *point*.

You can use the arrow keys <kbd>←</kbd> <kbd>↑</kbd> <kbd>↓</kbd> <kbd>→</kbd> and <kbd>HOME</kbd> <kbd>END</kbd> <kbd>PageUp</kbd> <kbd>PageDown</kbd>.
While you can use the arrow keys <kbd>←</kbd> <kbd>↑</kbd> <kbd>↓</kbd> <kbd>→</kbd> and <kbd>HOME</kbd> <kbd>END</kbd> <kbd>PageUp</kbd> <kbd>PageDown</kbd>,
I recommend learning faster motions like `forward-paragraph` to move more efficiently.

Here is how to move the cursor:
Here are the main cursor movements:

| *Key* | *Command* | *Description* |
|---------------------------------------|------------------------|----------------------------------------------------------|
Expand All @@ -58,12 +63,12 @@ Here is how to move the cursor:

> Note that these keys mostly work by default with readline (e.g. in bash).
That covers 99% of my cursor movement needs, and with a little practice it's easy to get used to.
In particular, notice how <kbd>ctrl</kbd> is used for short movement while <kbd>alt</kbd> makes longer movement.
This covers most cursor movements, and with little practices you can memorize the commands.
Notice how <kbd>ctrl</kbd> is used for short movement while <kbd>alt</kbd> makes longer movement.

Checkout the `M-x help-with-tutorial` to get some practice.

## Window navigation
### Window navigation

In this section I introduce how to manage the window layout.

Expand All @@ -78,7 +83,7 @@ In this section I introduce how to manage the window layout.

To move between windows, run `M-x windmove-default-keybindings` to use <kbd>shift</kbd>+<kbd>arrows</kbd> for moving the cursor to another window.

## File
### File

In this section I introduce how to open and save a file.

Expand All @@ -88,27 +93,90 @@ In this section I introduce how to open and save a file.
| `C-x C-s` | save-buffer | Save current buffer in visited file if modified. |
| `C-x k` | kill-buffer | Kill the buffer specified by BUFFER. |

### Edition

In this section I introduce how to edit buffers.

| *Key* | *Command* | *Description* |
|---------|--------------------|-----------------------------------------------------|
| `C-SPC` | set-mark-command | Set the mark where point is, and activate it. |
| `M-w` | kill-ring-save | Save ("copy") text between point and mark. |
| `C-w` | kill-region | Kill ("cut") text between point and mark. |
| `C-k` | kill-line | Kill the rest of the current line. |
| `M-DEL` | backward-kill-word | Kill previous word. |
| `C-y` | yank | Reinsert ("paste") the last stretch of killed text. |

To replace text:

| *Key* | *Command* | *Description* |
|---------|----------------------|--------------------------------------------------|
| `M-%` | query-replace | Replace some STRING occurrences. |
| `C-M-%` | query-replace-regexp | Replace some things after point matching REGEXP. |

Once Emacs find a match, press:

- <kbd>y</kbd> to replace
- <kbd>n</kbd> to skip
- <kbd>!</kbd> to do all replacement without asking.
- <kbd>ctrl</kbd>+<kbd>g</kbd> to cancel.


## Customization

In this section I introduce how to customize behaviors.
In this second session we learn how to customize Emacs behaviors and setup some quality of life.

### winner-mode

Run `M-x winner-mode` to records the changes in window configuration so that you can revert any layout mistake with `M-x winner-undo`, for example after running `delete-other-windows` by mistake.

### savehist-mode

## Configuration
Run `M-x savehist-mode` to save the minibuffer history. That way, pressing `M-x` shows the last used commands.

In this section I introduce how to persist configuration to your `~/.emacs.el` file.
### dot emacs

Add the following to your `~/.emacs` file to ensure the settings persist accross restart:

```scheme
;; Use shift+arrow to change window
(windmove-default-keybindings)
;; Records window configuration and enable `M-x winner-undo` command to revert change
(winner-mode)
;; Keep track of useful commands
(savehist-mode)
;; backup into one flat dir
(setq backup-directory-alist '(("." . "~/.emacs.d/backup")))
;; store custom variable to ~/.emacs.d/custom.el
(setq custom-file (locate-user-emacs-file "custom.el"))
;; Do not ask for permission to kill a buffer
(global-set-key (kbd "C-x k") 'kill-current-buffer)
```

## Package
Run `M-x eval-buffer` to apply the settings now.

### package-install

Run `M-x package-install` to install modes for custom syntax, for example install:

- `markdown-mode`
- `haskell-mode`

Add other modes like `yaml-mode`, `go-mode` depending on your usage.


## Development

In this section I introduce how to install packages.
In this session we learn how to write software with Emacs

## Language server
### Language server

In this section I introduce how to use a language server.

## Magit
### Magit

In this section I introduce how to git.

0 comments on commit 9597f10

Please sign in to comment.