ESS[SAS]: somebody forgot about the SUM statement (probably me)
[ess.git] / lisp / essl-sas.el
blob26bbca4a7ebc2f43d7b9ccda068875b74ce35e00
1 ;;; essl-sas.el --- SAS customization
3 ;; Copyright (C) 1997--2008 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)
19 ;; any later version.
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.
30 ;;; Commentary:
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
36 ;;; Author: Tom Cook
37 ;;; Dept. of Biostatistics
38 ;;; University of Wisconsin - Madison
39 ;;; Madison, WI 53706
40 ;;; cook@biostat.wisc.edu
41 ;;;
42 ;;; Acknowledgements:
43 ;;; Menu code for XEmacs/Lucid emacs and startup mods
44 ;;; contributed by arossini@biostats.hmc.psu.edu
45 ;;;
46 ;;; Last change: 2/1/95
47 ;;; Last change: 01/15/02
49 (ess-message "[essl-sas:] (require 'ess) ...")
50 (require 'ess)
51 (ess-message "[essl-sas:] (require 'ess-mode) ...")
52 (require 'ess-mode)
53 (require 'ess-cust)
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
75 on this mode."
76 (interactive "P")
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
88 the mode line."
89 (interactive "P")
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."
99 (interactive)
100 (SAS-mode)
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."
106 (interactive)
107 (fundamental-mode)
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."
120 :group 'ess-sas
121 :type 'integer)
123 (defcustom sas-indent-ignore-comment "*"
124 "*Comments that start with this string are ignored in indentation."
125 :group 'ess-sas
126 :type 'string)
128 (defcustom sas-require-confirmation t
129 "*Require confirmation when revisiting a modified sas-output file."
130 :group 'ess-sas
131 :type 'boolean)
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'."
137 :group 'ess-sas
138 :type 'string)
140 (defcustom sas-pre-run-hook nil
141 "Hook to execute prior to running SAS via `submit-sas'."
142 :group 'ess-sas
143 :type 'hook)
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."
148 ; :group 'ess-sas
149 ; :type 'string)
151 (defcustom sas-notify t
152 "*Beep and display message when job is done."
153 :group 'ess-sas
154 :type 'boolean)
156 (defcustom sas-error-notify t
157 "*If `sas-notify' t, indicate errors in log file upon completion."
158 :group 'ess-sas
159 :type 'boolean)
161 (defcustom sas-get-options nil
162 "Options to be passed to SAS in sas-get-dataset."
163 :group 'ess-sas
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."
168 :group 'ess-sas)
170 (defcustom sas-page-number-max-line 3
171 "*Number of lines from the page break, to search for the page
172 number."
173 :group 'ess-sas
174 :type 'integer)
176 (defcustom sas-notify-popup nil
177 "*If this and sas-notify are t), popup a window when SAS job ends."
178 :group 'ess-sas
179 :type 'boolean)
181 (defcustom sas-tmp-libname "_tmp_"
182 "*Libname to use for sas-get-dataset."
183 :group 'ess-sas
184 :type 'string)
186 (defcustom sas-file-name nil
187 "*The name of the current sas file."
188 :group 'ess-sas
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)."
195 :group 'ess-sas
196 :type 'string)
198 (defcustom sas-comment-chars (concat sas-white-chars ";")
199 "Doc?"
200 :group 'ess-sas
201 :type 'string)
203 (defcustom ess-sas-run-make-regexp nil
204 "If you do not want to run make-regexp, then set to nil."
205 :group 'ess-sas
206 :type '(choice (const nil) string))
208 (require 'essa-sas)
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!
245 ;;; ...
248 (defvar SAS-mode-font-lock-keywords
249 (if ess-sas-run-make-regexp
250 (list
251 ;; SAS comments
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)
260 ;; SAS statements
262 (cons (concat
263 "\\<"
264 "%?do[ \t]*" (make-regexp '("over" "%?until" "%?while") t) "?"
265 "\\>")
266 font-lock-keyword-face)
268 (cons (concat
269 "\\<"
270 (make-regexp
272 "abort" "array" "attrib" "by" "delete" "display" "dm"
273 "drop" "error" "file" "filename" "footnote\\(10?\\|[2-9]\\)?"
274 "format"
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"
287 ) t) "\\>")
288 font-lock-keyword-face)
290 ;; SAS statements that must be followed by a semi-colon
291 (cons (concat
292 "\\<"
293 (make-regexp
295 "cards4?" "end" "%end" "endsas" "list" "lostcard" "page"
296 "return" "stop"
297 ) t) "\\>" "[ \t]*;")
298 font-lock-keyword-face)
300 ;; SAS/GRAPH statements not handled above
301 (cons (concat
302 "\\<"
303 (make-regexp
304 '("axis" "legend" "pattern" "symbol") t) "\\([1-9][0-9]?\\)?"
305 "\\>")
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)
314 (cons (concat
315 "\\<"
316 (make-regexp
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 "\\<"
333 ;;;(make-regexp '(
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 "\\<"
352 ;;;(make-regexp '(
353 "airy" "band" "blshift" "brshift" "bnot" "bor" "bxor"
354 "cnonct" "fnonct" "tnonct" "compbl" "dairy" "dequote"
355 "ibessel" "jbessel"
356 "indexw" "inputc" "inputn" "lowcase"
357 "putc" "putn" "quote" "resolve" "soundex" "sysprod"
358 "tranwrd" "trimn"
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)
367 (list
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)
377 ;; SAS comments
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)
396 "proc[ \t]+"
397 ;;SAS/Base, SAS/Graph, SAS/FSP and common add-ons
398 "\\(append"
399 "\\|b\\(genmod\\|lifereg\\|phreg\\)"
400 "\\|c\\(a\\(lendar\\|talog\\)\\|port\\|o\\(mpare\\|ntents\\|py\\|rr\\)\\)"
401 "\\|d\\(atasets\\|bcstab\\|isplay\\)\\|ex\\(plode\\|port\\)"
402 "\\|f\\(orm\\(at\\|s\\)\\|req\\|s\\(browse\\|edit\\|l\\(etter\\|ist\\)\\|view\\)\\)"
403 "\\|g?\\(chart\\|p\\(lot\\|rint\\)\\)"
404 "\\|g\\(anno\\|contour\\|device\\|font\\|\\(key\\)?map\\|options\\|project"
405 "\\|re\\(duce\\|move\\|play\\)\\|slide\\|testit\\|3\\(d\\|grid\\)\\)"
406 "\\|[cg]?import\\|i\\(ml\\|nsight\\)\\|means\\|options\\|p\\(menu\\|rintto\\)"
407 "\\|r\\(ank\\|e\\(gistry\\|port\\)\\)"
408 "\\|s\\(ort\\|ql\\|tandard\\|ummary\\)"
409 "\\|t\\(abulate\\|emplate\\|imeplot\\|ran\\(spose\\|tab\\)\\)\\|univariate"
410 ;;SAS/Stat and SAS/ETS
411 "\\|a\\(ceclus\\|nova\\|rima\\|utoreg\\)\\|boxplot"
412 "\\|c\\(a\\(lis\\|n\\(corr\\|disc\\)\\|tmod\\)\\|itibase\\|luster\\|o\\(mputab\\|rresp\\)\\)"
413 "\\|discrim\\|expand\\|f\\(a\\(ctor\\|stclus\\)\\|orecast\\|req\\)"
414 "\\|g\\(enmod\\|l\\(immix\\|m\\(mod\\|power\\|select\\)?\\)\\)\\|inbreed\\|k\\(de\\|rige2d\\)"
415 "\\|l\\(attice\\|ife\\(reg\\|test\\)\\|o\\(ess\\|gistic\\)\\)"
416 "\\|m\\(ds\\|ixed\\|o\\(de\\(clus\\|l\\)\\|rtgage\\)\\|ulttest\\)"
417 "\\|n\\(ested\\|l\\(in\\|mixed\\)\\|par1way\\)\\|orthoreg"
418 "\\|p\\(dlreg\\|hreg\\|l\\(an\\|s\\)\\|ower\\|r\\(in\\(comp\\|qual\\)\\|obit\\)\\)\\|r\\(sr\\)?eg"
419 "\\|s\\(core\\|im\\(2d\\|lin\\)\\|pectra\\|t\\(atespace\\|dize\\|epdisc\\)\\|urvey\\(means\\|reg\\|select\\)\\|yslin\\)"
420 "\\|t\\(phreg\\|pspline\\|r\\(ansreg\\|ee\\)\\|test\\)"
421 "\\|var\\(clus\\|comp\\|iogram\\)\\|x11"
422 "\\)") font-lock-constant-face)
424 ;;(cons (concat "\\(^[0-9]*\\|;\\|%then\\|%else\\)[ \t]*"
425 ;;"\\(%\\(go[ \t]*to\\|i\\(f\\|n\\(clude\\|put\\)\\)\\|let\\|put\\|sysexec\\)\\)"
426 ;;"\\>") font-lock-constant-face)
427 (cons "\\<%\\(go[ \t]*to\\|i\\(f\\|n\\(clude\\|put\\)\\)\\|let\\|put\\|sysexec\\)\\>"
428 font-lock-constant-face)
430 (cons "\\<%\\(by\\|else\\|t\\(o\\|hen\\)\\)\\>"
431 font-lock-constant-face)
433 ;; SAS dataset options/PROC statements followed by an equal sign/left parentheses
435 (cons (concat
436 "[ \t(,]"
437 "\\(attrib\\|by\\|compress\\|d\\(ata\\|rop\\)\\|f\\(irstobs\\|ormat\\)"
438 "\\|i\\(d\\|f\\|n\\)\\|ke\\(ep\\|y\\)\\|l\\(abel\\|ength\\)"
439 "\\|o\\(bs\\|rder\\|ut\\)\\|rename\\|s\\(ortedby\\|plit\\)"
440 "\\|var\\|where\\)"
441 "[ \t]*=")
442 font-lock-keyword-face)
443 (cons "\\<\\(in\\(:\\|dex[ \t]*=\\)?\\|until\\|wh\\(en\\|ile\\)\\)[ \t]*("
444 font-lock-keyword-face)
446 ;; SAS statements
447 (cons (concat
448 "\\(^[0-9]*\\|):\\|[;,]\\|then\\|else\\)[ \t]*"
449 "\\(a\\(bort\\|rray\\|ttrib\\)\\|b\\(ayes\\|y\\)"
450 "\\|c\\(hange\\|lass\\|ontrast\\)"
451 "\\|d\\(elete\\|isplay\\|m\\|o\\([ \t]+\\(data\\|over\\)\\)?\\|rop\\)"
452 "\\|e\\(rror\\|stimate\\|xc\\(hange\\|lude\\)\\)"
453 "\\|f\\(ile\\(name\\)?\\|o\\(otnote\\(10?\\|[2-9]\\)?\\|rmat\\)\\|req\\)"
454 "\\|go\\([ \t]*to\\|ptions\\)"
455 "\\|hazardratio\\|[hv]bar\\(3d\\)?"
456 "\\|i\\(d\\|f\\|n\\(dex\\|f\\(ile\\|ormat\\)\\|put\\|value\\)\\)"
457 "\\|keep\\|l\\(abel\\|ength\\|i\\(bname\\|nk\\|st\\)\\|smeans\\)"
458 "\\|m\\(anova\\|e\\(ans\\|rge\\)\\|issing\\|od\\(el\\|ify\\)\\)\\|note"
459 "\\|o\\(ds\\|ptions\\|therwise\\|utput\\)\\|p\\(arms\\|lot2?\\|ut\\)"
460 "\\|r\\(andom\\|e\\(name\\|peated\\|tain\\)\\)"
461 "\\|s\\(ave\\|e\\(lect\\|t\\)\\|kip\\|trata\\|um\\(by\\)?\\)"
462 "\\|t\\(ables?\\|i\\(me\\|tle\\(10?\\|[2-9]\\)?\\)\\)\\|update"
463 "\\|va\\(lue\\|r\\)\\|w\\(eight\\|here\\|i\\(ndow\\|th\\)\\)"
465 ;; IML statements that are not also SAS statements
466 "\\|append\\|c\\(lose\\(file\\)?\\|reate\\)\\|edit\\|f\\(ind\\|orce\\|ree\\)"
467 "\\|insert\\|load\\|mattrib\\|p\\(a[ru]se\\|rint\\|urge\\)"
468 "\\|re\\(move\\|peat\\|place\\|set\\|sume\\)"
469 "\\|s\\(et\\(in\\|out\\)\\|how\\|ort\\|tore\\|ummary\\)\\|use\\)?"
471 "\\>") font-lock-keyword-face)
475 ;; (cons "\\<\\(\\(then\\|else\\)[ \t]*\\)?\\(do\\([ \t]*over\\)?\\|else\\)\\>"
476 ;; font-lock-keyword-face)
478 ;; SAS statements that must be followed by a semi-colon
479 (cons (concat
480 "\\(^[0-9]*\\|):\\|[;,]\\|then\\|else\\)[ \t]*"
481 "\\(cards4?\\|datalines\\|end\\|l\\(ostcard\\)\\|page\\|return\\|stop\\)?"
482 "[ \t]*;") font-lock-keyword-face)
484 ;; SAS/GRAPH statements not handled above
485 (cons (concat
486 "\\(^[0-9]*\\|):\\|[;,]\\)[ \t]*"
487 "\\(axis\\|legend\\|pattern\\|symbol\\)"
488 "\\([1-9][0-9]?\\)?\\>") font-lock-keyword-face)
490 ;; SAS Datastep functions and SAS macro functions
491 ;(cons "%[a-z_][a-z_0-9]*[ \t]*[(;]"
492 ;; SAS macro functions occasionally defined with no arguments
493 ;; which means they can be followed by any character that can
494 ;; separate tokens, however, they are most likely to be followed
495 ;; by operat-ions/ors
496 (cons "%[a-z_][a-z_0-9]*[- \t();,+*/=<>]"
497 font-lock-function-name-face)
498 (cons "\\<call[ \t]+[a-z_][a-z_0-9]*[ \t]*("
499 font-lock-function-name-face)
501 (cons (concat
502 "\\<"
503 "\\(a\\(bs\\|r\\(cos\\|sin\\)\\|tan\\)\\|b\\(etainv\\|yte\\)"
504 "\\|c\\(eil\\|inv\\|o\\(llate\\|mpress\\|sh?\\)\\|ss\\|v\\)"
505 "\\|dacc\\(db\\(\\|sl\\)\\|s\\(l\\|yd\\)\\|tab\\)"
506 "\\|dep\\(db\\(\\|sl\\)\\|s\\(l\\|yd\\)\\|tab\\)"
507 "\\|d\\(a\\(te\\(\\|jul\\|part\\|time\\)\\|y\\)\\|hms\\|i\\(f[0-9]*\\|m\\|gamma\\)\\)"
508 "\\|e\\(rfc?\\|xp\\)"
509 "\\|f\\(i\\(nv\\|p\\(namel?\\|state\\)\\)\\|loor\\|uzz\\)\\|gam\\(inv\\|ma\\)"
510 "\\|h\\(bound\\|ms\\|our\\)\\|i\\(n\\(dexc?\\|put\\|t\\(\\|ck\\|nx\\|rr\\)\\)\\|rr\\)"
511 "\\|juldate\\|kurtosis\\|l\\(ag[0-9]*\\|bound\\|e\\(ft\\|ngth\\)\\|gamma\\|og\\(\\|10\\|2\\)\\)"
512 "\\|m\\(ax\\|dy\\|ean\\|in\\(\\|ute\\)\\|o\\(d\\|nth\\|rt\\)\\)"
513 "\\|n\\(\\|etpv\\|miss\\|o\\(rmal\\|t\\)\\|pv\\)"
514 "\\|prob\\([ft]\\|b\\(eta\\|nml\\)\\|chi\\|gam\\|hypr\\|it\\|n\\(egb\\|orm\\)\\)"
515 "\\|ordinal\\|p\\(oisson\\|ut\\)\\|qtr\\|r\\(e\\(peat\\|verse\\)\\|ight\\|ound\\)"
516 "\\|ran\\(bin\\|cau\\|exp\\|g\\(am\\|e\\)\\|k\\|nor\\|poi\\|t\\(bl\\|ri\\)\\|uni\\)"
517 "\\|s\\(aving\\|can\\|econd\\|i\\(gn\\|nh?\\)\\|qrt\\|t\\(d\\(\\|err\\)\\|fips\\|namel?\\)\\|u\\(bstr\\|m\\)\\|ymget\\)"
518 "\\|t\\(anh?\\|i\\(me\\(\\|part\\)\\|nv\\)\\|oday\\|r\\(anslate\\|i\\(gamma\\|m\\)\\|unc\\)\\)"
519 "\\|u\\(niform\\|pcase\\|ss\\)\\|v\\(ar\\|erify\\)"
520 "\\|weekday\\|y\\(ear\\|yq\\)\\|zip\\(fips\\|namel?\\|state\\)"
522 ;;; ;; SAS functions introduced in Technical Report P-222
524 "\\|airy\\|b\\(and\\|lshift\\|not\\|or\\|rshift\\|xor\\)"
525 "\\|c\\(nonct\\|ompbl\\)\\|d\\(airy\\|equote\\)\\|fnonct\\|tnonct"
526 "\\|i\\(bessel\\|n\\(dexw\\|put[cn]\\)\\)\\|jbessel\\|put[cn]"
527 "\\|lowcase\\|quote\\|resolve\\|s\\(oundex\\|ysprod\\)\\|tr\\(anwrd\\|imn\\)"
529 ;;; ;; IML functions that are not also Datastep functions
530 "\\|a\\(ll\\|ny\\|pply\\|rmasim\\)\\|b\\(lock\\|ranks\\|tran\\)"
531 "\\|c\\(har\\|hoose\\|on\\(cat\\|tents\\|vexit\\|vmod\\)\\|ovlag\\|shape\\|usum\\|vexhull\\)"
532 "\\|d\\(atasets\\|esignf?\\|et\\|iag\\|o\\|uration\\)"
533 "\\|e\\(chelon\\|igv\\(al\\|ec\\)\\)\\|f\\(ft\\|orward\\)\\|ginv"
534 "\\|h\\(alf\\|ankel\\|dir\\|ermite\\|omogen\\)"
535 "\\|i\\(\\|fft\\|nsert\\|nv\\(updt\\)?\\)\\|j\\(\\|root\\)\\|loc\\|mad"
536 "\\|n\\(ame\\|col\\|leng\\|row\\|um\\)\\|o\\(pscal\\|rpol\\)"
537 "\\|p\\(olyroot\\|roduct\\|v\\)\\|r\\(anktie\\|ates\\|atio\\|emove\\|eturn\\|oot\\|owcatc?\\)"
538 "\\|s\\(etdif\\|hape\\|olve\\|plinev\\|pot\\|qrsym\\|ssq\\|torage\\|weep\\|ymsqr\\)"
539 "\\|t\\(\\|eigv\\(al\\|ec\\)\\|oeplitz\\|race\\|risolv\\|ype\\)"
540 "\\|uni\\(on\\|que\\)\\|v\\(alue\\|ecdiag\\)\\|x\\(mult\\|sect\\)\\|yield"
542 ;;; ;; SCL functions that are known to work with SAS macro function %sysfunc
544 "\\|attr[cn]\\|c\\(exist\\|lose\\)\\|d\\(close\\|num\\|open\\|read\\)"
545 "\\|exist\\|f\\(close\\|etchobs\\|i\\(leexist\\|nfo\\)\\|open\\|put\\|write\\)"
546 "\\|get\\(option\\|var[cn]\\)\\|lib\\(name\\|ref\\)\\|op\\(en\\|t\\(getn\\|setn\\)\\)"
547 "\\|pathname\\|sysmsg\\|var\\(fmt\\|l\\(abel\\|en\\)\\|n\\(ame\\|um\\)\\|type\\)\\)"
548 "[ \t]*(") font-lock-function-name-face)
550 "Font Lock regexs for SAS.")
553 (defvar SAS-editing-alist
554 '((sentence-end . ";[\t\n */]*")
555 (paragraph-start . "^[ \t]*$")
556 (paragraph-separate . "^[ \t]*$")
557 (paragraph-ignore-fill-prefix . t)
558 ;;(fill-paragraph-function . 'lisp-fill-paragraph)
559 (adaptive-fill-mode . nil)
560 (indent-line-function . 'sas-indent-line)
561 ;;(indent-region-function . 'sas-indent-region)
562 (require-final-newline . t)
563 (comment-start . "** ")
564 (comment-start-skip . "[*][*] ")
565 (comment-end . " **;")
566 (comment-end-skip . " [*][*];")
567 (comment-column . 40)
568 ;;(comment-indent-function . 'lisp-comment-indent)
569 (parse-sexp-ignore-comments . t)
570 (ess-style . ess-default-style)
571 (ess-local-process-name . nil)
572 ;;(ess-keep-dump-files . 'ask)
573 (tab-stop-list . ess-sas-tab-stop-list)
574 (ess-mode-syntax-table . SAS-syntax-table)
575 (font-lock-keywords-case-fold-search . t)
576 (font-lock-defaults . '(SAS-mode-font-lock-keywords)))
577 "General options for editing SAS source files.")
579 (defun beginning-of-sas-statement (arg &optional comment-start)
580 "Move point to beginning of current sas statement."
581 (interactive "P")
582 (let ((pos (point))
584 (if (search-forward ";" nil 1) (forward-char -1))
585 (re-search-backward ";[ \n*/]*$" (point-min) 1 arg)
586 (skip-chars-forward sas-comment-chars)
587 (if comment-start nil
588 (if (looking-at "\\*/")
589 (progn (forward-char 2)
590 (skip-chars-forward sas-comment-chars)))
591 (while (looking-at "/\\*")
592 (if (not (search-forward "*/" pos t 1)) ;;(;; (point-max) 1 1)
593 (forward-char 2))
594 (skip-chars-forward sas-white-chars)))))
596 (defun sas-indent-line ()
597 "Indent function for SAS mode."
598 (interactive)
599 (let (indent prev-end
600 (pos (- (point-max) (point)))
601 (case-fold-search t)
602 (cur-ind (current-indentation))
603 (comment-col (sas-comment-start-col))) ;; 2/1/95 TDC
604 (save-excursion
605 (cond ((progn
606 (back-to-indentation)
607 (or (bobp)
608 (looking-at
609 "data[ ;]\\|proc[ ;]\\|run[ ;]\\|endsas[ ;]\\|g?options[ ;]\\|%macro[ ;]\\|%mend[ ;]")))
610 ;; Case where current statement is DATA, PROC, etc...
611 (setq prev-end (point))
612 (goto-char (point-min))
613 ;; Added 6/27/94
614 ;; May get fooled if %MACRO, %DO, etc embedded in comments
615 (setq indent
616 (+ (* (- (sas-how-many "^[ \t]*%macro\\|[ \t]+%do"
617 prev-end)
618 (sas-how-many "^[ \t]*%mend\\|%end" prev-end))
619 sas-indent-width) comment-col))) ;; 2/1/95 TDC
620 ;; Case where current line begins with sas-indent-ignore-comment
621 ;; added 6/27/94 to leave "* ;" comments alone.
622 ((progn
623 (back-to-indentation)
624 (and (not (looking-at "*/"))
625 (looking-at (concat sas-indent-ignore-comment "\\|/\\*"))))
626 (setq indent (current-indentation)))
627 ;; Case where current statement not DATA, PROC etc...
628 (t (beginning-of-line 1)
629 (skip-chars-backward sas-white-chars)
630 (if (bobp) nil
631 (backward-char 1))
632 (cond
633 ((looking-at ";") ; modified 1/31/95
634 (setq indent (sas-next-statement-indentation)))
635 ((save-excursion;; added 4/28/94 to properly check
636 (if (bobp) () (backward-char 1));; for end of comment
637 (setq prev-end (point))
638 (looking-at "*/"));; improved 1/31/95
639 (save-excursion
640 (search-backward "*/"
641 (point-min) 1 1); comment start is first /*
642 (search-forward "/*"
643 prev-end 1 1) ; after previous */
644 (backward-char 2) ; 2/1/95 TDC
645 (skip-chars-backward sas-white-chars)
646 (setq indent
647 (if (bobp) 0
648 (if (looking-at ";")
649 (sas-next-statement-indentation)
650 (+ (current-indentation) sas-indent-width))))))
652 ;; added 6/27/94 to leave "* ;" comments alone
653 ((save-excursion
654 (progn
655 (beginning-of-sas-statement 1 t)
656 (and (not (looking-at "*/"))
657 (looking-at sas-indent-ignore-comment))))
658 (setq indent cur-ind))
659 ((progn
660 (beginning-of-sas-statement 1)
661 (bobp));; added 4/13/94
662 (setq indent sas-indent-width));; so the first line works
664 (if (progn
665 (save-excursion
666 (beginning-of-line 1)
667 (skip-chars-backward sas-white-chars)
668 (if (bobp) nil (backward-char 1))
669 (or (looking-at ";")
670 (bobp) (backward-char 1) (looking-at "\\*/"))))
671 (setq indent (+ (current-indentation) sas-indent-width))
672 (setq indent (current-indentation))))))))
673 (save-excursion
674 (let (beg end)
675 (back-to-indentation)
676 (setq end (point))
677 (beginning-of-line 1)
678 (setq beg (point))
679 (delete-region beg end)
680 (indent-to indent)))
681 (if (> (- (point-max) pos) (point))
682 (goto-char (- (point-max) pos)))))
685 ;;(defun sas-indent-region (start end)
686 ;; "Indent a region of SAS code."
687 ;; (interactive "r")
688 ;; (save-excursion
689 ;; (let ((endmark (copy-marker end)))
690 ;; (goto-char start)
691 ;; (and (bolp) (not (eolp))
692 ;; (sas-indent-line))
693 ;; (indent-sexp endmark)
694 ;; (set-marker endmark nil))))
697 (defun indent-sas-statement (arg)
698 "Indent all continuation lines sas-indent-width spaces from first
699 line of statement."
700 (interactive "p")
701 (let (end)
702 (save-excursion
703 (if (> arg 0)
704 (while (and (> arg 0) (search-forward ";" (point-max) 1 1))
705 (setq end (point))
706 (if (bobp) nil (backward-char 1))
707 (beginning-of-sas-statement 1)
708 (forward-char 1)
709 (indent-region (point)
711 (+ (current-column) (1- sas-indent-width)))
712 (search-forward ";" (point-max) 1 1)
713 (setq arg (1- arg)))))))
715 ;; added 9/31/94
716 (defun sas-next-statement-indentation ()
717 "Returns the correct indentation of the next sas statement.
718 The current version assumes that point is at the end of the statement.
719 This will (hopefully) be fixed in later versions."
720 (if (bobp) 0
721 (save-excursion
722 (let ((prev-end (point)))
723 (beginning-of-sas-statement 1)
724 (while (and (not (bobp))
725 (not (looking-at "*/"))
726 (looking-at sas-indent-ignore-comment))
727 (skip-chars-backward sas-white-chars)
728 (if (bobp) nil
729 (backward-char 1))
730 (setq prev-end (point))
731 (beginning-of-sas-statement 1 t))
732 (if (or
733 (looking-at
734 "data[ \n\t;]\\|proc[ \n\t]\\|%?do[ \n\t;]\\|%macro[ \n\t]\\|/\\*")
735 (save-excursion
736 (re-search-forward
737 "\\b%?then\\>[ \n\t]*\\b%?do\\>\\|\\b%?else\\>[ \n\t]*\\b%?do\\>"
738 prev-end 1 1))) ; fixed 1/30/95 to avoid being fooled by
739 ; variable names starting with "do"
740 (+ (current-indentation) sas-indent-width)
741 (if (looking-at "%?end[ ;\n]\\|%mend[ ;\n]\\|\\*/")
742 (max (- (current-indentation) sas-indent-width) 0)
743 (current-indentation)))))))
745 ;; added 2/1/95
746 (defun sas-comment-start-col ()
747 "If the current line is inside a /* */ comment, returns column in which the
748 opening /* appears. returns 0 otherwise."
749 (let ((pos (point)))
750 (save-excursion
751 (if (and (search-backward "*/" (point-min) 1 1)
752 (search-forward "/*" pos 1 1))
753 (current-indentation)
754 0))))
757 ;; Created 6/27/94 to verify that RUN; statements match PROC and DATA
758 ;; statements. Useful since indentation my be goofy w/o "RUN;"
759 (defun sas-check-run-statements ()
760 "Check to see that \"run\" statements are matched with proc, data statements."
761 (interactive)
762 (let (pos
763 (ok t)
764 (eob-ok t))
765 (save-excursion
766 (beginning-of-line)
767 (while ok
768 (if (re-search-forward
769 "\\(^[ \t]*run[ ;]\\)\\|\\(^[ \t]*proc \\|^[ \t]*data[ ;]\\)"
770 nil 1)
771 (if (match-beginning 2)
772 (if (re-search-forward
773 "\\(^[ \t]*run[ ;]\\)\\|\\(^[ \t]*proc \\|^[ \t]*data[ ;]\\)"
774 nil t)
775 (progn (setq pos (point))
776 (setq ok (match-beginning 1)))
777 (setq eob-ok nil pos (point-max))))
778 (setq ok nil)))
779 (setq ok (eobp)))
780 (if (and ok eob-ok) (message "Run statements match")
781 (goto-char pos)
782 (beep)
783 (message "Missing Run Statement."))))
786 (defun sas-fix-life-tables (start end)
787 "Remove censored and duplicate observations from life tables generated by
788 Proc Lifetest. Operates on current region. A major space saver if there is
789 heavy censoring."
790 (interactive "r")
791 (save-excursion
792 (shell-command-on-region
793 start end
794 "sed \"\\? *\\. *\\. *\\. ?d\"" t)))
795 ;;(vip-goto-line 1)
796 ;;(setq ex-g-flag nil
797 ;;ex-g-variant nil)
798 ;;(vip-ex "1,$g/ \\. \\. \\. /d")))
800 (defun sas-fix-page-numbers (offset &optional page-num)
801 "Fix number of current page in sas output files after editing. Add
802 OFFSET to actual page number."
803 (interactive "P")
804 (if (not offset) (setq offset 0))
805 (if (not page-num) (setq page-num (sas-page-number)))
806 (save-excursion
807 (if (/= (preceding-char) ?\C-l) (backward-page 1))
808 (let (end len mstart mend)
809 (save-excursion
810 (forward-line sas-page-number-max-line)
811 (setq end (point)))
812 (if (re-search-forward
813 "\\(^[0-9]+[ ]\\)\\|\\([ ][0-9]+$\\)"
814 end t)
815 (progn (setq len (- (match-end 0) (match-beginning 0))
816 mstart (match-beginning 0)
817 mend (match-end 0))
818 (delete-region mstart mend)
819 (if (eolp)
820 (insert (format
821 (concat "%" len "d") (+ page-num offset)))
822 (insert (substring
823 (concat (+ (sas-page-number) offset) " ")
824 0 len))))))))
826 (defun sas-page-fix (start)
827 "Fix page numbers in sas output from point to end of file.
828 If START is given this will be the number for the current page."
829 (interactive "P")
830 (let (offset (pnum (sas-page-number)))
831 (if (not start) (setq offset 0)
832 (setq offset (- start pnum)))
833 (while (not (eobp))
834 (sas-fix-page-numbers offset pnum)
835 (setq pnum (1+ pnum))
836 (forward-page 1))))
838 (defun fix-page-breaks ()
839 "Fix page breaks in SAS 6 print files."
840 (interactive)
841 (save-excursion
842 (goto-char (point-min))
843 (if (looking-at "\f") (delete-char 1))
844 (replace-regexp "^\\(.+\\)\f" "\\1\n\f\n")
845 (goto-char (point-min))
846 (replace-regexp "^\f\\(.+\\)" "\f\n\\1")
847 (goto-char (point-min))
848 (replace-regexp "
849 $" "")
850 (goto-char (point-min))
851 (replace-regexp "
852 \\([^
853 \\$]+\\)" "\n\\1")
854 (goto-char (point-max))
855 (if (not (bobp))
856 (progn (backward-char 1)
857 (if (not (looking-at "\n"))
858 (progn (forward-char 1) (open-line 1)))))))
860 (defun sas-page-number ()
861 ;; like what-page except it returns an integer page number
862 "Return page number of point in current buffer."
863 (let ((opoint (point))) (save-excursion
864 (goto-char (point-min))
865 (1+ (sas-how-many page-delimiter opoint)))))
867 (defun sas-how-many (regexp &optional end)
868 ;; a copy of `how-many' which returns an integer
869 ;; rather than a message
870 "Return number of matches for REGEXP following point."
871 (let ((count 0) opoint)
872 (save-excursion
873 (while (and (not (eobp))
874 (progn (setq opoint (point))
875 (re-search-forward regexp end t)))
876 (if (= opoint (point))
877 (forward-char 1)
878 (setq count (1+ count))))
879 count)))
881 (defun beginning-of-sas-proc ()
882 "Move point to beginning of sas proc, macro or data step."
883 (interactive)
884 (let ((case-fold-search t))
885 (forward-char -1)
886 (while (not (or (looking-at "data\\|proc\\|%macro")
887 (bobp)))
888 (re-search-backward "proc\\|data\\|%macro" (point-min) 1)
889 (beginning-of-sas-statement 1))))
891 (defun next-sas-proc (arg)
892 "Move point to beginning of next sas proc."
893 (interactive "P")
894 (let ((case-fold-search t))
895 (forward-char 1)
896 (if (re-search-forward
897 "^[ \t]*\\(data[ ;]\\|proc[ ;]\\|endsas[ ;]\\|g?options[ ;]\\|%macro[ ;]\\)"
898 nil t arg)
899 (beginning-of-sas-statement 1)
900 (forward-char -1))))
902 (defun set-sas-file-name ()
903 "Stores the name of the current sas file."
904 (let ((name (buffer-file-name)))
905 (cond ((not name))
906 ((string-match (substring name -4 nil)
907 "\\.sas\\|\\.lst\\|\\.log")
909 (setq sas-file-name (substring name 0 (- (length name) 4)))
910 (setq sas-buffer-name (buffer-name))
911 (setq sas-file-root (substring sas-buffer-name 0
912 (- (length sas-buffer-name) 4))))
913 (t (message "This file does not have a standard suffix")))))
915 ;; created 6/27/94
916 (defun sas-set-alternate-file-name (name)
917 "Stores the NAME of an alternate sas file.
918 When this file is submitted with `submit-sas', the alternate file will
919 be submitted instead. `sas-submitable' is automatically sets to t."
920 (interactive "f")
921 (cond ((string-match (substring name -4 nil)
922 "\\.sas\\|\\.lst\\|\\.log")
923 (setq sas-file-name (substring name 0 (- (length name) 4)))
924 (setq sas-submitable t))
925 (t (message "This file does not have a standard suffix"))))
927 (defun switch-to-sas-source ()
928 "Switches to sas source file associated with the current file."
929 (interactive)
930 (switch-to-sas-file "sas"))
932 (defun switch-to-sas-lst ()
933 "Switches to sas source file associated with the current file."
934 (interactive)
935 (switch-to-sas-file "lst"))
937 (defun switch-to-sas-log ()
938 "Switches to sas source file associated with the current file."
939 (interactive)
940 (switch-to-sas-file "log"))
942 (defun switch-to-sas-source-other-window ()
943 "Switches to sas source file associated with the current file."
944 (interactive)
945 (switch-to-sas-file-other-window "sas"))
947 (defun switch-to-sas-lst-other-window ()
948 "Switches to sas source file associated with the current file."
949 (interactive)
950 (switch-to-sas-file-other-window "lst"))
952 (defun switch-to-sas-log-other-window ()
953 "Switches to sas source file associated with the current file."
954 (interactive)
955 (switch-to-sas-file-other-window "log"))
957 ;;(defun switch-to-sas-file (suff &optional revert silent)
958 ;; "Switches to sas \"SUFF\" file associated with the current file"
959 ;; (let* ((sfile sas-file-name)
960 ;; (buf (get-file-buffer (concat sfile "." suff)))
961 ;; (sas-require-confirmation
962 ;; (and sas-require-confirmation (not revert))))
963 ;; (if (or sas-require-confirmation (string-equal suff "sas") (not buf))
964 ;; (find-file (concat sfile "." suff))
965 ;; (progn (switch-to-buffer buf)
966 ;; (if (not (verify-visited-file-modtime (current-buffer)))
967 ;; (progn (revert-buffer t t)
968 ;; (if (not silent)
969 ;; (message "File has changed on disk. Buffer automatically updated."))))))
970 ;; (setq sas-file-name sfile))
971 ;; (if (string-equal suff "sas")
972 ;; (if (not (string-equal major-mode "sas-mode"))
973 ;; (sas-mode))
974 ;; (if (not (string-equal major-mode "sasl-mode"))
975 ;; (sasl-mode))))
977 ;;(defun switch-to-sas-file-other-window (suff)
978 ;; "Switches to sas \"SUFF\" file associated with the current file"
979 ;; (let* ((sfile sas-file-name)
980 ;; (buf (get-file-buffer (concat sfile "." suff))))
981 ;; (if (or sas-require-confirmation (string-equal suff "sas") (not buf))
982 ;; (find-file-other-window (concat sfile "." suff))
983 ;; (progn (switch-to-buffer-other-window buf)
984 ;; (if (not (verify-visited-file-modtime (current-buffer)))
985 ;; (progn (revert-buffer t t)
986 ;; (message "File has changed on disk. Buffer automatically updated.")))))
987 ;; (setq sas-file-name sfile))
988 ;; (if (string-equal suff "sas")
989 ;; (if (not (string-equal major-mode "sas-mode"))
990 ;; ;;(sas-mode)
991 ;; )
992 ;; (if (not (string-equal major-mode "sasl-mode"))
993 ;; ;;(sasl-mode)
994 ;; )))
996 (defun switch-to-sas-file (suff)
997 "Switches to sas \"SUFF\" file associated with the current file."
998 (switch-to-buffer (set-sas-file-buffer suff)))
1000 (defun switch-to-sas-file-other-window (suff)
1001 "Switches to sas \"SUFF\" file associated with the current file."
1002 (switch-to-buffer-other-window (set-sas-file-buffer suff)))
1004 ;; The following was created 6/7/94 to handle buffers without messing up
1005 ;; windows.
1007 (defun set-sas-file-buffer (suff &optional revert silent)
1008 "Sets current buffer to sas \"SUFF\" file associated with the current file."
1009 (let* ((sfile sas-file-name)
1010 (buf (get-file-buffer (concat sfile "." suff)))
1011 (sas-require-confirmation
1012 (and sas-require-confirmation (not revert))))
1013 (if (or sas-require-confirmation (string-equal suff "sas") (not buf))
1014 (set-buffer (find-file-noselect (concat sfile "." suff)))
1015 (progn (set-buffer buf)
1016 (if (not (verify-visited-file-modtime (current-buffer)))
1017 (progn (revert-buffer t t)
1018 (if (not silent)
1019 (message "File has changed on disk. Buffer automatically updated."))))))
1020 (setq sas-file-name sfile))
1021 ;;(if (string-equal suff "sas")
1022 ;; (if (not (string-equal major-mode "sas-mode")) (sas-mode))
1023 ;; (if (not (string-equal major-mode "sasl-mode"))(sasl-mode))
1024 (current-buffer))
1026 (defun switch-to-sas-process-buffer ()
1027 "Switch to sas-process-buffer."
1028 (interactive)
1029 (let (buf proc-name)
1030 (setq proc-name (concat "SAS" sas-file-name)
1031 buf (concat "*" proc-name "*"))
1032 (switch-to-buffer-other-window buf)))
1034 (defun submit-sas ()
1035 ;; 6/17/94 added sas-submitable local variable.
1036 "Submit SAS file as shell command."
1037 (interactive)
1038 (if ;; can file be run, or is it only for inclusion?
1039 (or sas-submitable
1040 (progn
1041 (beep)
1042 (y-or-n-p
1043 (format
1044 "Submission is disabled for this file. Submit it anyway? "))))
1045 (progn
1046 ;; if buffer name has changed, tell user
1047 (if (or
1048 (string-equal sas-buffer-name (buffer-name))
1049 (not
1050 (y-or-n-p
1051 (format
1052 "The name of this buffer has changed. Submit the new file? "))))
1053 (setq sas-buffer-name (buffer-name))
1054 (set-sas-file-name))
1055 (let ((sas-file sas-file-name)
1056 (sas-root sas-file-root)
1057 ;;(sas-buf sas-buffer-name)
1058 proc-name
1059 buf)
1061 ;; Save buffer to SAS the right file :-).
1062 (if (buffer-modified-p)
1063 (if (y-or-n-p (format "Buffer %s is modified. Save it? "
1064 (buffer-name)))
1065 (save-buffer)))
1066 (setq proc-name (concat "SAS" sas-file)
1067 buf (concat "*" proc-name "*"))
1068 (if (get-buffer buf)
1069 (save-window-excursion (switch-to-buffer buf)
1070 (erase-buffer)
1071 (setq default-directory
1072 (file-name-directory sas-file))))
1074 (run-hooks 'sas-pre-run-hook) ;; added 8/24/94
1075 (message "---- Submitting SAS job ----")
1076 ;; (switch-to-buffer buf)
1077 (make-comint proc-name
1078 sas-program ;added sas-program 4/29/94
1080 sas-root)
1081 (save-window-excursion
1082 (switch-to-buffer buf)
1083 (setq sas-file-name sas-file)
1084 (bury-buffer buf))
1086 (message "---- SAS job submitted ---- ")
1088 (if sas-notify;; added 4/7/94
1089 (set-process-sentinel (get-process proc-name) 'sas-sentinel)
1090 (display-buffer buf t))))
1091 (message "---- File not submitted ----")))
1093 ;; 5/2/94 Modified sas-sentinel to check for errors in log file upon
1094 ;; completion.
1095 (defun sas-sentinel (proc arg);; created 4/7/94
1096 "Notify user that SAS run is done."
1097 (beep)
1098 ;;(if (string-equal arg "finished\n")
1099 (save-excursion
1100 (let (msg buf win (sbuf (concat "*" (process-name proc) "*")))
1101 (setq msg
1102 (format "SAS %s %s"
1103 (substring arg 0 -1)
1104 (if sas-error-notify
1105 ;;(save-window-excursion
1106 (progn
1107 (set-buffer sbuf)
1108 (setq buf (set-sas-file-buffer "log" t t))
1109 (goto-char (point-min))
1110 (setq win (get-buffer-window buf))
1111 (save-window-excursion
1112 (if win
1113 (progn
1114 (select-window win)
1115 (if (re-search-forward "^ERROR" nil t)
1116 " (See .log file for errors)"
1117 ""))
1118 (switch-to-buffer buf)
1119 (if (re-search-forward "^ERROR" nil t)
1120 " (See .log file for errors)"
1121 ""))))
1122 "")))
1123 (set-buffer sbuf)
1124 (goto-char (point-max))
1125 (insert msg)
1126 (bury-buffer (get-buffer sbuf))
1127 ;;(if (and sas-notify-popup window-system)
1128 ;; (x-popup-dialog t
1129 ;; (list "SAS Menu" (cons msg nil) )))
1130 ;;(if (not (minibuffer-window-active-p)) (princ msg))
1131 (princ msg))))
1133 ;; 5/2/94 Modified run-sas-on-region to separate log and output buffers.
1135 ;;(defun run-sas-on-region (start end append &optional buffer)
1136 ;; "Submit region to SAS"
1137 ;; (interactive "r\nP")
1138 ;; (message "---- Running SAS ----")
1139 ;; (let ((sfile sas-file-name)
1140 ;; (shell-file-name "/bin/sh")
1141 ;; serror buff)
1142 ;; (setq buffer (or buffer "*SAS output*"))
1143 ;; (save-excursion
1144 ;; (shell-command-on-region
1145 ;; start end;; added sas-program
1146 ;; (concat sas-program " -nonews -stdio 2> /tmp/_temp_.log" nil))
1147 ;; (get-buffer-create "*SAS Log*")
1148 ;; (save-window-excursion
1149 ;; (switch-to-buffer "*SAS Log*")
1150 ;; (erase-buffer)
1151 ;; (insert-file-contents "/tmp/_temp_.log")
1152 ;; (delete-file "/tmp/_temp_.log")
1153 ;; (setq serror (re-search-forward "^ERROR" nil t))
1154 ;; (if serror () (bury-buffer)))
1155 ;; (setq buff (get-buffer-create buffer))
1156 ;; (save-window-excursion
1157 ;; (switch-to-buffer buff)
1158 ;; (setq sas-file-name sfile)
1159 ;; (if append
1160 ;; (progn
1161 ;; (end-of-buffer)
1162 ;; (insert "\f\n"))
1163 ;; (erase-buffer))
1164 ;; (if (get-buffer "*Shell Command Output*")
1165 ;; (progn (insert-buffer "*Shell Command Output*")
1166 ;; (kill-buffer "*Shell Command Output*"))
1167 ;; (insert "SAS completed with no output."))
1168 ;; (if append () (sasl-mode))
1169 ;; (message "---- SAS Complete ----")))
1170 ;; (if (not serror)
1171 ;; (switch-to-buffer-other-window buff)
1172 ;; (switch-to-buffer-other-window "*SAS Log*")
1173 ;; (goto-char serror)
1174 ;; (beep)
1175 ;; (message "Error found in log file.")
1176 ;; )))
1178 (defun switch-to-dataset-log-buffer ()
1179 "Switch to log buffer for run-sas-on-region."
1180 (interactive)
1181 (switch-to-buffer-other-window "*SAS Log*"))
1183 (defun switch-to-dataset-source-buffer ()
1184 "Switch to source buffer for run-sas-on-region."
1185 (interactive)
1186 (switch-to-buffer-other-window (format " *sas-tmp-%s*" sas-dataset)))
1188 ;;(defun sas-get-dataset (filename &optional arg opts-p append buffer vars)
1189 ;; "Run proc contents and proc print on SAS dataset. Automatically prompts
1190 ;;for SAS options to use. Default options are defined by the variable
1191 ;;`sas-get-options'. Output may be updated from within output buffer with
1192 ;;C-cr if dataset changes. Also, the source code which generates the output
1193 ;;may be edited with C-cs. Typing C-cr within the output buffer reexecutes
1194 ;;the (modified) source code."
1195 ;; (interactive "fName of SAS dataset (file name):")
1196 ;; (let ((file (file-name-nondirectory filename))
1197 ;; (dir (file-name-directory filename))
1198 ;; (opts sas-get-options)
1199 ;; (minibuffer-history sas-get-options-history)
1200 ;; buf); fsize)
1201 ;; (setq buffer (or buffer (concat "*" file "*")))
1202 ;; (setq opts (if opts-p opts (read-string "SAS options: " opts)))
1203 ;; (setq sas-get-options-history minibuffer-history)
1204 ;; (cond ((string-match (substring file -6 nil) "\\.ssd01")
1205 ;; (setq file (substring file 0 (- (length file) 6))))
1206 ;; (t (error "This file is not a SAS dataset.")))
1207 ;; (setq buf (format " *sas-tmp-%s*" file))
1208 ;; (get-buffer-create buf)
1209 ;; (save-window-excursion
1210 ;; (switch-to-buffer buf)
1211 ;; (erase-buffer)
1212 ;; (setq default-directory dir)
1213 ;; (if opts
1214 ;; (insert (format "options %s ;\n" opts)))
1215 ;; (insert (format "title \"Contents of SAS dataset `%s'\" ;\n" file))
1216 ;; (insert (format "libname %s '%s' ;\n" sas-tmp-libname dir))
1217 ;; (if (not (equal arg 1))
1218 ;; (insert (format "proc contents data = %s.%s ;\n" sas-tmp-libname file)))
1219 ;; (if (equal arg 2) ()
1220 ;; (insert (format "proc print data = %s.%s ;\n" sas-tmp-libname file))
1221 ;; (if vars (insert (format " var %s ;\n" vars))))
1222 ;; (run-sas-on-region (point-min) (point-max) append
1223 ;; buffer)
1224 ;; (get-buffer buffer)
1225 ;; (if append () (sasd-mode)) ;; added 5/5/94
1226 ;; (setq sas-dataset file))
1227 ;; (if (get-buffer-window buffer t)
1228 ;; (raise-frame (window-frame (get-buffer-window buffer t)))
1229 ;; (display-buffer buffer (not append)))
1230 ;; ))
1232 ;;(defun revert-sas-dataset ()
1233 ;; "Revert current sas dataset from disk version"
1234 ;; (interactive)
1235 ;; (let* ((file sas-dataset)
1236 ;; (buf (format " *sas-tmp-%s*" file))
1237 ;; (pos (point)))
1238 ;; (save-window-excursion
1239 ;; (switch-to-buffer buf)
1240 ;; (run-sas-on-region (point-min) (point-max) nil
1241 ;; (concat "*" file ".ssd01*"))
1242 ;; )
1243 ;; (goto-char pos) ;; added 6/9/94
1244 ;; (sasd-mode) ;; added 5/5/94
1245 ;; (setq sas-dataset file)))
1247 (defun sas-insert-local-variables () ;; created 6/17/94
1248 "Add local variables code to end of sas source file."
1249 (interactive)
1250 (save-excursion
1251 (if (re-search-forward "* *Local Variables: *;" nil t)
1253 (goto-char (point-max))
1254 (insert "
1256 ** Local Variables: ;
1257 ** End: ;
1258 page ;
1259 "))))
1263 ;;-*-emacs-lisp-*-
1264 ;;; file name: sas-data.el
1266 ;;; Version 1.0
1268 ;;; sas-data-mode: manage sas datasets
1269 ;;; Copyright (C) 1994 Tom Cook
1271 ;;; This program is free software; you can redistribute it and/or modify
1272 ;;; it under the terms of the GNU General Public License as published by
1273 ;;; the Free Software Foundation; either version 2 of the License, or
1274 ;;; (at your option) any later version.
1276 ;;; This program is distributed in the hope that it will be useful,
1277 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1278 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1279 ;;; GNU General Public License for more details.
1281 ;;; You should have received a copy of the GNU General Public License
1282 ;;; along with this program; if not, write to the Free Software
1283 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1285 ;;; Author: Tom Cook
1286 ;;; Dept. of Biostatistics
1287 ;;; University of Wisconsin - Madison
1288 ;;; Madison, WI 53706
1289 ;;; cook@biostat.wisc.edu
1290 ;; Created: 8/11/94
1292 ;; variables section
1293 (defvar sas-dir-mode-map nil)
1294 (defvar sas-directory-name nil
1295 "Name of directory associated with this buffer.")
1296 (make-variable-buffer-local 'sas-directory-name)
1297 (defvar sas-dir-buf-end nil)
1298 (make-variable-buffer-local 'sas-dir-buf-end)
1299 (defvar sas-sorted-by-num nil)
1300 (make-variable-buffer-local 'sas-sorted-by-num)
1301 ;; user variables
1303 ;; keymaps etc...
1305 (if sas-dir-mode-map ()
1306 (setq sas-dir-mode-map (make-sparse-keymap))
1307 ;;(define-key sas-dir-mode-map "c" 'sas-contents)
1308 (define-key sas-dir-mode-map "p" 'sas-print)
1309 (define-key sas-dir-mode-map "m" 'sas-mark-item)
1310 (define-key sas-dir-mode-map "u" 'sas-unmark-item)
1311 (define-key sas-dir-mode-map " " 'sas-next-line)
1312 (define-key sas-dir-mode-map "\C-n" 'sas-next-line)
1313 (define-key sas-dir-mode-map "\C-p" 'sas-prev-line)
1314 (define-key sas-dir-mode-map "\177" 'sas-prev-line-undo)
1315 (define-key sas-dir-mode-map "\C-b" 'sas-backward-page-narrow)
1316 (define-key sas-dir-mode-map "\C-v" 'sas-forward-page-narrow)
1317 (define-key sas-dir-mode-map "\C-m" 'sas-goto-dataset)
1318 (define-key sas-dir-mode-map [mouse-2] 'sas-mouse-goto-dataset)
1319 (define-key sas-dir-mode-map "t" 'sas-dir-goto-page)
1320 (define-key sas-dir-mode-map "q" 'bury-buffer)
1321 (define-key sas-dir-mode-map "g" 'sas-revert-library)
1322 (define-key sas-dir-mode-map "1" 'digit-argument)
1323 (define-key sas-dir-mode-map "2" 'digit-argument)
1324 (define-key sas-dir-mode-map "3" 'digit-argument)
1325 (define-key sas-dir-mode-map "4" 'digit-argument)
1326 (define-key sas-dir-mode-map "5" 'digit-argument)
1327 (define-key sas-dir-mode-map "6" 'digit-argument)
1328 (define-key sas-dir-mode-map "7" 'digit-argument)
1329 (define-key sas-dir-mode-map "8" 'digit-argument)
1330 (define-key sas-dir-mode-map "9" 'digit-argument)
1331 (define-key sas-dir-mode-map [menu-bar sas run]
1332 '("Submit File " . submit-sas))
1335 ;(require 'sas)
1337 (defun sas-dir-mode ()
1338 "Major mode for managing sas files."
1339 (interactive)
1340 (kill-all-local-variables)
1341 (use-local-map sas-dir-mode-map)
1342 (setq major-mode 'sas-dir-mode)
1343 (setq mode-name "SAS")
1344 (setq sas-directory-name (expand-file-name default-directory))
1345 (toggle-read-only 1))
1348 ;;(defun sas-make-library (directory &optional update)
1349 ;; "Create a buffer with the names of all sas datasets from DIRECTORY."
1350 ;; (interactive "DDirectory Name: ")
1351 ;; (let ((dir (expand-file-name directory)) buf out cont pos)
1352 ;; (setq buf (format " *sas-tmp-%s*" dir))
1353 ;; (setq out (concat "*SAS-dir-" dir))
1354 ;; (setq cont (concat "*SAS-cont-" dir))
1355 ;; (get-buffer-create buf)
1356 ;; (if (get-buffer out)
1357 ;; (if update
1358 ;; (progn
1359 ;; (set-buffer out)
1360 ;; (setq buffer-read-only nil)))
1361 ;; (setq update t))
1362 ;; (pop-to-buffer out)
1363 ;; (setq default-directory dir)
1364 ;; (setq pos (point))
1365 ;; (if update
1366 ;; (progn
1367 ;; (save-window-excursion
1368 ;; (set-buffer buf)
1369 ;; (erase-buffer)
1370 ;; (setq default-directory dir)
1371 ;; (insert "options linesize=70 pagesize=1000 ;\n")
1372 ;; (insert (format "title \"Contents of SAS directory `%s'\" ;\n"
1373 ;; dir))
1374 ;; (insert (format "libname %s '%s' ;\n" sas-tmp-libname dir))
1375 ;; (insert (format "proc contents data = %s._all_ directory details memtype=data ;\n" sas-tmp-libname))
1376 ;; (run-sas-on-region (point-min) (point-max) nil
1377 ;; out)
1378 ;; (set-buffer out)
1379 ;; (goto-char (point-min))
1380 ;; (if (= (sas-how-many page-delimiter (point-max)) 0)
1381 ;; (let ((buffer-read-only nil))
1382 ;; (erase-buffer)
1383 ;; (insert "There are no SAS datasets in this directory")
1384 ;; (pop-to-buffer out))
1385 ;; (save-excursion
1386 ;; (set-buffer (get-buffer-create cont))
1387 ;; (setq buffer-read-only t)
1388 ;; (let ((buffer-read-only nil))
1389 ;; (erase-buffer)
1390 ;; (insert-buffer out)
1391 ;; (delete-region (point-min)
1392 ;; (or (re-search-forward page-delimiter nil t)
1393 ;; (point-min)))
1394 ;; (sas-page-fix 1)
1395 ;; (goto-char (point-min))
1396 ;; (sas-dir-mode)
1397 ;; (sas-narrow-to-page)))
1398 ;; (if (re-search-forward page-delimiter nil t)
1399 ;; (delete-region (progn (beginning-of-line) (point))
1400 ;; (point-max)))
1401 ;; (sas-insert-set-properties (point-min) (point-max))
1402 ;; )
1403 ;; (switch-to-buffer out t)
1404 ;; (goto-char (point-min))
1405 ;; (sas-dir-mode)
1406 ;; (setq sas-dir-buf-end (point-max)))
1407 ;; (goto-char pos)
1408 ;; (sas-move-to-filename (point-max))))))
1411 (defun sas-move-to-filename (&optional eol)
1412 (or eol (setq eol (progn (end-of-line) (point))))
1413 (beginning-of-line)
1414 (if (re-search-forward "\\(^ *[0-9]+ *<*\\)[^:0-9\n]" eol t)
1415 (goto-char (match-end 1))))
1417 (defun sas-next-line (arg)
1418 "Move down one line."
1419 (interactive "p")
1420 (forward-line arg)
1421 (sas-move-to-filename (point-max)))
1422 ;;(and (< (point) sas-dir-buf-end)
1423 ;;(forward-line arg)
1424 ;;(sas-move-to-filename sas-dir-buf-end)))
1426 (defun sas-prev-line (arg)
1427 "Move up one line."
1428 (interactive "p")
1429 (beginning-of-line)
1430 (re-search-backward "^ *[0-9]+ *<*[^:0-9\n]" (point-min) t)
1431 (sas-move-to-filename sas-dir-buf-end))
1433 (defun sas-insert-set-properties (beg end)
1434 (save-excursion
1435 (goto-char beg)
1436 (while (< (point) end)
1437 (if (sas-move-to-filename)
1438 (put-text-property (point)
1439 (+ 8 (point))
1440 'mouse-face 'highlight))
1441 (forward-line 1))))
1443 (defun sas-get-filename ()
1444 "Return name of dataset on current line."
1445 (interactive)
1446 (save-excursion
1447 (if (string-equal "*SAS-dir" (substring (buffer-name) 0 8))
1448 (sas-move-to-filename)
1449 (goto-char (point-min))
1450 (re-search-forward "Data Set Name: [^.]*\\."))
1451 (expand-file-name
1452 (downcase (concat sas-directory-name
1453 (buffer-substring
1454 (point)
1455 (save-excursion
1456 (skip-chars-forward "A-Z0-9_")
1457 (point))) ".ssd01")))))
1459 (defun sas-get-file-number ()
1460 "Return name of dataset on current line."
1461 (interactive)
1462 (if (sas-move-to-filename)
1463 (progn (forward-word -1)
1464 (re-search-forward "[0-9]*")
1465 (string-to-number
1466 (buffer-substring (match-beginning 0)
1467 (match-end 0))))))
1469 ;;(defun sas-contents ()
1470 ;; "Run proc contents on current file."
1471 ;; (interactive)
1472 ;; (let ((buffer-read-only nil) (sas-get-options "linesize=70"))
1473 ;; (sas-get-dataset (sas-get-filename) 2 t t (buffer-name))
1474 ;; (end-of-buffer)
1475 ;; (backward-page-top-of-window 1)))
1477 ;;(defun sas-print ()
1478 ;; "Run proc contents on current file."
1479 ;; (interactive)
1480 ;; (sas-get-dataset (sas-get-filename) 1 nil nil nil
1481 ;; (sas-create-var-string)))
1483 (defun sas-goto-page (arg)
1484 "Goto top of page ARG. If no ARG, then goto top of file."
1485 (interactive "P")
1486 (goto-char 1)
1487 (if arg
1488 (if (> arg 1)
1489 (progn
1490 (re-search-forward page-delimiter (point-max) 1 (1- arg)))))
1491 (skip-chars-forward sas-white-chars); was " \f\n" till 5.1.13
1492 (recenter 1))
1494 (defun forward-page-top-of-window (arg)
1495 "Move forward to page boundary and leave first line at top of window.
1496 With arg, repeat, or go back if negative. A page boundary is any line
1497 whose beginning matches the regexp `page-delimiter'."
1498 (interactive "p")
1499 (forward-page arg)
1500 (recenter 0))
1502 (defun backward-page-top-of-window (arg)
1503 "Move backward to page boundary and leave first line at top of window.
1504 With arg, repeat, or go back if negative. A page boundary is any line
1505 whose beginning matches the regexp `page-delimiter'."
1506 (interactive "p")
1507 (forward-page (- arg))
1508 (recenter 0))
1510 (defun sas-narrow-to-page ()
1511 (save-excursion
1512 (let* ((min (point-min))
1513 (max (point-max)))
1514 ;;(omin (point-min))
1515 ;;(omax (point-max)))
1516 (if (or (bolp) (beginning-of-line)
1517 (looking-at page-delimiter))
1518 (forward-char 1)
1519 (forward-page -1))
1520 (setq min (point))
1521 (forward-page 1)
1522 (beginning-of-line)
1523 (setq max (point))
1524 (narrow-to-region min max))))
1526 (defun sas-forward-page-narrow (arg)
1527 "Move forward to page boundary and narrow to page.
1528 With arg, repeat, or go back if negative. A page boundary is any line
1529 whose beginning matches the regexp `page-delimiter'."
1530 (interactive "p")
1531 (widen)
1532 (forward-page arg)
1533 (sas-narrow-to-page)
1534 (goto-char (point-min)))
1536 (defun sas-backward-page-narrow (arg)
1537 "Move backward to page boundary and narrow to page.
1538 With arg, repeat, or go back if negative. A page boundary is any line
1539 whose beginning matches the regexp `page-delimiter'."
1540 (interactive "p")
1541 (goto-char (point-min))
1542 (widen)
1543 (forward-page (- arg))
1544 (sas-narrow-to-page))
1546 (defun sas-goto-dataset (&optional page)
1547 (interactive)
1548 (and sas-directory-name
1549 (let ((page (or page (sas-get-file-number))))
1550 ;;(dir sas-directory-name))
1551 (if page
1552 (progn
1553 (switch-to-buffer-other-window
1554 (concat "*SAS-cont-" sas-directory-name))
1555 (widen)
1556 (sas-goto-page page)
1557 (sas-narrow-to-page)
1558 (goto-char (point-min)))))))
1560 ;;(defun sas-mouse-goto-dataset (event)
1561 ;; (interactive "e")
1562 ;; (let (page buf)
1563 ;; (save-window-excursion
1564 ;; (save-excursion
1565 ;; (set-buffer (window-buffer (posn-window (event-end event))))
1566 ;; (save-excursion
1567 ;; (goto-char (posn-point (event-end event)))
1568 ;; (setq page (sas-get-file-number)))
1569 ;; (sas-goto-dataset page)
1570 ;; (setq buf (buffer-name))))
1571 ;; (set-buffer buf)
1572 ;; (goto-char (point-min))
1573 ;; (display-buffer buf)))
1576 (defun sas-dir-goto-page (page)
1577 (interactive "p")
1578 (widen)
1579 (sas-goto-page page)
1580 (sas-narrow-to-page))
1582 (defun sas-mark-item (&optional next)
1583 (interactive)
1584 (sas-move-to-filename)
1585 (beginning-of-line)
1586 (let ((buffer-read-only nil))
1587 (if (re-search-forward "^\\( *[0-9]+ *\\) \\([A-Z][A-Z_0-9]*\\) "
1588 (save-excursion (end-of-line) (point)) t)
1589 (replace-match "\\1<\\2>")))
1590 (or next (sas-next-line 1)))
1592 (defun sas-unmark-item ()
1593 (interactive)
1594 (save-excursion
1595 (beginning-of-line)
1596 (let ((buffer-read-only nil))
1597 (if (re-search-forward "^\\( *[0-9]+ *\\)<\\([A-Z][A-Z_0-9]*\\)>"
1598 (save-excursion (end-of-line) (point)) t)
1599 (replace-match "\\1 \\2 ")))))
1601 (defun sas-prev-line-undo (arg)
1602 (interactive "p")
1603 (sas-prev-line arg)
1604 (sas-unmark-item)
1605 (sas-move-to-filename))
1607 (defun sas-create-var-string ()
1608 (and (string-equal "*SAS-cont" (substring (buffer-name) 0 9))
1609 (let (str)
1610 (goto-char (point-min))
1611 (while
1612 (re-search-forward "^\\( *[0-9]+ *\\)<\\([A-Z][A-Z_0-9]*\\)>"
1613 nil t)
1614 (setq str (concat str " " (buffer-substring (match-beginning 2)
1615 (match-end 2)))))
1616 str)))
1618 ;;(defun sas-revert-library ()
1619 ;; "Update current library."
1620 ;; (interactive)
1621 ;; (if sas-directory-name
1622 ;; (sas-make-library sas-directory-name t)))
1624 (provide 'essl-sas)
1626 \f ; Local variables section
1628 ;;; This file is automatically placed in Outline minor mode.
1629 ;;; The file is structured as follows:
1630 ;;; Chapters: ^L ;
1631 ;;; Sections: ;;*;;
1632 ;;; Subsections: ;;;*;;;
1633 ;;; Components: defuns, defvars, defconsts
1634 ;;; Random code beginning with a ;;;;* comment
1635 ;;; Local variables:
1636 ;;; mode: emacs-lisp
1637 ;;; mode: outline-minor
1638 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
1639 ;;; End:
1641 ;;; essl-sas.el ends here