All,

I also made other additions.  Instead of littering the list, I have put all
additions on the emacswiki:

http://www.emacswiki.org/emacs/ess-smart-underscore.el

Matt.

On Thu, Jul 14, 2011 at 11:30 AM, Matthew Fidler
<matthew.fidler@gmail.com>wrote:

> Pierre,
>
> This has bugged me for awhile too.  I actually like the underscore
> producing <-.  However it annoys me when the underscore produces <- in
> variable names.  Thinking about how R is structured I believe this most
> often occur when refering to variables in a dataset, that is
>
> dat$one_two
>
> It can be also annoying if you purposely defined a variable with an
> underscore:
>
> one_two <- 3
>
> one_two+3
>
> I have redefined ess-smart-underscore to handle these situations a little
> more intelligenty (that is guess you want to insert an underscore)
>
> The function is as follows:
>
> (defun ess-smart-underscore ()
>   "Smart \"_\" key: insert `ess-S-assign', unless in string/comment.
> 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. "
>   (interactive)
>   ;;(insert (if (ess-inside-string-or-comment-p (point)) "_" ess-S-assign))
>   (if (or
>        (ess-inside-string-or-comment-p (point))
>        ;; Data
>        (save-match-data (looking-back "[$][A-Za-z0-9.]+"))
>        ;; Look for variable
>        (save-match-data
>   (save-excursion
>     (let (word)
>       (looking-back "\\<[A-Za-z0-9.]+")
>       (setq word (match-string 0))
>       (message "Word: %s" word)
>       (re-search-backward (format "^[ \t]*%s_[A-Za-z0-9.]*[
> \t]*\\(<-\\|=\\)" word) nil t))))
>        (not (equal ess-language "S")))
>       (insert "_")
>     ;; Else one keypress produces ess-S-assign; a second keypress will
> delete
>     ;; ess-S-assign and instead insert _
>     ;; Rather than trying to count a second _ keypress, just check whether
>     ;; the current point is preceded by ess-S-assign.
>     (let ((assign-len (length ess-S-assign)))
>       (if (and
>     (>= (point) (+ assign-len (point-min))) ;check that we can move back
>     (save-excursion
>              (backward-char assign-len)
>              (looking-at ess-S-assign)))
>    ;; If we are currently looking at ess-S-assign, replace it with _
>    (progn
>      (delete-backward-char assign-len)
>      (insert "_"))
>  (delete-horizontal-space)
>  (insert ess-S-assign)))))
>
>
>
>   On Fri, Jul 8, 2011 at 6:53 PM, Richard M. Heiberger <rmh@temple.edu>wrote:
>
>>  Just turn it off.
>> C-h k _
>> takes you to the description of ess-smart-underscore.
>> >From there, click on ess-S-assign and then on customize.
>> The "_" is hard-wired in the defun, so reversing it would be a programming
>> nuisance.
>>
>> Rich
>>
>>
>> On Fri, Jul 8, 2011 at 7:36 PM, Pierre Kleiber <pkleiber.hi@gmail.com
>> >wrote:
>>
>> > I am working in an environment where many folks use "_" in variable and
>> > function names, and I think if would be lots less trouble to have a
>> single
>> > underline generate "_" and two consecutive underlines generate " <- ".
>> Can
>> > anyone suggest a way to reverse the action of "_" and "__"?
>> >
>> > Thanks, Pierre
>> > --
>> >
>> ------------------------------**------------------------------**---------
>> > Pierre Kleiber, Ph.D                  Email: pierre.kleiber@noaa.gov
>> > Pacific Island Fisheries Science Center        Tel. wk: 808 983-5399
>> > NOAA Fisheries                                      hm: 808 737-7544
>> > 2570 Dole St., Honolulu, HI 96822-2396
>> >
>> ------------------------------**------------------------------**---------
>> > "♫ It's a long long way from Amphioxus, but we all come from there ♫"
>> >                                       --- Philip H. Pope
>> >
>> > ______________________________**________________
>> > ESS-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/**listinfo/ess-help<
>> https://stat.ethz.ch/mailman/listinfo/ess-help>
>> >
>>
>>        [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>>
>> ESS-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/ess-help
>>
>>
>

	[[alternative HTML version deleted]]

