From 72aa9219773cb0717c4f27a28056c4fef5ce2e6a Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 29 Jul 2013 14:08:53 +0100 Subject: Emacs: add eval-and-replace and bind to C-c e --- emacs/init.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/emacs/init.el b/emacs/init.el index 43a1314b..26defe92 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -972,6 +972,18 @@ Also returns nil if pid is nil." (add-hook 'emacs-lisp-mode-hook 'imenu-elisp-sections) +(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))))) + +(bind-key "C-c e" #'eval-and-replace) + ;;;; Programming (use-package auto-compile -- cgit 1.4.1