R-mode indenting

Leif Albers lalbers at wiwi.uni-bielefeld.de
Tue Jan 27 18:11:39 CET 2004


Hello,

when using ess-mode with R, I stumbled across a little
problem concerning the indenting done in R mode.

Let me show you how Ess indents following code: (I hope you
are using monospaced fonts ...)

    foo <- function( param1,
                    param2 )

While it should look like:

    foo <- function( param1,
                     param2 )

This can be corrected by inserting a single line into the
function ess-calculate-indent (defined in
ess-mode.el). (Where, see at the bottom of the message.)

When the function looks for a paren in some previous line,
it stops right after the paren and then returns
(current-column). I just inserted (skip-chars-forward " \t")
which does the job.

Unfortunalety this is not everything. For some reason R-mode
uses *two* calculate-indent functions. One is
ess-calculate-indent, the other is S-calculate-indent (from
essl-s.el). They are exactly the same (except for comments
and formatting). For some reason, both functions are
used. If you want my patch to work, you either have to apply
it to both functions, or you have to erase the obsolete
version.

Leif Albers

----------------------
In ess-mode.el, in the function ess-calculate indent you
find following lines of code. Insert the new line marked
with "<- here"
----------------------
	     (let ((bol (save-excursion (beginning-of-line) (point))))
	       
	       ;; modified by shiba at isac 7.3.1992
	       (cond ((and (numberp ess-expression-offset)
			   (re-search-backward "[ \t]*expression[ \t]*" bol t))
		      ;; This regexp match every "expression".
		      ;; modified by shiba
		      ;;(forward-sexp -1)
		      (beginning-of-line)
		      (skip-chars-forward " \t")
		      ;; End
		      (+ (current-column) ess-expression-offset))
		     ((and (numberp ess-arg-function-offset)
			   (re-search-backward
			    "=[ \t]*\\s\"*\\(\\w\\|\\s_\\)+\\s\"*[ \t]*"
			    bol t))
		      (forward-sexp -1)
		      (+ (current-column) ess-arg-function-offset))
		     ;; "expression" is searched before "=".
		     ;; End
		     (t
		      (progn (goto-char (+ 1 containing-sexp))
			     (skip-chars-forward " \t")				; <- here




More information about the ESS-help mailing list