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