[ESS] Help setting key binding for ess

Seth Falcon sethfalcon at gmail.com
Tue Mar 21 15:00:59 CET 2006


Sorry, should have sent it inline...

Index: essl-s.el
===================================================================
--- essl-s.el	(revision 3535)
+++ essl-s.el	(working copy)
@@ -246,6 +246,9 @@
   (if (file-exists-p outline-file)
       (setq ess-function-outline-file outline-file)))
 
+(defvar ess-S-assign-key "_"
+  "This key will be mapped to insert ess-S-assign '<-'")
+
  ; Function Definitions
 
 (defun S-comment-indent ()
@@ -591,6 +594,27 @@
 		     "\\1\n}" 'fix nil verbose)
     ))
 
+(defun ess-insert-S-assign ()
+  (interactive)
+  (insert ess-S-assign))
+
+(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)))
+    (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 'ess-insert-S-assign)
+      (define-key inferior-ess-mode-map ess-S-assign-key 
+        'ess-insert-S-assign))))
+
 (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




More information about the ESS-help mailing list