ESS/SAS key bindings.

Thomas Gerds gerds at paracelsus.fdm.uni-freiburg.de
Fri Sep 27 12:46:28 CEST 2002


Bo Peng <bpeng at stat.rice.edu> writes:

> The idea ways (to me) to use ESS/SAS mode would be:
> 
> In batch mode:
> 
> 1. open emacs
> 2. F3, run, F4 go back to program window etc. 
>   Problem: with ess-sas-local-unix-keys, I can not
>   use F4 to go from sh or log window to the program window.
>   This only works for ess-sas-global-unix-keys.
> 
> In interactive mode:
> 
> 1. open emacs
> 2. M-x SAS
> 3. Since ESS know that I am in interactive mode, I would like to use
>   F3 to submit the buffer, F4, F5, F6 switch between program, SAS.lst, 
>   SAS.log window. 
>   Problems: 
>     a) No easy way to switch between windows. (F3, F4 will cause
>        confusion now.)
>     b) Log and lst window do not automatically go to the 
>        beginning of the newest log/output.
>     c) Key bindings for ess-mode-map does not work for sas-mode. 
>        I have to use sas-mode-local-map instead.
> 
> Mixture of batch and interactive mode: Very confusing.
> 
> 
> In general, I would like to customize ESS/SAS with:
> 
> 1. set ess-sas-global-unix-keys when I open a SAS file. I could
>    not find a sas-mode-hook to do this.
> 
> 2. In batch mode, map F4, F5, F6 keys for shell, output and list window
>    so that I can switch between windows easily. (This is less intrusive
>    than ess-sas-global-unix-keys.)
> 
> 3. In interactive mode, map F4, F5, F6 to switch between SAS.lst,
>    SAS.log and the program window.
> 
> 
> Since I am new to ESS/SAS, my wishes might not be appropriate. Any
> suggestion is welcome.

in (x)emacs (buffer) local key bindings are best set in the
corresponding mode hook:

you could define (in your .emacs/init.el) after (require 'ess):

(defun my-ess-mode ()
  (interactive)
  (cond ((string= "R" ess-dialect)
	 (message "my-r-mode")
	 ;; customization for ESS[R] here
	 (define-key ess-mode-map 'f8 'push-window-configuration))
	((string= "SAS" ess-dialect)
	 (message "my-SAS-mode")
	 ;; customization for ESS[SAS] here
	 ;; the following is the body of ess-sas-global-unix-keys (modified)
	 (define-key sas-mode-local-map (quote [f2]) 'ess-revert-wisely)
	 (define-key sas-mode-local-map (quote [f3]) 'ess-sas-submit)
	 (define-key sas-mode-local-map [(control f3)] 'ess-sas-submit-region)
	 (define-key sas-mode-local-map (quote [f4]) 'ess-sas-goto-sas)
	 (define-key sas-mode-local-map (quote [f5]) 'ess-sas-goto-log)
	 (define-key sas-mode-local-map [(control f5)] 'ess-sas-append-log)
	 (define-key sas-mode-local-map (quote [f6]) 'ess-sas-goto-lst)
	 (define-key sas-mode-local-map [(control f6)] 'ess-sas-append-lst)
	 (define-key sas-mode-local-map (quote [f7]) 'ess-sas-goto-file-1)
	 (define-key sas-mode-local-map (quote [f8]) 'shell)
	 (define-key sas-mode-local-map (quote [f9]) 'ess-sas-data-view)
	 (define-key sas-mode-local-map (quote [f10]) 'ess-sas-toggle-sas-log-mode)
	 (define-key sas-mode-local-map (quote [f11]) 'ess-sas-goto-file-2)
	 (define-key sas-mode-local-map (quote [f12]) 'ess-sas-graph-view)
	 (if (and ess-sas-edit-keys-toggle
		  (equal emacs-major-version 19) (equal emacs-minor-version 28))
	     (define-key sas-mode-local-map [C-tab] 'ess-sas-backward-delete-tab)
					;else
	   (define-key sas-mode-local-map [(control tab)] 'ess-sas-backward-delete-tab))
	 (define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path))
	((string= "STATA" ess-dialect)
	 ;; customization for ESS[STA] here
	 )))

and then hook this into the appropriate place:

(add-hook 'ess-mode-hook 'my-ess-mode)       

now if you want different keys for SAS interactive mode then probably 
the following helps:

(add-hook 'ess-post-run-hook (lambda ()
          (define-key sas-mode-local-map (quote [f3]) 'ess-eval-region)))


for defining keys local keys also for SAS log and SAS lst the easiest
thing would be to make a local copy of the functions 

(defun SAS-log-mode ()
  "`ess-transcript-mode' for SAS."
  (interactive)
  (SAS-mode)
  (ess-transcript-minor-mode 1)
  (define-key 'f4 'ess-sas-goto-sas)
  (toggle-read-only t)) ;; to protect the buffer.

(defun SAS-listing-mode()
  "Fundamental mode with `ess-listing-minor-mode' and read-only."
  (interactive)
  (fundamental-mode)
  (ess-listing-minor-mode t)
  (use-local-map sas-mode-local-map)
  (define-key 'f4 'ess-sas-goto-sas)
  (toggle-read-only t)) ;; to protect the buffer.

extended with your key-bindings ... 

hope this helps a bit.

cheers,
tomy



-- 
no signature
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
ess-help mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: ess-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the ESS-help mailing list