1 ;;; essd-sas.el --- SAS customization
3 ;; Copyright (C) 1997--2001 Richard M. Heiberger and A. J. Rossini
4 ;; Copyright (C) 2002--2004 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Author: Richard M. Heiberger <rmh@astro.ocis.temple.edu>
8 ;; Created: 20 Aug 1997
9 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
11 ;; Keywords: start up, configuration.
13 ;; This file is part of ESS.
15 ;; This file is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; This file is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to
27 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 ;; This file defines all the SAS customizations for ESS behaviors. See
31 ;; essl-sas and essa-sas for the underlying general modifications.
36 (ess-message "[essd-sas:] require 'comint & 'shell ...")
41 ;;(ess-message "[essd-sas:] require 'essa-sas ...")
43 (ess-message "[essd-sas:] require 'essl-sas ...")
45 (ess-message "[essd-sas:] (autoload ..) (def** ..) ...")
48 (autoload 'inferior-ess
"ess-inf" no-doc t
)
49 (autoload 'ess-mode
"ess-mode" no-doc t
)
50 (autoload 'ess-proc-name
"ess-inf" no-doc nil
)
52 (defvar inferior-SAS-args
"-stdio -linesize 80 -noovp -nosyntaxcheck"
53 "*Arguments to use for starting SAS.")
55 (defvar inferior-SAS-args-temp nil
56 "Hack variable, needed for args preprocessing.
57 Better logic needed! (see 2 uses, in this file).")
61 (defun ess-SAS-pre-run-hook (temp-ess-dialect)
62 "Set up log and list files for interactive SAS."
64 (let* ((ess-shell-buffer-name-flag (get-buffer "*shell*"))
67 ;; ess-local-process-name is defined after this function.
68 ;; it needs to be defined prior to this function.
69 (tmp-procname (let ((ntry 0)
71 ;; find a non-existent process
75 (get-process (ess-proc-name
78 (ess-proc-name ntry temp-ess-dialect
)))
79 ;; Following was tmp-local-process-name. Stolen from inferior-ess
80 (ess-sas-lst-bufname (concat "*" tmp-procname
".lst*"))
81 (ess-sas-log-bufname (concat "*" tmp-procname
".log*"))
82 (explicit-shell-file-name "/bin/sh")
83 inferior-SAS-redirect-args
87 (ess-write-to-dribble-buffer
88 (format "(ess-SAS-pre-run-hook 1): ess-lang=%s, ess-dialect=%s, temp-dialect=%s, buf=%s \n"
93 ;; If someone is running a *shell* buffer, rename it to avoid
94 ;; inadvertent nuking.
95 (if ess-shell-buffer-name-flag
97 (set-buffer "*shell*")
98 (setq ess-shell-buffer-name
99 (rename-buffer "*ess-shell-regular*" t
))))
101 ;; Construct the LST buffer for output
102 (if (get-buffer ess-sas-lst-bufname
)
105 (accept-process-output (get-buffer-process (current-buffer)))
106 (sleep-for 2) ; need to wait, else working too fast!
107 (setq ess-sas-lst
(ess-insert-accept "tty"))
110 (ess-listing-minor-mode t
)
111 (rename-buffer ess-sas-lst-bufname t
))
113 ;; Construct the LOG buffer for output
114 (if (get-buffer ess-sas-log-bufname
)
117 (accept-process-output (get-buffer-process (current-buffer)))
118 (sleep-for 2) ; need to wait, else working too fast!
119 (setq ess-sas-log
(ess-insert-accept "tty"))
122 (ess-transcript-minor-mode t
)
123 (rename-buffer ess-sas-log-bufname t
))
125 (setq inferior-SAS-redirect-args
(concat " "
130 inferior-SAS-args-temp
(concat inferior-SAS-redirect-args
133 ;; Restore the *shell* buffer
134 (if ess-shell-buffer-name-flag
136 (set-buffer ess-shell-buffer-name
)
137 (rename-buffer "*shell*")))
139 (delete-other-windows)
140 (split-window-vertically)
141 (split-window-vertically)
142 (switch-to-buffer (nth 2 (buffer-list)))
144 (switch-to-buffer ess-sas-log-bufname
)
145 (split-window-vertically)
147 (switch-to-buffer ess-sas-lst-bufname
)
151 (setq inferior-SAS-program-name
152 (concat ess-etc-directory
"ess-sas-sh-command"))
153 (setq inferior-ess-program inferior-SAS-program-name
)))
155 (defun ess-insert-accept (command)
156 "Submit command to process, get next line."
158 (goto-char (point-max))
161 (accept-process-output (get-buffer-process (current-buffer)))
164 (ess-tty-name (progn (end-of-line) (buffer-substring beg
(point)))))
165 (goto-char (point-max))
169 (defvar SAS-customize-alist
170 '((ess-local-customize-alist .
'SAS-customize-alist
)
171 (ess-language .
"SAS")
172 (ess-dialect .
"SAS")
173 (ess-mode-editing-alist . SAS-editing-alist
) ; from essl-sas.el
174 (ess-mode-syntax-table . SAS-syntax-table
)
175 (inferior-ess-program . inferior-SAS-program-name
)
176 (ess-help-sec-regex .
"^[A-Z. ---]+:$")
177 (ess-help-sec-keys-alist .
" ")
178 (ess-object-name-db-file .
"ess-sas-namedb.el")
179 (inferior-ess-objects-command .
"objects(%d)");;FIXME
180 (inferior-ess-help-command .
"help(\"%s\",pager=\"cat\",window=F)\n");;FIXME
181 (inferior-ess-exit-command .
"endsas;\n")
182 (ess-loop-timeout .
500000 )
183 (inferior-ess-primary-prompt .
"^")
184 (inferior-ess-secondary-prompt .
"^")
185 (comint-use-prompt-regexp-instead-of-fields . t
) ;; emacs 21 and up
186 (inferior-ess-start-file . nil
) ;"~/.ess-SAS")
187 (inferior-ess-start-args . inferior-SAS-args-temp
)
188 (inferior-ess-font-lock-keywords . SAS-mode-font-lock-keywords
)
189 ;; (ess-pre-run-hook . 'ess-SAS-pre-run-hook)
190 (ess-local-process-name . nil
))
191 "Variables to customize for SAS")
193 ;;; The functions of interest (mode, inferior mode)
195 (defvar sas-mode-local-map nil
"contains modified local keymap for SAS")
197 (defun SAS-mode (&optional proc-name
)
198 "Major mode for editing SAS source. See ess-mode for more help."
200 (setq ess-customize-alist SAS-customize-alist
)
201 (ess-mode SAS-customize-alist proc-name
)
203 ;; Local map settings, AFTER initialization (only if not yet defined)
204 (if sas-mode-local-map
206 (setq sas-mode-local-map
(copy-keymap (current-local-map)))
207 (ess-sas-edit-keys-set ess-sas-edit-keys-toggle
)
208 (if ess-sas-local-unix-keys
(ess-sas-local-unix-keys))
209 (if ess-sas-local-pc-keys
(ess-sas-local-pc-keys))
210 (if ess-sas-global-unix-keys
(ess-sas-global-unix-keys))
211 (if ess-sas-global-pc-keys
(ess-sas-global-pc-keys)))
212 (define-key sas-mode-local-map
"\C-ci" 'ess-eval-line-and-step-invisibly
)
213 (define-key sas-mode-local-map
";" 'ess-electric-run-semicolon
)
216 ; interactive and batch commands share sas-mode-local-map,
217 ; but the associated commands are very different
218 ; what would be better is two maps like
219 ; sas-batch-mode-local-map and sas-interactive-mode-local-map
220 ; or smart function definitions that would do the appropriate
221 ; thing for either batch or interactive sessions
222 ; however, neither of these solutions are planned
223 ; therefore, no key definitions can be shared between
224 ; batch and interactive at this time, hence the lines that
225 ; are commented below: uncomment at your own risk
226 ; (define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
227 ; (define-key sas-mode-local-map "\C-c\C-b" 'ess-sas-submit)
228 ; (define-key sas-mode-local-map "\C-c\C-r" 'ess-sas-submit-region)
229 ; (define-key sas-mode-local-map "\C-c\C-x" 'ess-sas-goto-log)
230 ; (define-key sas-mode-local-map "\C-c\C-y" 'ess-sas-goto-lst)
232 (use-local-map sas-mode-local-map
))
235 (defun ess-electric-run-semicolon (arg)
236 "Insert character. If the line contains \"run;\" and nothing else then indent line."
238 (if ess-sas-edit-keys-toggle
(insert ";") (let (insertpos)
242 (skip-chars-backward " \t")
244 (and (looking-at "run")
246 (skip-chars-backward " \t")
249 (insert last-command-char
)
252 (if insertpos
(goto-char (1+ insertpos
)))
256 (goto-char insertpos
)
257 (self-insert-command (prefix-numeric-value arg
)))
258 (self-insert-command (prefix-numeric-value arg
))))))
261 "Call 'SAS', from SAS Institute."
263 (setq-default ess-customize-alist SAS-customize-alist
)
264 (let* ((temp-dialect "SAS")) ;(cdr (rassoc ess-dialect SAS-customize-alist))))
265 (ess-write-to-dribble-buffer
266 (format "(SAS): ess-dial=%s, temp-dial=%s\n"
269 (ess-SAS-pre-run-hook temp-dialect
)
273 (use-local-map sas-mode-local-map
))))
276 (defun ess-multi-frame-SAS ()
277 "Put running SAS buffers into separate frames.
278 Load this function M-x load-file essx-sas.el RET.
279 Then find-file myfile.sas. If myfile.sas is already in a buffer, kill-buffer
280 it and then find-file it again.
281 Place the cursor in a myfile.sas buffer. Run SAS with M-x SAS,
282 Return the cursor to the myfile.sas buffer,
283 then enter C-c C-w to put *SAS* *SAS.log* *SAS.lst* buffers into
286 (delete-other-windows)
290 (set-buffer "*SAS.log*")
292 (set-buffer "*SAS.lst*")
296 (define-key ess-mode-map
"\C-c\C-w" 'ess-multi-frame-SAS
)
302 \f ; Local variables section
304 ;;; This file is automatically placed in Outline minor mode.
305 ;;; The file is structured as follows:
308 ;;; Subsections: ;;;*;;;
309 ;;; Components: defuns, defvars, defconsts
310 ;;; Random code beginning with a ;;;;* comment
314 ;;; outline-minor-mode: nil
315 ;;; mode: outline-minor
316 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
319 ;;; essd-sas.el ends here