diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index aab917fa..836043c1 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -2397,6 +2397,29 @@ Taken from http://endlessparentheses.com/eval-result-overlays-in-emacs-lisp.html (end-of-defun) (point))))) #+END_SRC +**** Reevalute defvars when running eval-last-sexp +What follows is a function that checks to see if what precedes point is a defvar +and reevaluates it as a setq if it is +#+BEGIN_SRC emacs-lisp +(defun imalison:defvar-at-point () + (let* ((preceding-sexp (elisp--preceding-sexp))) + (when (and (listp preceding-sexp) (equal (car preceding-sexp) 'defvar)) + preceding-sexp))) + +(defun imalison:maybe-eval-defvar-as-setq () + (interactive) + (let ((the-defvar (imalison:defvar-at-point))) + (when the-defvar + (eval `(setq ,@(cdr the-defvar)))))) +#+END_SRC +Now we add advice to eval-last-sexp so that it has this behavior. +#+BEGIN_SRC emacs-lisp +(defun imalison:maybe-setq-instead (fn &rest args) + (or (imalison:maybe-eval-defvar-as-setq) + (apply fn args))) + +(advice-add 'eval-last-sexp :around 'imalison:maybe-setq-instead) +#+END_SRC **** Init hook #+BEGIN_SRC emacs-lisp (defvar imalison:check-parens nil)