[ESS] Help setting key binding for ess

Martin Maechler maechler at stat.math.ethz.ch
Tue Mar 21 18:06:52 CET 2006


>>>>> "Seth" == Seth Falcon <sethfalcon at gmail.com>
>>>>>     on Tue, 21 Mar 2006 05:33:25 -0800 writes:

    Seth> "A.J. Rossini" <blindglobe at gmail.com> writes:
    >> We really ought to use a defvar for this setting, so apologies,
    >> Seth.

    Seth> Here is a patch that creates a variable ess-S-assign-key that the user
    Seth> can use to specify a key that should get mapped to '<-'.

    Seth> It doesn't use ess-smart-underscore, because that stops making sense
    Seth> if you haven't mapped '_'.

    Seth> For example, to have C-= insert '<-', you can put the following in
    Seth> .emacs:

    Seth> (setq ess-S-assign-key [?\C-=])
    Seth> (ess-toggle-S-assign-key t)

quite nice;  thank you, Seth!

However, the reversion (revert to previous state with smart
underscore) does not work, contrary to what the function name
suggests.

I've applied your patch and improved it slightly 
 (- in doc string: `..', not `...`
  - use local function instead of global ess-insert-S-assign ) :

to 

(defun ess-toggle-S-assign-key (force)
  "Set the key defined in `ess-S-assign-key'"
  (interactive "P")
  (require 'ess-mode)
  (require 'ess-inf)
  (let ((uscore (lookup-key ess-mode-map ess-S-assign-key))
	(insert-S-assign #'(lambda() (interactive) (insert ess-S-assign))))
    (if (and uscore
	     ;; (stringp uscore) (string= uscore ess-S-assign)
	     (not force))
	(progn
	  (define-key ess-mode-map	    ess-S-assign-key nil)
	  (define-key inferior-ess-mode-map ess-S-assign-key nil))
      ;; else : "force" or uscore is "nil", i.e. default
      (define-key ess-mode-map	        ess-S-assign-key insert-S-assign)
      (define-key inferior-ess-mode-map ess-S-assign-key insert-S-assign))))


-- but I think one would really want the change such that a
second call to (ess-toggle-S-assign-key .) 
would revert to smart underscore.

Martin




More information about the ESS-help mailing list