-
-
Notifications
You must be signed in to change notification settings - Fork 12
Configuring Emacs for Lissp
If you're not already familiar with Emacs or at least very interested in learning it, a more modern editor with a Parinfer plugin may be easier to get started with. (E.g., Pulsar)
Emacs has been the traditional editor of choice for Lisp and is a Lisp dialect in its own right. However, it predates the familiar GUI paradigm, making it rather idiosyncratic by modern sensibilities. There is a learning curve. Those expecting a modern IDE will find its default configuration inadequate, but bringing Emacs up to that level requires many third-party packages which often break with updates or interact poorly. Doom Emacs or Spacemacs can give you a head start but one should expect to need some custom configuration anyway.
Lissp was designed to parse in nearly the same way as traditional Lisps, like Common Lisp or Emacs Lisp, although there are some subtleties around reader macros and whitespace. This means any editor with a Lisp mode should mostly just work.
When you open a .lissp
file in Emacs, use M‑x lisp-mode
. You can automate this in your config with something like
;; in dotspacemacs/user-init
(add-to-list 'auto-mode-alist '("\\.lissp\\'" . lisp-mode))
Vanilla Emacs is configured to replace a run of 8 spaces with a tab (although Spacemacs doesn't do this). This perhaps made some sense in the bygone era of constrained hardware because it could somewhat compress a text file, but mixing in tabs is only asking for trouble now. The Lissp reader does not allow tabs as whitespace. You will need to turn this feature off while editing Lissp.
The Lissp REPL should work OK in an M‑x ansi-term
. A typical setup would split the screen and show the REPL and the .lissp
file being edited together. You can paste in an ansi-term with S‑<insert>
(M‑x term-paste
), or switch to line mode with C‑c C‑j
for editing in the terminal buffer, but a simple process-send-region
helper function makes this much easier. This version sends to the buffer named *target*
. Use M‑x rename-buffer
to give the ansi-term buffer running the Lissp REPL that name.
(defun region->*target* (beg end)
(interactive "r")
(process-send-region "*target*" beg end))
Once the defun is evaluated, it will be available with M‑x region->*target*
. You'll probably want to add this to your config if you edit Lissp much. You can also add a keybinding as normal. E.g., in Spacemacs,
;; dotspacemacs/user-config
(spacemacs/set-leader-keys-for-major-mode 'lisp-mode "oe" 'region->*target*)
region->*target*
works better in char mode (the default). If your ansi-term is in line mode, you can switch back with C‑c C‑k
.
I highly recommend using Parinfer when editing Lissp, especially when using Evil. If you're already very comfortable with structural editing, you may not need it, but it is possible to use both. E.g., in Spacemacs:
(defun evil-state-watcher (symbol newval operation where)
(when (and (not (eq newval 'lisp))
(eq evil-state 'lisp))
(smartparens-mode 0)))
;; dotspacemacs/user-init
(add-hook 'lisp-mode-hook 'parinfer-rust-mode)
;; dotspacemacs/user-config
(electric-indent-mode 0)
(add-to-list 'spacemacs-indent-sensitive-modes 'lisp-mode)
(add-variable-watcher 'evil-state #'evil-state-watcher)