⌨️ My Emacs configurations.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lisp
var
.gitignore
.gitmodules
.travis.yml
LICENSE.txt
README.org
init.el

README.org

Andrew Schwartzmeyer’s Emacs configurations

https://travis-ci.org/andschwa/.emacs.d.svg?branch=master

Utilizes jwiegley’s use-package macro to cleanly and quickly require, install via `package.el`, and setup various extensions. Enables lots of lovely minor modes, and conditionally loads operating and local system specific code.

Notable packages

  • Magit is the best way to interact with Git
  • Projectile gives contexts for each project
  • use-package organizes init.el and manages packages
  • Flycheck provides on-the-fly syntax and compilation checking
  • dtrt-indent intelligently guesses indentation rules
  • hl-todo highlights TODOs in source code
  • which-key makes keybindings actually discoverable
  • Whitespace Butler unobtrusively cleans up whitespace

Elisp

add-hook and eval-after-load for conditional execution

expand-file-name and f-expand for filename expansion

file-name-basename and file-name-nondirectory etc.

message and princ for printing

concat and format for strings

get-buffer-create for buffers

add-to-list and append for lists

mapcar with list of results

mapconcat for string of results

dolist for mapc with implicit bind

cadr for last item of pair, as in, (car (cdr foo))

cons to append without copying

remove to filter items from list

getenv, setenv, compilation-environment for env

executable-find for binaries

nth and elt for indexing a list

cond is better than if / else

let and let* for local variables

save-excursion to restore point

replace-regexp-in-string

shell-command-to-string

dash.el modern list library

Key bindings

Universal arg: C-u

Negative arg: (C|M|C-M)-- like M- M-l to downcase backwards

Numeric args: (C|M|C-M)-(0...9)

Repeat command: C-x z follow with z

Jump to mark: C-u C-SPC (local) C-x C-SPC (global)

Toggle between point and mark: C-x C-x

Narrowing: C-x n region n defun d widen w

https://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html

Zap to char: M-z (remapped to zap-up-to-char)

Delete horizontal whitespace: M-\ or keep one space M-SPC

Delete vertical whitespace (blank lines): C-x C-o (like “undo C-o”)

Delete indendation / join line with previous: M-^

Append next kill: C-M-w

Back to indentation: M-m

