Power Emacs

Table of Contents

1 Getting started

Just a few preliminary steps to make things work nicely.

1.1 installing emacs

1.2 emacs –daemon

This command will start emacs as a daemon. This is really how all software should work. It will sit in the background and do the heavy lifting, keeping all your buffers/files/state open.

If you crash or have to log out, everything is still there in the background.

When you want to run emacs, you run emacsclient. It creates an appropriately graphical or terminal or whatever "window" (known as a frame in emacs) which connects to the daemon to show your buffers. This is very handy for remote work, and many other things.

It's basically how every application should work, but only Emacs is advanced enough to have it.

1.2.1 Multiple open

You can open the same file multiple times and everything is shared between those sessions; where vim would complain about other processes being open, Emacs will communicate to keep everything in sync. It just works perfectly and seamlessly like you'd want. This is based on emacs –daemon, emacs running in daemon mode. It lets you do other cool, fancy, useful things. For instance, you can open as many graphical and terminal (client) instances of emacs as you want, each editing whatever file or files you want, and they all share the same buffers and registers and all that stuff.

1.3 keybinding notation

  • C-h for Ctrl-h
  • M-! for Alt-! (Alt is historically known as the Meta key)
  • C-x C-c for Ctrl-x then immediately Ctrl-c

1.4 Ctrl

You must remap CapsLock to Ctrl, it's the law.

1.4.1 OS X

  1. Open System Preferences → Keyboard and choose Modifier Keys:

    mac1.png

  2. Then select which of the four modifier keys should send Control:

    mac2.png

1.4.2 Linux

It may be in your desktop environment. for GNOME, check Tweak Tool -> Typing -> Ctrl key position.
If you don't see it, use xmodmap:

