[ESS] Curly brace indentation

Jan T Kim jttk|m @end|ng |rom goog|em@||@com
Thu Dec 8 17:37:55 CET 2016


Hi Martin and All,

thanks for your reply, please see my comments inline below:

On Thu, Dec 08, 2016 at 09:09:10AM +0100, Martin Maechler wrote:
> >>>>> Jan T Kim via ESS-help <ess-help using r-project.org>
> >>>>>     on Tue, 6 Dec 2016 01:11:20 +0000 writes:
> 
>     > 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.
> 
> What exactly is  "if I type" ?
> - in an emacs buffer for a foo.R file (i.e. a buffer in R-mode),
> right ?

yes -- I used a filename ending with ".R", the mode shows as
"(ESS[S] [none] ElDoc)".

With the "if I type" sample I basically mean to express that the
indentation after the opening curly brace is automatically generated,
rather than typed by me.

> Well, I don't see this
>   (and I would never use unnecessary  ' ; '  nor
>    unnecessary return(.)  .. but that's not really relevant here)
> 
> Specifically, after typing [Enter] at the end of the line
>    return(x * x);
> of course the cursor on the next line is below the first letter
> 'r' of 'return';

yes, that's what I get as well...

> but then if you type "}"  and [Enter] or [Tab]  then it alings
> correctly.
> 
> Don't you see that?

... but no, that "electric" alignment of the closing curly brace
is not what I get. The brace doesn't move to the left, it appears
below the "r" of "return" and stays there.

> If yes,  how could ESS behave any better?

The behaviour you describe is what I would like.

As some additional detail about the system, this is a newly
installed Ubuntu 16.04.1 LTS (Xenial Xerus), and the ESS package
is

    ii  ess            16.10-1xenia all          Emacs mode for statistical ...

Best regards, Jan


>     > 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")
>     > (progn
>     > ; (message "modified ess-electric-brace running")
>     > (ess-electric-brace arg)
>     > (ess-indent-command)
>     > )
>     > )
> 
> 
>     > (defun jtk-ess-mode-hook ()
>     > (progn
>     > (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 using gmail.com                                |
>     > |             WWW:   http://www.jtkim.dreamhosters.com/              |
>     > *-----=<  hierarchical systems are for files, not for humans  >=-----*
> 
>     > ______________________________________________
>     > ESS-help using r-project.org mailing list
>     > https://stat.ethz.ch/mailman/listinfo/ess-help




More information about the ESS-help mailing list