Simplify ESS layer autoloads and add keybindings for starting REPLs

This commit is contained in:
Ista Zahn 2015-10-11 23:01:45 -04:00 committed by syl20bnr
parent f89ec043fd
commit a761c0def4
2 changed files with 41 additions and 66 deletions

View file

@ -16,14 +16,16 @@ To use this contribution add it to your =~/.spacemacs=
(setq-default dotspacemacs-configuration-layers '(ess)) (setq-default dotspacemacs-configuration-layers '(ess))
#+END_SRC #+END_SRC
*Important:*
In order to speed up the boot time of =Spacemacs=, =ESS= must be loaded
manually via the key binding: ~SPC e s s~
* Key Bindings * Key Bindings
** Inferior REPL process ** Inferior REPL process
Start an =R= inferior REPL process with ~SPC m s i~. Start an inferior REPL process with these commands:
| Keybinding | Description |
|------------+---------------------|
| ~SCP msir~ | start R process |
| ~SPC msis~ | start Stata process |
| ~SPC msiS~ | start SAS process |
| ~SPC msij~ | start Julia process |
Send code to inferior process commands: Send code to inferior process commands:

View file

@ -21,72 +21,42 @@
)) ))
(defun ess/init-ess () (defun ess/init-ess ()
;; ESS is not quick to load so we just load it when (use-package ess-site
;; we need it (see my-keybindings.el for the associated :mode (("\\.sp\\'" . S-mode)
;; keybinding) ("/R/.*\\.q\\'" . R-mode)
(defun load-ess-on-demand () ("\\.[qsS]\\'" . S-mode)
(interactive) ("\\.ssc\\'" . S-mode)
(-all? '---truthy? (list ("\\.SSC\\'" . S-mode)
(require 'ess-site) ("\\.[rR]\\'" . R-mode)
(require 'ess-R-object-popup) ("\\.[rR]nw\\'" . Rnw-mode)
(require 'ess-R-data-view)))) ("\\.[sS]nw\\'" . Snw-mode)
("\\.[rR]profile\\'" . R-mode)
(evil-leader/set-key "ess" 'load-ess-on-demand) ("NAMESPACE\\'" . R-mode)
("CITATION\\'" . R-mode)
(use-package ess ("\\.omg\\'" . omegahat-mode)
:defer t ("\\.hat\\'" . omegahat-mode)
("\\.lsp\\'" . XLS-mode)
("\\.do\\'" . STA-mode)
("\\.ado\\'" . STA-mode)
("\\.[Ss][Aa][Ss]\\'" . SAS-mode)
("\\.jl\\'" . ess-julia-mode)
("\\.[Ss]t\\'" . S-transcript-mode)
("\\.Sout" . S-transcript-mode)
("\\.[Rr]out" . R-transcript-mode)
("\\.Rd\\'" . Rd-mode)
("\\.[Bb][Uu][Gg]\\'" . ess-bugs-mode)
("\\.[Bb][Oo][Gg]\\'" . ess-bugs-mode)
("\\.[Bb][Mm][Dd]\\'" . ess-bugs-mode)
("\\.[Jj][Aa][Gg]\\'" . ess-jags-mode)
("\\.[Jj][Oo][Gg]\\'" . ess-jags-mode)
("\\.[Jj][Mm][Dd]\\'" . ess-jags-mode))
:commands (R stata julia SAS)
:init :init
(progn (progn
(setq auto-mode-alist (append
'(("\\.sp\\'" . S-mode)
("/R/.*\\.q\\'" . R-mode)
("\\.[qsS]\\'" . S-mode)
("\\.ssc\\'" . S-mode)
("\\.SSC\\'" . S-mode)
("\\.[rR]\\'" . R-mode)
("\\.[rR]nw\\'" . Rnw-mode)
("\\.[sS]nw\\'" . Snw-mode)
("\\.[rR]profile\\'" . R-mode)
("NAMESPACE\\'" . R-mode)
("CITATION\\'" . R-mode)
("\\.omg\\'" . omegahat-mode)
("\\.hat\\'" . omegahat-mode)
("\\.lsp\\'" . XLS-mode)
("\\.do\\'" . STA-mode)
("\\.ado\\'" . STA-mode)
("\\.[Ss][Aa][Ss]\\'" . SAS-mode)
("\\.[Ss]t\\'" . S-transcript-mode)
("\\.Sout" . S-transcript-mode)
("\\.[Rr]out" . R-transcript-mode)
("\\.Rd\\'" . Rd-mode)
("\\.[Bb][Uu][Gg]\\'" . ess-bugs-mode)
("\\.[Bb][Oo][Gg]\\'" . ess-bugs-mode)
("\\.[Bb][Mm][Dd]\\'" . ess-bugs-mode)
("\\.[Jj][Aa][Gg]\\'" . ess-jags-mode)
("\\.[Jj][Oo][Gg]\\'" . ess-jags-mode)
("\\.[Jj][Mm][Dd]\\'" . ess-jags-mode))
auto-mode-alist))
(defun ess/auto-load-hack (mode-symbol)
(eval
`(defun ,mode-symbol ()
"This is a function that will hijack itself with its
definition from ess. The reason this exists is that ess does
not play nicely with autoloads"
(when (load-ess-on-demand)
(,mode-symbol)))))
(defvar ess/r-modes-list '(R-mode R-transcript-mode Rd-mode Rnw-mode S-mode S-transcript-mode
SAS-mode STA-mode Snw-mode XLS-mode ess-bugs-mode ess-jags-mode omegahat-mode)
"This is the list of modes defined by ess")
(mapc (lambda (sym) (ess/auto-load-hack sym)) ess/r-modes-list)
(push '(company-R-args company-R-objects) company-backends-ess-mode))) (push '(company-R-args company-R-objects) company-backends-ess-mode)))
;; R -------------------------------------------------------------------------- ;; R --------------------------------------------------------------------------
(with-eval-after-load 'ess-site (with-eval-after-load 'ess-site
(add-to-list 'auto-mode-alist '("\\.R$" . R-mode))
;; Follow Hadley Wickham's R style guide ;; Follow Hadley Wickham's R style guide
(setq ess-first-continued-statement-offset 2 (setq ess-first-continued-statement-offset 2
ess-continued-statement-offset 0 ess-continued-statement-offset 0
@ -94,7 +64,10 @@ not play nicely with autoloads"
ess-nuke-trailing-whitespace-p t ess-nuke-trailing-whitespace-p t
ess-default-style 'DEFAULT) ess-default-style 'DEFAULT)
(evil-leader/set-key-for-mode 'ess-mode (evil-leader/set-key-for-mode 'ess-mode
"msi" 'R "msir" 'R
"msis" 'stata
"msiS" 'SAS
"msij" 'julia
;; noweb ;; noweb
"mcC" 'ess-eval-chunk-and-go "mcC" 'ess-eval-chunk-and-go
"mcc" 'ess-eval-chunk "mcc" 'ess-eval-chunk