0

How to efficiently program in Emacs ESS-mode the key

"<"     "[less than]"

to

"<- "   "[less than][dash][space]"   

Just like the MacOS version of R utilizes.

PascalVKooten
  • 20,643
  • 17
  • 103
  • 160

2 Answers2

2

Looks like there is an existing function for it in the file ess-s-l.el. It would appear that you can use the variable ess-S-assign-key for this:

;; This is by Seth Falcon, modeled after ess-toggle-underscore (see below).
(defun ess-toggle-S-assign-key (force)
  "Possibly bind the key in `ess-S-assign-key' to inserting `ess-S-assign'.
If `ess-S-assign-key' is \"_\", simply use \\[ess-toggle-underscore].
Otherwise, unless the prefix argument FORCE is set,
toggle between the new and the previous assignment."
  (interactive "P")
  (require 'ess-mode)
  (require 'ess-inf)
  (let ((current-action (lookup-key ess-mode-map ess-S-assign-key))
        (insert-S-assign (lambda() (interactive)
                           (delete-horizontal-space) (insert ess-S-assign))))
    (if (and (stringp ess-S-assign-key)
             (string= ess-S-assign-key "_"))
        (ess-toggle-underscore force)
      ;; else "do things here"
      (let* ((current-is-S-assign (eq current-action insert-S-assign))
             (new-action (if force insert-S-assign
                           ;; else "not force" (default):
                           (if (or current-is-S-assign
                                   (eq ess-S-assign-key-last insert-S-assign))
                               ess-S-assign-key-last
                             insert-S-assign))))
        (message "[ess-toggle-S-assign-key:] current: '%s', new: '%s'"
                 current-action new-action)
        (define-key ess-mode-map          ess-S-assign-key new-action)
        (define-key inferior-ess-mode-map ess-S-assign-key new-action)
        (if (not (and force current-is-S-assign))
            (setq ess-S-assign-key-last current-action))))))
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
1

Perhaps this is ESS version dependent.

In my version of ESS (12.03), it seems that you can bind ">" to 'ess-insert-S-assign to get what you like.

Look at the ess- commands available to you (M-x ess-<TAB><TAB> and search in the *Completions* buffer that just popped up for assign) to see which command will be the likely culprit that you should bind to ">".

If that does not work for you -- perhaps you might need to upgrade.

Steve Lianoglou
  • 7,183
  • 2
  • 25
  • 21