PurplSite

Codeberg logo

Emacs

./img/xkcd-real-programmers.png

https://xkcd.com/378/

Interesting video on the history of Emacs: https://youtu.be/8dpnow-j000

Me

Ben Whitley github.com/purplg Just someone who loves computers.

I have a tendency to move fast (sorry!), so please remind me to slow down if I go too fast.

What is Emacs?

Emacs is a Lisp engine that was turned into an editor. The core is written in C but most of it is written in Emacs Lisp. This enables you to change pretty much anything about it at runtime.

It's harder to find things Emacs can't do.

Text editor

Emacs is an OS that lacks a decent text editor

Everything is a buffer. Use the same editing tools, everywhere!

Built-in Emacs keybindings

C-x M-c M-butterfly

Evil

Vim in Emacs? Sacrilege.

Meow?

I dunno, but people seem to like it.

Minimalistic, modal editing.

Web browser

I never use this functionality, but it exists.

(eww "https://google.com")
(eww "https://www.gnu.org/software/emacs/")
(eww "https://orgmode.org")

File browser

Example with this later

Git porcelain (Magit)

The best Git frontend out there.

Window manager

Emacs X Window Manager (EXWM) is a window manager that uses Emacs for its windowing. Every X11 client (window) is treated as Emacs buffer. It's for the ultra-enthusiasts!

IDE

Thanks Microsoft! (???)

lsp-mode

  • Most robust feature set.
  • Supports most of the LSP protocol.
  • Heavyweight

eglot

  • Recently merged into Emacs 29.
  • Growing since merged.
  • Middleweight

lsp-bridge

  • Async
  • Fast
  • Lightweight

Emacs is unfortunately very single-threaded. It's old. So lsp-bridge uses external Python service to handle asynchronous LSP requests.

Task manager (org-mode)

  • TODO list
  • Agenda
  • Personal Wiki (Roam/Zettelkasten)
  • Note-taking

Jupyter notebook (well yes, but also no)

org-babel

Word processor

  • Org
  • Markdown
  • LaTeX

E-mail client

via IMAP or POP

Social media client

  • Mastodon
  • Twitter
  • Reddit

Presentation application

You're lookin' at it

Chat

Telegram Matrix IRC

Anything else you can imagine (well mostly)

Why Emacs?

Fun

Emacs Lisp is a joy to write and being able to customize anything to your liking is a lot of fun!

Don't like it? Change it.

I forked the package used to present this, org-present, to show org options since this presentation is very meta.

  • Live, hackable environment
  • Only the core of Emacs is in C. Most is in Emacs Lisp.
  • This allows you redefine pretty much any function at runtime
(emacs-version)
(defun emacs-version (&optional here)
"But now it returns this")

Known for high quality built-in documentation

Look up any symbol for references, definition, docstrings, and much more with a simple keychord.

Dired

Browse and manage files. This is actually a package called dirvish, but it just a prettifies dired and adds features.

Visual block renaming

Everything is a buffer Example

Sidebar

It's nice having the same interface in various places. Things work the way you expect.

Org mode

An interactive markup language. Notes, TODOs, documents, whatever.

[2/5] Make sandwich

DONE Place bread on plate

TODO Add ham

TODO Add cheese

TODO Apply mustard

DONE Throw away mayonnaise

TODO Buy more bread

SCHEDULED: <2023-02-27 Mon>

Magit

Probably the best frontend to Git out there, albeit a bit of a learning curve.

Supports pretty much every git function there is.

Makes rebasing super easy. Much easier than trying to do it from the command line. Especially when editing commit history.

Babel

Literate configuration

Invert relationship of code and comments. Put code in your comments.

Jupyter notebook-like features

Structured output

Multiple languages that can work together!

Export supported languages outputs to common data structures (tables, lists, etc) as the input to another code block.

Babel - Code blocks

import random

print(random.randint(1, 100))

Babel - Sessions

Assign some variable in session "one"

session_name = "session-one"

Assign some variable in session "two"

session_name = "session-two"

Print out session_name in session "one"

print(session_name)

Print out session_name in session "two"

print(session_name)

Babel - Multiple languages

Here we name a block greeting. The stdout of this block will be saved into a variable with this name.

a = "Hello!"
print(a)

For bash block, we store the output of the greeting block into a variable named input.

echo $input

For emacs-lisp block, we store the output of the greeting block into a variable named input.

(s-trim (reverse input))

Now let's flip it back around with bash

echo ${input} | rev

Babel - Structure output

First we create a new code block that creates a list of number-words from 0 to 9.

return ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]

Using Python in a different block, we iterate through each number and print the length

(re-search-forward "^[[:space:]]*\\(#\\+\\)\\([^[:space:]]+\\).*" nil t)
(match-string 2)
for number in numbers:
  print(f"{number:>5}: {len(number)}")

Or we can use bash, for some reason

for number in ${numbers[@]}; do
  printf "%5s: %u\n" ${number} $(echo ${number} | wc -c)
done

Babel

But enough about programming. Let's talk about configuration management.

Babel - Literacy

A very popular way people configure Emacs (or other software) is using a Literate Config. A Literate Config is a bunch of code blocks that get tangled into files.

Features

A focus on documentation

The documentation-first approach of a literate config is the inverse of putting comments in your code where instead you put code in your comments.

Structure and organization

Adds a layer of programmability where you can include or exclude certain blocks of code programmatically.

Static content generation

Utilize org-export functionality to export to different non-org formats. E.g. HTML, Markdown, LaTeX, and more.

C-c C-e

#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup

Examples

A mildly contrived example where I adapted my ZSH config to a literate config ./examples/tangle.html

My actual literate Sway config ~/.config/sway/config.html

A user named Phundrak who has an excellent example of what a literate config can be. Dotfiles source Generated content

Sacha Chua

Sacha Chua contributes and maintains several blogs about the happenings inside the Emacs community. And she does it all with Emacs and org-mode

Here is one of her blogs, Emacs News, where she publishes weekly posts on new packages, community events, upcoming changes to Emacs, etc. Website Source

And her dotfiles are also published with org-mode! Sacha Chua Source

TRAMP

Tramp allows editing remote files with support for many transport backends, include SSH, FTP, sudo (???), docker (and podman), etc.

SPC f f /ssh:user@host:

SPC f f /sudo:/etc/passwd

You can even chain transports together:

/ssh:user@remotehost|sudo:root@remotehost:/path/to/file

Serial

You can even read from serial devices. This is great because since you can read and write from the comfort of Emacs!

Start fake tty sockets

socat -d -d pty,raw,echo=0 pty,raw,echo=0

Read

/usr/bin/cat < /dev/pts/1

Write

echo "Hello" > /dev/pts/2
(serial-term "/dev/pts/1" 9600)
(serial-term "/dev/pts/2" 9600)

hass

A little self-promotion, but it's a really good example of Emacs uses.

Home Assistant is open source home automation software that acts as a hub for connection all your smart devices together.

Features

  • Hooks into Home Assistent events and triggering things to happen within Emacs
  • Build dashboards for quickly viewing and _executing actions
  • Adds an interactive function to call Home Assistent services anywhere in Emacs

That's it

Questions? Comments? I could talk about this all day