# Emacs Key Binding for eval-defun in lisp-mode

September 22, 2009
By

(This article was first published on Blogistic Reflections, and kindly contributed to R-bloggers)

When I use R in Emacs through the ESS package, C-c C-c in a .R buffer will send a “block” of code to the inferior R process for evaluation. This was added just a few years ago, but my fingers are now trained to use that key combination for evaluating any block of code. Since I have been learning Emacs Lisp, I decided that a good idea would be to make C-c C-c a binding to eval-defun. I really like how it is working out as I have to redefine my Lisp functions many times!

Just put the following in your .emacs file to get this behavior. However, please note the following from the eval-defun help string, “If the current defun is actually a call to defvar’ or defcustom’, evaluating it this way resets the variable using its initial value expression even if the variable already has some other value. (Normally defvar’ and defcustom’ do not alter the value if there already is one.)”

(define-key lisp-mode-shared-map "C-cC-c" 'eval-defun)


R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...