[ESS] reformat source code

Yihui Xie xie at yihui.name
Mon Jun 17 19:14:01 CEST 2013


To replace = with <-, I think regular expressions are less reliable
than codetools. You may want to take a look at the function
replace_assignment() here:
https://github.com/yihui/formatR/blob/master/R/utils.R (credit goes to
Kohske Takahashi: https://github.com/yihui/formatR/pull/20)

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 206-667-4385 Web: http://yihui.name
Fred Hutchinson Cancer Research Center, Seattle


On Sat, Jun 15, 2013 at 1:00 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
>
>     > 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



More information about the ESS-help mailing list