[emacs] Add eval and replace

This commit is contained in:
Correl Roush 2019-09-23 16:51:24 -04:00
parent 36da199c48
commit 02d14a5b75

View file

@ -795,3 +795,19 @@ Manage background services
(use-package! uuidgen
:commands (uuidgen))
#+end_src
* Eval and Replace
Taken from [[http://emacsredux.com/blog/2013/06/21/eval-and-replace/][Emacs Redux]]
#+begin_src emacs-lisp
(defun eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(current-buffer))
(error (message "Invalid expression")
(insert (current-kill 0)))))
(global-set-key (kbd "C-)") 'eval-and-replace)
#+end_src