Editing Lisp Code with ErgoEmacs Keybinding without ParEdit

Perm url with updates: http://xahlee.org/emacs/ergoemacs_and_paredit.html

This page shows you how to edit lisp code using ErgoEmacs keybinding and without paredit mode.

For programing lisp in emacs, there's a mode called “paredit-mode”, see: ParEdit.

Jorge Dias posted in twitter, asking how to get it to work with ErgoEmacs Keybinding, because a lot keys clash.

I never tried ParEdit mode, because i'm not sure by principle it is efficient. Here's what i do.

Setting Up Bracket Highlighting

When cursor is on a bracket, the entire bracketed region is highlighted. For how to setup, see: How to Edit Lisp Code with Emacs.

Brackets Are ALWAYS Inserted/Removed in Pairs

Any brackets are ALWAYS inserted and removed in pairs. For how to setup, see: How to Edit Lisp Code with Emacs.

Navigating Brackets

To navigate nested brackets as tree structure, use built-in keys provided by GNU Emacs. e.g. 【Ctrl+Alt+】【Ctrl+Alt+】【Ctrl+Alt+】【Ctrl+Alt+】. For detail, see: How to Edit Lisp Code with Emacs.

To move cursor to previous/next brackets freely, i use these keys {【Alt+】,【Alt+】,【Alt+】,【Alt+】}. See: Emacs: Commands and Keys to Navigate Brackets.

Selecting/Moving/Deleting Lisp Expressions

To select a lisp expression, put cursor on the beginning bracket, press the key 【Alt+8】 to select the entire expression, 【Alt+x】 to cut.

Both are in ErgoEmacs keybinding. For the code and detail, see:

Remove Empty Lines; Compact Ending Brackets

To remove empty lines, type 【Alt+w】 (shrink-whitespaces)

To compact ending brackets, place your cursor there then press 【Alt+q】 (compact-uncompact-block)

Pretty Format Lisp Code

Another principle i use is NEVER SPEND EFFORT TO MANUALLY PRETTY FORMAT CODE on a line-by-line basis.

When you need to make the format pretty, do them in batch on a region. Select text or whole file, then use the built-in command 【Ctrl+Alt+\】 (indent-region).

Ideally, the formatting should be done automatically, as in auto-fill-mode and Mathematica. I haven't coded this in ErgoEmacs yet. See:

elisp abbrev + auto-complete-mode + yasnippet

For name completion and function templates, i use {elisp abbrev, auto-complete-mode, yasnippet}, all are bundled and with ErgoEmacs and already configured.

  • elisp abbrev setup lets you expand abbrev to full function name. e.g. bsnp ▮buffer-substring-no-properties ▮ (See: YASnippet Templates for Emacs Lisp Mode.)
  • YASnippet lets you expand from lisp function name to a complete expression template. e.g. search-forward▮(search-forward "▮" &optional BOUND NOERROR COUNT).
  • “auto-complete-mode” lets you complete any lisp function or variable names. e.g. 【buffer- Tab】 shows a menu of elisp symbols that start with “buffer-”.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs