[ESS] commenting region

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Tue Aug 7 16:18:12 CEST 2007


Stephen Bond writes:
 > Is there a way to comment out a whole region in ESS similar to the emacs
 > capability in C and Fortran modes?

You should find that the same commenting commands apply in ESS to
those in C, e.g. M-; and M-x comment-region

Stephen

File: ess.info, Node: Indenting, Next: Other edit buffer commands,
Prev: Evaluating code, Up: Editing

7.5 Indenting and formatting S code
===================================

ESS now provides a sophisticated mechanism for indenting S source code
(thanks to Ken'ichi Shibayama).  Compound statements (delimited by `{'
and `}') are indented relative to their enclosing block.  In addition,
the braces have been electrified to automatically indent to the correct
position when inserted, and optionally insert a newline at the
appropriate place as well.  Lines which continue an incomplete
expression are indented relative to the first line of the expression.
Function definitions, `if' statements, calls to `expression()' and loop
constructs are all recognized and indented appropriately.  User
variables are provided to control the amount if indentation in each
case, and there are also a number of predefined indentation styles to
choose from.

   Comments are also handled specially by ESS, using an idea borrowed
from the Emacs-Lisp indentation style.  By default, comments beginning
with `###' are aligned to the beginning of the line.  Comments
beginning with `##' are aligned to the current level of indentation for
the block containing the comment.  Finally, comments beginning with `#'
are aligned to a column on the right (the 40th column by default, but
this value is controlled by the variable `comment-column',) or just
after the expression on the line containing the comment if it extends
beyond the indentation column.  You turn off the default behavior by
adding the line `(setq ess-fancy-comments nil)' to your `.emacs' file.  

   The indentation commands provided by ESS are: 

   * `TAB' (`ess-indent-command')
     Indents the current line as S code.  If a prefix argument is given,
     all following lines which are part of the same (compound)
     expression are indented by the same amount (but relative indents
     are preserved).

   * `RET' (`newline-and-indent')
     `LFD' (_newline-and-indent_)
     Insert a newline, and indent the next line.  (Note that most
     keyboards nowadays do not have a <LINEFEED> key, but `C-j' is
     equivalent.)

   * `ESC C-q' aka `M-C-q' aka `C-M-q' (`ess-indent-exp')
     Indents each line in the S (compound) expression which follows
     point.  Very useful for beautifying your S code.

   * `{' and `}' (`ess-electric-brace')
     The braces automatically indent to the correct position when typed.

   * `M-;' (`indent-for-comment')
     Indents an existing comment line appropriately, or inserts an
     appropriate comment marker.

   * `M-x ess-set-style'
     Set the formatting style in this buffer to be one of the predefined
     styles: `GNU', `BSD', `K&R', `CLB', and `C++'.  The `DEFAULT'
     style uses the default values for the indenting variables (unless
     they have been modified in your `.emacs' file.)  This command
     causes all of the formatting variables to be buffer-local.




More information about the ESS-help mailing list