[ESS] Curly brace indentation

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Thu Dec 8 09:09:10 CET 2016


>>>>> 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 ?

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';
but then if you type "}"  and [Enter] or [Tab]  then it alings
correctly.

Don't you see that?
If yes,  how could ESS behave any better?




    > 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