Skip to content

Commit

Permalink
Add emacs tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Sep 27, 2024
1 parent 356a6f4 commit 9fb4924
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 12 deletions.
Binary file added content/emacs/media/emacs-tut-quick-help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions content/emacs/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
title: Emacs Tutorial
tags: [emacs]
---

There are many tutorials, but this one is mine.

## History

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

Start Emacs in the terminal like this: `emacs -nw [file]`.
You can ensure a clean start using the `-Q` option.

Emacs keybindings use the <kbd>alt</kbd> and <kbd>ctrl</kbd> modifier like this:

- `M-x` means press <kbd>alt</kbd>+<kbd>x</kbd>. `M` stands for *meta*, and it is the *alt* key on PC keyboard.
- `C-x 1` means press <kbd>ctrl</kbd>+<kbd>1</kbd>, release <kbd>ctrl</kbd> then press <kbd>1</kbd>.
- `C-h C-q` means press <kbd>ctrl</kbd>+<kbd>h</kbd> then <kbd>ctrl</kbd>+<kbd>q</kbd>. You can also maintain <kbd>ctrl</kbd> while pressing <kbd>h</kbd> then <kbd>q</kbd>.

When you are stuck or if you want to exit a menu, hit `C-g` multiple time to stop what emacs is doing.
If you ever need to quit emacs, hit `C-x C-c`, but you shouldn't do that :).

After starting Emacs, run the `help-quick` command by pressing `C-h C-q`, your terminal will look like this:

![emacs-tut-quick-help](media/emacs-tut-quick-help.png)

At the bottom you now have a helpful quick help window to show you the essential commands.
Once you are comfortable, just close it by running the same command again.

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

Here is how to move the cursor:

| *Key* | *Command* | *Description* |
|---------------------------------------|------------------------|----------------------------------------------------------|
| `C-a` or <kbd>HOME</kbd> | move-beginning-of-line | Move point to visible beginning of current logical line. |
| `C-e` or <kbd>END</kbd> | move-end-of-line | Move point to end of current line as displayed. |
| `C-f` or <kbd>→</kbd> | forward-char | Move forward to the next character. |
| `M-f` or <kbd>ctrl</kbd>+<kbd>→</kbd> | forward-word | Move forward to the next word. |
| `C-b` or <kbd>←</kbd> | backward-char | Move backward to the previous character. |
| `M-b` or <kbd>ctrl</kbd>+<kbd>←</kbd> | backward-word | Move backward to the previous word. |
| `C-p` or <kbd>↑</kbd> | previous-line | Move vertically up |
| `M-{` | backward-paragraph | Move backward to start of paragraph. |
| `C-n` or <kbd>↓</kbd> | next-line | Move vertically down |
| `M-}` | forward-paragraph | Move forward to end of paragraph. |
| `M->` | end-of-buffer | Move point to the end of the buffer. |
| `M-<` | beginning-of-buffer | Move point to the beginning of the buffer. |
| `C-v` or <kbd>PageDown</kbd> | scroll-up-command | Scroll text of selected window upward. |
| `M-v` or <kbd>PageUp</kbd> | scroll-down-command | Scroll text of selected window down. |

> Note that these keys mostly works by default with readline (e.g. in bash).
That cover 99% of my cursor movement needs, and with a little practices it's easy to get used to. In particular, notice how <kbd>ctrl</kbd> is used for short move while <kbd>alt</kbd> makes longer move.

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

## Window navigation

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

| *Key* | *Command* | *Description* |
|---------|----------------------|------------------------------------------------------|
| `C-x 1` | delete-other-windows | Make WINDOW fill its frame. |
| `C-x 2` | split-window-below | Split WINDOW into two windows, one above the other. |
| `C-x 3` | split-window-right | Split WINDOW into two side-by-side windows. |
| `C-x 0` | delete-window | Delete WINDOW. |
| `C-x o` | other-window | Select another window in cyclic ordering of windows. |
| `C-x b` | switch-to-buffer | Display buffer in the selected window. |

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

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

| *Key* | *Command* | *Description* |
|-----------|-------------|--------------------------------------------------|
| `C-x C-f` | find-file | Edit file FILENAME. |
| `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. |

## Customization

In this section I introduce how to customize behaviors.

## Configuration

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

```scheme
;; Do not ask for permission to kill a buffer
(global-set-key (kbd "C-x k") 'kill-current-buffer)
```

## Package

In this section I introduce how to install packages.

## Language server

In this section I introduce language server.

## Magit

In this section I introduce how to git.
2 changes: 1 addition & 1 deletion content/project/devenv.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ tags: [nix]

Provide the best in class developer experience for [[programing-languages]] enthusiast.

It integrates an [[emacs]] distribution.
It integrates an [[softwares/emacs]] distribution.

Source: https://github.com/podenv/devenv
11 changes: 0 additions & 11 deletions content/zettle/softwares/emacs.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ My configuration is mostly provided by [[devenv]] and customized in my [dot-file
| C-h v | check variable doc |
| C-h m | check mode doc |

## Navigation

| **key** | **info** |
|---------|--------------------------|
| C-x 1 | fullscreen frame |
| C-x 2 | split frame horizontally |
| C-x 3 | split frame vertically |
| C-x 0 | close current frame |
| C-x o | move between frame |
| C-x b | switch buffer |

## Commands

| **key** | **info** |
Expand Down

0 comments on commit 9fb4924

Please sign in to comment.