# (Emacs+Org-Mode) Make Eval Expression A Little Easier

Once you’ve been using Emacs for a while you end up using eval-expression a lot. 99% of the time I use it to make function calls. I never noticed before that it is kind of tedious to reach for S-M-; and then () despite using it so much. Here is a binding and a function definition that make it easier to use binding it close to home and inserting the round parentheses.

(global-set-key (kbd "M-;") #'my-eval-expression)
(define-key org-mode-map (kbd "M-;") nil)
(progn

(let ((map (make-sparse-keymap)))
(define-key map [(control ?g)] #'minibuffer-keyboard-quit)
(define-key map [up]   nil)
(define-key map [down] nil)
map))

(let ((minibuffer-completing-symbol t))
(minibuffer-with-setup-hook
(lambda ()
(emacs-lisp-mode)
(setq font-lock-mode t)
(funcall font-lock-function 1)
(insert "()")
(backward-char))

(defun my-eval-expression (expression &optional arg)
"Attribution: URL https://lists.gnu.org/archive/html/help-gnu-emacs/2014-07/msg00135.html'."
current-prefix-arg))
(if arg
(insert (pp-to-string (eval expression lexical-binding)))
(pp-display-expression (eval expression lexical-binding)
"*Pp Eval Output*"))))


## 4 thoughts on “(Emacs+Org-Mode) Make Eval Expression A Little Easier”

1. Mathias Dahl says:

Great idea! ;-) Another tips to save a little bit of typing is to learn M-(. It takes a bit to get a habit of using it though.

1. Grant says:

Once you get in the habit of using eval-expression you are right, you will be hooked.

1. Mathias Dahl says:

I was thinking about insert-parentheses’, but sure… :)

1. Grant says:

Hahaha yes.