diff --git a/layers/+lang/emacs-lisp/README.org b/layers/+lang/emacs-lisp/README.org index 358e38f4a..e8496f91a 100644 --- a/layers/+lang/emacs-lisp/README.org +++ b/layers/+lang/emacs-lisp/README.org @@ -6,9 +6,9 @@ - [[#description][Description]] - [[#install][Install]] - [[#auto-compile][Auto-compile]] + - [[#working-with-lisp-files-barfage-slurpage--more][Working with lisp files (barfage, slurpage & more)]] - [[#key-bindings][Key bindings]] - - [[#working-with-lisp-files-barfage-slurpage--more][Working with lisp files (barfage, slurpage & more)]] - - [[#leader][Leader]] + - [[#smartparens][smartparens]] - [[#srefactor][srefactor]] * Description @@ -34,8 +34,7 @@ feature use this line in your =dotspacemacs/user-config= function. You can also exclude the =auto-compile= package. -* Key bindings -** Working with lisp files (barfage, slurpage & more) +* 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. @@ -43,24 +42,32 @@ lisp. As this state works the same for all files, the documentation is in global [[https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.org#lisp-key-bindings][DOCUMENTATION.org]]. In general, use ~SPC k~ to interact with the lisp-state. -** Leader +* Key bindings -| Key Binding | Description | -|----------------------------+------------------------------------------------------------| -| ~SPC m g g~ | go to definition of symbol under point | -| ~SPC m h h~ | describe symbol at point | -| ~SPC m c c~ | byte compile the current file | -| ~SPC m c l~ | popup compile-log buffer | -| ~SPC m e $~ or ~SPC m e l~ | go to end of current line and evaluate | -| ~SPC m e b~ | evaluate current buffer | -| ~SPC m e c~ | evaluate current form (start with =defun=, =setq=, etc...) | -| ~SPC m e e~ | evaluate sexp before point | -| ~SPC m e r~ | evaluate current region | -| ~SPC m e f~ | evaluation current function | -| ~SPC m ​,​~ | toggle =lisp state= | -| ~SPC m t b~ | run tests of current buffer | -| ~SPC m t q~ | run =ert= | -| ~SPC m d m~ | open [[https://github.com/joddie/macrostep][macrostep]] transient-state | +| Key Binding | Description | +|----------------------------+----------------------------------------| +| ~SPC m g g~ | go to definition of symbol under point | +| ~SPC m h h~ | describe symbol at point | +| ~SPC m c c~ | byte compile the current file | +| ~SPC m c l~ | popup compile-log buffer | +| ~SPC m e $~ or ~SPC m e l~ | go to end of current line and evaluate | +| ~SPC m e b~ | evaluate current buffer | +| ~SPC m e C~ | evaluate current =defun= or =setq= | +| ~SPC m e e~ | evaluate sexp before point | +| ~SPC m e f~ | evaluation current function | +| ~SPC m e r~ | evaluate current region | +| ~SPC m ​,​~ | toggle =lisp state= | +| ~SPC m t b~ | run tests of current buffer | +| ~SPC m t q~ | run =ert= | +| ~SPC m d m~ | open [[https://github.com/joddie/macrostep][macrostep]] transient-state | + +** smartparens +If =smartparens= is used the following additional key bindings are available: + +| Key Binding | Description | +|-------------+------------------------------| +| ~SPC m e c~ | evaluate sexp around point | +| ~SPC m e s~ | evaluate symbol around point | ** srefactor The [[file:../../semantic/README.org][semantic]] layer should be installed for these key bindings to become active. diff --git a/layers/+lang/emacs-lisp/funcs.el b/layers/+lang/emacs-lisp/funcs.el index 4b07d987d..85150d67d 100644 --- a/layers/+lang/emacs-lisp/funcs.el +++ b/layers/+lang/emacs-lisp/funcs.el @@ -29,3 +29,36 @@ (not (fboundp symb))) (find-variable-other-window symb) (find-function-at-point)))) + + +;; smartparens integration + +(defun spacemacs/eval-current-form-sp (&optional arg) + "Call `eval-last-sexp' after moving out of one level of +parentheses. Will exit any strings and/or comments first. +An optional ARG can be used which is passed to `sp-up-sexp' to move out of more +than one sexp. +Requires smartparens because all movement is done using `sp-up-sexp'." + (interactive "p") + (require 'smartparens) + (let ((evil-move-beyond-eol t)) + ;; evil-move-beyond-eol disables the evil advices around eval-last-sexp + (save-excursion + (let ((max 10)) + (while (and (> max 0) + (sp-point-in-string-or-comment)) + (decf max) + (sp-up-sexp))) + (sp-up-sexp arg) + (call-interactively 'eval-last-sexp)))) + +(defun spacemacs/eval-current-symbol-sp () + "Call `eval-last-sexp' on the symbol around point. +Requires smartparens because all movement is done using `sp-forward-symbol'." + (interactive) + (require 'smartparens) + (let ((evil-move-beyond-eol t)) + ;; evil-move-beyond-eol disables the evil advices around eval-last-sexp + (save-excursion + (sp-forward-symbol) + (call-interactively 'eval-last-sexp)))) diff --git a/layers/+lang/emacs-lisp/packages.el b/layers/+lang/emacs-lisp/packages.el index 277b042c7..a60d3a485 100644 --- a/layers/+lang/emacs-lisp/packages.el +++ b/layers/+lang/emacs-lisp/packages.el @@ -93,6 +93,7 @@ "cc" 'emacs-lisp-byte-compile "e$" 'lisp-state-eval-sexp-end-of-line "eb" 'eval-buffer + "eC" 'spacemacs/eval-current-form "ee" 'eval-last-sexp "er" 'eval-region "ef" 'eval-defun @@ -167,35 +168,6 @@ "=s" 'srefactor-lisp-format-sexp)))) (defun emacs-lisp/post-init-smartparens () - (advice-remove 'elisp--preceding-sexp 'evil--preceding-sexp) - - (defun spacemacs/eval-current-form-sp (&optional arg) - "Call `eval-last-sexp' after moving out of one level of -parentheses. Will exit any strings and/or comments first. -Requires smartparens because all movement is done using -`sp-up-sexp'. An optional ARG can be used which is passed to -`sp-up-sexp' to move out of more than one sexp." - (interactive "p") - (require 'smartparens) - (save-excursion - (let ((max 10)) - (while (and (> max 0) - (sp-point-in-string-or-comment)) - (decf max) - (sp-up-sexp))) - (sp-up-sexp arg) - (call-interactively 'eval-last-sexp))) - - (defun spacemacs/eval-current-symbol-sp () - "Call `eval-last-sexp' on the symbol around point. Requires -smartparens because all movement is done using -`sp-forward-symbol'." - (interactive) - (require 'smartparens) - (save-excursion - (sp-forward-symbol) - (call-interactively 'eval-last-sexp))) - (dolist (mode '(emacs-lisp-mode lisp-interaction-mode)) (spacemacs/set-leader-keys-for-major-mode mode "ec" 'spacemacs/eval-current-form-sp