Skip to content

Latest commit

 

History

History
328 lines (270 loc) · 13.7 KB

README.org

File metadata and controls

328 lines (270 loc) · 13.7 KB

Emacs Lisp layer

img/emacs.png

Table of Contents

Description

This layer gathers all the configuration related to emacs-lisp. This should always be in your dotfile, it is not recommended to uninstall it.

Features:

  • Auto-completion using company
  • Linting using flycheck integration
  • Linting package file metadata using flycheck-package
  • Repl support via IELM
  • Support for specific lisp navigation styles via emacs-lisp-mode
  • Auto-compile via auto-compile package
  • Debugging via edebug
  • Ert test runner with overseer
  • Nameless package prefix with optional nameless
  • Structurally safe editing using optional evil-cleverparens
  • Visual feedback when evaluation using eval-sexp-fu
  • Provide Emacs Lisp API usage examples using elisp-demos

Install

To use this configuration layer, add it to your ~/.spacemacs. You will need to add emacs-lisp to the existing dotspacemacs-configuration-layers list in this file.

Auto-compile

This layer adds the auto-compile package to automatically keep the byte-compiled version of your Emacs lisp files synced with the uncompiled version on every save. If there are any compiler errors in the file, you will see a counter show up in the mode line. You can hover over these numbers to get a description or view the compiler output with the SPC m c l key binding. To disable the feature use this line in your dotspacemacs/user-config function.

(remove-hook 'emacs-lisp-mode-hook 'auto-compile-mode)

You can also exclude the auto-compile package.

Working with lisp files (barfage, slurpage & more)

Spacemacs comes with a special lisp-state for working with lisp code that supports slurpage, barfage and more tools you’ll likely want when working with lisp.

As this state works the same for all files, the documentation is in global DOCUMENTATION.org. In general, use SPC k to interact with the lisp-state.

Debugging Elisp

Here is an interactive quick start to debug Emacs Lisp from an emacs-lisp-mode buffer.

To follow this tutorial open the code of the following source block in an emacs-lisp-mode buffer. One way to do this is to first find this emacs-lisp layer documentation file in Spacemacs using SPC h l emacs-lisp RET. This will open the current file in space-doc-mode. Toggle off space-doc-mode using =, T V= so that Spacemacs will switch to org-mode. Now you can place the cursor somewhere inside the code block and press ~, ‘~ to open the code in an interactive emacs-lisp-buffer.

(defun helloworld (name)
  (let ((n (subroutine name)))
    (message (format "Hello world, %s!" name))))

(defun subroutine (s)
  (concat "my dear " s))

(helloworld "Spacemacs")

Steps: Now from within the emacs-lisp-buffer

  1. Evaluate each sexp by putting your point in each of them and press ~, e f~ or press ~, e b~ to evaluate all code in the buffer at once.
  2. To debug the helloworld function, put your cursor on the defun keyword and

press SPC m d f (or ~, d f~), it will put a breakpoint on the function (we say that we instrumentalise this function) so whenever the Lisp interpreter encounters this function it will start the debugger.

  1. Then go to the closing parenthesis of (helloworld "Spacemacs") and press

~, e e~ to evaluate it, if you are using vim editing style you end up in evilified state otherwise you end up in emacs state and *Debugging* is displayed in the mode line.

  1. Press s to go to next step up to the opening parenthesis of (subroutine name),
  2. Press i to go into the subroutine where you can press s to step in

function or press o to go out of it.

  1. Press a to stop debugging.

Using the inspector

This layer adds the inspector package to provide an easy way for inspecting data structures. Find more information about its usage here and see key bindings.

Nameless

Nameless hides package namespaces in your emacs-lisp code, and replaces it by leading > It can be toggled with SPC m T n.

By default nameless is deactivated, to enable it set the layer variable emacs-lisp-hide-namespace-prefix to t.

NOTE: nameless is known to cause problems when spacemacs is used inside a terminal window, use with caution.

(setq-default dotspacemacs-configuration-layers '(
  (emacs-lisp :variables emacs-lisp-hide-namespace-prefix t)))

Aliases

This layer defines some global aliases for Spacemacs:

aliasnamespace
.Sdotspacemacs
CLconfiguration-layer
Sspacemacs
SBspacemacs-buffer

