[ESS] reformat source code

Mathieu Basille basille.web at ase-research.org
Sat Jun 15 17:49:00 CEST 2013


And to add up to the overall confusion, there's also the possibility to 
actually use the R parser to format R code, via 
'ess-indent-region-as-R-function' designed by Vitalie Spinu (but not part 
of ESS?). The only drawback is that it can only format the first 'element' 
of a region, being a single complete code line or a function...

See: http://www.emacswiki.org/emacs/ESSRParser

Mathieu.


Le 06/15/2013 04:00 AM, Martin Maechler a écrit :
>>>>>> Kasper Daniel Hansen <kasperdanielhansen at gmail.com>
>>>>>>      on Fri, 14 Jun 2013 22:59:09 +0200 writes:
>
>      > Thanks Rainer and Andreas I knew there was something along
>      > these lines; but I could not find it with a cursory
>      > (admittedly) look in the manual.
>
> yeah.. we know, the manual is far from perfect, and we are glad
> for patches..
>
> (read on!)
>
>      > Best, Kasper
>
>
>      > On Fri, Jun 14, 2013 at 3:06 PM, Andreas Leha <
>      > andreas.leha at med.uni-goettingen.de> wrote:
>
>      >> Rainer M Krug <Rainer at krugs.de> writes:
>      >>
>      >> >>
>      >> >> Is there an easy way to replace = assignments with <-?
>      >> >
>      >> > Other then M-% and to decide fir each, I don't think
>      >> so?
>      >> >
>      >>
>      >> There is ess-fix-EQ-assign.
>      >>
>      >> There are also ess-MM-fix-src and ess-fix-miscellaneous
>      >> which might be of interest here.
>
>      >> Best, Andreas
>
> Indeed, thank you, Andreas!
>
> All of three of them have emerged historically, mostly tended to
> by myself.  Notably,  'ess-MM-fix-src,  as the name still
> alludes to, have been my own  "code fixups" which after years of
> successful use had been added to ESS where I've kept "MM" as
> some changes may be a matter of taste only.
>
> OTOH, the  ess-fix-miscellaneous -- BTW, much easier to find:
>        M-x ess-fix [TAB] --
> originally have been uniformly agreed on improvements, notably replacing
> the bad use of 'T' and 'F' by the correct use of 'TRUE' and 'FALSE'
> {don't start a flame war here if you disagree.. this has been part of
>   R and R-core's design since ever, even if bad IDEs do colorize
>   T and F as if they were the same as TRUE and FALSE}.
>
> All of these fixups are not perfect, notably can have both false
> positives and negatives.
> The ess-fix-EQ-assign, i.e., substituting
>       "="  by  "<-"  (including surrounding whitespace!)
> replacement could be made perfect in principle, if ESS would use
> R's parser and R itself to analyze  which of the "=" are
> assignments and which mean setting of function arguments.
> Currently it's not at all perfect as the doc string and the
> comments (all functions are in  ess/lisp/ess-s-l.el ) show.
> IMO, the fact that this is not easy, is exactly a *proof* why
> using '<-' and '=' diligently in your own code adds much to code
> legibility both for yourself (notably when re-reading code you
> wrote a while ago!) and for other readers of your code.
>
> Also, what these functions do not do much is syntatic
> indentation (*after* having fixed up some the '# ..' comments),
> and I have always wondered if we should not try to do so.
>
> In summary, a complete overhaul / redesign of these code fixups
> would actually be desirable.
> If some of you feels somewhat comfortable with emacs lisp and
> is willing to put in some effort, I'd be happy to consider
> collaboration here.
>
> Martin
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>

-- 

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard



More information about the ESS-help mailing list