[ESS] proposal re: underscore, part 2

Rodney Sparapani rsparapa at mcw.edu
Wed Apr 11 16:35:42 CEST 2012


Matthew Fidler wrote:
> Francois,
> 
> I agree with your assesment of the extra keystroke.  I tried the " _"
> option for awhile and found it to be a little less ideal.  Hence this
> option is turned off by default in my ess-smart-underscore.el package.
> However, the underscore is guessed by context.  In my redifnition of
> ess-smart-underscore, the following documentation describes the behavior
> 
> Smart "_" key: insert `ess-S-assign', unless:
>   1. in string/comment
>   2. after a $ (like d$one_two) (toggle with `ess-S-underscore-after-$')
>   3. when the underscore is part of a variable definition previously
> defined.
>      (toggle with `ess-S-underscore-after-defined')
>   4. when the underscore is after a \"=\" or \"<-\" on the same line.
>      (toggle with `ess-S-underscore-after-<-or-=')
>   5. inside a parenthetical statement () or [].
>      (toggle with `ess-S-underscore-when-inside-paren')
>   6. At the beginning of a line.
>   7. In a variable that contains underscores already (for example foo_a)
>      (toggle with `ess-S-underscore-when-variable-contains-underscores')
>   8. The preceding character is not a tab/space
>      (toggle with `ess-S-underscore-when-last-character-is-a-space'.  Not
> enabled by default.)
> 
> 
> An exception to #4 is in the following situation:
> 
> a <- b |
> 
> pressing an underscore here would produce
> 
> a <- b <-
> 
> However when in the following situation
> 
> a <- b|
> 
> pressing an underscore would produce
> 
> a <- b_
> 
> This behavior can be toggled by `ess-S-space-underscore-is-assignment'
> 
> If the underscore key is pressed a second time, the assignment
> operator is removed and replaced by the underscore.  `ess-S-assign',
> typically \" <- \", can be customized.  In ESS modes other than R/S,
> an underscore is always inserted.
> 
> I find this behaviour better than the traditional "_" behavior.
> 
> Matt.

Hi Matt:

Very nice!  I just checked in a sneaky change for ESS[BUGS/JAGS]
to mimic ESS[S/R] for this purpose.  So, to get this functionality
in ESS[BUGS]:

(require 'ess-smart-underscore)
(require 'ess-bugs-d)
(define-key ess-bugs-mode-map "_" 'ess-smart-underscore)

And similar changes will do it for ESS[JAGS].

I've also been experimenting with ...
(define-key ess-bugs-mode-map "=" 'ess-smart-underscore)

Rodney



More information about the ESS-help mailing list