Emacs: ParEdit, Smartparens, Lispy, and ErgoEmacs, xah-fly-keys

By Xah Lee. Date: . Last updated: .

For programing lisp in emacs, there are several packages to help you.

Here's a method, i think is simpler and can compete with packages similar to paredit in efficiency.

The gist, is to never treat lisp code as lines. In particular, never manually indent/format by line. ใ€”see Emacs: Why I Don't Use pareditใ€•

if you want to try, the commands are:

The above are general, is extremely useful to me in any programing mode too, such as those with {} [] ().

You can pull those commands out from above, and set keys for them yourself. ใ€”see Emacs Keys: Define Keyใ€•

Or, you can just use Xah Fly Keys and Xah Emacs Lisp Mode. All the commands are there, with keys setup.

These commands are also in ergoemacs-mode at http://ergoemacs.github.io/, except โ€œxah-elisp-prettify-root-sexpโ€.

Bracket Highlight

You should also turn on bracket highlight.

ใ€”see Emacs Init: Highlight Bracketsใ€•

Always Insert Brackets in Pairs

You should ALWAYS insert/ remove brackets in pairs. Make this a habit.

Use xah-insert-paren

ใ€”see Emacs: Insert Brackets by Pair ๐Ÿš€ใ€•

Navigating Brackets

Moving cursor to brackets is one of the most important navigation command. Because, all programing language source code, use brackets (){}[] extensively as a unit.

Use โ€ข xah-backward-left-bracket โ€ข xah-forward-right-bracket

ใ€”see Emacs: Move Cursor to Bracket ๐Ÿš€ใ€•

Select Lisp Expression

To select a lisp expression, xah-extend-selection once or twice.

Move Lisp Expression

Select it first, then just press 1 key to cut. Then paste it elsewhere.

Delete Lisp Expressions

put cursor on the right of a bracket, then xah-delete-backward-char-or-bracket-text.

Always delete Brackets in Pairs

To delete bracket pairs (not including inner text), put cursor on the right of a bracket, then Ctrl+u then xah-delete-backward-char-or-bracket-text.

Remove Empty Lines; Compact Ending Brackets

To remove empty lines:

In xah-elisp-mode, press Tab with cursor before a word. The command is xah-elisp-prettify-root-sexp. ใ€”see Emacs: Xah Elisp Mode ๐Ÿ“ฆใ€•

Or see:

Pretty Format Lisp Code

In xah-elisp-mode, press Tab with cursor before a word. The command is xah-elisp-prettify-root-sexp. It will re-indent the extire lisp expression the cursor is in. ใ€”see Emacs: Xah Elisp Mode ๐Ÿ“ฆใ€•

If you are not using xah-elisp-mode, then you can select the whole, then Alt+x indent-region ใ€Ctrl+Alt+\ใ€‘

Thanks to [ Jorge Dias ] โฎhttps://twitter.com/dias_jorgeโฏ.