56

GitHub - countvajhula/symex.el: An evil way to edit Lisp symbolic expressions (&...

 4 years ago
source link: https://github.com/countvajhula/symex.el
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.rst

Symex (pron. "sym-ex", pl. symexes): A Lisp symbolic expression, which designates a computation to be performed.

symex.el

An evil way to edit Lisp symbolic expressions ("symexes") as trees in Emacs

Symex the Squirrel

Symex mode (pronounced sym-ex, as in symbolic expression) is a vim-inspired way of editing Lisp code as trees. Entering symex mode allows you to reason about your code in terms of its structure, similar to other tools like paredit and lispy. But while those packages provide a curated number of useful tree operations, symex mode treats the tree structure explicitly so that arbitrary tree navigations and operations can be described using an expressive DSL, and invoked conveniently in a vim-style modal interface implemented with a Hydra.

At the moment, symex mode uses paredit, lispy, and evil-cleverparens to provide much of its low level functionality. In the future, this layer of primitives may be replaced with a layer that explicitly uses the abstract syntax tree, for greater precision.

Screenshot

Installation and Usage

Install the package the usual way via MELPA (pending, see here for status). Then add the following config to your init.d:

(global-set-key (kbd "s-;") 'symex-mode-interface)  ; or whatever keybinding you like
(dolist (mode-name symex-lisp-modes)
  (let ((mode-hook (intern (concat (symbol-name mode-name)
                                   "-hook"))))
    (add-hook mode-hook 'symex-mode))))

This provides a keybinding to load the symex editing interface, and also enables the symex minor mode in all recognized lisp modes (the minor mode is simply there to ensure that manual edits respect the tree structure, e.g. keeps parens balanced like paredit).

A Note on the Name

A little while ago I was discussing Lisp syntax with @apromessi:

Me: "...And so we have these sex-puhs..."

A: "Excuse me?"

Me: "Oh, I mean ess expressions! It stands for symbolic expression."

A: "Why not just call it sym-ex?"

Me: [mindblown]

A: "..."

Lisp has inherited a few oddball names from its deep prehistory, including the infamous car and cdr for the first and the rest of the elements in a list. But S-expression / sex-puh / symbolic expression are all somewhat of a mouthful too. Here are a few reasons why we might want to consider using "sym-ex" instead:

"Symbolic expression": 6 syllables, long in written form too

"S-expression": 4 syllables, I find this name confusing at least partially because it is a single-letter acronym which is unusual. In addition, it is long in written form.

"Sexpuh" / "sex-p" / "sexpr": 2 syllables, short in written form. But I mean, these are terrible.

"s-ex": Speaks for itself.

"Symex": 2 syllables, short in written form, has normal linguistic analogues like "complex/complexes," and it's fun to say! Symex also sounds like Ibex, and that's obviously a plus.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK