[Emacs] Handle defvars with eval-last-sexp
This commit is contained in:
parent
8eb53dc33e
commit
d177f3bbcd
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user