setting ess-style now works from *customized* ess-default-style
[ess.git] / lisp / essa-sas.el
blob7ad90474c80054123d1523ae7d11eb81382e7e11
1 ;;; essa-sas.el -- clean-room implementation of many SAS-mode features
3 ;; Copyright (C) 1997--2005 A.J. Rossini, Rich M. Heiberger, Martin
4 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6 ;; Original Author: Rodney A. Sparapani <rsparapa@mcw.edu>
7 ;; Maintainer: ESS-core@stat.math.ethz.ch
8 ;; Created: 17 November 1999
9 ;; Keywords: SAS
11 ;; This file is part of ESS
13 ;; This file is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; This file is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;; In short: you may use this code any way you like, as long as you
28 ;; don't charge money for it, remove this notice, or hold anyone liable
29 ;; for its results.
31 ;; Code:
33 ;;; Table of Contents
34 ;;; Section 1: Variable Definitions
35 ;;; Section 2: Function Definitions
36 ;;; Section 3: Key Definitions
38 ;;; Section 1: Variable Definitions
40 (defvar ess-sas-file-path "."
41 "Full path-name of the sas file to perform operations on.")
43 (defcustom ess-sas-data-view-libname " "
44 "*SAS code to define a library for `ess-sas-data-view-fsview'
45 or `ess-sas-data-view-insight'."
46 :group 'ess-sas
47 :type 'string)
49 (defcustom ess-sas-data-view-submit-options
50 (if ess-microsoft-p "-noenhancededitor -nosysin -log NUL:"
51 "-nodms -nosysin -log /dev/null -terminal")
52 "*The command-line options necessary for your OS with respect to
53 `ess-sas-data-view-fsview' and `ess-sas-data-view-insight'."
54 :group 'ess-sas
55 :type 'string)
57 (defcustom ess-sas-data-view-fsview-command "; proc fsview data="
58 "*SAS code to open a SAS dataset with `ess-sas-data-view-fsview'."
59 :group 'ess-sas
60 :type 'string)
62 (defcustom ess-sas-data-view-fsview-statement " "
63 "*SAS code to perform a PROC FSVIEW statement with `ess-sas-data-view-fsview'."
64 :group 'ess-sas
65 :type 'string)
67 (make-variable-buffer-local 'ess-sas-data-view-fsview-statement)
69 (defcustom ess-sas-data-view-insight-command "; proc insight data="
70 "*SAS code to open a SAS dataset with `ess-sas-data-view-insight'."
71 :group 'ess-sas
72 :type 'string)
74 (defcustom ess-sas-data-view-insight-statement " "
75 "*SAS code to perform a PROC FSVIEW statement with `ess-sas-data-view-insight'."
76 :group 'ess-sas
77 :type 'string)
79 (make-variable-buffer-local 'ess-sas-data-view-insight-statement)
81 (defcustom ess-sas-graph-view-suffix-regexp
82 "[.]\\([eE]?[pP][sS]\\|[pP][dD][fF]\\|[gG][iI][fF]\\|[jJ][pP][eE]?[gG]\\|[tT][iI][fF][fF]?\\)"
83 "*GSASFILE suffix regexp."
84 :group 'ess-sas
85 :type 'string)
87 (defcustom ess-sas-graph-view-viewer-alist
88 ;;creates something like
89 ;;'(("[pP][dD][fF]" . "/usr/local/bin/acroread") ("[eE]?[pP][sS]" . "/usr/local/bin/gv")))
90 (let ((ess-tmp-alist nil)
91 (ess-tmp-file nil))
93 (setq ess-tmp-file (executable-find (if ess-microsoft-p "gsview32" "gsview")))
95 (if (not ess-tmp-file) (setq ess-tmp-file (executable-find "gv")))
97 (if (not ess-tmp-file) (setq ess-tmp-file (executable-find "ghostview")))
99 (if ess-tmp-file
100 (setq ess-tmp-alist (list (cons "[eE]?[pP][sS]" ess-tmp-file)
101 (cons "[pP][dD][fF]" ess-tmp-file)))
103 (setq ess-tmp-file (executable-find (if ess-microsoft-p "acrord32" "acroread")))
105 (if ess-tmp-file
106 (setq ess-tmp-alist (cons "[pP][dD][fF]" ess-tmp-file)))))
108 "*Associate file name extensions with graphics image file viewers."
109 :group 'ess-sas
110 :type 'string)
112 ;;(defcustom ess-sas-smart-back-tab nil
113 ;; "*Set to t to make C-TAB insert an end/%end; statement to close a block."
114 ;; :group 'ess-sas
117 (defcustom ess-sas-log-max 0
118 "*If >0 and .log file exceeds this many bytes, just \"refresh\" this many bytes."
119 :group 'ess-sas
120 :type 'integer)
122 (defcustom ess-sas-shell-buffer "*shell*"
123 "*Name that you want to use for the shell buffer; buffer-local."
124 :group 'ess-sas
125 :type 'string)
127 (make-variable-buffer-local 'ess-sas-shell-buffer)
129 (defcustom ess-sas-shell-buffer-remote-host nil
130 "*Remote host that you want to open a shell on."
131 :group 'ess-sas
132 :type '(choice (const nil) string))
134 (make-variable-buffer-local 'ess-sas-shell-buffer-remote-host)
136 (defcustom ess-sas-shell-buffer-remote-init "ssh"
137 "*Command to open a shell on a remote host."
138 :group 'ess-sas
139 :type 'string)
141 (make-variable-buffer-local 'ess-sas-shell-buffer-remote-init)
143 (defcustom ess-sas-submit-mac-virtual-pc nil
144 "*Non-nil means that you want to run Windows SAS in a
145 Virtual PC emulator on your Mac; buffer-local."
146 :group 'ess-sas
147 :type 'boolean)
149 (make-variable-buffer-local 'ess-sas-submit-mac-virtual-pc)
151 (defcustom ess-sas-submit-command sas-program
152 "*Command to invoke SAS in batch; buffer-local."
153 :group 'ess-sas
154 :type 'string)
156 (make-variable-buffer-local 'ess-sas-submit-command)
158 (defcustom ess-sas-submit-command-options "-rsasuser"
159 "*Options to pass to SAS in batch; buffer-local."
160 :group 'ess-sas
161 :type 'string)
163 (make-variable-buffer-local 'ess-sas-submit-command-options)
165 (defvar ess-sas-submit-method
166 (if ess-microsoft-p
167 (if (w32-shell-dos-semantics) 'ms-dos 'sh)
168 (if (or (equal system-type 'Apple-Macintosh)
169 (and ess-sas-submit-mac-virtual-pc (equal system-type 'darwin)))
170 'apple-script 'sh))
171 "Method used by `ess-sas-submit'.
172 The default is based on the value of the emacs variable `system-type'
173 and, on Windows, the function `w32-shell-dos-semantics'.
174 'sh if *shell* runs sh, ksh, csh, tcsh or bash
175 'ms-dos if *shell* follows MS-DOS semantics
176 'apple-script *shell* unavailable in Mac Classic, use AppleScript,
177 also for Windows SAS in Virtual PC on Mac OS X
179 Unix users will get 'sh by default.
181 Windows users running bash in *shell* will get 'sh by default.
183 Windows users running MS-DOS in *shell* will get 'ms-dos by default.
185 Users accessing a remote machine with `telnet', `rlogin', `ssh', etc.,
186 should set this variable to 'sh regardless of their local shell
187 (since their remote shell is 'sh).")
189 (make-variable-buffer-local 'ess-sas-submit-method)
191 (defcustom ess-sas-graph-view-viewer-default
192 (if ess-microsoft-p "kodakimg"
193 (if (equal ess-sas-submit-method 'sh) "sdtimage"))
194 "*Default graphics image file viewer."
195 :group 'ess-sas
196 :type 'string)
198 (defcustom ess-sas-submit-post-command
199 (if (equal ess-sas-submit-method 'sh) "&"
200 (if ess-microsoft-p "-icon"))
201 "*Command-line statement to post-modify SAS invocation"
202 :group 'ess-sas
203 :type 'string)
205 (defcustom ess-sas-submit-pre-command ;;"nohup"
206 (if (equal ess-sas-submit-method 'sh)
207 ;; nice is tricky, higher numbers give you lower priorities
208 ;; if you are using csh/tcsh, the default priority is 4
209 ;; if you are using most other shells, the default priority is 10,
210 ;; and some implementations are higher, i.e. zsh unless you
211 ;; specify "setopt no_bg_nice" in your ~/.zshrc
212 ;; therefore, on the same machine, you can run at a higher or
213 ;; lower priority by changing shells, although, the command
214 ;; line is the same!
215 ;; the following code should give you a priority of 10 regardless
216 ;; of which shell is in use, but it will default to the old
217 ;; behavior if csh or variant is not recognized
218 ;; this should avoid the necessity of each user needing to set this
219 ;; variable correctly based on the shell that they use and provide
220 ;; an environment where all shells are treated equally
222 (let* ((temp-shell (getenv "SHELL"))
223 ;; AJR: old CYGWIN versions return nil for (getenv
224 ;; "SHELL"), so we need to deal with it 'cause I have to
225 (temp-char (if temp-shell
226 (string-match "/" temp-shell)
227 nil)))
228 (while temp-char
229 (setq temp-shell (substring temp-shell (+ 1 temp-char)))
230 (setq temp-char (string-match "/" temp-shell)))
232 (cond ((or (equal temp-shell "csh") (equal temp-shell "tcsh"))
233 "nohup nice +6")
234 (t "nohup nice")))
235 (if ess-microsoft-p "start"))
236 "*Command-line statement to precede SAS invocation, e.g. start or nohup"
237 :group 'ess-sas
238 :type 'string)
240 (defcustom ess-sas-suffix-1 "txt"
241 "*The first suffix to associate with SAS."
242 :group 'ess-sas
243 :type 'string)
245 (defcustom ess-sas-suffix-2 "csv"
246 "*The second suffix to associate with SAS."
247 :group 'ess-sas
248 :type 'string)
250 (defcustom ess-sas-suffix-regexp
251 (concat "[.]\\([sS][aA][sS]\\|[lL][oO][gG]\\|[lL][sS][tT]"
252 (if ess-sas-suffix-1 (concat
253 "\\|" (downcase ess-sas-suffix-1) "\\|" (upcase ess-sas-suffix-1)))
254 (if ess-sas-suffix-2 (concat
255 "\\|" (downcase ess-sas-suffix-2) "\\|" (upcase ess-sas-suffix-2)))
256 "\\)")
257 "*Regular expression for SAS suffixes."
258 :group 'ess-sas
259 :type 'string)
261 (defcustom ess-sleep-for (if ess-microsoft-p 5 0)
262 "*`ess-sas-submit-sh' may need to pause before sending output
263 to the shell on Windows when `ess-sas-submit-method' is 'sh."
264 :group 'ess-sas
265 :type 'number)
267 (defcustom ess-sas-tab-stop-list
268 '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120)
269 "List of tab stop positions used by `tab-to-tab-stop' in ESS[SAS]."
270 :group 'ess-sas)
272 (defcustom ess-sas-temp-root "-temp"
273 "*Appended to root name of the temporary .sas file for `ess-sas-submit-region'."
274 :group 'ess-sas
275 :type 'string)
277 (defvar ess-sas-versions '("sas")
278 "List of partial strings for versions of SAS to access within ESS.
279 Each string specifies the start of a filename. If a filename
280 beginning with one of these strings is found on `exec-path', a M-x
281 command for that version of SAS is made available. For example, if the
282 file \"sas8\" is found and this variable includes the string
283 \"sas\", a function called `M-x SAS8' will be available to run that
284 version of SAS.
285 If duplicate versions of the same program are found (which happens if
286 the same path is listed on `exec-path' more than once), they are
287 ignored by calling `ess-uniq-list'.
288 If you set this variable, you need to restart Emacs (and set this variable
289 before ess-site is loaded) for it to take effect.")
292 ;;; Section 2: Function Definitions
295 (defun ess-ebcdic-to-ascii-search-and-replace ()
296 "*Search and replace EBCDIC text with ASCII equivalents."
297 (interactive)
298 (let ((ess-tmp-dd (executable-find "dd")) (ess-tmp-recode (executable-find "recode"))
299 (ess-tmp-util nil) (ess-tmp-util-args nil))
301 (if ess-tmp-dd (progn
302 (setq ess-tmp-util ess-tmp-dd)
303 (setq ess-tmp-util-args "conv=ascii"))
305 (setq ess-tmp-util ess-tmp-recode)
306 (setq ess-tmp-util-args "EBCDIC..ISO-8859-1"))
308 (if ess-tmp-util
309 (while (search-forward-regexp "[^\f\t\n -~][^\f\t\n -?A-JQ-Yb-jp-y]*[^\f\t\n -~]?" nil t)
310 (call-process-region (match-beginning 0) (match-end 0)
311 ess-tmp-util t (list t nil) t ess-tmp-util-args)))))
313 (defun ess-exit-notify-sh (string)
314 "Detect completion or failure of submitted job and notify the user."
315 (let* ((exit-done "\\[[0-9]+\\]\\ *\\+*\\ *\\(Exit\\|Done\\).*$")
316 (beg (string-match exit-done string)))
317 (if beg
318 (message (substring string beg (match-end 0))))))
322 (defun ess-sas-append-log ()
323 "Append ess-temp.log to the current .log file."
324 (interactive)
325 (ess-sas-goto "log" 'revert)
326 (goto-char (point-max))
327 (insert-file-contents (concat (ess-sas-temp-root) ".log"))
328 (save-buffer))
330 (defun ess-sas-append-lst ()
331 "Append ess-temp.lst to the current .lst file."
332 (interactive)
333 (ess-sas-goto "lst" 'revert)
334 (goto-char (point-max))
335 (insert-file-contents (concat (ess-sas-temp-root) ".lst"))
336 (save-buffer))
338 (defun ess-sas-backward-delete-tab ()
339 "Moves the cursor to the previous tab-stop, deleting any characters
340 on the way."
341 (interactive)
343 (let* (;; point of search
344 ;;(ess-sas-search-point nil)
345 ;; column of search
346 ;;(ess-sas-search-column nil)
347 ;; limit of search
348 ;;(ess-sas-search-limit nil)
349 ;; text to be inserted after a back-tab, if any
350 ;;(ess-sas-end-text "end;")
351 ;; current-column
352 (ess-sas-column (current-column))
353 ;; remainder of current-column and sas-indent-width
354 (ess-sas-remainder (% ess-sas-column sas-indent-width)))
356 (if (not (= ess-sas-column 0))
357 (progn
358 (if (= ess-sas-remainder 0)
359 (setq ess-sas-remainder sas-indent-width))
361 (let ((backward-delete-char-untabify-method 'nil))
362 (backward-delete-char-untabify ess-sas-remainder t)
363 (setq ess-sas-column (- ess-sas-column ess-sas-remainder))
364 (move-to-column ess-sas-column)
365 (setq left-margin ess-sas-column))
369 ;; this feature was far too complicated to perfect
370 ;; (if ess-sas-smart-back-tab (progn
371 ;; (save-excursion
372 ;; (setq ess-sas-search-point
373 ;; (search-backward-regexp "end" nil t))
375 ;; (if (and ess-sas-search-point
376 ;; (search-backward-regexp "%" (+ ess-sas-search-point -1) t))
377 ;; (setq ess-sas-search-point (+ ess-sas-search-point -1))
378 ;; )
380 ;; (if (and ess-sas-search-point
381 ;; (not (equal ess-sas-column (current-column))))
382 ;; (setq ess-sas-search-point nil))
383 ;; )
385 ;; (save-excursion
386 ;; (setq ess-sas-search-point
387 ;; (search-backward-regexp "do\\|select"
388 ;; ess-sas-search-point t))
390 ;; (setq ess-sas-search-column (current-column))
392 ;; (if ess-sas-search-point (progn
393 ;; (save-excursion
394 ;; (search-backward-regexp "^" nil t)
395 ;; (setq ess-sas-search-limit (point))
396 ;; )
398 ;; (if (search-backward-regexp "if.*then\\|else" ess-sas-search-limit t)
399 ;; (setq ess-sas-search-point (point)))
401 ;; (if (search-backward-regexp "%" ess-sas-search-limit t) (progn
402 ;; (setq ess-sas-end-text "%end;")
403 ;; (setq ess-sas-search-point (point))
404 ;; ))
406 ;; (setq ess-sas-search-column (current-column))
408 ;; (if (not (equal ess-sas-column ess-sas-search-column))
409 ;; (setq ess-sas-search-point nil))
410 ;; )))
412 ;; (if ess-sas-search-point (insert ess-sas-end-text))
413 ;; ))
415 (defun ess-sas-cd ()
416 "Change directory, taking into account various issues with respect to
417 `ess-sas-file-path'."
418 ;(interactive)
419 (ess-sas-file-path)
420 (ess-sas-goto-shell t)
421 (if (equal ess-sas-submit-method 'sh)
422 (insert "cd " (car (last (split-string (file-name-directory ess-sas-file-path)
423 "\\([a-zA-Z][a-zA-Z]:\\|]\\)"))))
424 (if (equal ess-sas-submit-method 'ms-dos) (progn
425 (if (string-equal ":" (substring ess-sas-file-path 1 2)) (progn
426 (insert (substring ess-sas-file-path 0 2))
427 (comint-send-input)))
428 (insert "cd \"" (convert-standard-filename
429 (file-name-directory ess-sas-file-path)) "\""))))
430 (comint-send-input))
432 (defun ess-sas-create-local-variables-alist (&optional file-or-buffer)
433 "Create an alist of local variables from file-or-buffer, use the
434 current buffer if nil."
436 (if file-or-buffer (set-buffer (ess-get-file-or-buffer file-or-buffer)))
438 (ess-change-alist 'ess-kermit-remote-directory ess-kermit-remote-directory nil))
440 (defun ess-sas-data-view-fsview (&optional ess-sas-data)
441 "Open a dataset for viewing with PROC FSVIEW."
442 (interactive)
443 (ess-save-and-set-local-variables)
445 (save-excursion (let ((ess-tmp-sas-data nil)
446 (ess-tmp-sas-data-view-fsview-statement ess-sas-data-view-fsview-statement)
447 (ess-search-regexp
448 "[ \t=]\\([a-zA-Z_][a-zA-Z_0-9]*[.][a-zA-Z_][a-zA-Z_0-9]*\\)\\(&.*\\)?[. ,()\t;/]")
449 (ess-search-except
450 "^\\([wW][oO][rR][kK]\\|[fF][iI][rR][sS][tT]\\|[lL][aA][sS][tT]\\)[.]"))
452 (if ess-sas-data nil (save-match-data
453 (search-backward-regexp "[ \t=]" nil t)
455 (save-excursion
456 (setq ess-tmp-sas-data
457 (ess-search-except ess-search-regexp ess-search-except)))
459 (if (not ess-tmp-sas-data)
460 (setq ess-tmp-sas-data
461 (ess-search-except ess-search-regexp ess-search-except t)))
463 (setq ess-sas-data (read-string "Permanent SAS Dataset: " ess-tmp-sas-data))
465 (ess-sas-goto-shell t)
466 (ess-sas-cd)
468 (insert (concat ess-sas-submit-pre-command " " ess-sas-submit-command
469 " -initstmt \"" ess-sas-data-view-libname ess-sas-data-view-fsview-command
470 ess-sas-data ";" ess-tmp-sas-data-view-fsview-statement "; run;\" "
471 ess-sas-submit-command-options " "
472 ess-sas-data-view-submit-options " " ess-sas-submit-post-command))
473 (comint-send-input)
474 )))))
476 (defun ess-sas-data-view-insight (&optional ess-sas-data)
477 "Open a dataset for viewing with PROC INSIGHT."
478 (interactive)
479 (ess-save-and-set-local-variables)
481 (save-excursion (let ((ess-tmp-sas-data nil)
482 (ess-tmp-sas-data-view-insight-statement ess-sas-data-view-insight-statement)
483 (ess-search-regexp
484 "[ \t=]\\([a-zA-Z_][a-zA-Z_0-9]*[.][a-zA-Z_][a-zA-Z_0-9]*\\)\\(&.*\\)?[. ,()\t;]")
485 (ess-search-except
486 "^\\([wW][oO][rR][kK]\\|[fF][iI][rR][sS][tT]\\|[lL][aA][sS][tT]\\)[.]"))
488 (if ess-sas-data nil (save-match-data
489 (search-backward-regexp "[ \t=]" nil t)
491 (save-excursion
492 (setq ess-tmp-sas-data
493 (ess-search-except ess-search-regexp ess-search-except)))
495 (if (not ess-tmp-sas-data)
496 (setq ess-tmp-sas-data
497 (ess-search-except ess-search-regexp ess-search-except t)))
499 (setq ess-sas-data (read-string "Permanent SAS Dataset: " ess-tmp-sas-data))
501 (ess-sas-goto-shell t)
502 (ess-sas-cd)
504 (insert (concat ess-sas-submit-pre-command " " ess-sas-submit-command
505 " -initstmt \"" ess-sas-data-view-libname ess-sas-data-view-insight-command
506 ess-sas-data ";" ess-tmp-sas-data-view-insight-statement "; run;\" "
507 ess-sas-data-view-submit-options " " ess-sas-submit-post-command))
508 (comint-send-input)
509 )))))
511 (defun ess-sas-graph-view ()
512 "Open a GSASFILE for viewing."
513 (interactive)
514 ; (ess-sas-file-path)
515 (ess-sas-goto-log 'no-error-check)
517 (save-excursion (let (
518 (ess-tmp-length (length ess-sas-graph-view-viewer-alist))
519 (ess-tmp-counter 0)
520 (ess-tmp-graph nil)
521 (ess-tmp-graph-alist nil)
522 (ess-tmp-glyph nil)
523 (ess-tmp-graph-regexp
524 (concat "[ ]RECORDS[ ]WRITTEN[ ]TO[ ]\n?[ ]*\\(\\(\n\\|[^.]\\)*"
525 ess-sas-graph-view-suffix-regexp "\\)")))
526 ; (concat "['\"]\\(.*" ess-sas-graph-suffix-regexp "\\)['\"]")))
528 (save-match-data
529 (search-backward-regexp "[ \t=]" nil t)
531 (save-excursion
532 (setq ess-tmp-graph (ess-search-except ess-tmp-graph-regexp)))
534 (if (not ess-tmp-graph)
535 (setq ess-tmp-graph (ess-search-except ess-tmp-graph-regexp nil t)))
537 (setq ess-tmp-graph (read-string "GSASFILE: "
538 (or ess-tmp-graph ess-sas-file-path)))
540 (if (fboundp 'ess-xemacs-insert-glyph) (progn
541 (if (string-match "[.][gG][iI][fF]" ess-tmp-graph)
542 (setq ess-tmp-glyph 'gif)
543 ;;else
544 (if (string-match "[.][jJ][pP][eE]?[gG]" ess-tmp-graph)
545 (setq ess-tmp-glyph 'jpeg)))))
547 ;;GNU Emacs graphics file image viewing mode loaded?
548 (if (and (boundp 'auto-image-file-mode) auto-image-file-mode
549 (string-match "[.][jJ][pP][eE]?[gG]" ess-tmp-graph))
550 (find-file ess-tmp-graph)
551 ;;else XEmacs graphics file image viewing mode loaded?
552 (if (and (fboundp 'image-mode)
553 (string-match "[.]\\([jJ][pP][eE]?[gG]\\|[gG][iI][fF]\\)"
554 ess-tmp-graph))
555 (find-file ess-tmp-graph)
556 ;;else XEmacs graphics file image viewing primitives loaded?
557 (if ess-tmp-glyph (progn
558 (switch-to-buffer (file-name-nondirectory ess-tmp-graph))
559 (ess-xemacs-insert-glyph
560 (make-glyph (vector ess-tmp-glyph :file ess-tmp-graph))))
562 ;;else use the appropriate graphics file image viewer
563 (while (< ess-tmp-counter ess-tmp-length)
564 (setq ess-tmp-graph-alist
565 (nth ess-tmp-counter ess-sas-graph-view-viewer-alist))
566 (setq ess-tmp-graph-regexp (car ess-tmp-graph-alist))
568 (if (string-match
569 (concat "[.]" ess-tmp-graph-regexp) ess-tmp-graph)
570 (progn
571 (ess-sas-goto-shell t)
572 (insert ess-sas-submit-pre-command " "
573 (cdr ess-tmp-graph-alist) " " ess-tmp-graph
574 (if (equal ess-sas-submit-method 'sh) " &"))
575 (setq ess-tmp-glyph 'alist)
576 (setq ess-tmp-counter ess-tmp-length))
577 ;;else
578 (setq ess-tmp-counter (+ ess-tmp-counter 1))))
580 (if (not ess-tmp-glyph) (progn
581 (ess-sas-goto-shell t)
582 (insert ess-sas-submit-pre-command " "
583 ess-sas-graph-view-viewer-default " " ess-tmp-graph
584 (if (equal ess-sas-submit-method 'sh) " &"))))
586 (comint-send-input))))))))
588 (defun ess-sas-file-path ()
589 "Define `ess-sas-file-path' to be the current buffer depending on suffix."
590 (interactive)
592 (save-match-data (let ((ess-sas-temp-file (expand-file-name (buffer-name))))
593 (if (string-match ess-sas-suffix-regexp ess-sas-temp-file) ;;(progn
594 (setq ess-sas-file-path
595 (nth 0 (split-string ess-sas-temp-file "[<]")))))))
596 ;; (setq ess-directory (file-name-directory ess-sas-file-path)))))))
598 (defun ess-sas-file-path-remote-host ()
599 "Return the remote host, if any, associated with `ess-sas-file-path'."
600 (interactive)
602 (let* ((temp-colon-pos (string-match ":" ess-sas-file-path))
603 (temp-list
604 (if (or (not temp-colon-pos) (> temp-colon-pos 2))
605 (if (equal ess-sas-file-path ".") nil
606 (split-string (file-name-directory ess-sas-file-path)
607 "\\(@\\|:\\|]\\)"))
608 (list ess-sas-file-path)))
609 (temp-list-length (length temp-list)))
610 (if (= temp-list-length 1) (setq temp-list nil)
611 (if (= temp-list-length 2) (setq temp-list (car temp-list))
612 (setq temp-list (nth 1 temp-list))))
614 (if temp-list (setq temp-list
615 (car (last (split-string temp-list "/")))))
616 temp-list))
618 (defun ess-sas-goto (suffix &optional revert no-create)
619 "Find a file associated with a SAS file by suffix and revert if necessary."
620 (let ((ess-temp-regexp (concat ess-sas-suffix-regexp "\\(@.+\\)?")))
621 (save-match-data
622 (if (or (string-match ess-temp-regexp (expand-file-name (buffer-name)))
623 (string-match ess-temp-regexp ess-sas-file-path))
624 (progn
625 (ess-sas-file-path)
626 (let* (
627 (ess-sas-temp-file (replace-match (concat "." suffix) t t
628 ess-sas-file-path))
629 (ess-sas-temp-buff (find-buffer-visiting ess-sas-temp-file))
630 (ess-temp-kermit-remote-directory ess-kermit-remote-directory))
632 (if ess-sas-temp-buff (switch-to-buffer ess-sas-temp-buff)
633 ;; else
634 (if no-create (setq revert nil)
635 (if (file-exists-p ess-sas-temp-file)
636 (find-file ess-sas-temp-file))))
637 ;; else
638 ;; (let* ((ess-sas-buffer-list (buffer-list))
639 ;; (ess-sas-buffer-list-index 0)
640 ;; (ess-sas-buffer-list-file nil)
641 ;; (ess-sas-buffer-list-length (length ess-sas-buffer-list)))
642 ;; (while (< ess-sas-buffer-list-index ess-sas-buffer-list-length)
643 ;; (setq ess-sas-buffer-list-file
644 ;; (buffer-file-name (nth ess-sas-buffer-list-index ess-sas-buffer-list)))
645 ;; (if (and ess-sas-buffer-list-file
646 ;; (string-match (concat "." suffix) ess-sas-buffer-list-file))
647 ;; (switch-to-buffer (nth ess-sas-buffer-list-index ess-sas-buffer-list))
648 ;; (setq ess-sas-buffer-list-index ess-sas-buffer-list-length)
649 ;; )
650 ;; (setq ess-sas-buffer-list-index (+ 1 ess-sas-buffer-list-index))
651 ;; )))
653 (if (and (not no-create)
654 (or (string-equal suffix "log")
655 (string-equal suffix "lst")))
656 (ess-kermit-get (file-name-nondirectory ess-sas-temp-file)
657 ess-temp-kermit-remote-directory))
659 (if revert
660 (if (and (> ess-sas-log-max 0) (string-equal suffix "log")
661 (> (nth 7 (file-attributes ess-sas-temp-file))
662 ess-sas-log-max))
663 (progn
664 (insert-file-contents ess-sas-temp-file nil 0
665 ess-sas-log-max t)
668 (ess-revert-wisely)) nil)))))))
670 ;;(defun ess-sas-file (suffix &optional revert)
671 ;; "Please use `ess-sas-goto' instead."
672 ;; (let* ((tail (downcase (car (split-string
673 ;; (car (last (split-string (buffer-name) "[.]"))) "[<]"))))
674 ;;(if (fboundp 'file-name-extension) (file-name-extension (buffer-name))
675 ;; (substring (buffer-name) -3)))
676 ;; (tail-in-tail-list (member tail (list "sas" "log" "lst"
677 ;; ess-sas-suffix-1 ess-sas-suffix-2)))
678 ;; (root (if tail-in-tail-list (expand-file-name (buffer-name))
679 ;; ess-sas-file-path))
680 ;; (ess-sas-arg (concat (file-name-sans-extension root) "." suffix))
681 ;; (ess-sas-buf (find-buffer-visiting ess-sas-arg)))
682 ;; (if (equal tail suffix) (if revert (ess-revert-wisely))
683 ;; (if (not ess-sas-buf) (find-file ess-sas-arg)
684 ;; (switch-to-buffer ess-sas-buf)
685 ;; (if revert (ess-revert-wisely))))))
688 (defun ess-sas-goto-file-1 ()
689 "Switch to ess-sas-file-1 and revert from disk."
690 (interactive)
691 (ess-sas-goto ess-sas-suffix-1 'revert))
693 (defun ess-sas-goto-file-2 ()
694 "Switch to ess-sas-file-2 and revert from disk."
695 (interactive)
696 (ess-sas-goto ess-sas-suffix-2 'revert))
698 (defun ess-sas-goto-log (&optional ess-tmp-no-error-check)
699 "Switch to the .log file, revert from disk and search for error messages."
700 (interactive)
702 (let ((ess-sas-error (concat
703 "^ERROR [0-9]+-[0-9]+:\\|^ERROR:\\|_ERROR_=1 _N_=\\|_ERROR_=1[ ]?$"
704 "\\|NOTE: MERGE statement has more than one data set with repeats"
705 "\\|NOTE: Variable .* is uninitialized."
706 "\\|NOTE: SAS went to a new line when INPUT statement reached past"
707 "\\|NOTE 485-185: Informat .* was not found"
708 "\\|NOTE: Estimated G matrix is not positive definite."
709 "\\|NOTE: Compressing data set .* increased size by"
710 "\\|NOTE: ERROR DETECTED IN ANNOTATE="
711 "\\|WARNING: Apparent symbolic reference .* not resolved."
712 "\\|WARNING: Length of character variable has already been set."
713 "\\|WARNING: Not all variables in the list "
714 "\\|WARNING: RUN statement ignored due to previous errors."
715 "\\|WARNING: Values exist outside the axis range"
716 "\\|Bus Error In Task\\|Segmentation Violation In Task"))
717 (ess-sas-save-point nil) (ess-sas-pop-mark nil))
719 (if (ess-sas-goto "log" 'revert) (progn
720 (setq ess-sas-save-point (point))
721 (goto-char (point-min)))
722 (setq ess-sas-save-point (point)))
724 (if ess-tmp-no-error-check (goto-char ess-sas-save-point)
725 (if (or (search-forward-regexp ess-sas-error nil t)
726 (and (goto-char (point-min))
727 (search-forward-regexp ess-sas-error nil t)))
728 (if (and (boundp 'zmacs-regions) zmacs-regions)
729 (progn
730 (if ess-sas-pop-mark (pop-mark)
731 (setq ess-sas-pop-mark t))
732 (push-mark (match-beginning 0) t)
733 (zmacs-activate-region)))
734 (goto-char ess-sas-save-point)))))
736 (defun ess-sas-goto-lst ()
737 "Switch to the .lst file and revert from disk."
738 (interactive)
739 (ess-sas-goto "lst" 'revert))
741 (defun ess-sas-goto-sas (&optional revert)
742 "Switch to the .sas file."
743 (interactive)
744 (ess-sas-goto "sas" revert))
746 (defun ess-sas-goto-shell (&optional set-buffer)
747 "Set `ess-sas-file-path' and goto `ess-sas-shell-buffer'. If
748 optional argument is non-nil, then set-buffer rather than switch."
749 (interactive)
750 (ess-sas-file-path)
752 ; The following let* block is an attempt to deal with remote directories.
753 (let* ((temp-shell-buffer-remote-host
754 (or ess-sas-shell-buffer-remote-host (ess-sas-file-path-remote-host)))
755 (temp-shell-buffer-remote-init ess-sas-shell-buffer-remote-init)
756 (temp-shell-buffer
757 (if temp-shell-buffer-remote-host
758 (concat "*" temp-shell-buffer-remote-host "*")
759 ess-sas-shell-buffer))
762 (if (get-buffer temp-shell-buffer)
763 (if set-buffer (set-buffer temp-shell-buffer)
764 (switch-to-buffer temp-shell-buffer))
765 (shell)
766 (rename-buffer temp-shell-buffer)
768 (if temp-shell-buffer-remote-host (progn
769 (insert (concat
770 temp-shell-buffer-remote-init " " temp-shell-buffer-remote-host))
771 (comint-send-input))
774 (if (eq ess-sas-submit-method 'sh)
775 (add-hook 'comint-output-filter-functions 'ess-exit-notify-sh)) ;; 19.28
776 ;; nil t) works for newer emacsen
780 (goto-char (point-max))
781 ; (insert "cd " ess-temp-directory)
782 ; (comint-send-input))
785 (defun ess-sas-interactive ()
786 "And now for something completely different."
787 (interactive)
788 (ess-sas-file-path)
790 (let ((ess-temp-sas-file
791 (nth 0 (split-string
792 (car (last (split-string ess-sas-file-path "\\([a-zA-Z][a-zA-Z]:\\|]\\)"))) "[.]"))))
793 ;; (message "%s" ess-temp-sas-file)
794 (setq ess-sas-shell-buffer "*iESS[SAS]*")
795 (ess-sas-goto-shell)
796 (insert (concat ess-sas-submit-command " " ess-sas-submit-command-options
797 " -altlog " ess-temp-sas-file ".log -altprint "
798 ess-temp-sas-file ".lst -stdio < /dev/tty"))
799 (comint-send-input)
800 (ess-add-ess-process)
801 (ess-sas-goto-sas)
802 (setq ess-sas-submit-method 'iESS)
803 (setq ess-eval-visibly-p nil)
805 ;;(defun ess-sas-interactive ()
806 ;; (interactive)
807 ;; (ess-sas-file-path)
808 ;; (setq ess-sas-submit-method 'iESS)
810 ;; (let ((ess-temp-stderr " ") (ess-temp-stdout " ") (ess-temp-stdin " "))
811 ;; (setq ess-sas-shell-buffer "*LOG*")
812 ;; (ess-sas-goto-shell)
813 ;; (insert "tty")
814 ;; (comint-send-input)
815 ;; (sleep-for ess-sleep-for)
816 ;; (save-excursion (setq ess-temp-stderr (ess-search-except "\\(/dev/[a-z0-9/]+\\)" nil t)))
817 ;; (setq ess-sas-shell-buffer "*OUTPUT*")
818 ;; (ess-sas-goto-shell)
819 ;; (insert "tty")
820 ;; (comint-send-input)
821 ;; (sleep-for ess-sleep-for)
822 ;; (save-excursion (setq ess-temp-stdout (ess-search-except "\\(/dev/[a-z0-9/]+\\)" nil t)))
823 ;; (setq ess-sas-shell-buffer "*PROGRAM*")
824 ;; (ess-sas-goto-shell)
825 ;;;; (insert "tty")
826 ;; (comint-send-input)
827 ;; (sleep-for ess-sleep-for)
828 ;; (insert "sh")
829 ;; (comint-send-input)
830 ;; (sleep-for ess-sleep-for)
831 ;; (save-excursion (setq ess-temp-stdin (ess-search-except "\\(/dev/[a-z0-9/]+\\)" nil t)))
832 ;; (insert (concat ess-sas-submit-command " " ess-sas-submit-command-options " -stdio <"
833 ;; ess-temp-stdin " >1 " ess-temp-stdout " >2 " ess-temp-stderr))
834 ;; (comint-send-input)
835 ;; (ess-add-ess-process)
836 ;; (ess-sas-goto-sas)
837 ;;))
839 (defun ess-sas-kill-buffers ()
840 "Kill all buffers related to a .sas file."
841 (interactive)
842 (ess-sas-file-path)
843 (ess-sas-goto "log" nil t)
844 (kill-buffer nil)
845 (ess-sas-goto "lst" nil t)
846 (kill-buffer nil)
847 (ess-sas-goto ess-sas-suffix-1 nil t)
848 (kill-buffer nil)
849 (ess-sas-goto ess-sas-suffix-2 nil t)
850 (kill-buffer nil)
851 (ess-sas-goto "sas" nil t)
852 (kill-buffer nil)
855 ;(eval-when-compile
856 (condition-case nil
857 (progn
858 (require 'rtf-support)
859 (when (featurep 'rtf-support)
861 (defun ess-sas-rtf-portrait (&optional ess-tmp-font-size)
862 "Creates an MS RTF portrait file from the current buffer."
863 (interactive)
864 (ess-sas-file-path)
866 (if (equal ess-tmp-font-size nil)
867 (setq ess-tmp-font-size "18"))
869 (let
870 ((ess-temp-rtf-file (replace-in-string ess-sas-file-path "[.][^.]*$" ".rtf")))
871 ;(expand-file-name (buffer-name)) "[.][^.]*$" ".rtf")))
872 (rtf-export ess-temp-rtf-file)
873 (ess-sas-goto "rtf" t)
874 (goto-char (point-min))
875 (replace-regexp "\\\\fmodern .*;" "\\\\fmodern courier;" )
876 (goto-char (point-min))
878 (while (replace-regexp "\\\\fs[0-9]+" (concat "\\\\fs" ess-tmp-font-size)) nil)
880 (save-buffer)))
882 (defun ess-sas-rtf-us-landscape ()
883 "Creates an MS RTF US landscape file from the current buffer."
884 (interactive)
885 (ess-sas-rtf-portrait "16")
886 (ess-sas-goto "rtf" t)
887 (goto-char (point-min))
888 (forward-line 3)
889 (insert (concat "{\\*\\pgdsctbl\n"
890 "{\\pgdsc0\\pgdscuse195\\lndscpsxn\\pgwsxn15840\\pghsxn12240\\marglsxn1800\\margrsxn1800\\margtsxn1440\\margbsxn1440\\pgdscnxt0 Default;}}\n"
891 "\\landscape\\paperh12240\\paperw15840\\margl1800\\margr1800\\margt1440\\margb1440\\sectd\\sbknone\\lndscpsxn\\pgwsxn15840\\pghsxn12240\\marglsxn1800\\margrsxn1800\\margtsxn1440\\margbsxn1440\\ftnbj\\ftnstart1\\ftnrstcont\\ftnnar\\aenddoc\\aftnrstcont\\aftnstart1\\aftnnrlc\n"))
892 (save-buffer))
894 (defun ess-sas-rtf-a4-landscape ()
895 "Creates an MS RTF A4 landscape file from the current buffer."
896 (interactive)
897 (ess-sas-rtf-portrait "16")
898 (ess-sas-goto "rtf" t)
899 (goto-char (point-min))
900 (forward-line 3)
901 (insert (concat "{\\*\\pgdsctbl\n"
902 "{\\pgdsc0\\pgdscuse195\\lndscpsxn\\pgwsxn16837\\pghsxn11905\\marglsxn1800\\margrsxn1800\\margtsxn1440\\margbsxn1440\\pgdscnxt0 Default;}}\n"
903 "\\landscape\\paperh11905\\paperw16837\\margl1800\\margr1800\\margt1440\\margb1440\\sectd\\sbknone\\lndscpsxn\\pgwsxn16837\\pghsxn11905\\marglsxn1800\\margrsxn1800\\margtsxn1440\\margbsxn1440\\ftnbj\\ftnstart1\\ftnrstcont\\ftnnar\\aenddoc\\aftnrstcont\\aftnstart1\\aftnnrlc\n"))
904 (save-buffer))
906 (error nil)) ;)
908 (defun ess-sas-submit ()
909 "Save the .sas file and submit to shell using a function that
910 depends on the value of `ess-sas-submit-method'"
911 (interactive)
912 (ess-sas-file-path)
913 (ess-sas-goto-sas)
914 (save-buffer)
915 (hack-local-variables)
916 ;(ess-save-and-set-local-variables)
918 (cond
919 ((eq ess-sas-submit-method 'apple-script)
920 (ess-sas-submit-mac ess-sas-submit-command
921 ess-sas-submit-command-options))
922 ((eq ess-sas-submit-method 'ms-dos)
923 (ess-sas-submit-windows ess-sas-submit-command
924 ess-sas-submit-command-options))
925 ((eq ess-sas-submit-method 'iESS)
926 (ess-sas-submit-iESS ess-sas-submit-command
927 ess-sas-submit-command-options))
928 ((eq ess-sas-submit-method 'sh)
929 (ess-sas-submit-sh ess-sas-submit-command
930 ess-sas-submit-command-options))
931 (t (ess-sas-submit-sh ess-sas-submit-command
932 ess-sas-submit-command-options)))
933 ; (ess-sas-goto-sas)
936 (defun ess-sas-submit-iESS (arg1 arg2)
937 "iESS
938 Submit a batch job in an inferior-ESS buffer. The buffer should
939 (1) have telnet access and be running a shell on a remote machine
941 (2) be running a shell on the local machine.
943 The user can telnet to the remote computer and then declare the
944 *telnet-buffer* to be an inferior ESS buffer with the `ess-add-ess-process'
945 command. When using a remote computer, the .sas file must live on the
946 remote computer and be accessed through `ange-ftp'. When
947 `ess-sas-submit' saves a file, it is therefore saved on the remote
948 computer. The various functions such as `ess-sas-goto-lst' retrieve
949 their files from the remote computer. Local copies of the .sas .lst
950 .log and others may be made manually with `write-buffer'."
951 ;; (ess-eval-linewise (concat "cd default-directory))
952 (ess-force-buffer-current "Process to load into: ")
953 (ess-eval-linewise
954 (concat "cd " (car (last
955 (split-string (file-name-directory ess-sas-file-path) "\\(:\\|]\\)")))))
956 (ess-eval-linewise (concat arg1 " " arg2 " " (buffer-name) " &")))
958 (defun ess-sas-submit-mac (arg1 arg2)
959 "If you are using Mac SAS, then arg1, `ess-sas-submit-command', should be
960 the AppleScript command \"invoke SAS using program file\", and, if necessary,
961 arg2, `ess-sas-submit-command-options', is a string of the form
962 \"with options { \\\"option-1\\\", \\\"option-2\\\", etc.}\". If you are
963 using Windows SAS with the PC emulator Virtual PC, then `ess-sas-submit-command'
964 should be ..."
965 ;(ess-save-and-set-local-variables)
967 (do-applescript (concat arg1 " \""
968 (if (not ess-sas-submit-mac-virtual-pc)
969 (unix-filename-to-mac default-directory))
970 (buffer-name) "\"" arg2)))
972 (defun ess-sas-submit-region ()
973 "Write region to temporary file, and submit to SAS."
974 (interactive)
975 (ess-sas-file-path)
976 (write-region (region-beginning) (region-end)
977 (concat (ess-sas-temp-root) ".sas"))
979 (save-excursion
980 (ess-sas-goto-shell t)
982 (if (and (w32-shell-dos-semantics)
983 (string-equal ":" (substring ess-sas-file-path 1 2)))
984 (progn
985 (insert (substring ess-sas-file-path 0 2))
986 (comint-send-input)
989 (insert "cd \"" (convert-standard-filename
990 (file-name-directory ess-sas-file-path)) "\"")
991 (comint-send-input)
993 (insert (concat ess-sas-submit-pre-command " " ess-sas-submit-command
994 " " (ess-sas-temp-root) " " ess-sas-submit-post-command))
995 (comint-send-input)
999 (defun ess-sas-submit-sh (arg1 arg2)
1000 "Unix or bash in the *shell* buffer.
1001 Multiple processing is supported on this platform.
1002 SAS may not be found in your PATH. You can alter your PATH to include
1003 SAS or you can specify the PATHNAME (PATHNAME can NOT contain spaces),
1004 i.e. let arg1 be your local equivalent of
1005 \"/usr/local/sas612/sas\"."
1006 (if (string-equal (substring
1007 (file-name-nondirectory ess-sas-file-path) 0 1) ess-kermit-prefix)
1008 (progn
1009 (ess-kermit-send)
1010 (ess-sas-goto-shell t)
1011 (insert ess-sas-submit-pre-command " " arg1 " "
1012 (substring (file-name-sans-extension
1013 (file-name-nondirectory ess-sas-file-path)) 1)
1014 " " arg2 " " ess-sas-submit-post-command))
1015 ;;else
1016 (ess-sas-goto-shell t)
1017 ; (if ess-microsoft-p
1018 ; (insert "cd " (file-name-directory ess-sas-file-path))
1019 ; (insert "cd " (car (last (split-string
1020 ; (file-name-directory ess-sas-file-path) "\\(:\\|]\\)")))))
1021 (insert "cd " (car (last (split-string (file-name-directory ess-sas-file-path)
1022 "\\([a-zA-Z][a-zA-Z]:\\|]\\)"))))
1023 (comint-send-input)
1024 (insert ess-sas-submit-pre-command " " arg1 " "
1025 (file-name-sans-extension (file-name-nondirectory ess-sas-file-path))
1026 " " arg2 " " ess-sas-submit-post-command))
1027 (ess-sleep)
1028 (comint-send-input))
1030 (defun ess-sas-submit-windows (arg1 arg2)
1031 "Windows using MS-DOS prompt in the *shell* buffer.
1032 Multiple processing is supported on this platform.
1033 On most Windows installations, SAS will not be found in your
1034 PATH so you should alter your PATH to include SAS, i.e.
1036 SET PATH=%PATH%;C:\\Program Files\\SAS
1038 Or you can specify the PATHNAME directly (you must escape
1039 spaces by enclosing the string in \\\"'s), i.e. let
1040 `ess-sas-submit-command' be \"\\\"C:\\Program Files\\SAS\\sas.exe\\\"\".
1041 Keep in mind that the maximum command line length in MS-DOS is
1042 127 characters so altering your PATH is preferable."
1043 ;(ess-save-and-set-local-variables)
1044 (ess-sas-goto-shell t)
1045 (if (string-equal ":" (substring ess-sas-file-path 1 2))
1046 (progn
1047 (insert (substring ess-sas-file-path 0 2))
1048 (comint-send-input)
1051 (insert "cd \"" (convert-standard-filename
1052 (file-name-directory ess-sas-file-path)) "\"")
1053 (comint-send-input)
1054 (insert ess-sas-submit-pre-command " " arg1 " -sysin \""
1055 (file-name-sans-extension (file-name-nondirectory ess-sas-file-path)) "\" "
1056 arg2 " " ess-sas-submit-post-command)
1057 (comint-send-input))
1059 (defun ess-sas-tab-to-tab-stop ()
1060 "Tab to next tab-stop and set left margin."
1061 (interactive)
1062 (tab-to-tab-stop)
1063 (setq left-margin (current-column))
1066 (defun ess-sas-temp-root ()
1067 "Return `ess-sas-file-path' sans extension with `ess-sas-temp-root' appended."
1068 (concat (file-name-sans-extension ess-sas-file-path) ess-sas-temp-root))
1070 (defun ess-sas-transcript (&optional strip)
1071 "Comment .log messages to create a .sas program; use C-u to strip."
1072 (interactive "P")
1073 (save-excursion
1074 (goto-char (point-min))
1076 (while (search-forward-regexp (concat
1077 "^\\(\\(1[ \t]+The SAS System\\|\f\\|NOTE\\|WARNING\\|ERROR\\|"
1078 "[ \t]+\\(\\(real\\|cpu\\) time\\|Licensed to\\|Engine:\\|"
1079 "Physical Name:\\|File Name=\\|Owner Name=\\|Group Name=\\|"
1080 "Access Permission=\\|File Size (bytes)=\\|Pipe command=\\|"
1081 "RECFM=[DFNPV],LRECL=\\|[0-9]+:[0-9]+[ /t]+[0-9]+:[0-9]+\\|"
1082 "[1-9][0-9]* at [0-9]+:[0-9]+[ /t]+[1-9][0-9]* at [0-9]+:[0-9]+\\)\\).*$"
1083 "\\|[0-9]+\\([ \t]+!\\)?\\|MPRINT([_A-Z]+):\\|"
1084 "[ \t]+\\(values at the places given by: (Line):(Column).\\|"
1085 "The m\\(in\\|ax\\)imum record length was [1-9][0-9]*.\\|"
1086 "One or more lines were truncated.\\|"
1087 "Each place is given by: (Number of times) at (Line):(Column).\\|"
1088 "[0-9][0-9]:[0-9][0-9] [MTWFS][aeioudhnrst]+day, [JFMASOND]"
1089 "[aeiouybcghlmnprstv]+ [1-9][0-9]?, 20[0-9][0-9]\\)\\)")
1090 nil t) (replace-match (if strip " " "/*\\&*/") t))
1093 (defun ess-sas-toggle-sas-listing-mode (&optional force)
1094 "Toggle SAS-listing-mode for .lst files."
1095 (interactive)
1096 (ess-sas-goto-lst)
1098 (if (equal (cdr (assoc "\\.[lL][sS][tT]\\'" auto-mode-alist)) 'SAS-listing-mode) (progn
1099 (setq auto-mode-alist (delete '("\\.[lL][sS][tT]\\'" . SAS-listing-mode) auto-mode-alist))
1100 (setq buffer-read-only nil)
1101 (ess-listing-minor-mode 0))
1102 (setq auto-mode-alist (append '(("\\.[lL][sS][tT]\\'" . SAS-listing-mode)) auto-mode-alist))
1103 (setq buffer-read-only t)
1104 (ess-listing-minor-mode 1)))
1106 (defun ess-sas-toggle-sas-log-mode ()
1107 "Toggle SAS-log-mode for .log files."
1108 (interactive)
1109 (ess-sas-goto-log t)
1111 (if (equal (cdr (assoc "\\.[lL][oO][gG]\\'" auto-mode-alist)) 'SAS-log-mode) (progn
1112 (setq auto-mode-alist (delete '("\\.[lL][oO][gG]\\'" . SAS-log-mode) auto-mode-alist))
1113 (setq buffer-read-only nil)
1114 (ess-transcript-minor-mode 0)
1115 (font-lock-mode 0))
1116 (setq auto-mode-alist (append '(("\\.[lL][oO][gG]\\'" . SAS-log-mode)) auto-mode-alist))
1117 (setq buffer-read-only t)
1118 (ess-transcript-minor-mode 1)
1119 (font-lock-mode 1)
1120 (font-lock-fontify-buffer)))
1122 (defun ess-sas-versions-create ()
1123 "Generate the `M-x SASV' functions for starting other versions of SAS.
1124 See `ess-sas-versions' for strings that determine which functions are created.
1126 The local variable `ess-sas-versions-created' is used to return list of
1127 the new SAS defuns, if any, that were created. The defuns will normally
1128 be placed on the menubar upon ESS initialisation."
1130 ;; This works by creating a temp buffer where the template function is
1131 ;; edited so that V is replaced by the version number
1132 (let ((template "")
1133 (beg)
1134 (versions)
1135 (version)
1136 (eval-buf (get-buffer-create "*ess-temp-sas-evals*"))
1137 (ess-sas-versions-created)
1140 ;; This is the template function used for creating M-x SASV.
1141 (setq template "(defun SASV (&optional start-args)
1142 \"Call SASV, i.e., the SAS version 'SASV' using ESS.
1143 This function was generated by `ess-sas-versions-create'.\"
1144 (interactive \"P\")
1145 (let ((inferior-SAS-program-name \"SASV\"))
1146 (SAS start-args)))
1149 (save-excursion
1150 (set-buffer eval-buf)
1151 ;; clear the buffer.
1152 (delete-region (point-min) (point-max))
1154 ;; Find which versions of SAS we want. Remove the pathname, leaving just
1155 ;; the name of the executable.
1156 (setq versions
1157 (ess-uniq-list
1158 (mapcar 'file-name-nondirectory
1159 (apply 'nconc
1160 (mapcar 'ess-find-exec-completions
1161 ess-sas-versions)))))
1162 (ess-write-to-dribble-buffer
1163 (format "(SAS): ess-sas-versions-create making M-x defuns for %s"
1164 (mapconcat 'identity versions " ")))
1165 (setq ess-sas-versions-created versions) ;keep copy for returning at end.
1166 ;; Iterate over each string in VERSIONS, creating a new defun each time.
1167 (while versions
1168 (setq version (car versions)
1169 versions (cdr versions))
1170 (setq beg (point))
1171 (insert template)
1172 (goto-char beg)
1173 (while (search-forward "SASV" nil t)
1174 (replace-match version t t))
1175 (goto-char (point-max))
1177 ;; buffer has now been created with defuns, so eval them!
1178 (eval-buffer)
1179 (kill-buffer eval-buf)
1181 ess-sas-versions-created))
1184 ;;; Section 3: Key Definitions
1187 (defun ess-sas-edit-keys-set (&optional arg)
1188 "Set TAB/RET key in `SAS-mode'.
1189 If arg is nil
1190 TAB is `sas-indent-line' and
1191 RET is `newline-and-indent'.
1192 Else
1193 TAB is `ess-sas-tab-to-tab-stop',
1194 C-TAB is `ess-sas-backward-delete-tab' and
1195 RET is `newline'."
1196 (interactive)
1198 (if arg
1199 (progn
1200 (if (and (equal emacs-major-version 19) (equal emacs-minor-version 28))
1201 (define-key sas-mode-local-map [C-tab] 'ess-sas-backward-delete-tab)
1202 ;;else
1203 (define-key sas-mode-local-map [(control tab)] 'ess-sas-backward-delete-tab))
1204 (define-key sas-mode-local-map [return] 'newline)
1205 (define-key sas-mode-local-map "\t" 'ess-sas-tab-to-tab-stop))
1206 ;;else
1207 (define-key sas-mode-local-map [return] 'newline-and-indent)
1208 (define-key sas-mode-local-map "\t" 'sas-indent-line)))
1210 (defvar ess-sas-edit-keys-toggle nil
1211 "Toggle TAB/RET key in `SAS-mode'.
1212 nil binds TAB to `sas-indent-line' and RET to `newline-and-indent'.
1213 Non-nil binds TAB to `ess-sas-tab-to-tab-stop',
1214 C-TAB to `ess-sas-backward-delete-tab', and RET to `newline'.")
1216 (defun ess-sas-edit-keys-toggle (&optional arg)
1217 "Toggle `ess-sas-edit-keys-toggle'. Optional arg is still
1218 accepted for backward compatibility, however, arg is ignored."
1219 (interactive)
1221 (setq ess-sas-edit-keys-toggle (not ess-sas-edit-keys-toggle))
1222 (ess-sas-edit-keys-set ess-sas-edit-keys-toggle)
1225 (defvar ess-sas-global-pc-keys nil
1226 "Non-nil if function keys use PC-like SAS key definitions in all modes.")
1228 (defun ess-sas-global-pc-keys ()
1229 "PC-like SAS key definitions"
1230 (interactive)
1231 (when (featurep 'rtf-support)
1232 (global-set-key [(control f1)] 'ess-sas-rtf-portrait)
1233 (global-set-key [(control f2)] 'ess-sas-rtf-us-landscape))
1234 (global-set-key (quote [f2]) 'ess-revert-wisely)
1235 (global-set-key (quote [f3]) 'ess-sas-goto-shell)
1236 (global-set-key (quote [f4]) 'ess-sas-goto-file-1)
1237 (global-set-key (quote [f5]) 'ess-sas-goto-sas)
1238 (global-set-key (quote [f6]) 'ess-sas-goto-log)
1239 (global-set-key [(control f6)] 'ess-sas-append-log)
1240 (global-set-key (quote [f7]) 'ess-sas-goto-lst)
1241 (global-set-key [(control f7)] 'ess-sas-append-lst)
1242 (global-set-key (quote [f8]) 'ess-sas-submit)
1243 (global-set-key [(control f8)] 'ess-sas-submit-region)
1244 (global-set-key (quote [f9]) 'ess-sas-data-view-fsview)
1245 (global-set-key [(control f9)] 'ess-sas-data-view-insight)
1246 (global-set-key (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1247 (global-set-key [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1248 (global-set-key (quote [f11]) 'ess-sas-goto-file-2)
1249 (global-set-key [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1250 (global-set-key (quote [f12]) 'ess-sas-graph-view)
1251 (if (and ess-sas-edit-keys-toggle
1252 (equal emacs-major-version 19) (equal emacs-minor-version 28))
1253 (global-set-key [C-tab] 'ess-sas-backward-delete-tab)
1254 ;else
1255 (global-set-key [(control tab)] 'ess-sas-backward-delete-tab))
1256 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1257 (setq ess-sas-global-pc-keys t)
1258 (setq ess-sas-global-unix-keys nil)
1259 (setq ess-sas-local-pc-keys nil)
1260 (setq ess-sas-local-unix-keys nil)
1263 (defvar ess-sas-global-unix-keys nil
1264 "Non-nil if function keys use Unix-like SAS key definitions in all modes.")
1266 (defun ess-sas-global-unix-keys ()
1267 "Unix/Mainframe-like SAS key definitions"
1268 (interactive)
1269 (when (featurep 'rtf-support)
1270 (global-set-key [(control f1)] 'ess-sas-rtf-portrait)
1271 (global-set-key [(control f2)] 'ess-sas-rtf-us-landscape))
1272 (global-set-key (quote [f2]) 'ess-revert-wisely)
1273 (global-set-key (quote [f3]) 'ess-sas-submit)
1274 (global-set-key [(control f3)] 'ess-sas-submit-region)
1275 (global-set-key (quote [f4]) 'ess-sas-goto-sas)
1276 (global-set-key (quote [f5]) 'ess-sas-goto-log)
1277 (global-set-key [(control f5)] 'ess-sas-append-log)
1278 (global-set-key (quote [f6]) 'ess-sas-goto-lst)
1279 (global-set-key [(control f6)] 'ess-sas-append-lst)
1280 (global-set-key (quote [f7]) 'ess-sas-goto-file-1)
1281 (global-set-key (quote [f8]) 'ess-sas-goto-shell)
1282 (global-set-key (quote [f9]) 'ess-sas-data-view-fsview)
1283 (global-set-key [(control f9)] 'ess-sas-data-view-insight)
1284 (global-set-key (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1285 (global-set-key [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1286 (global-set-key (quote [f11]) 'ess-sas-goto-file-2)
1287 (global-set-key [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1288 (global-set-key (quote [f12]) 'ess-sas-graph-view)
1289 (if (and ess-sas-edit-keys-toggle
1290 (equal emacs-major-version 19) (equal emacs-minor-version 28))
1291 (global-set-key [C-tab] 'ess-sas-backward-delete-tab)
1292 ;else
1293 (global-set-key [(control tab)] 'ess-sas-backward-delete-tab))
1294 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1295 (setq ess-sas-global-pc-keys nil)
1296 (setq ess-sas-global-unix-keys t)
1297 (setq ess-sas-local-pc-keys nil)
1298 (setq ess-sas-local-unix-keys nil)
1301 (defvar ess-sas-local-pc-keys nil
1302 "Non-nil if function keys use PC-like SAS key definitions
1303 in SAS-mode and related modes.")
1305 (defun ess-sas-local-pc-keys ()
1306 "PC-like SAS key definitions."
1307 (interactive)
1308 (when (featurep 'rtf-support)
1309 (define-key sas-mode-local-map [(control f1)] 'ess-sas-rtf-portrait)
1310 (define-key sas-mode-local-map [(control f2)] 'ess-sas-rtf-us-landscape))
1311 (define-key sas-mode-local-map (quote [f2]) 'ess-revert-wisely)
1312 (define-key sas-mode-local-map (quote [f3]) 'ess-sas-goto-shell)
1313 (define-key sas-mode-local-map (quote [f4]) 'ess-sas-goto-file-1)
1314 (define-key sas-mode-local-map (quote [f5]) 'ess-sas-goto-sas)
1315 (define-key sas-mode-local-map (quote [f6]) 'ess-sas-goto-log)
1316 (define-key sas-mode-local-map [(control f6)] 'ess-sas-append-log)
1317 (define-key sas-mode-local-map (quote [f7]) 'ess-sas-goto-lst)
1318 (define-key sas-mode-local-map [(control f7)] 'ess-sas-append-lst)
1319 (define-key sas-mode-local-map (quote [f8]) 'ess-sas-submit)
1320 (define-key sas-mode-local-map [(control f8)] 'ess-sas-submit-region)
1321 (define-key sas-mode-local-map (quote [f9]) 'ess-sas-data-view-fsview)
1322 (define-key sas-mode-local-map [(control f9)] 'ess-sas-data-view-insight)
1323 (define-key sas-mode-local-map (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1324 (define-key sas-mode-local-map [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1325 (define-key sas-mode-local-map (quote [f11]) 'ess-sas-goto-file-2)
1326 (define-key sas-mode-local-map [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1327 (define-key sas-mode-local-map (quote [f12]) 'ess-sas-graph-view)
1328 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1329 (setq ess-sas-global-pc-keys nil)
1330 (setq ess-sas-global-unix-keys nil)
1331 (setq ess-sas-local-pc-keys t)
1332 (setq ess-sas-local-unix-keys nil)
1335 (defvar ess-sas-local-unix-keys nil
1336 "Non-nil if function keys use Unix-like SAS key definitions
1337 in SAS-mode and related modes.")
1339 (defun ess-sas-local-unix-keys ()
1340 "Unix/Mainframe-like SAS key definitions"
1341 (interactive)
1342 (when (featurep 'rtf-support)
1343 (define-key sas-mode-local-map [(control f1)] 'ess-sas-rtf-portrait)
1344 (define-key sas-mode-local-map [(control f2)] 'ess-sas-rtf-us-landscape))
1345 (define-key sas-mode-local-map (quote [f2]) 'ess-revert-wisely)
1346 (define-key sas-mode-local-map (quote [f3]) 'ess-sas-submit)
1347 (define-key sas-mode-local-map [(control f3)] 'ess-sas-submit-region)
1348 (define-key sas-mode-local-map (quote [f4]) 'ess-sas-goto-sas)
1349 (define-key sas-mode-local-map (quote [f5]) 'ess-sas-goto-log)
1350 (define-key sas-mode-local-map [(control f5)] 'ess-sas-append-log)
1351 (define-key sas-mode-local-map (quote [f6]) 'ess-sas-goto-lst)
1352 (define-key sas-mode-local-map [(control f6)] 'ess-sas-append-lst)
1353 (define-key sas-mode-local-map (quote [f7]) 'ess-sas-goto-file-1)
1354 (define-key sas-mode-local-map (quote [f8]) 'ess-sas-goto-shell)
1355 (define-key sas-mode-local-map (quote [f9]) 'ess-sas-data-view-fsview)
1356 (define-key sas-mode-local-map [(control f9)] 'ess-sas-data-view-insight)
1357 (define-key sas-mode-local-map (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1358 (define-key sas-mode-local-map [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1359 (define-key sas-mode-local-map (quote [f11]) 'ess-sas-goto-file-2)
1360 (define-key sas-mode-local-map [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1361 (define-key sas-mode-local-map (quote [f12]) 'ess-sas-graph-view)
1362 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1363 (setq ess-sas-global-pc-keys nil)
1364 (setq ess-sas-global-unix-keys nil)
1365 (setq ess-sas-local-pc-keys nil)
1366 (setq ess-sas-local-unix-keys t)
1369 (provide 'essa-sas)
1371 \f ; Local variables section
1373 ;;; This file is automatically placed in Outline minor mode.
1374 ;;; The file is structured as follows:
1375 ;;; Chapters: ^L ;
1376 ;;; Sections: ;;*;;
1377 ;;; Subsections: ;;;*;;;
1378 ;;; Components: defuns, defvars, defconsts
1379 ;;; Random code beginning with a ;;;;* comment
1381 ;;; Local variables:
1382 ;;; mode: emacs-lisp
1383 ;;; outline-minor-mode: nil
1384 ;;; mode: outline-minor
1385 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
1386 ;;; End:
1388 ;;; essa-sas.el ends here