[ESS] fixing spaces in function arguments

Alexander Stoddard astoddar at mail.med.upenn.edu
Thu Mar 1 17:50:44 CET 2007


> I like to follow the convention of no spaces around "=" in argument
> specifications.  I often receive code that doesn't follow this, so I
> thought one of the ess-fix-* functions might take care of that.  But
> unfortunately not, so stealing from ess-fix-miscellaneous (which  
> actually
> does the opposite), I did:
>
>
> (defun ess-fix-EQ-spaces (&optional from verbose)
>   "Remove spaces around equal sign from current \\[point] or FROM.
> VERBOSE shows message in minibuffer for replacements."
>   (interactive "d\nP")
>   (save-excursion
>     (goto-char from)
>     (ess-rep-regexp "[ \t]+=[ \t]+" "=" nil nil verbose)))
>

I can't comment on your  elisp, as I am a lisp neophyte,  but it  
looks like ess-rep-regexp (found in ess-utils.el) is a wrapper around  
a normal regexp search and replace operation. It prevents the  
replacement from occurring within a string or single line comment,  
and provides some feed back when verbose is true.

Regarding the regex you are using, it won't catch the really  
malformed cases where the space only occurs on one side of the "=".   
Maybe you could use "[\t]?" instead of "[ \t]+".

Kind regards,
Alex Stoddard




More information about the ESS-help mailing list