csrhodes / swankr

SWANK for R
10 stars 5 forks source link

+TITLE: swankr: SWANK (and SLIME) for R

+AUTHOR: Christophe Rhodes

+EMAIL: csr21@cantab.net

;;; SLIME (require 'slime) (setq slime-net-coding-system 'utf-8-unix) (slime-setup '(slime-asdf slime-repl slime-scratch slime-presentations slime-media)) (setq slime-lisp-implementations '((sbcl ("sbcl" "--dynamic-space-size" "2048" "--load" "/home/csr21/src/lisp/quicklisp/setup.lisp")) (git-sbcl ("sh" "/home/csr21/src/lisp/sbcl/run-sbcl.sh" "--dynamic-space-size" "2048")) (R ("R" "--no-save" "--max-vsize=4096M" "--interactive") :init (lambda (port-filename coding-system) (load "/home/csr21/src/R/swankr/swankr") (format "source('/home/csr21/src/R/swankr/swank.R', keep.source=TRUE, chdir=TRUE)\nstartSwank('%s')\n" port-filename))))) (global-set-key (kbd "s-s") 'slime-selector)

+end_src

*** Additional refinements In addition, for keybindings like =C-c C-c= to work properly, emacs needs to be told how to guess where a function definition begins. This can be achieved with /e.g./

+BEGIN_SRC emacs-lisp

(add-hook 'ess-mode-hook (lambda () (setq defun-prompt-regexp "^\(\(\sw\|\s_\)+\|\s\"\S\"+\s\"\)\s-\(=\|<-\)\s-function\s-(.)\s-*")))

+END_SRC

Fontification of quoted function names is suboptimal by default in ESS; the following form in =~/.emacs= fixes that for ESS 5.11.

+BEGIN_SRC emacs-lisp

(eval-after-load "ess-common" (setq ess-R-mode-font-lock-keywords (append (list '("\(\sw\|\s_\)+\s-\(=\|<-\)\s-function" 1 font-lock-function-name-face t) '("\s\"\(\S\"+\)\s\"\s-\(=\|<-\)\s-function" 1 font-lock-function-name-face t)) ess-R-mode-font-lock-keywords)))

+END_SRC

*** Running After performing the installation steps above, =M-- M-x slime RET R RET= should start swank. You will be prompted to accept a version mismatch -- simply accept -- then the SLIME REPL should start up, giving a prompt. Enjoy!

[fn:2] a free software environment for statistical computing and graphics: http://www.r-project.org/.

[fn:3] also known as ESS, an emacs mode for interacting with a number of statistical software packages, including R: http://ess.r-project.org/.