From 90b572a6b820f86acab5f3d59db6a2474b82fc03 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Thu, 8 Aug 2013 13:05:25 -0400 Subject: [PATCH] [emacs] eval-and-replace --- .emacs.d/init.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 75ffa59..a005fec 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -129,6 +129,17 @@ (file-writable-p buffer-file-name)) (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))) +(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) + (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful.