spacemacs/layers/+lang/emacs-lisp/funcs.el
syl20bnr a5c87776d1 emacs-lisp: fix eval-last-sexp and add SPC m e C
Important evil advices for eval-last-sexp were removed for smartparens users,
it made eval-last-sexp not working correctly in normal state by evaluating the
sexp before the evil cursor and it was impossible to evaluate an sexp when the
cursor was on the last character of a line.

Also add SPC m e C which will execute the first defun or setq sexp encountered
before point.
2016-12-24 12:06:17 -05:00

65 lines
2.1 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; funcs.el --- Emacs Lisp functions File
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; idea from http://www.reddit.com/r/emacs/comments/312ge1/i_created_this_function_because_i_was_tired_of/
(defun spacemacs/eval-current-form ()
"Looks for the current def* or set* command then evaluates, unlike `eval-defun', does not go to topmost function"
(interactive)
(save-excursion
(search-backward-regexp "(def\\|(set")
(forward-list)
(call-interactively 'eval-last-sexp)))
(defun spacemacs/nav-find-elisp-thing-at-point-other-window ()
"Find thing under point and go to it another window."
(interactive)
(let ((symb (variable-at-point)))
(if (and symb
(not (equal symb 0))
(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))))