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-bracketxah-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 (xah-elisp-mode.el)]

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 (xah-elisp-mode.el)]

If you are not using xah-elisp-mode, then you can select the whole, then Alt+x indent-regionCtrl+Alt+\

Thanks to [ Jorge Dias ] [ https://twitter.com/dias_jorge ].