curl [[http://www.cmucc.org/talks/fall14/xmodmaprc]] > ~/.xmodmaprc

Then run this command on startup (or when you want to swap):

xmodmap ~/.xmodmaprc

1.4.3 Windows

Google it (you need to do registry editing).

1.5 links

Just read the Emacs manual, and the manuals of various modes! But if you want a change of pace:

2 Learning and Documentation

2.1 Emacs tutorial: C-h t

Even more helpful than the vim tutorial. Do it even if you use evil-mode - just press C-z first to enter the Emacs state.

2.2 C-h

The beautiful, amazing help command

  • C-h k Type a keybinding to get what it does
  • C-h f Put your cursor on a function name, or just type one, to get its docs
  • C-h v Put your cursor on a variable, or just type one, to get its docs
  • C-h m Get info about the keybindings of the current major mode (for evil-mode, many things will be listed as shadowed)

2.3 Emacs Manual

The Emacs manual is seriously useful. Legitimately, seriously, look there first when you want to do something. It is the best documentation I have ever seen. Buy a real copy too! http://www.gnu.org/software/emacs/manual/emacs.html

2.4 Elisp Manual

Again, seriously amazing. Mainly useful if you want to do some more advanced customization or extending. Again, it is the best documentation I have ever seen. https://www.gnu.org/software/emacs/manual/elisp.html

3 Customization

3.1 basic init.el (workshop)

If you don't already have an init.el,

wget http://www.cmucc.org/talks/fall14/init.el -O ~/.emacs.d/init.el

If you do have an init.el, download it anyway and compare. There's some useful stuff. If you want to use evil-mode (and you don't already have an init.el),

wget http://www.cmucc.org/talks/fall14/init-vim.el -O ~/.emacs.d/init.el

3.2 Bootstrapping config

The first few lines of this config install the packages you'll need in addition to stock Emacs. Emacs ships with a package management system, so this is trivial.

4 Practices that go well with Emacs

4.1 keyboard based workflow

Basically anything that enables a keyboard based workflow. By not moving your hands to the mouse or even to Home/End/etc, you can type and edit faster. Just make sure you know how to touch type.

4.2 Semantic Linefeeds!

One sentence (or clause) per line. Pretty much every kind of structured text will just ignore single newlines (LaTeX, Markdown). So, when using an editor that has a lot of tools for manipulating lines (pretty much everything), you gain a lot of power with this organization! http://rhodesmill.org/brandon/2012/one-sentence-per-line/

4.3 tools with emacs-nature

4.3.1 browser

  • conkeror
  • keysnail

4.3.2 shell

Readline already has Emacs keybindings by default. C-x C-e in bash by default drops you into your $EDITOR, which is hopefully some variation of emacsclient

4.3.3 file manager

Dired is already quite okay.

4.3.4 editing elsewhere

OS X has some fancy thing where you can have emacs keybindings in every text editing field. I'd be jealous, if Emacs keybindings didn't suck.

5 Packages and functionality

5.1 TRAMP

TRAMP stands for "Transparent Remote Access, Multiple Protocols". It basically integrates ssh (as well as some other protocols - I use the sudo one occassionally) with Emacs. This is really deep integration, so pretty much everything in Emacs can be done transparently over the network. In fact, I used it when I was writing these notes, which I'm writing in Emacs using It's All Text. I'm on my laptop, and I wanted to get to some notes on my desktop, earth. So, I just did C-x C-f /ssh:earth:/home/sbaugh/myemacsnotes and I had the notes open in a buffer. (for evil-mode users, :e instead of C-x C-f) This all tab-completed of course; Emacs knows the host "earth" that I defined in my .ssh/config, and it opened the connection as soon as I hit tab for the first time after typing the "ssh:mydesktop:" component, so I could have tab-completion on the remote path. This works for remote file operations with M-x dired, opening a remote shell with M-x eshell, pretty much everything. For serious shell work I still ssh to hosts directly, of course. But for just editing things, it's very handy to be able to remotely edit a file that lives on a host that doesn't have my Emacs or vim configuration.

5.2 magit

A really great git interface, makes things convenient without abstraction.

5.3 evil-mode

  • advantage: the find and replace is visual and incremental

    :%s/rep..ce/replace

5.3.1 undo-tree

(undo-tree-visualize)

5.4 org-mode

A very useful note-taking, planning and publishing mode. http://orgmode.org/

5.5 dunnet

(dunnet)

6 elisp and extension

6.1 Lisp basics

http://learnxinyminutes.com/docs/elisp/ (I really like that site)

More in depth stuff: https://github.com/chrisdone/elisp-guide

If you really want to learn Lisp, go for the classic, mighty, wizardly book: SICP http://mitpress.mit.edu/sicp/ (It's very famous)

6.2 write a time-tracking extension (workshop)

Use quantified self extension as an example of the ease of configuration

7 Advanced

7.1 org-mode

You can pretty much do everything in org-mode, it's an extremely powerful organization and publishing system. Look at the manual, it's great. http://orgmode.org/manual/index.html

7.2 Clojure

Now that you're in Emacs, you can use Clojure SO WELL it's insane. Emacs is made for Lisps, and Clojure is a modern, hip Lisp. http://www.braveclojure.com

7.3 architectural elegance

Like I said earlier, Emacs is mostly made up of modular Elisp packages. This builds on a small core of C code, which just provides an Elisp interpreter, UI primitives, system integration, and a few hot-spot functions that need maximum efficiency. The rest is all Elisp that can be modified by the user at will.

Emacs is capalbe of asynchronous operations, and easily integrates external programs. I use the Emacs gdb interface all the time, and if I want to grep my project, it'll show up incrementally in a buffer without blocking the UI or stopping me from editing.

Vim on the other hand… well… it has its own built-in C reimplementation of spell-checking and encryption. Emacs just uses aspell and PGP. And we all know the troubles vim has with asynchronicity and integrating external programs.

Created: 2014-09-10 Wed 20:07

Emacs 24.3.93.1 (Org mode 8.2.6)

Validate