[ESS] Curly brace indentation

Jan T Kim jttkim at googlemail.com
Tue Dec 6 02:11:20 CET 2016

Hello All,

since some time, I get the following indentation behaviour: If I type

    f <- function(x)
    return(x * x);

this gets indented as

    f <- function(x)
	return(x * x);

i.e. the closing curly brace is not vertically aligned with the opening one.

If I then go on and indent the buffer (C-x h C-M-\), the indentation is
updated to

    f <- function(x)
	return(x * x);

so the opening and closing curly braces are now vertically aligned.

This behaviour started several months ago. Reviewing the change logs,
I speculate that upgrading (via Ubuntu package manager) to a package
providing 15.09, where "the indentation logic has been refactored",
may be the cause of the change, but as I've done little R coding for
a while I can't really pinpoint this.

I recently got a new computer at work and used that opportunity to
check that the behaviour occurs with a new account, i.e. without any
~/.emacs file.

After some code delving and hacking I've managed to adjust the electric
curly braces by adding this to my .emacs:

    (defun jtk-ess-electric-brace (arg)
      "modified / extended ess-electric-brace"
      (interactive "P")
	; (message "modified ess-electric-brace running")
	(ess-electric-brace arg)

    (defun jtk-ess-mode-hook ()
	(local-set-key (kbd "{") 'jtk-ess-electric-brace)
	(local-set-key (kbd "}") 'jtk-ess-electric-brace)

So essentially I have the brace indented immediately after inserting
it via the original ess-electric-brace command. However, this solution
is not 100% perfect as the indentation of closing braces occurs only
after some delay caused by briefly flashing the cursor at the corresponding
opening brace.

Quite possibly I'm using a clumsy approach to try to get indentation during
typing consistent with that produced by indent-region, so suggestions where
I may have messed up are welcome.

Best regards & thanks in advance for any pointers, Jan
 +- Jan T. Kim -------------------------------------------------------+
 |             email: jttkim at gmail.com                                |
 |             WWW:   http://www.jtkim.dreamhosters.com/              |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

More information about the ESS-help mailing list