Skip to content

Commit

Permalink
(minor) emacs-ide: fix headings
Browse files Browse the repository at this point in the history
  • Loading branch information
vindarel committed Mar 31, 2021
1 parent 8acb8b6 commit 92e26c4
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions emacs-ide.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Using Emacs as an IDE
---
title: Emacs
---

## Using Emacs as an IDE

This page is meant to provide an introduction to using [Emacs](https://www.gnu.org/software/emacs/) as a Lisp IDE.

Expand All @@ -12,7 +16,7 @@ straightforward way to get going.

<a name="Slide-2"></a>

## Why Use Emacs?
### Why Use Emacs?

* Emacs has fantastic support for working with Lisp code
* Not tying yourself into a single CL vendor's editor
Expand All @@ -32,7 +36,7 @@ straightforward way to get going.

<a name="Slide-3"></a>

## Emacs Lisp vs Common Lisp
### Emacs Lisp vs Common Lisp

* Learning Emacs Lisp is useful and similar (but different from CL):
* Dynamic scope is everywhere
Expand All @@ -50,7 +54,7 @@ straightforward way to get going.

<a name="Slide-slime"></a>

### SLIME: Superior Lisp Interaction Mode for Emacs
#### SLIME: Superior Lisp Interaction Mode for Emacs

[SLIME](http://common-lisp.net/project/slime/) is the goto major mode
for CL programming.
Expand All @@ -77,7 +81,7 @@ for CL programming.

Check out this **[video tutorial](https://www.youtube.com/watch?v=sBcPNr1CKKw)** ! (and the author's channel, full of great stuff)

#### SLIME fancy, contrib packages and other extensions
##### SLIME fancy, contrib packages and other extensions

SLIME's functionalities live in packages and so-called [contrib
modules](https://common-lisp.net/project/slime/doc/html/Contributed-Packages.html)
Expand Down Expand Up @@ -109,7 +113,7 @@ others
- Fuzzy-search of the REPL history,
- Fuzzy-search of the _apropos_ documentation.

#### REPL interactions
##### REPL interactions

From the SLIME REPL, press `,` to prompt for commands. There is completion
over the available systems and packages. Examples:
Expand All @@ -124,7 +128,7 @@ and many more.
With the `slime-quicklisp` contrib, you can also `,ql` to list all systems
available for installation.

### SLY: Sylvester the Cat's Common Lisp IDE
#### SLY: Sylvester the Cat's Common Lisp IDE

[SLY](https://github.com/joaotavora/sly) is a SLIME fork that contains
the following improvements:
Expand All @@ -137,7 +141,7 @@ the following improvements:
* Contribs are first class SLY citizens, enabled by default, loaded with ASDF on demand.
* Support for [NAMED-READTABLES](https://github.com/joaotavora/sly-named-readtables), [macrostep.el](https://github.com/joaotavora/sly-macrostep) and [quicklisp](https://github.com/joaotavora/sly-quicklisp).

## Finding one's way into Emacs' built-in documentation
### Finding one's way into Emacs' built-in documentation

Emacs comes with built-in tutorials and documentation. Moreover, it is
a self-documented and self-discoverable editor, capable of introspection to let you
Expand All @@ -161,7 +165,7 @@ The help keybindings start with either `C-h` or `F1`. Important ones are:

Some Emacs packages give even more help.

### More help and discoverability packages
#### More help and discoverability packages

Sometimes, you start typing a key sequence but you can't remember it
completely. Or, you wonder what other keybindings are related. Comes
Expand All @@ -179,7 +183,7 @@ See also [Helpful](https://github.com/Wilfred/helpful), an alternative to the bu
<img src="assets/emacs-helpful.png" style="height: 450px"/>


### Learn Emacs with the built-in tutorial
#### Learn Emacs with the built-in tutorial

Emacs ships its own tutorial. You should give it a look to learn the most important keybindings and concepts.

Expand All @@ -188,15 +192,15 @@ Call it with `M-x help-with-tutorial` (where `M-x` is `alt-x`).

<a name="Slide-9"></a>

## Working with Lisp Code
### Working with Lisp Code

In this short tutorial we'll see how to:

* edit Lisp code
* evaluate and compile Lisp code
* search Lisp code

### Packages for structured editing
#### Packages for structured editing

In addition to the built-in Emacs commands, you have several packages at your disposal
that will help to keep the parens and/or the indentation balanced.
Expand Down Expand Up @@ -228,11 +232,11 @@ go up the list. See explanations and even more on

<a name="Slide-10"></a>

### Editing
#### Editing

Emacs has, of course, built-in commands to deal with s-expressions.

#### Forward/Backward/Up/Down movement and selection by s-expressions
##### Forward/Backward/Up/Down movement and selection by s-expressions

Use `C-M-f` and `C-M-b` (`forward-sexp` and `backward-sexp`) to move
in units of s-expressions.
Expand All @@ -245,7 +249,7 @@ Use `C-M-@` to highlight an entire sexp. Then press `C-M-u` to expand
the selection "upwards" and `C-M-d` to move forward down one level of
parentheses.

#### Deleting s-expressions
##### Deleting s-expressions

Use `C-M-k` (`kill-sexp`) and `C-M-backspace` (`backward-kill-sexp`) (but caution: this keybinding may restart the system on GNU/Linux).

Expand Down Expand Up @@ -274,7 +278,7 @@ and you press `C-M-k`, you get:
~~~


#### Indenting s-expressions
##### Indenting s-expressions

Indentation is automatic for Lisp forms.

Expand Down Expand Up @@ -325,7 +329,7 @@ do (print j))

You can also select a region and call `M-x indent-region`.

#### Support for parenthesis
##### Support for parenthesis

Use `M-(` to insert a pair of parenthesis (`()`), `M-x check-parens`
to spot malformed sexps, `C-u <n> M-(` to enclose sexps with parens,
Expand All @@ -340,7 +344,7 @@ For example (point is before the parenthesis):
(|(- 2 2))
~~~

#### Code completion
##### Code completion

Use the built-in `C-c TAB` to complete symbols in SLIME. You can get tooltips
with [company-mode](http://company-mode.github.io/).
Expand All @@ -352,20 +356,20 @@ In the REPL, it's simply TAB.
Use Emacs' hippie-expand, bound to `M-/`, to complete any string
present in other open buffers.

#### Hiding/showing code
##### Hiding/showing code

Use `C-x n n` (narrow-to-region) and `C-x n w` to widen back.

See also [code folding](http://wikemacs.org/wiki/Folding).

#### Comments
##### Comments

Insert a comment, comment a region with `M-;`, adjust text with `M-q`.


<a name="Slide-11"></a>

### Evaluating and Compiling Lisp in SLIME
#### Evaluating and Compiling Lisp in SLIME

Compile the entire **buffer** by pressing `C-c C-k` (`slime-compile-and-load-file`).

Expand Down Expand Up @@ -427,9 +431,9 @@ See also [eval-in-repl](https://github.com/kaz-yos/eval-in-repl) to send any for

<a name="Slide-12"></a>

### Searching Lisp Code
#### Searching Lisp Code

#### Standard Emacs text search (isearch forward/backward, regexp searches, search/replace)
##### Standard Emacs text search (isearch forward/backward, regexp searches, search/replace)

`C-s` does an incremental search forward (e.g. - as each key is
the search string is entered, the source file is searched for the
Expand All @@ -450,27 +454,27 @@ and backward respectively)
expression search/replace


#### Finding occurrences (occur, grep)
##### Finding occurrences (occur, grep)

Use `M-x grep`, `rgrep`, `occur`

See also interactive versions with
[helm-swoop](http://wikemacs.org/wiki/Helm-swoop), helm-occur,
[ag.el](https://github.com/Wilfred/ag.el).

#### Go to definition
##### Go to definition

Put the cursor on any symbol and press `M-.` (`slime-edit-definition`) to go to its
definition. Press `M-,` to come back.

#### Go to symbol, list symbols in current source
##### Go to symbol, list symbols in current source

Use `C-u M-.` (`slime-edit-definition` with a prefix argument, also available as `M-- M-.`) to autocomplete the symbol and navigate to it. This command always asks for a symbol even if the cursor is on one. It works with any loaded definition. Here's a little [demonstration video](https://www.youtube.com/watch?v=ZAEt73JHup8).

You can think of it as a `imenu` completion that always work for any Lisp symbol. Add in [Slime's fuzzy completion][slime-fuzzy] for maximum powerness!


#### Crossreferencing: find who's calling, referencing, setting a symbol
##### Crossreferencing: find who's calling, referencing, setting a symbol

Slime has nice cross-referencing facilities. For example, you can ask
what calls a particular function, what expands a macro, or where a global variable is being used.
Expand Down Expand Up @@ -498,14 +502,14 @@ of the above, it lists every kind of references.

<a name="Slide-13"></a>

## Lisp Documentation in Emacs - Learning About Lisp Symbols
### Lisp Documentation in Emacs - Learning About Lisp Symbols

### Argument lists
#### Argument lists

When you put the cursor on a function, SLIME will show its signature
in the minibuffer.

### Documentation lookup
#### Documentation lookup

The main shortcut to know is:

Expand All @@ -518,16 +522,16 @@ Other bindings which may be useful:
- **C-c C-d #** for reader macros
- **C-c C-d ~** for format directives

### Inspect
#### Inspect

You can call `(inspect 'symbol)` from the REPL or call it with `C-c I` from a source file.

### Macroexpand
#### Macroexpand

Use `C-c M-m` to macroexpand a macro call


### Consult the CLHS offline
#### Consult the CLHS offline

~~~lisp
(ql:quickload "clhs")
Expand All @@ -539,16 +543,16 @@ Then add this to your Emacs configuration:
(load "~/.quicklisp/clhs-use-local.el" 'noerror)
~~~

## Miscellaneous
### Miscellaneous

### Synchronizing packages
#### Synchronizing packages

**C-c ~** (`slime-sync-package-and-default-directory`): When run in a
buffer with a lisp file it will change the current package of the REPL
to the package of that file and also set the current directory of the REPL
to the parent directory of the file.

### Calling code
#### Calling code

**C-c C-y** (`slime-call-defun`): When the point is inside a defun and
C-c C-y is pressed,
Expand Down Expand Up @@ -594,7 +598,7 @@ For defclass: `(make-instance ‘class-name )`.

(thanks to [Slime tips](https://slime-tips.tumblr.com/page/2))

### Exporting symbols
#### Exporting symbols

**C-c x** (*slime-export-symbol-at-point*) from the `slime-package-fu`
contrib: takes the symbol at point and modifies the `:export` clause of
Expand Down Expand Up @@ -628,16 +632,16 @@ or strings:
(lambda (n) (format "\"%s\"" (upcase n))))
~~~

### Project Management
#### Project Management

ASDF is the de-facto build facility. It is shipped in most Common Lisp implementations.

* [ASDF](https://common-lisp.net/project/asdf/)
* [ASDF best practices](https://gitlab.common-lisp.net/asdf/asdf/blob/master/doc/best_practices.md)

## Questions/Answers
### Questions/Answers

### utf-8 encoding
#### utf-8 encoding

You might want to set this to your init file:

Expand All @@ -658,7 +662,7 @@ This will avoid getting `ascii stream decoding error`s when you have
non-ascii characters in files you evaluate with SLIME.


### Default cut/copy/paste keybindings
#### Default cut/copy/paste keybindings

*I am so used to C-c, C-v and friends to copy and paste text that
the default Emacs shortcuts don't make any sense to me.*
Expand All @@ -671,9 +675,9 @@ Luckily, you have a solution! Install [cua-mode](http://www.emacswiki.org/cgi-bi
~~~


## Appendix
### Appendix

### All Slime REPL shortcuts
#### All Slime REPL shortcuts

Here is the reference of all Slime shortcuts that work in the REPL.

Expand Down Expand Up @@ -733,7 +737,7 @@ C-c M-i slime-fuzzy-complete-symbol
C-c M-o slime-repl-clear-buffer
```

### All other Slime shortcuts
#### All other Slime shortcuts

Here are all the default keybindings defined by Slime mode.

Expand Down Expand Up @@ -902,6 +906,6 @@ C-c C-v M-o slime-clear-presentations

[slime-fuzzy]: https://common-lisp.net/project/slime/doc/html/Fuzzy-Completion.html

## See also
### See also

- [Common Lisp REPL exploration guide](https://bnmcgn.github.io/lisp-guide/lisp-exploration.html) - a concise and curated set of highlights to find one's way in the REPL.

0 comments on commit 92e26c4

Please sign in to comment.