[ESS] Indentation level

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Fri May 14 13:05:24 CEST 2010


> Yes, the default is definitely 2 and has always been so.
> As R-core, we've set "our default" to 4, and indeed I have been preferring
> that myself;
> but nonetheless, the ESS default has always been 2.
> 
> One way to set it to 4 and change other things as well, is using
> what we have had in the "R Internals" (and previously "R Extensions") manual
> for many years;
> e.g. from the Swiss (CH) CRAN mirror:
> 
>     http://stat.ethz.ch/CRAN/doc/manuals/R-ints.html#R-coding-standards
> (about one page down):
> 
>      ;;; ESS
>      (add-hook 'ess-mode-hook
>                (lambda ()
>                  (ess-set-style 'C++ 'quiet)
>                  ;; Because
>                  ;;                                 DEF GNU BSD K&R C++
>                  ;; ess-indent-level                  2   2   8   5   4
>                  ;; ess-continued-statement-offset    2   2   8   5   4
>                  ;; ess-brace-offset                  0   0  -8  -5  -4
>                  ;; ess-arg-function-offset           2   4   0   0   0
>                  ;; ess-expression-offset             4   2   8   5   4
>                  ;; ess-else-offset                   0   0   0   0   0
>                  ;; ess-close-brace-offset            0   0   0   0
> 0
> 
>           [.... other recommendatinos omitted here ...]
> 
> and as others have said repeatedly on this thread:
> Yes, you should and I think *must* set this via adding to the ess-mode-hook
> BTW: In the above Emacs code, most are comments showing you the diverse
> style settings,
> mentioning indeed that the default ("DEF") is at 2.


(This is mostly relevant for ess-core...)

To follow up on this thread, this question of setting ess-indent-level
was asked last year:

http://article.gmane.org/gmane.emacs.ess.general/3995


where I suggested the workaround of doing:

(defun myindent-ess-hook ()
  (setq ess-indent-level 4))

(add-hook 'ess-mode-hook 'myindent-ess-hook) 

which has been reported in this thread.  I've now investigated further,
and ess-indent-level is set by the function ess-set-style, which is
called when a new R buffer is opened, via the call to ess-mode.  So
currently I think it makes no sense to have variables such as
ess-indent-level customizable.  This is my fault, as I think I
customized them many years ago!  Instead, it would make sense to allow 
users to customize the default style, which is exactly what Tony
suggested and I disagreed with many years ago.  Here is the relevant
output from vc-annotate on ess-custom.el:

  1421    rossini ;;; **FIXME**  The following NEEDS to be customized.
  3090   maechler ;; SJE: I disagree; this variable should not be
                     customized; individual vars, 
  3062    stephen ;; such as ess-indent-level are already customizable.
  1286        ess (defvar ess-default-style-list

This would then give us a chance to promote the R-coding standards that
Martin cites above.

Stephen



More information about the ESS-help mailing list