1 ;;; essl-sas.el --- SAS customization
3 ;; Copyright (C) 1997--2004 A.J. Rossini, Rich M. Heiberger, Martin
4 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6 ;; Original Authors: Richard M. Heiberger <rmh@astro.ocis.temple.edu>,
7 ;; A.J. Rossini <rossini@u.washington.edu>,
8 ;; Rodney Sparapani <rsparap@mcw.edu>
9 ;; Created: 20 Aug 1997
10 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
12 ;; Keywords: start up, configuration.
14 ;; This file is part of ESS (Emacs Speaks Statistics).
16 ;; This file is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; This file is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;;; This is based upon Version 1.4 of SAS mode:
34 ;;; sas-mode: indent, run etc, SAS programs.
35 ;;; Copyright (C) 1994--1997 Tom Cook
37 ;;; Dept. of Biostatistics
38 ;;; University of Wisconsin - Madison
40 ;;; cook@biostat.wisc.edu
43 ;;; Menu code for XEmacs/Lucid emacs and startup mods
44 ;;; contributed by arossini@biostats.hmc.psu.edu
46 ;;; Last change: 2/1/95
47 ;;; Last change: 01/15/02
49 (ess-message "[essl-sas:] (require 'ess) ...")
51 (ess-message "[essl-sas:] (require 'ess-mode) ...")
55 (ess-message "[essl-sas:] (autoload ..) (def** ..) etc ...")
57 (autoload 'ess-transcript-mode
"ess-trns" "ESS source eval mode." t
)
59 (put 'ess-transcript-minor-mode
'permanent-local t
)
60 (or (assq 'ess-transcript-minor-mode minor-mode-alist
)
61 (setq minor-mode-alist
62 (append minor-mode-alist
63 (list '(ess-transcript-minor-mode " ESStr")))))
65 (put 'ess-listing-minor-mode
'permanent-local t
)
66 (or (assq 'ess-listing-minor-mode minor-mode-alist
)
67 (setq minor-mode-alist
68 (append minor-mode-alist
69 (list '(ess-listing-minor-mode " ESSlst")))))
71 (defun ess-transcript-minor-mode (&optional arg
)
72 "Toggle Ess-Transcript minor mode.
73 With arg, turn Ess-Transcript minor mode on if arg is positive, off
74 otherwise. See the command `ess-transcript-mode' for more information
77 (setq ess-transcript-minor-mode
78 (if (null arg
) (not ess-transcript-minor-mode
)
79 (> (prefix-numeric-value arg
) 0)))
80 (force-mode-line-update)
81 (setq mode-line-process
82 '(" [" ess-local-process-name
"]")))
84 (defun ess-listing-minor-mode (&optional arg
)
85 "Toggle Ess-Listing minor mode.
86 With arg, turn Ess-Listing minor mode on if arg is positive, off
87 otherwise. Ess-Listing mode is used solely to place an indicator on
90 (setq ess-listing-minor-mode
91 (if (null arg
) (not ess-listing-minor-mode
)
92 (> (prefix-numeric-value arg
) 0)))
93 (force-mode-line-update)
94 (setq mode-line-process
95 '(" [" ess-local-process-name
"]")))
97 (defun SAS-log-mode ()
98 "`ess-transcript-mode' for SAS."
101 (ess-transcript-minor-mode 1)
102 (toggle-read-only t
)) ;; to protect the buffer.
104 (defun SAS-listing-mode()
105 "Fundamental mode with `ess-listing-minor-mode' and read-only."
108 (ess-listing-minor-mode 1)
109 (use-local-map sas-mode-local-map
)
110 (toggle-read-only t
)) ;; to protect the buffer.
112 (fset 'sas-log-mode
'SAS-log-mode
)
113 (fset 'SAS-transcript-mode
'SAS-log-mode
)
114 (fset 'sas-transcript-mode
'SAS-log-mode
)
115 (fset 'sas-mode
'SAS-mode
)
116 (fset 'sas-listing-mode
'SAS-listing-mode
)
118 (defcustom sas-indent-width
4
119 "*Amount to indent sas statements."
123 (defcustom sas-indent-ignore-comment
"*"
124 "*Comments that start with this string are ignored in indentation."
128 (defcustom sas-require-confirmation t
129 "*Require confirmation when revisiting a modified sas-output file."
133 ;; user can specify the sas program name
134 (defcustom sas-program
135 (if (equal system-type
'Apple-Macintosh
) "invoke SAS using program file" "sas")
136 "*Command to invoke SAS, default for buffer-local `ess-sas-submit-command'."
140 (defcustom sas-pre-run-hook nil
141 "Hook to execute prior to running SAS via `submit-sas'."
145 ;never used--see ess-sas-submit-command-options in essa-sas.el
146 ;(defcustom sas-options-string ""
147 ; "*Options to be passed to sas as if typed on the command line."
151 (defcustom sas-notify t
152 "*Beep and display message when job is done."
156 (defcustom sas-error-notify t
157 "*If `sas-notify' t, indicate errors in log file upon completion."
161 (defcustom sas-get-options nil
162 "Options to be passed to SAS in sas-get-dataset."
164 :type
'(choice (const nil
) string
))
166 (defcustom sas-get-options-history nil
167 "History list of Options passed to SAS in sas-get-dataset."
170 (defcustom sas-page-number-max-line
3
171 "*Number of lines from the page break, to search for the page
176 (defcustom sas-notify-popup nil
177 "*If this and sas-notify are t), popup a window when SAS job ends."
181 (defcustom sas-tmp-libname
"_tmp_"
182 "*Libname to use for sas-get-dataset."
186 (defcustom sas-file-name nil
187 "*The name of the current sas file."
189 :type
'(choice (const nil
) file
))
191 ;; The next two are ``the inside of [...] in a regexp'' to be used in
192 ;; (skip-chars-(for|back)ward SAS-..-chars)
193 (defcustom sas-white-chars
" \t\n\f"
194 "This does NOT escape blanks (RMH, 2000/03/20)."
198 (defcustom sas-comment-chars
(concat sas-white-chars
";")
203 (defcustom ess-sas-run-make-regexp nil
204 "If you do not want to run make-regexp, then set to nil."
206 :type
'(choice (const nil
) string
))
210 (defvar sas-buffer-name nil
)
211 (defvar sas-file-root nil
)
212 (defvar sas-submitable nil
)
213 (defvar sas-dataset nil
)
214 (defvar SAS-syntax-table nil
"Syntax table for SAS code.")
216 (if SAS-syntax-table nil
217 (setq SAS-syntax-table
(make-syntax-table))
219 ;; (if (equal system-type 'windows-nt)
220 ;; ;; backslash is punctuation (used in MS file names)
221 ;; (modify-syntax-entry ?\\ "." SAS-syntax-table)
222 ;; ;; backslash is an escape character
223 ;; (modify-syntax-entry ?\\ "\\" SAS-syntax-table))
224 (modify-syntax-entry ?
\\ "." SAS-syntax-table
) ;; backslash is punctuation
225 (modify-syntax-entry ?
+ "." SAS-syntax-table
)
226 (modify-syntax-entry ?-
"." SAS-syntax-table
)
227 (modify-syntax-entry ?
= "." SAS-syntax-table
)
228 (modify-syntax-entry ?%
"w" SAS-syntax-table
)
229 (modify-syntax-entry ?
< "." SAS-syntax-table
)
230 (modify-syntax-entry ?
> "." SAS-syntax-table
)
231 (modify-syntax-entry ?
& "w" SAS-syntax-table
)
232 (modify-syntax-entry ?|
"." SAS-syntax-table
)
233 (modify-syntax-entry ?
\' "\"" SAS-syntax-table
)
234 (modify-syntax-entry ?
* ". 23" SAS-syntax-table
) ; comment character
235 (modify-syntax-entry ?\
; "." SAS-syntax-table)
236 (modify-syntax-entry ?_
"w" SAS-syntax-table
)
237 (modify-syntax-entry ?
< "." SAS-syntax-table
)
238 (modify-syntax-entry ?
> "." SAS-syntax-table
)
239 (modify-syntax-entry ?
/ ". 14" SAS-syntax-table
) ; comment character
240 (modify-syntax-entry ?.
"w" SAS-syntax-table
))
242 (require 'font-lock
); fontification also works in terminals!
243 ;; (if (or window-system
244 ;; noninteractive) ; compilation!
248 (defvar SAS-mode-font-lock-keywords
249 (if ess-sas-run-make-regexp
252 (cons "^[ \t]*%?\\*.*;" font-lock-comment-face
)
253 (cons ";[ \t]*%?\\*.*;" font-lock-comment-face
)
254 (list "/\\*\\([^*/]\\)*\\*/" 0 font-lock-comment-face t
)
256 ;; SAS execution blocks, DATA/RUN, PROC/RUN, %MACRO/%MEND
257 (cons "\\<\\(data\\|run\\|%macro\\|%mend\\)\\>" font-lock-constant-face
)
258 (cons "\\<proc[ \t]+[a-z][a-z_0-9]+" font-lock-constant-face
)
264 "%?do[ \t]*" (make-regexp '("over" "%?until" "%?while") t
) "?"
266 font-lock-keyword-face
)
272 "abort" "array" "attrib" "by" "delete" "display" "dm"
273 "drop" "error" "file" "filename" "footnote\\(10?\\|[2-9]\\)?"
275 "%go[ \t]*to" "%if" "%then" "%else"
276 "go[ \t]*to" "if" "then" "else"
277 "infile" "informat" "input" "%input" "keep" "label"
278 "length" "libname" "link"
279 "merge" "missing" "modify" "note" "options" "goptions" "output"
280 "otherwise" "put" "%put" "rename" "retain" "select" "when" "set"
281 "skip" "title\\(10?\\|[2-9]\\)?" "where" "window" "update" "out"
282 "change" "class" "exchange" "exclude" "freq" "id" "index"
283 "model" "plot" "save" "sum" "tables?" "var" "weight" "with"
284 "manova" "repeated" "value" "random" "means" "lsmeans"
285 ;; SAS macro statements not handled above
286 "%global" "%include" "%local" "%let" "%sysexec"
288 font-lock-keyword-face
)
290 ;; SAS statements that must be followed by a semi-colon
295 "cards4?" "end" "%end" "endsas" "list" "lostcard" "page"
297 ) t
) "\\>" "[ \t]*;")
298 font-lock-keyword-face
)
300 ;; SAS/GRAPH statements not handled above
304 '("axis" "legend" "pattern" "symbol") t
) "\\([1-9][0-9]?\\)?"
306 font-lock-keyword-face
)
308 ;; SAS functions and SAS macro functions
309 (cons "%[a-z_][a-z_0-9]*[ \t]*[(;]"
310 font-lock-function-name-face
)
311 (cons "\\<call[ \t]+[a-z_][a-z_0-9]*[ \t]*("
312 font-lock-function-name-face
)
318 "abs" "arcos" "arsin" "atan" "betainv" "byte" "ceil" "cinv"
319 "collate" "compress" "cosh?" "css" "cv"
320 "daccdb" "daccdbsl" "daccsl" "daccsyd" "dacctab"
321 "depdb" "depdbsl" "depsl" "depsyd" "deptab"
322 "date" "datejul" "datepart" "datetime" "day" "hms" "dhms" "dif"
323 "digamma" "dim" "erfc?" "exp" "finv"
324 "fipnamel?" "fipstate" "floor" "fuzz" "gaminv" "gamma"
325 "hbound" "hour" "indexc?" "input" "int" "intck" "intnx" "intrr"
326 "irr" "juldate" "kurtosis" "lag" "lbound" "left" "length"
327 "lgamma" "log" "log10" "log2" "max" "mdy" "mean" "min" "minute"
328 "mod" "month" "mort" "n" "netpv" "nmiss" "normal" "npv"
329 ;;;) t) "\\>" "[ \t]*(")
330 ;;; font-lock-function-name-face)
332 ;;; (cons (concat "\\<"
334 "probbeta" "probbnml" "probchi" "probf" "probgam" "probhypr"
335 "probit" "probnegb" "probnorm" "probt"
336 "ordinal" "poisson" "put" "qtr" "range" "rank" "repeat"
337 "ranbin" "rancau" "ranexp" "rangam" "rannor" "ranpoi"
338 "rantbl" "rantri" "ranuni"
339 "reverse" "right" "round" "saving" "scan" "second" "sign" "sinh?"
340 "sqrt" "std" "stderr" "stfips" "stnamel?" "substr" "sum"
341 "symget" "tanh?" "time" "timepart" "tinv" "today" "translate"
342 "trigamma" "trim" "trunc" "uniform" "upcase" "uss" "var"
343 "verify" "weekday" "year" "yyq"
344 "zipfips" "zipnamel?" "zipstate"
345 ;;;) t) "\\>" "[ \t]*(")
346 ;;; font-lock-function-name-face)
349 ;;; ;; SAS functions introduced in Technical Report P-222
350 ;;; ;; SCL functions that are known to work with SAS macro function %sysfunc
351 ;;; (cons (concat "\\<"
353 "airy" "band" "blshift" "brshift" "bnot" "bor" "bxor"
354 "cnonct" "fnonct" "tnonct" "compbl" "dairy" "dequote"
356 "indexw" "inputc" "inputn" "lowcase"
357 "putc" "putn" "quote" "resolve" "soundex" "sysprod"
359 "%sysfunc" "attrc" "attrn" "cexist" "close" "dclose" "dnum"
360 "dopen" "dread" "exist" "fclose" "fetchobs" "fileexist"
361 "finfo" "fopen" "fput" "fwrite" "getoption"
362 "getvarc" "getvarn" "libname" "libref" "open" "optgetn" "optsetn"
363 "pathname" "sysmsg" "varfmt" "varlabel" "varnum" "vartype"
364 ) t
) "\\>" "[ \t]*(")
365 font-lock-function-name-face
)
368 ;; .log NOTE: messages
369 (cons "^NOTE: .*$" font-lock-constant-face
)
371 ;; .log ERROR: messages
372 (cons "^ERROR: .*$" font-lock-keyword-face
)
374 ;; .log WARNING: messages
375 (cons "^WARNING: .*$" font-lock-function-name-face
)
378 ;; /* */ handled by grammar above
379 ;; (list "/\\*.*\\*/" 0 font-lock-comment-face t)
380 (cons "\\(^[0-9]*\\|;\\)[ \t]*\\(%?\\*\\|comment\\).*\\(;\\|$\\)" font-lock-comment-face
)
382 ;; SAS execution blocks, DATA/RUN, PROC/RUN, SAS Macro Statements
383 (cons "\\<%do[ \t]*\\(%until\\|%while\\)?\\>"
384 font-lock-constant-face
)
385 ;;(cons (concat "\\(^[0-9]*\\|;\\)[ \t]*"
386 ;;"%\\(end\\|global\\|local\\|m\\(acro\\|end\\)\\)"
387 ;;"\\>") font-lock-constant-face)
388 (cons "\\<%\\(end\\|global\\|local\\|m\\(acro\\|end\\)\\)\\>"
389 font-lock-constant-face
)
391 (cons (concat "\\(^[0-9]*\\|;\\|):\\|%then\\|%else\\)[ \t]*"
392 "\\(data\\|endsas\\|finish\\|quit\\|run\\|start\\)[ \t\n;]")
393 font-lock-constant-face
)
394 (cons (concat "\\(^[0-9]*\\|;\\|):\\|%then\\|%else\\)[ \t]*"
395 ;;"proc[ \t]+[a-z][a-z_0-9]+") font-lock-constant-face)
397 ;;SAS/Base, SAS/Graph, SAS/FSP and common add-ons
399 "\\|c\\(a\\(lendar\\|talog\\)\\|port\\|o\\(mpare\\|ntents\\|py\\|rr\\)\\)"
400 "\\|d\\(atasets\\|bcstab\\|isplay\\)\\|ex\\(plode\\|port\\)"
401 "\\|f\\(orm\\(at\\|s\\)\\|req\\|s\\(browse\\|edit\\|l\\(etter\\|ist\\)\\|view\\)\\)"
402 "\\|g?\\(chart\\|p\\(lot\\|rint\\)\\)"
403 "\\|g\\(anno\\|contour\\|device\\|font\\|\\(key\\)?map\\|options\\|project"
404 "\\|re\\(duce\\|move\\|play\\)\\|slide\\|testit\\|3\\(d\\|grid\\)\\)"
405 "\\|[cg]?import\\|i\\(ml\\|nsight\\)\\|means\\|options\\|p\\(menu\\|rintto\\)"
406 "\\|r\\(ank\\|e\\(gistry\\|port\\)\\)"
407 "\\|s\\(ort\\|ql\\|tandard\\|ummary\\)"
408 "\\|t\\(abulate\\|imeplot\\|ran\\(spose\\|tab\\)\\)\\|univariate"
409 ;;SAS/Stat and SAS/ETS
410 "\\|a\\(ceclus\\|nova\\|rima\\|utoreg\\)\\|boxplot"
411 "\\|c\\(a\\(lis\\|n\\(corr\\|disc\\)\\|tmod\\)\\|itibase\\|luster\\|o\\(mputab\\|rresp\\)\\)"
412 "\\|discrim\\|expand\\|f\\(a\\(ctor\\|stclus\\)\\|orecast\\|req\\)"
413 "\\|g\\(enmod\\|lm\\(mod\\|power\\)?\\)\\|inbreed\\|k\\(de\\|rige2d\\)"
414 "\\|l\\(attice\\|ife\\(reg\\|test\\)\\|o\\(ess\\|gistic\\)\\)"
415 "\\|m\\(ds\\|ixed\\|o\\(de\\(clus\\|l\\)\\|rtgage\\)\\|ulttest\\)"
416 "\\|n\\(ested\\|l\\(in\\|mixed\\)\\|par1way\\)\\|orthoreg"
417 "\\|p\\(dlreg\\|hreg\\|l\\(an\\|s\\)\\|ower\\|r\\(in\\(comp\\|qual\\)\\|obit\\)\\)\\|rs?reg"
418 "\\|s\\(core\\|im\\(2d\\|lin\\)\\|pectra\\|t\\(atespace\\|dize\\|epdisc\\)\\|urvey\\(means\\|reg\\|select\\)\\|yslin\\)"
419 "\\|t\\(phreg\\|pspline\\|r\\(ansreg\\|ee\\)\\|test\\)"
420 "\\|var\\(clus\\|comp\\|iogram\\)\\|x11"
421 "\\)") font-lock-constant-face
)
423 ;;(cons (concat "\\(^[0-9]*\\|;\\|%then\\|%else\\)[ \t]*"
424 ;;"\\(%\\(go[ \t]*to\\|i\\(f\\|n\\(clude\\|put\\)\\)\\|let\\|put\\|sysexec\\)\\)"
425 ;;"\\>") font-lock-constant-face)
426 (cons "\\<%\\(go[ \t]*to\\|i\\(f\\|n\\(clude\\|put\\)\\)\\|let\\|put\\|sysexec\\)\\>"
427 font-lock-constant-face
)
429 (cons "\\<%\\(by\\|else\\|t\\(o\\|hen\\)\\)\\>"
430 font-lock-constant-face
)
432 ;; SAS dataset options/PROC statements followed by an equal sign/left parentheses
436 "\\(attrib\\|by\\|compress\\|d\\(ata\\|rop\\)\\|f\\(irstobs\\|ormat\\)"
437 "\\|i\\(d\\|f\\|n\\)\\|ke\\(ep\\|y\\)\\|l\\(abel\\|ength\\)"
438 "\\|o\\(bs\\|rder\\|ut\\)\\|rename\\|s\\(ortedby\\|plit\\)"
441 font-lock-keyword-face
)
442 (cons "\\<\\(in\\(:\\|dex[ \t]*=\\)?\\|until\\|wh\\(en\\|ile\\)\\)[ \t]*("
443 font-lock-keyword-face
)
447 "\\(^[0-9]*\\|):\\|[;,]\\|then\\|else\\)[ \t]*"
448 "\\(a\\(bort\\|rray\\|ttrib\\)\\|by"
449 "\\|c\\(hange\\|lass\\|ontrast\\)"
450 "\\|d\\(elete\\|isplay\\|m\\|o\\([ \t]+\\(data\\|over\\)\\)?\\|rop\\)"
451 "\\|e\\(rror\\|stimate\\|xc\\(hange\\|lude\\)\\)"
452 "\\|f\\(ile\\(name\\)?\\|o\\(otnote\\(10?\\|[2-9]\\)?\\|rmat\\)\\|req\\)"
453 "\\|go\\([ \t]*to\\|ptions\\)"
454 "\\|i\\(d\\|f\\|n\\(dex\\|f\\(ile\\|ormat\\)\\|put\\|value\\)\\)"
455 "\\|keep\\|l\\(abel\\|ength\\|i\\(bname\\|nk\\|st\\)\\|smeans\\)"
456 "\\|m\\(anova\\|e\\(ans\\|rge\\)\\|issing\\|od\\(el\\|ify\\)\\)\\|note"
457 "\\|o\\(ptions\\|therwise\\|utput\\)\\|p\\(arms\\|lot\\|ut\\)"
458 "\\|r\\(andom\\|e\\(name\\|peated\\|tain\\)\\)"
459 "\\|s\\(ave\\|e\\(lect\\|t\\)\\|kip\\|trata\\|umby\\)"
460 "\\|t\\(ables?\\|i\\(me\\|tle\\(10?\\|[2-9]\\)?\\)\\)\\|update"
461 "\\|va\\(lue\\|r\\)\\|w\\(eight\\|here\\|i\\(ndow\\|th\\)\\)"
463 ;; IML statements that are not also SAS statements
464 "\\|append\\|c\\(lose\\(file\\)?\\|reate\\)\\|edit\\|f\\(ind\\|orce\\|ree\\)"
465 "\\|insert\\|load\\|mattrib\\|p\\(a[ru]se\\|rint\\|urge\\)"
466 "\\|re\\(move\\|peat\\|place\\|set\\|sume\\)"
467 "\\|s\\(et\\(in\\|out\\)\\|how\\|ort\\|tore\\|ummary\\)\\|use\\)?"
469 "\\>") font-lock-keyword-face
)
473 ;; (cons "\\<\\(\\(then\\|else\\)[ \t]*\\)?\\(do\\([ \t]*over\\)?\\|else\\)\\>"
474 ;; font-lock-keyword-face)
476 ;; SAS statements that must be followed by a semi-colon
478 "\\(^[0-9]*\\|):\\|[;,]\\|then\\|else\\)[ \t]*"
479 "\\(cards4?\\|datalines\\|end\\|l\\(ostcard\\)\\|page\\|return\\|stop\\)?"
480 "[ \t]*;") font-lock-keyword-face
)
482 ;; SAS/GRAPH statements not handled above
484 "\\(^[0-9]*\\|):\\|[;,]\\)[ \t]*"
485 "\\(axis\\|legend\\|pattern\\|symbol\\)"
486 "\\([1-9][0-9]?\\)?\\>") font-lock-keyword-face
)
488 ;; SAS Datastep functions and SAS macro functions
489 ;(cons "%[a-z_][a-z_0-9]*[ \t]*[(;]"
490 ;; SAS macro functions occasionally defined with no arguments
491 ;; which means they can be followed by any character that can
492 ;; separate tokens, however, they are most likely to be followed
493 ;; by operat-ions/ors
494 (cons "%[a-z_][a-z_0-9]*[- \t();,+*/=<>]"
495 font-lock-function-name-face
)
496 (cons "\\<call[ \t]+[a-z_][a-z_0-9]*[ \t]*("
497 font-lock-function-name-face
)
501 "\\(a\\(bs\\|r\\(cos\\|sin\\)\\|tan\\)\\|b\\(etainv\\|yte\\)"
502 "\\|c\\(eil\\|inv\\|o\\(llate\\|mpress\\|sh?\\)\\|ss\\|v\\)"
503 "\\|dacc\\(db\\(\\|sl\\)\\|s\\(l\\|yd\\)\\|tab\\)"
504 "\\|dep\\(db\\(\\|sl\\)\\|s\\(l\\|yd\\)\\|tab\\)"
505 "\\|d\\(a\\(te\\(\\|jul\\|part\\|time\\)\\|y\\)\\|hms\\|i\\(f[0-9]*\\|m\\|gamma\\)\\)"
506 "\\|e\\(rfc?\\|xp\\)"
507 "\\|f\\(i\\(nv\\|p\\(namel?\\|state\\)\\)\\|loor\\|uzz\\)\\|gam\\(inv\\|ma\\)"
508 "\\|h\\(bound\\|ms\\|our\\)\\|i\\(n\\(dexc?\\|put\\|t\\(\\|ck\\|nx\\|rr\\)\\)\\|rr\\)"
509 "\\|juldate\\|kurtosis\\|l\\(ag[0-9]*\\|bound\\|e\\(ft\\|ngth\\)\\|gamma\\|og\\(\\|10\\|2\\)\\)"
510 "\\|m\\(ax\\|dy\\|ean\\|in\\(\\|ute\\)\\|o\\(d\\|nth\\|rt\\)\\)\\|n\\(\\|etpv\\|miss\\|ormal\\|pv\\)"
511 "\\|prob\\([ft]\\|b\\(eta\\|nml\\)\\|chi\\|gam\\|hypr\\|it\\|n\\(egb\\|orm\\)\\)"
512 "\\|ordinal\\|p\\(oisson\\|ut\\)\\|qtr\\|r\\(e\\(peat\\|verse\\)\\|ight\\|ound\\)"
513 "\\|ran\\(bin\\|cau\\|exp\\|g\\(am\\|e\\)\\|k\\|nor\\|poi\\|t\\(bl\\|ri\\)\\|uni\\)"
514 "\\|s\\(aving\\|can\\|econd\\|i\\(gn\\|nh?\\)\\|qrt\\|t\\(d\\(\\|err\\)\\|fips\\|namel?\\)\\|u\\(bstr\\|m\\)\\|ymget\\)"
515 "\\|t\\(anh?\\|i\\(me\\(\\|part\\)\\|nv\\)\\|oday\\|r\\(anslate\\|i\\(gamma\\|m\\)\\|unc\\)\\)"
516 "\\|u\\(niform\\|pcase\\|ss\\)\\|v\\(ar\\|erify\\)"
517 "\\|weekday\\|y\\(ear\\|yq\\)\\|zip\\(fips\\|namel?\\|state\\)"
519 ;;; ;; SAS functions introduced in Technical Report P-222
521 "\\|airy\\|b\\(and\\|lshift\\|not\\|or\\|rshift\\|xor\\)"
522 "\\|c\\(nonct\\|ompbl\\)\\|d\\(airy\\|equote\\)\\|fnonct\\|tnonct"
523 "\\|i\\(bessel\\|n\\(dexw\\|put[cn]\\)\\)\\|jbessel\\|put[cn]"
524 "\\|lowcase\\|quote\\|resolve\\|s\\(oundex\\|ysprod\\)\\|tr\\(anwrd\\|imn\\)"
526 ;;; ;; IML functions that are not also Datastep functions
527 "\\|a\\(ll\\|ny\\|pply\\|rmasim\\)\\|b\\(lock\\|ranks\\|tran\\)"
528 "\\|c\\(har\\|hoose\\|on\\(cat\\|tents\\|vexit\\|vmod\\)\\|ovlag\\|shape\\|usum\\|vexhull\\)"
529 "\\|d\\(atasets\\|esignf?\\|et\\|iag\\|o\\|uration\\)"
530 "\\|e\\(chelon\\|igv\\(al\\|ec\\)\\)\\|f\\(ft\\|orward\\)\\|ginv"
531 "\\|h\\(alf\\|ankel\\|dir\\|ermite\\|omogen\\)"
532 "\\|i\\(\\|fft\\|nsert\\|nv\\(updt\\)?\\)\\|j\\(\\|root\\)\\|loc\\|mad"
533 "\\|n\\(ame\\|col\\|leng\\|row\\|um\\)\\|o\\(pscal\\|rpol\\)"
534 "\\|p\\(olyroot\\|roduct\\|v\\)\\|r\\(anktie\\|ates\\|atio\\|emove\\|eturn\\|oot\\|owcatc?\\)"
535 "\\|s\\(etdif\\|hape\\|olve\\|plinev\\|pot\\|qrsym\\|ssq\\|torage\\|weep\\|ymsqr\\)"
536 "\\|t\\(\\|eigv\\(al\\|ec\\)\\|oeplitz\\|race\\|risolv\\|ype\\)"
537 "\\|uni\\(on\\|que\\)\\|v\\(alue\\|ecdiag\\)\\|x\\(mult\\|sect\\)\\|yield"
539 ;;; ;; SCL functions that are known to work with SAS macro function %sysfunc
541 "\\|attr[cn]\\|c\\(exist\\|lose\\)\\|d\\(close\\|num\\|open\\|read\\)"
542 "\\|exist\\|f\\(close\\|etchobs\\|i\\(leexist\\|nfo\\)\\|open\\|put\\|write\\)"
543 "\\|get\\(option\\|var[cn]\\)\\|lib\\(name\\|ref\\)\\|op\\(en\\|t\\(getn\\|setn\\)\\)"
544 "\\|pathname\\|sysmsg\\|var\\(fmt\\|l\\(abel\\|en\\)\\|n\\(ame\\|um\\)\\|type\\)\\)"
545 "[ \t]*(") font-lock-function-name-face
)
547 "Font Lock regexs for SAS.")
550 (defvar SAS-editing-alist
551 '((sentence-end .
";[\t\n */]*")
552 (paragraph-start .
"^[ \t]*$")
553 (paragraph-separate .
"^[ \t]*$")
554 (paragraph-ignore-fill-prefix . t
)
555 ;;(fill-paragraph-function . 'lisp-fill-paragraph)
556 (adaptive-fill-mode . nil
)
557 (indent-line-function .
'sas-indent-line
)
558 ;;(indent-region-function . 'sas-indent-region)
559 (require-final-newline . t
)
560 (comment-start .
"** ")
561 (comment-start-skip .
"[*][*] ")
562 (comment-end .
" **;")
563 (comment-end-skip .
" [*][*];")
564 (comment-column .
40)
565 ;;(comment-indent-function . 'lisp-comment-indent)
566 (parse-sexp-ignore-comments . t
)
567 (ess-set-style . ess-default-style
)
568 (ess-local-process-name . nil
)
569 ;;(ess-keep-dump-files . 'ask)
570 (tab-stop-list . ess-sas-tab-stop-list
)
571 (ess-mode-syntax-table . SAS-syntax-table
)
572 (font-lock-keywords-case-fold-search . t
)
573 (font-lock-defaults .
'(SAS-mode-font-lock-keywords)))
574 "General options for editing SAS source files.")
576 (defun beginning-of-sas-statement (arg &optional comment-start
)
577 "Move point to beginning of current sas statement."
581 (if (search-forward ";" nil
1) (forward-char -
1))
582 (re-search-backward ";[ \n*/]*$" (point-min) 1 arg
)
583 (skip-chars-forward sas-comment-chars
)
584 (if comment-start nil
585 (if (looking-at "\\*/")
586 (progn (forward-char 2)
587 (skip-chars-forward sas-comment-chars
)))
588 (while (looking-at "/\\*")
589 (if (not (search-forward "*/" pos t
1)) ;;(;; (point-max) 1 1)
591 (skip-chars-forward sas-white-chars
)))))
593 (defun sas-indent-line ()
594 "Indent function for SAS mode."
596 (let (indent prev-end
597 (pos (- (point-max) (point)))
599 (cur-ind (current-indentation))
600 (comment-col (sas-comment-start-col))) ;; 2/1/95 TDC
603 (back-to-indentation)
606 "data[ ;]\\|proc[ ;]\\|run[ ;]\\|endsas[ ;]\\|g?options[ ;]\\|%macro[ ;]\\|%mend[ ;]")))
607 ;; Case where current statement is DATA, PROC, etc...
608 (setq prev-end
(point))
609 (goto-char (point-min))
611 ;; May get fooled if %MACRO, %DO, etc embedded in comments
613 (+ (* (- (sas-how-many "^[ \t]*%macro\\|[ \t]+%do"
615 (sas-how-many "^[ \t]*%mend\\|%end" prev-end
))
616 sas-indent-width
) comment-col
))) ;; 2/1/95 TDC
617 ;; Case where current line begins with sas-indent-ignore-comment
618 ;; added 6/27/94 to leave "* ;" comments alone.
620 (back-to-indentation)
621 (and (not (looking-at "*/"))
622 (looking-at (concat sas-indent-ignore-comment
"\\|/\\*"))))
623 (setq indent
(current-indentation)))
624 ;; Case where current statement not DATA, PROC etc...
625 (t (beginning-of-line 1)
626 (skip-chars-backward sas-white-chars
)
630 ((looking-at ";") ; modified 1/31/95
631 (setq indent
(sas-next-statement-indentation)))
632 ((save-excursion;; added 4/28/94 to properly check
633 (if (bobp) () (backward-char 1));; for end of comment
634 (setq prev-end
(point))
635 (looking-at "*/"));; improved 1/31/95
637 (search-backward "*/"
638 (point-min) 1 1); comment start is first /*
640 prev-end
1 1) ; after previous */
641 (backward-char 2) ; 2/1/95 TDC
642 (skip-chars-backward sas-white-chars
)
646 (sas-next-statement-indentation)
647 (+ (current-indentation) sas-indent-width
))))))
649 ;; added 6/27/94 to leave "* ;" comments alone
652 (beginning-of-sas-statement 1 t
)
653 (and (not (looking-at "*/"))
654 (looking-at sas-indent-ignore-comment
))))
655 (setq indent cur-ind
))
657 (beginning-of-sas-statement 1)
658 (bobp));; added 4/13/94
659 (setq indent sas-indent-width
));; so the first line works
663 (beginning-of-line 1)
664 (skip-chars-backward sas-white-chars
)
665 (if (bobp) nil
(backward-char 1))
667 (bobp) (backward-char 1) (looking-at "\\*/"))))
668 (setq indent
(+ (current-indentation) sas-indent-width
))
669 (setq indent
(current-indentation))))))))
672 (back-to-indentation)
674 (beginning-of-line 1)
676 (delete-region beg end
)
678 (if (> (- (point-max) pos
) (point))
679 (goto-char (- (point-max) pos
)))))
682 ;;(defun sas-indent-region (start end)
683 ;; "Indent a region of SAS code."
686 ;; (let ((endmark (copy-marker end)))
688 ;; (and (bolp) (not (eolp))
689 ;; (sas-indent-line))
690 ;; (indent-sexp endmark)
691 ;; (set-marker endmark nil))))
694 (defun indent-sas-statement (arg)
695 "Indent all continuation lines sas-indent-width spaces from first
701 (while (and (> arg
0) (search-forward ";" (point-max) 1 1))
703 (if (bobp) nil
(backward-char 1))
704 (beginning-of-sas-statement 1)
706 (indent-region (point)
708 (+ (current-column) (1- sas-indent-width
)))
709 (search-forward ";" (point-max) 1 1)
710 (setq arg
(1- arg
)))))))
713 (defun sas-next-statement-indentation ()
714 "Returns the correct indentation of the next sas statement.
715 The current version assumes that point is at the end of the statement.
716 This will (hopefully) be fixed in later versions."
719 (let ((prev-end (point)))
720 (beginning-of-sas-statement 1)
721 (while (and (not (bobp))
722 (not (looking-at "*/"))
723 (looking-at sas-indent-ignore-comment
))
724 (skip-chars-backward sas-white-chars
)
727 (setq prev-end
(point))
728 (beginning-of-sas-statement 1 t
))
731 "data[ \n\t;]\\|proc[ \n\t]\\|%?do[ \n\t;]\\|%macro[ \n\t]\\|/\\*")
734 "\\b%?then\\>[ \n\t]*\\b%?do\\>\\|\\b%?else\\>[ \n\t]*\\b%?do\\>"
735 prev-end
1 1))) ; fixed 1/30/95 to avoid being fooled by
736 ; variable names starting with "do"
737 (+ (current-indentation) sas-indent-width
)
738 (if (looking-at "%?end[ ;\n]\\|%mend[ ;\n]\\|\\*/")
739 (max (- (current-indentation) sas-indent-width
) 0)
740 (current-indentation)))))))
743 (defun sas-comment-start-col ()
744 "If the current line is inside a /* */ comment, returns column in which the
745 opening /* appears. returns 0 otherwise."
748 (if (and (search-backward "*/" (point-min) 1 1)
749 (search-forward "/*" pos
1 1))
750 (current-indentation)
754 ;; Created 6/27/94 to verify that RUN; statements match PROC and DATA
755 ;; statements. Useful since indentation my be goofy w/o "RUN;"
756 (defun sas-check-run-statements ()
757 "Check to see that \"run\" statements are matched with proc, data statements."
765 (if (re-search-forward
766 "\\(^[ \t]*run[ ;]\\)\\|\\(^[ \t]*proc \\|^[ \t]*data[ ;]\\)"
768 (if (match-beginning 2)
769 (if (re-search-forward
770 "\\(^[ \t]*run[ ;]\\)\\|\\(^[ \t]*proc \\|^[ \t]*data[ ;]\\)"
772 (progn (setq pos
(point))
773 (setq ok
(match-beginning 1)))
774 (setq eob-ok nil pos
(point-max))))
777 (if (and ok eob-ok
) (message "Run statements match")
780 (message "Missing Run Statement."))))
783 (defun sas-fix-life-tables (start end
)
784 "Remove censored and duplicate observations from life tables generated by
785 Proc Lifetest. Operates on current region. A major space saver if there is
789 (shell-command-on-region
791 "sed \"\\? *\\. *\\. *\\. ?d\"" t
)))
793 ;;(setq ex-g-flag nil
795 ;;(vip-ex "1,$g/ \\. \\. \\. /d")))
797 (defun sas-fix-page-numbers (offset &optional page-num
)
798 "Fix number of current page in sas output files after editing. Add
799 OFFSET to actual page number."
801 (if (not offset
) (setq offset
0))
802 (if (not page-num
) (setq page-num
(sas-page-number)))
804 (if (/= (preceding-char) ?\C-l
) (backward-page 1))
805 (let (end len mstart mend
)
807 (forward-line sas-page-number-max-line
)
809 (if (re-search-forward
810 "\\(^[0-9]+[ ]\\)\\|\\([ ][0-9]+$\\)"
812 (progn (setq len
(- (match-end 0) (match-beginning 0))
813 mstart
(match-beginning 0)
815 (delete-region mstart mend
)
818 (concat "%" len
"d") (+ page-num offset
)))
820 (concat (+ (sas-page-number) offset
) " ")
823 (defun sas-page-fix (start)
824 "Fix page numbers in sas output from point to end of file.
825 If START is given this will be the number for the current page."
827 (let (offset (pnum (sas-page-number)))
828 (if (not start
) (setq offset
0)
829 (setq offset
(- start pnum
)))
831 (sas-fix-page-numbers offset pnum
)
832 (setq pnum
(1+ pnum
))
835 (defun fix-page-breaks ()
836 "Fix page breaks in SAS 6 print files."
839 (goto-char (point-min))
840 (if (looking-at "\f") (delete-char 1))
841 (replace-regexp "^\\(.+\\)\f" "\\1\n\f\n")
842 (goto-char (point-min))
843 (replace-regexp "^\f\\(.+\\)" "\f\n\\1")
844 (goto-char (point-min))
847 (goto-char (point-min))
851 (goto-char (point-max))
853 (progn (backward-char 1)
854 (if (not (looking-at "\n"))
855 (progn (forward-char 1) (open-line 1)))))))
857 (defun sas-page-number ()
858 ;; like what-page except it returns an integer page number
859 "Return page number of point in current buffer."
860 (let ((opoint (point))) (save-excursion
861 (goto-char (point-min))
862 (1+ (sas-how-many page-delimiter opoint
)))))
864 (defun sas-how-many (regexp &optional end
)
865 ;; a copy of `how-many' which returns an integer
866 ;; rather than a message
867 "Return number of matches for REGEXP following point."
868 (let ((count 0) opoint
)
870 (while (and (not (eobp))
871 (progn (setq opoint
(point))
872 (re-search-forward regexp end t
)))
873 (if (= opoint
(point))
875 (setq count
(1+ count
))))
878 (defun beginning-of-sas-proc ()
879 "Move point to beginning of sas proc, macro or data step."
881 (let ((case-fold-search t
))
883 (while (not (or (looking-at "data\\|proc\\|%macro")
885 (re-search-backward "proc\\|data\\|%macro" (point-min) 1)
886 (beginning-of-sas-statement 1))))
888 (defun next-sas-proc (arg)
889 "Move point to beginning of next sas proc."
891 (let ((case-fold-search t
))
893 (if (re-search-forward
894 "^[ \t]*\\(data[ ;]\\|proc[ ;]\\|endsas[ ;]\\|g?options[ ;]\\|%macro[ ;]\\)"
896 (beginning-of-sas-statement 1)
899 (defun set-sas-file-name ()
900 "Stores the name of the current sas file."
901 (let ((name (buffer-file-name)))
903 ((string-match (substring name -
4 nil
)
904 "\\.sas\\|\\.lst\\|\\.log")
906 (setq sas-file-name
(substring name
0 (- (length name
) 4)))
907 (setq sas-buffer-name
(buffer-name))
908 (setq sas-file-root
(substring sas-buffer-name
0
909 (- (length sas-buffer-name
) 4))))
910 (t (message "This file does not have a standard suffix")))))
913 (defun sas-set-alternate-file-name (name)
914 "Stores the NAME of an alternate sas file.
915 When this file is submitted with `submit-sas', the alternate file will
916 be submitted instead. `sas-submitable' is automatically sets to t."
918 (cond ((string-match (substring name -
4 nil
)
919 "\\.sas\\|\\.lst\\|\\.log")
920 (setq sas-file-name
(substring name
0 (- (length name
) 4)))
921 (setq sas-submitable t
))
922 (t (message "This file does not have a standard suffix"))))
924 (defun switch-to-sas-source ()
925 "Switches to sas source file associated with the current file."
927 (switch-to-sas-file "sas"))
929 (defun switch-to-sas-lst ()
930 "Switches to sas source file associated with the current file."
932 (switch-to-sas-file "lst"))
934 (defun switch-to-sas-log ()
935 "Switches to sas source file associated with the current file."
937 (switch-to-sas-file "log"))
939 (defun switch-to-sas-source-other-window ()
940 "Switches to sas source file associated with the current file."
942 (switch-to-sas-file-other-window "sas"))
944 (defun switch-to-sas-lst-other-window ()
945 "Switches to sas source file associated with the current file."
947 (switch-to-sas-file-other-window "lst"))
949 (defun switch-to-sas-log-other-window ()
950 "Switches to sas source file associated with the current file."
952 (switch-to-sas-file-other-window "log"))
954 ;;(defun switch-to-sas-file (suff &optional revert silent)
955 ;; "Switches to sas \"SUFF\" file associated with the current file"
956 ;; (let* ((sfile sas-file-name)
957 ;; (buf (get-file-buffer (concat sfile "." suff)))
958 ;; (sas-require-confirmation
959 ;; (and sas-require-confirmation (not revert))))
960 ;; (if (or sas-require-confirmation (string-equal suff "sas") (not buf))
961 ;; (find-file (concat sfile "." suff))
962 ;; (progn (switch-to-buffer buf)
963 ;; (if (not (verify-visited-file-modtime (current-buffer)))
964 ;; (progn (revert-buffer t t)
966 ;; (message "File has changed on disk. Buffer automatically updated."))))))
967 ;; (setq sas-file-name sfile))
968 ;; (if (string-equal suff "sas")
969 ;; (if (not (string-equal major-mode "sas-mode"))
971 ;; (if (not (string-equal major-mode "sasl-mode"))
974 ;;(defun switch-to-sas-file-other-window (suff)
975 ;; "Switches to sas \"SUFF\" file associated with the current file"
976 ;; (let* ((sfile sas-file-name)
977 ;; (buf (get-file-buffer (concat sfile "." suff))))
978 ;; (if (or sas-require-confirmation (string-equal suff "sas") (not buf))
979 ;; (find-file-other-window (concat sfile "." suff))
980 ;; (progn (switch-to-buffer-other-window buf)
981 ;; (if (not (verify-visited-file-modtime (current-buffer)))
982 ;; (progn (revert-buffer t t)
983 ;; (message "File has changed on disk. Buffer automatically updated.")))))
984 ;; (setq sas-file-name sfile))
985 ;; (if (string-equal suff "sas")
986 ;; (if (not (string-equal major-mode "sas-mode"))
989 ;; (if (not (string-equal major-mode "sasl-mode"))
993 (defun switch-to-sas-file (suff)
994 "Switches to sas \"SUFF\" file associated with the current file."
995 (switch-to-buffer (set-sas-file-buffer suff
)))
997 (defun switch-to-sas-file-other-window (suff)
998 "Switches to sas \"SUFF\" file associated with the current file."
999 (switch-to-buffer-other-window (set-sas-file-buffer suff
)))
1001 ;; The following was created 6/7/94 to handle buffers without messing up
1004 (defun set-sas-file-buffer (suff &optional revert silent
)
1005 "Sets current buffer to sas \"SUFF\" file associated with the current file."
1006 (let* ((sfile sas-file-name
)
1007 (buf (get-file-buffer (concat sfile
"." suff
)))
1008 (sas-require-confirmation
1009 (and sas-require-confirmation
(not revert
))))
1010 (if (or sas-require-confirmation
(string-equal suff
"sas") (not buf
))
1011 (set-buffer (find-file-noselect (concat sfile
"." suff
)))
1012 (progn (set-buffer buf
)
1013 (if (not (verify-visited-file-modtime (current-buffer)))
1014 (progn (revert-buffer t t
)
1016 (message "File has changed on disk. Buffer automatically updated."))))))
1017 (setq sas-file-name sfile
))
1018 ;;(if (string-equal suff "sas")
1019 ;; (if (not (string-equal major-mode "sas-mode")) (sas-mode))
1020 ;; (if (not (string-equal major-mode "sasl-mode"))(sasl-mode))
1023 (defun switch-to-sas-process-buffer ()
1024 "Switch to sas-process-buffer."
1026 (let (buf proc-name
)
1027 (setq proc-name
(concat "SAS" sas-file-name
)
1028 buf
(concat "*" proc-name
"*"))
1029 (switch-to-buffer-other-window buf
)))
1031 (defun submit-sas ()
1032 ;; 6/17/94 added sas-submitable local variable.
1033 "Submit SAS file as shell command."
1035 (if ;; can file be run, or is it only for inclusion?
1041 "Submission is disabled for this file. Submit it anyway? "))))
1043 ;; if buffer name has changed, tell user
1045 (string-equal sas-buffer-name
(buffer-name))
1049 "The name of this buffer has changed. Submit the new file? "))))
1050 (setq sas-buffer-name
(buffer-name))
1051 (set-sas-file-name))
1052 (let ((sas-file sas-file-name
)
1053 (sas-root sas-file-root
)
1054 ;;(sas-buf sas-buffer-name)
1058 ;; Save buffer to SAS the right file :-).
1059 (if (buffer-modified-p)
1060 (if (y-or-n-p (format "Buffer %s is modified. Save it? "
1063 (setq proc-name
(concat "SAS" sas-file
)
1064 buf
(concat "*" proc-name
"*"))
1065 (if (get-buffer buf
)
1066 (save-window-excursion (switch-to-buffer buf
)
1068 (setq default-directory
1069 (file-name-directory sas-file
))))
1071 (run-hooks 'sas-pre-run-hook
) ;; added 8/24/94
1072 (message "---- Submitting SAS job ----")
1073 ;; (switch-to-buffer buf)
1074 (make-comint proc-name
1075 sas-program
;added sas-program 4/29/94
1078 (save-window-excursion
1079 (switch-to-buffer buf
)
1080 (setq sas-file-name sas-file
)
1083 (message "---- SAS job submitted ---- ")
1085 (if sas-notify
;; added 4/7/94
1086 (set-process-sentinel (get-process proc-name
) 'sas-sentinel
)
1087 (display-buffer buf t
))))
1088 (message "---- File not submitted ----")))
1090 ;; 5/2/94 Modified sas-sentinel to check for errors in log file upon
1092 (defun sas-sentinel (proc arg
);; created 4/7/94
1093 "Notify user that SAS run is done."
1095 ;;(if (string-equal arg "finished\n")
1097 (let (msg buf win
(sbuf (concat "*" (process-name proc
) "*")))
1100 (substring arg
0 -
1)
1101 (if sas-error-notify
1102 ;;(save-window-excursion
1105 (setq buf
(set-sas-file-buffer "log" t t
))
1106 (goto-char (point-min))
1107 (setq win
(get-buffer-window buf
))
1108 (save-window-excursion
1112 (if (re-search-forward "^ERROR" nil t
)
1113 " (See .log file for errors)"
1115 (switch-to-buffer buf
)
1116 (if (re-search-forward "^ERROR" nil t
)
1117 " (See .log file for errors)"
1121 (goto-char (point-max))
1123 (bury-buffer (get-buffer sbuf
))
1124 ;;(if (and sas-notify-popup window-system)
1125 ;; (x-popup-dialog t
1126 ;; (list "SAS Menu" (cons msg nil) )))
1127 ;;(if (not (minibuffer-window-active-p)) (princ msg))
1130 ;; 5/2/94 Modified run-sas-on-region to separate log and output buffers.
1132 ;;(defun run-sas-on-region (start end append &optional buffer)
1133 ;; "Submit region to SAS"
1134 ;; (interactive "r\nP")
1135 ;; (message "---- Running SAS ----")
1136 ;; (let ((sfile sas-file-name)
1137 ;; (shell-file-name "/bin/sh")
1139 ;; (setq buffer (or buffer "*SAS output*"))
1141 ;; (shell-command-on-region
1142 ;; start end;; added sas-program
1143 ;; (concat sas-program " -nonews -stdio 2> /tmp/_temp_.log" nil))
1144 ;; (get-buffer-create "*SAS Log*")
1145 ;; (save-window-excursion
1146 ;; (switch-to-buffer "*SAS Log*")
1148 ;; (insert-file-contents "/tmp/_temp_.log")
1149 ;; (delete-file "/tmp/_temp_.log")
1150 ;; (setq serror (re-search-forward "^ERROR" nil t))
1151 ;; (if serror () (bury-buffer)))
1152 ;; (setq buff (get-buffer-create buffer))
1153 ;; (save-window-excursion
1154 ;; (switch-to-buffer buff)
1155 ;; (setq sas-file-name sfile)
1161 ;; (if (get-buffer "*Shell Command Output*")
1162 ;; (progn (insert-buffer "*Shell Command Output*")
1163 ;; (kill-buffer "*Shell Command Output*"))
1164 ;; (insert "SAS completed with no output."))
1165 ;; (if append () (sasl-mode))
1166 ;; (message "---- SAS Complete ----")))
1168 ;; (switch-to-buffer-other-window buff)
1169 ;; (switch-to-buffer-other-window "*SAS Log*")
1170 ;; (goto-char serror)
1172 ;; (message "Error found in log file.")
1175 (defun switch-to-dataset-log-buffer ()
1176 "Switch to log buffer for run-sas-on-region."
1178 (switch-to-buffer-other-window "*SAS Log*"))
1180 (defun switch-to-dataset-source-buffer ()
1181 "Switch to source buffer for run-sas-on-region."
1183 (switch-to-buffer-other-window (format " *sas-tmp-%s*" sas-dataset
)))
1185 ;;(defun sas-get-dataset (filename &optional arg opts-p append buffer vars)
1186 ;; "Run proc contents and proc print on SAS dataset. Automatically prompts
1187 ;;for SAS options to use. Default options are defined by the variable
1188 ;;`sas-get-options'. Output may be updated from within output buffer with
1189 ;;C-cr if dataset changes. Also, the source code which generates the output
1190 ;;may be edited with C-cs. Typing C-cr within the output buffer reexecutes
1191 ;;the (modified) source code."
1192 ;; (interactive "fName of SAS dataset (file name):")
1193 ;; (let ((file (file-name-nondirectory filename))
1194 ;; (dir (file-name-directory filename))
1195 ;; (opts sas-get-options)
1196 ;; (minibuffer-history sas-get-options-history)
1198 ;; (setq buffer (or buffer (concat "*" file "*")))
1199 ;; (setq opts (if opts-p opts (read-string "SAS options: " opts)))
1200 ;; (setq sas-get-options-history minibuffer-history)
1201 ;; (cond ((string-match (substring file -6 nil) "\\.ssd01")
1202 ;; (setq file (substring file 0 (- (length file) 6))))
1203 ;; (t (error "This file is not a SAS dataset.")))
1204 ;; (setq buf (format " *sas-tmp-%s*" file))
1205 ;; (get-buffer-create buf)
1206 ;; (save-window-excursion
1207 ;; (switch-to-buffer buf)
1209 ;; (setq default-directory dir)
1211 ;; (insert (format "options %s ;\n" opts)))
1212 ;; (insert (format "title \"Contents of SAS dataset `%s'\" ;\n" file))
1213 ;; (insert (format "libname %s '%s' ;\n" sas-tmp-libname dir))
1214 ;; (if (not (equal arg 1))
1215 ;; (insert (format "proc contents data = %s.%s ;\n" sas-tmp-libname file)))
1216 ;; (if (equal arg 2) ()
1217 ;; (insert (format "proc print data = %s.%s ;\n" sas-tmp-libname file))
1218 ;; (if vars (insert (format " var %s ;\n" vars))))
1219 ;; (run-sas-on-region (point-min) (point-max) append
1221 ;; (get-buffer buffer)
1222 ;; (if append () (sasd-mode)) ;; added 5/5/94
1223 ;; (setq sas-dataset file))
1224 ;; (if (get-buffer-window buffer t)
1225 ;; (raise-frame (window-frame (get-buffer-window buffer t)))
1226 ;; (display-buffer buffer (not append)))
1229 ;;(defun revert-sas-dataset ()
1230 ;; "Revert current sas dataset from disk version"
1232 ;; (let* ((file sas-dataset)
1233 ;; (buf (format " *sas-tmp-%s*" file))
1235 ;; (save-window-excursion
1236 ;; (switch-to-buffer buf)
1237 ;; (run-sas-on-region (point-min) (point-max) nil
1238 ;; (concat "*" file ".ssd01*"))
1240 ;; (goto-char pos) ;; added 6/9/94
1241 ;; (sasd-mode) ;; added 5/5/94
1242 ;; (setq sas-dataset file)))
1244 (defun sas-insert-local-variables () ;; created 6/17/94
1245 "Add local variables code to end of sas source file."
1248 (if (re-search-forward "* *Local Variables: *;" nil t
)
1250 (goto-char (point-max))
1253 ** Local Variables: ;
1261 ;;; file name: sas-data.el
1265 ;;; sas-data-mode: manage sas datasets
1266 ;;; Copyright (C) 1994 Tom Cook
1268 ;;; This program is free software; you can redistribute it and/or modify
1269 ;;; it under the terms of the GNU General Public License as published by
1270 ;;; the Free Software Foundation; either version 2 of the License, or
1271 ;;; (at your option) any later version.
1273 ;;; This program is distributed in the hope that it will be useful,
1274 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1275 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1276 ;;; GNU General Public License for more details.
1278 ;;; You should have received a copy of the GNU General Public License
1279 ;;; along with this program; if not, write to the Free Software
1280 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1282 ;;; Author: Tom Cook
1283 ;;; Dept. of Biostatistics
1284 ;;; University of Wisconsin - Madison
1285 ;;; Madison, WI 53706
1286 ;;; cook@biostat.wisc.edu
1289 ;; variables section
1290 (defvar sas-dir-mode-map nil
)
1291 (defvar sas-directory-name nil
1292 "Name of directory associated with this buffer.")
1293 (make-variable-buffer-local 'sas-directory-name
)
1294 (defvar sas-dir-buf-end nil
)
1295 (make-variable-buffer-local 'sas-dir-buf-end
)
1296 (defvar sas-sorted-by-num nil
)
1297 (make-variable-buffer-local 'sas-sorted-by-num
)
1302 (if sas-dir-mode-map
()
1303 (setq sas-dir-mode-map
(make-sparse-keymap))
1304 ;;(define-key sas-dir-mode-map "c" 'sas-contents)
1305 (define-key sas-dir-mode-map
"p" 'sas-print
)
1306 (define-key sas-dir-mode-map
"m" 'sas-mark-item
)
1307 (define-key sas-dir-mode-map
"u" 'sas-unmark-item
)
1308 (define-key sas-dir-mode-map
" " 'sas-next-line
)
1309 (define-key sas-dir-mode-map
"\C-n" 'sas-next-line
)
1310 (define-key sas-dir-mode-map
"\C-p" 'sas-prev-line
)
1311 (define-key sas-dir-mode-map
"\177" 'sas-prev-line-undo
)
1312 (define-key sas-dir-mode-map
"\C-b" 'sas-backward-page-narrow
)
1313 (define-key sas-dir-mode-map
"\C-v" 'sas-forward-page-narrow
)
1314 (define-key sas-dir-mode-map
"\C-m" 'sas-goto-dataset
)
1315 (define-key sas-dir-mode-map
[mouse-2
] 'sas-mouse-goto-dataset
)
1316 (define-key sas-dir-mode-map
"t" 'sas-dir-goto-page
)
1317 (define-key sas-dir-mode-map
"q" 'bury-buffer
)
1318 (define-key sas-dir-mode-map
"g" 'sas-revert-library
)
1319 (define-key sas-dir-mode-map
"1" 'digit-argument
)
1320 (define-key sas-dir-mode-map
"2" 'digit-argument
)
1321 (define-key sas-dir-mode-map
"3" 'digit-argument
)
1322 (define-key sas-dir-mode-map
"4" 'digit-argument
)
1323 (define-key sas-dir-mode-map
"5" 'digit-argument
)
1324 (define-key sas-dir-mode-map
"6" 'digit-argument
)
1325 (define-key sas-dir-mode-map
"7" 'digit-argument
)
1326 (define-key sas-dir-mode-map
"8" 'digit-argument
)
1327 (define-key sas-dir-mode-map
"9" 'digit-argument
)
1328 (define-key sas-dir-mode-map
[menu-bar sas run
]
1329 '("Submit File " . submit-sas
))
1334 (defun sas-dir-mode ()
1335 "Major mode for managing sas files."
1337 (kill-all-local-variables)
1338 (use-local-map sas-dir-mode-map
)
1339 (setq major-mode
'sas-dir-mode
)
1340 (setq mode-name
"SAS")
1341 (setq sas-directory-name
(expand-file-name default-directory
))
1342 (toggle-read-only 1))
1345 ;;(defun sas-make-library (directory &optional update)
1346 ;; "Create a buffer with the names of all sas datasets from DIRECTORY."
1347 ;; (interactive "DDirectory Name: ")
1348 ;; (let ((dir (expand-file-name directory)) buf out cont pos)
1349 ;; (setq buf (format " *sas-tmp-%s*" dir))
1350 ;; (setq out (concat "*SAS-dir-" dir))
1351 ;; (setq cont (concat "*SAS-cont-" dir))
1352 ;; (get-buffer-create buf)
1353 ;; (if (get-buffer out)
1357 ;; (setq buffer-read-only nil)))
1359 ;; (pop-to-buffer out)
1360 ;; (setq default-directory dir)
1361 ;; (setq pos (point))
1364 ;; (save-window-excursion
1367 ;; (setq default-directory dir)
1368 ;; (insert "options linesize=70 pagesize=1000 ;\n")
1369 ;; (insert (format "title \"Contents of SAS directory `%s'\" ;\n"
1371 ;; (insert (format "libname %s '%s' ;\n" sas-tmp-libname dir))
1372 ;; (insert (format "proc contents data = %s._all_ directory details memtype=data ;\n" sas-tmp-libname))
1373 ;; (run-sas-on-region (point-min) (point-max) nil
1376 ;; (goto-char (point-min))
1377 ;; (if (= (sas-how-many page-delimiter (point-max)) 0)
1378 ;; (let ((buffer-read-only nil))
1380 ;; (insert "There are no SAS datasets in this directory")
1381 ;; (pop-to-buffer out))
1383 ;; (set-buffer (get-buffer-create cont))
1384 ;; (setq buffer-read-only t)
1385 ;; (let ((buffer-read-only nil))
1387 ;; (insert-buffer out)
1388 ;; (delete-region (point-min)
1389 ;; (or (re-search-forward page-delimiter nil t)
1392 ;; (goto-char (point-min))
1394 ;; (sas-narrow-to-page)))
1395 ;; (if (re-search-forward page-delimiter nil t)
1396 ;; (delete-region (progn (beginning-of-line) (point))
1398 ;; (sas-insert-set-properties (point-min) (point-max))
1400 ;; (switch-to-buffer out t)
1401 ;; (goto-char (point-min))
1403 ;; (setq sas-dir-buf-end (point-max)))
1405 ;; (sas-move-to-filename (point-max))))))
1408 (defun sas-move-to-filename (&optional eol
)
1409 (or eol
(setq eol
(progn (end-of-line) (point))))
1411 (if (re-search-forward "\\(^ *[0-9]+ *<*\\)[^:0-9\n]" eol t
)
1412 (goto-char (match-end 1))))
1414 (defun sas-next-line (arg)
1415 "Move down one line."
1418 (sas-move-to-filename (point-max)))
1419 ;;(and (< (point) sas-dir-buf-end)
1420 ;;(forward-line arg)
1421 ;;(sas-move-to-filename sas-dir-buf-end)))
1423 (defun sas-prev-line (arg)
1427 (re-search-backward "^ *[0-9]+ *<*[^:0-9\n]" (point-min) t
)
1428 (sas-move-to-filename sas-dir-buf-end
))
1430 (defun sas-insert-set-properties (beg end
)
1433 (while (< (point) end
)
1434 (if (sas-move-to-filename)
1435 (put-text-property (point)
1437 'mouse-face
'highlight
))
1440 (defun sas-get-filename ()
1441 "Return name of dataset on current line."
1444 (if (string-equal "*SAS-dir" (substring (buffer-name) 0 8))
1445 (sas-move-to-filename)
1446 (goto-char (point-min))
1447 (re-search-forward "Data Set Name: [^.]*\\."))
1449 (downcase (concat sas-directory-name
1453 (skip-chars-forward "A-Z0-9_")
1454 (point))) ".ssd01")))))
1456 (defun sas-get-file-number ()
1457 "Return name of dataset on current line."
1459 (if (sas-move-to-filename)
1460 (progn (forward-word -
1)
1461 (re-search-forward "[0-9]*")
1463 (buffer-substring (match-beginning 0)
1466 ;;(defun sas-contents ()
1467 ;; "Run proc contents on current file."
1469 ;; (let ((buffer-read-only nil) (sas-get-options "linesize=70"))
1470 ;; (sas-get-dataset (sas-get-filename) 2 t t (buffer-name))
1472 ;; (backward-page-top-of-window 1)))
1474 ;;(defun sas-print ()
1475 ;; "Run proc contents on current file."
1477 ;; (sas-get-dataset (sas-get-filename) 1 nil nil nil
1478 ;; (sas-create-var-string)))
1480 (defun sas-goto-page (arg)
1481 "Goto top of page ARG. If no ARG, then goto top of file."
1487 (re-search-forward page-delimiter
(point-max) 1 (1- arg
)))))
1488 (skip-chars-forward sas-white-chars
); was " \f\n" till 5.1.13
1491 (defun forward-page-top-of-window (arg)
1492 "Move forward to page boundary and leave first line at top of window.
1493 With arg, repeat, or go back if negative. A page boundary is any line
1494 whose beginning matches the regexp `page-delimiter'."
1499 (defun backward-page-top-of-window (arg)
1500 "Move backward to page boundary and leave first line at top of window.
1501 With arg, repeat, or go back if negative. A page boundary is any line
1502 whose beginning matches the regexp `page-delimiter'."
1504 (forward-page (- arg
))
1507 (defun sas-narrow-to-page ()
1509 (let* ((min (point-min))
1511 ;;(omin (point-min))
1512 ;;(omax (point-max)))
1513 (if (or (bolp) (beginning-of-line)
1514 (looking-at page-delimiter
))
1521 (narrow-to-region min max
))))
1523 (defun sas-forward-page-narrow (arg)
1524 "Move forward to page boundary and narrow to page.
1525 With arg, repeat, or go back if negative. A page boundary is any line
1526 whose beginning matches the regexp `page-delimiter'."
1530 (sas-narrow-to-page)
1531 (goto-char (point-min)))
1533 (defun sas-backward-page-narrow (arg)
1534 "Move backward to page boundary and narrow to page.
1535 With arg, repeat, or go back if negative. A page boundary is any line
1536 whose beginning matches the regexp `page-delimiter'."
1538 (goto-char (point-min))
1540 (forward-page (- arg
))
1541 (sas-narrow-to-page))
1543 (defun sas-goto-dataset (&optional page
)
1545 (and sas-directory-name
1546 (let ((page (or page
(sas-get-file-number))))
1547 ;;(dir sas-directory-name))
1550 (switch-to-buffer-other-window
1551 (concat "*SAS-cont-" sas-directory-name
))
1553 (sas-goto-page page
)
1554 (sas-narrow-to-page)
1555 (goto-char (point-min)))))))
1557 ;;(defun sas-mouse-goto-dataset (event)
1558 ;; (interactive "e")
1560 ;; (save-window-excursion
1562 ;; (set-buffer (window-buffer (posn-window (event-end event))))
1564 ;; (goto-char (posn-point (event-end event)))
1565 ;; (setq page (sas-get-file-number)))
1566 ;; (sas-goto-dataset page)
1567 ;; (setq buf (buffer-name))))
1569 ;; (goto-char (point-min))
1570 ;; (display-buffer buf)))
1573 (defun sas-dir-goto-page (page)
1576 (sas-goto-page page
)
1577 (sas-narrow-to-page))
1579 (defun sas-mark-item (&optional next
)
1581 (sas-move-to-filename)
1583 (let ((buffer-read-only nil
))
1584 (if (re-search-forward "^\\( *[0-9]+ *\\) \\([A-Z][A-Z_0-9]*\\) "
1585 (save-excursion (end-of-line) (point)) t
)
1586 (replace-match "\\1<\\2>")))
1587 (or next
(sas-next-line 1)))
1589 (defun sas-unmark-item ()
1593 (let ((buffer-read-only nil
))
1594 (if (re-search-forward "^\\( *[0-9]+ *\\)<\\([A-Z][A-Z_0-9]*\\)>"
1595 (save-excursion (end-of-line) (point)) t
)
1596 (replace-match "\\1 \\2 ")))))
1598 (defun sas-prev-line-undo (arg)
1602 (sas-move-to-filename))
1604 (defun sas-create-var-string ()
1605 (and (string-equal "*SAS-cont" (substring (buffer-name) 0 9))
1607 (goto-char (point-min))
1609 (re-search-forward "^\\( *[0-9]+ *\\)<\\([A-Z][A-Z_0-9]*\\)>"
1611 (setq str
(concat str
" " (buffer-substring (match-beginning 2)
1615 ;;(defun sas-revert-library ()
1616 ;; "Update current library."
1618 ;; (if sas-directory-name
1619 ;; (sas-make-library sas-directory-name t)))
1623 \f ; Local variables section
1625 ;;; This file is automatically placed in Outline minor mode.
1626 ;;; The file is structured as follows:
1629 ;;; Subsections: ;;;*;;;
1630 ;;; Components: defuns, defvars, defconsts
1631 ;;; Random code beginning with a ;;;;* comment
1632 ;;; Local variables:
1633 ;;; mode: emacs-lisp
1634 ;;; mode: outline-minor
1635 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
1638 ;;; essl-sas.el ends here