summary refs log tree commit diff stats
path: root/emacs
diff options
context:
space:
mode:
authorAlan Pearce2013-07-29 14:08:53 +0100
committerAlan Pearce2013-07-29 14:08:53 +0100
commit72aa9219773cb0717c4f27a28056c4fef5ce2e6a (patch)
treea4a55925ed0cf3d268728a1407ceeeee88bb4a96 /emacs
parentf26545a8cb75a4aeb0773ac309d8145aeb087d1d (diff)
downloadnixfiles-72aa9219773cb0717c4f27a28056c4fef5ce2e6a.tar.lz
nixfiles-72aa9219773cb0717c4f27a28056c4fef5ce2e6a.tar.zst
nixfiles-72aa9219773cb0717c4f27a28056c4fef5ce2e6a.zip
Emacs: add eval-and-replace and bind to C-c e
Diffstat (limited to 'emacs')
-rw-r--r--emacs/init.el12
1 files changed, 12 insertions, 0 deletions
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