You can define additional alias in function dotspacemacs/user-config of your dotfile:

(add-to-list 'nameless-global-aliases '("N" . "nameless"))

Structurally safe editing

This layer adds support for evil-cleverparens which allows to safely edit lisp code by keeping the s-expressions balanced.

By default this mode is not activated. You can turn it on locally on the active buffer with SPC m T s (s for safe).

To turn it on automatically for all emacs-lisp buffers call the following function in your dotspacemacs/user-config function:

(spacemacs/toggle-evil-safe-lisp-structural-editing-on-register-hook-emacs-lisp-mode)

or to enable it for all supported modes:

(spacemacs/toggle-evil-safe-lisp-structural-editing-on-register-hooks)

When enabled the symbol 🆂 should be displayed in the mode-line.

Key bindings

Key bindingDescription
SPC m g ggo to definition of symbol under point
SPC m g Ggo to definition of symbol under point in other window
SPC m h hdescribe symbol at point
SPC m c cbyte compile the current file
SPC m c lpopup compile-log buffer
SPC m e $ or SPC m e lgo to end of current line and evaluate
SPC m e bevaluate current buffer
SPC m e Cevaluate current defun or setq
SPC m e eevaluate sexp before point
SPC m e fevaluation current function
SPC m e revaluate current region
SPC m ​,​toggle lisp state
SPC m t brun tests of current buffer
SPC m t qrun ert
SPC m d mopen macrostep transient-state
SPC m :toggle nameless minor mode

Additional testing functions with overseer

Function related to test are present under the SPC m t prefix:

Key bindingDescription
SPC m t aoverseer test
SPC m t Atest debug
SPC m t trun test
SPC m t btest buffer
SPC m t ftest file
SPC m t gtest tags
SPC m t ptest prompt
SPC m t qtest quiet
SPC m t htest help

Additional evaluation functions

If smartparens is used the following additional key bindings are available:

Key bindingDescription
SPC m e cevaluate sexp around point
SPC m e sevaluate symbol around point

Format code

The semantic layer should be installed for these key bindings to become active.

Key bindingDescription
SPC m = bformat current buffer
SPC m = dformat current function
SPC m = oformat all on one line
SPC m = sformat current sexp

Debugging

To start debugging:

Key bindingDescription
SPC m d fon a defun symbol toggle on the instrumentalisation of the function
SPC m d Fon a defun symbol toggle off the instrumentalisation of the function
SPC m d tinsert (debug) to print the stack trace and re-evaluate the function

In edebug-mode (*Debugging* is displayed in the minor modes segment of the mode line)

Key bindingDescription
sstep
istep in
ostep out
Snext
fforward-sexp
Hgoto here
Iinstrument callee
cgo
Cfast continue
ttrace
Tfast trace
qquit
Qquit nonstop
astop
bset breakpoint
uunset breakpoint
Bnext breakpoint
xset conditional breakpoint
rprevious result
eevaluate expression
C-x C-eevaluate last sexp
wwhere
?help
dbacktrace

In edebug-eval-mode

Key bindingDescription
SPC m g wwhere
SPC m adelete evaluation item
SPC m kdelete evaluation item
~SPC m ,~update evaluation list
SPC m cupdate evaluation list
SPC m e eevaluate last sexp
SPC m e Eevaluate last sexp and print

In debugger-mode (Debugger is displayed in major mode segment of the mode line)

Key bindingDescription
<tab>forward
S-<tab>backward
RETbacktrace help follow
pbacktrace backward frame
ccontinue
Rrecord expression
dstep through
eeval expression
Jjump
Llist functions
bframe
rreturn value
uframe clear
C-vbacktrace toggle locals
qquit

Refactoring with emr

Key bindingDescription
SPC m r f eimplement function
SPC m r f dfind unused definitions
SPC m r e fextract function
SPC m r e vextract variable
SPC m r e lextract to let
SPC m r e cextract constant
SPC m r e aextract autoload
SPC m r i vinline variable
SPC m r i sinline let variable
SPC m r i finline function
SPC m r i ainsert autoload directive
SPC m r d ldelete let binding form
SPC m r d ddelete unused definition
SPC m e weval and replace

Inspector

inspector buffer

Key bindingDescription
RETinspect object
Lnavigate to previous object
qquit inspector

backtrace buffer

iinspect object