[ESS] [R] How to comment out a piece of a R code in XEmacs+ESS

Richard M. Heiberger rmh at temple.edu
Sun Jun 17 05:45:36 CEST 2007


Even better than Doug's suggestion is the M-; command.  Highlight
a region, type M-;, and the whole region is commented out.


M-; runs the command comment-dwim
   which is an interactive compiled Lisp function in `newcomment'.
It is bound to M-;.
(comment-dwim arg)

Call the comment command you want (Do What I Mean).
If the region is active and `transient-mark-mode' is on, call
  `comment-region' (unless it only consists of comments, in which
  case it calls `uncomment-region').
Else, if the current line is empty, insert a comment and indent it.
Else if a prefix arg is specified, call `comment-kill'.
Else, call `comment-indent'.




ESS, and Emacs more generally, recommends that you use ## for commenting a region, not
the single # that you proposed.  See section
7.5 Indenting and formatting S code
in file
   .../ess/doc/html/ess.html

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:

Rich




More information about the ESS-help mailing list