Surround with parentheses: M-( on region or with numeric arg

Sexps: C-M-(b backward) (f forward) (u up) (SPC mark) (k kill) (w copy)

Defuns: C-M-(a begin) (e end) (h mark)

Buffer: M-(< begin) (> end) C-x h (mark)

Magit sections: M-(n next) (p previous)

Sentences: M-(a backward) (e forward) (k kill) / C-x DEL (kill backward)

In C and C++ modes, these move over statements.

Paragraphs: M-({ backward) (} forward) (h mark)

Transpose: C-(char) M-(word) C-M-(sexp) t / C-x C-t (line)

The opposite of C-l is M-r recenter-positions

Reposition window to see comment/function: C-M-l

Comment: M-; (DWIM) C-x C-; (line) M-j (newline comment)

Occur: M-s o then e (edit) / M-(n next) (p previous)

Also multi-occur-in-matching-buffers

Search nearest symbol: M-s .

Casing:

words M-u (upper) l (lower) c (capitalize)

regions C-x C-(u upper) (l lower) / upcase-initials-region

“Close” client buffer: C-x # (server-edit)

Evaluate lisp: interactive M-: last sexp C-x C-e

Set fill prefix: C-x .

Fill-Prefix with point after prefix

Set fill column: C-x f

Toggle read-only C-x C-q

Writable modes

occur with e exit

wgrep with C-c C-p

wdired with C-x C-q

ivy occur with C-c C-o then follows wgrep

See =ivy-occur-mode=

List bindings: C-h b

Bindings for command: C-h w (where-is)

Inverse of C-h k

Quote next character: C-q

Newline: C-j

Tricks and tips

Interactive Emacs Lisp Mode ielm

Automatic alignment with align-current

Fall back to align-regexp. Prefix that for complex mode.

Replace uniq with delete-duplicate-lines

also flush-lines and keep-lines

Using quote marks within verbatim/code markup in org-mode

  • Unicode: <U200B> /xe2/x80/x8b ZERO WIDTH SPACE
  • Insert using: (C-x 8 RET 200b RET)

Quickly insert #+begin_src with <s <tab> and C-c C-, s

Sudo mode using Tramp C-x C-f /ssh:you@host|sudo:host:/file

Replace in files

From StackOverflow:

  1. M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
  2. Press t to “toggle mark” for all files found.
  3. Press Q for “Query-Replace in Files…”: you will be prompted for query/substitution regexps.
  4. Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.
  5. Press Y to finish replacing in all buffers.
  6. C-x C-s ! to save all buffers.

Replace with capture regexp

  • use regex groups like “ab\(c\)” where the parentheses are escaped because Emacs
  • refer to prior capture groups by \N where N is 1-indexed on the captured groups (e.g. back reference)

Renumber with regexp

  • see Wiki; the comma indicates elisp code to evaluate
  • e.g. [0-9]+ -> \,(+ 257 \#)
  • or by 8 starting at 10 \,(+ 10 (* 8 \#))

Capture all regexp matches

;; captures all non-terminals in Bison grammar
(save-excursion
  (while (re-search-forward "^\\([a-z_]+\\):" nil t)
    (princ (format "%s " (match-string 1)) (get-buffer-create "matches"))))

regexp-builder for replace

  • Use C-c C-i and choose the “string” syntax
  • Copy the regexp without the surrounding quotes
  • Use C-c C-q to close regexp-builder

Projectile commands

Project

switch
p
commander
m
command
!
async
&
make
c
make test
P
make tags
R
replace
r
dired
D
vcs
v
ag
ss
tag
j
buffers
b
kill
k
recent
e

File

alternate
a
test files
T
toggle test
t

Flycheck

(flycheck-compile) for debugging

ansi-term

  • Needs terminfo
  • Remove TERM from shell’s rc file
tic -o ~/.terminfo
/usr/local/Cellar/emacs/HEAD/share/emacs/24.4.50/etc/e/eterm-color.ti

Partially evaluate list elements

  • (add-to-list ‘somelist `(symbol . ,(expression to be evaluated)))
  • The backquote is like a normal quote except it evaluates elements marked with commas. RTFM

Temporarily disable ido-completion C-j

Set directory local variable eval to execute arbitrary code

See current faces list-faces-display

View Lossage

Use M-x view-lossage on C-h l to see the most recent 300 keystrokes, per Emacs Redux

Smartparens

https://ebzzry.github.io/emacs-pairs.html

Yank next movement/thing sp-select-next-thing on C-M-]

Remove surround quotes aka splice sp-splice-sexp on M-D

Emacs Syntax Explained

The C-j in C-q C-j is for inputing ASCII Line Feed char (used in unix as newline char), which does not have a corresponding key on the keyboard. The reason that C-j is for Line Feed is because it’s a notation from the ASCII standard. That is, the non-printables are represented by a Control followed by a letter, regardless whether there is a corresponding key on the keyboard. Line feed is the 10th ASCII char, and j is the 10th letter, so Line Feed is C-j. Similarly, C-i is for Horizontal Tab, C-m is for Carriage Return, C-[ is for Escape, C-l is for Form Feed, etc. http://ergoemacs.org/emacs/keystroke_rep.html

Setting (flyspell-use-meta-tab nil) unbinds C-M-i because it’s interpreted as M-TAB. This is because C-i and TAB are the same character in ASCII. This is most annoying on Windows where M-TAB AKA “alt-tab” switches windows.

https://www.gnu.org/software/emacs/elisp/html_node/Function-Keys.html

Faces

(use-package ivy
  :custom-face
  (ivy-current-match
   ((((class color) (background light))
     :background "#fdf6e3" :underline (:color "#859900"))
    (((class color) (background dark))
     :background "#002b36" :underline (:color "#859900")))))

Compiling Emacs from source

See INSTALL.REPO

update

git clone -b emacs-26 https://github.com/emacs-mirror/emacs.git

prepare

Can use build-dep emacs to get dependencies.

make distclean

Arch

sudo pacman -S texinfo libxft
# with GTK
sudo pacman -S gtk2 xorg-fonts-100dpi

CentOS 7

GTK+ and FreeType are needed to for the X11 build with proper font rendering. See other notes for X11 and Xft setup.

yum install gtk2-devel freetype gnutls-devel

Ubuntu 14.04

Still needs GTK and FreeType.

sudo apt-get install texi2html texinfo

Ubuntu 18.04

sudo apt build-dep emacs24
./autogen.sh
./configure --with-x-toolkit=gtk3
export GDK_SCALE=2

Windows

Follow nt/INSTALL

  • Install MinGW and MSYS (see Getting Started)
  • Run C:\MinGW\msys\1.0\postinstall\pi.bat to setup fstab
  • Add shortcut to C:\MinGW\msys\1.0\msys.bat

Fix line endings

Otherwise autoreconf will fail cryptically.

dos2unix.exe configure.ac

autoreconf

./autogen.sh

This runs the usual autoreconf -i -I m4

configure

Arch

./configure --without-all --with-x-toolkit=no --with-xft --with-makeinfo

OS X

./configure --without-all --with-x-toolkit=no --with-ns --with-toolkit-scroll-bars --with-makeinfo

CentOS 7

./configure --without-all --with-xft --with-makeinfo

Ubuntu 14.04

./configure --without-all --with-xft --with-makeinfo

Windows

Toolkit scroll-bars are required on Windows but excluded by --without-all, so explicitly include them.

./configure --without-all --with-w32 --with-toolkit-scroll-bars

Optional

--with-sound --with-gnutls --with-zlib --without-compress-install --with-libotf

make

bootstrap

make bootstrap

build docs

make info doc

install

sudo make install install-info install-doc

OS X

Copy nextstep/Emacs.app to desired location

post-install

Remove old packages

rm -rf ~/.emacs.d/elpa

Bugs

Buffer content invisible when tunneling X

GNU Bug Report #25474

(setq default-frame-alist
      (append default-frame-alist '((inhibit-double-buffering . t))))

derived-mode-p broken for aliased parents

GNU Bug Report #32795

(defun provided-mode-derived-p (mode &rest modes)
  "Non-nil if MODE is derived from one of MODES.
Uses the `derived-mode-parent' property of the symbol to trace backwards.
Non-nil even if MODE is derived from an alias of any of MODES.
If you just want to check `major-mode', use `derived-mode-p'."
  (while
      (and
       (not (memq mode modes))
       (let* ((parent (get mode 'derived-mode-parent))
              (parentfn (symbol-function parent)))
         (setq mode (if (and parentfn (symbolp parentfn)) parentfn parent)))))
  mode)