1 ;;; essa-sas.el -- clean-room implementation of many SAS-mode features
3 ;; Copyright (C) 1997--2004 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 "gv"))
95 (if (not ess-tmp-file
) (setq ess-tmp-file
(executable-find "ghostview")))
97 (if (not ess-tmp-file
) (setq ess-tmp-file
(executable-find
98 (if ess-microsoft-p
"gsview32" "gsview"))))
101 (setq ess-tmp-alist
(list (cons "[eE]?[pP][sS]" ess-tmp-file
)
102 (cons "[pP][dD][fF]" ess-tmp-file
)))
104 (setq ess-tmp-file
(executable-find (if ess-microsoft-p
"acrord32" "acroread")))
107 (setq ess-tmp-alist
(cons "[pP][dD][fF]" ess-tmp-file
)))))
109 "*Associate file name extensions with graphics image file viewers."
113 ;;(defcustom ess-sas-smart-back-tab nil
114 ;; "*Set to t to make C-TAB insert an end/%end; statement to close a block."
118 (defcustom ess-sas-log-max
2500000
119 "*If a .log file exceeds this many bytes, just \"refresh\" this many bytes."
123 (defcustom ess-sas-shell-buffer
"*shell*"
124 "*Name that you want to use for the shell buffer; buffer-local."
128 (make-variable-buffer-local 'ess-sas-shell-buffer
)
130 (defcustom ess-sas-shell-buffer-remote-host nil
131 "*Remote host that you want to open a shell on."
133 :type
'(choice (const nil
) string
))
135 (make-variable-buffer-local 'ess-sas-shell-buffer-remote-host
)
137 (defcustom ess-sas-shell-buffer-remote-init
"ssh"
138 "*Command to open a shell on a remote host."
142 (make-variable-buffer-local 'ess-sas-shell-buffer-remote-init
)
144 (defcustom ess-sas-submit-mac-virtual-pc nil
145 "*Non-nil means that you want to run Windows SAS in a
146 Virtual PC emulator on your Mac; buffer-local."
150 (make-variable-buffer-local 'ess-sas-submit-mac-virtual-pc
)
152 (defcustom ess-sas-submit-command sas-program
153 "*Command to invoke SAS in batch; buffer-local."
157 (make-variable-buffer-local 'ess-sas-submit-command
)
159 (defcustom ess-sas-submit-command-options
" "
160 "*Options to pass to SAS in batch; buffer-local."
164 (make-variable-buffer-local 'ess-sas-submit-command-options
)
166 (defvar ess-sas-submit-method
168 (if (w32-shell-dos-semantics) 'ms-dos
'sh
)
169 (if (or (equal system-type
'Apple-Macintosh
)
170 (and ess-sas-submit-mac-virtual-pc
(equal system-type
'darwin
)))
172 "Method used by `ess-sas-submit'.
173 The default is based on the value of the emacs variable `system-type'
174 and, on Windows, the function `w32-shell-dos-semantics'.
175 'sh if *shell* runs sh, ksh, csh, tcsh or bash
176 'ms-dos if *shell* follows MS-DOS semantics
177 'apple-script *shell* unavailable in Mac Classic, use AppleScript,
178 also for Windows SAS in Virtual PC on Mac OS X
180 Unix users will get 'sh by default.
182 Windows users running bash in *shell* will get 'sh by default.
184 Windows users running MS-DOS in *shell* will get 'ms-dos by default.
186 Users accessing a remote machine with `telnet', `rlogin', `ssh', etc.,
187 should set this variable to 'sh regardless of their local shell
188 (since their remote shell is 'sh).")
190 (make-variable-buffer-local 'ess-sas-submit-method
)
192 (defcustom ess-sas-graph-view-viewer-default
193 (if ess-microsoft-p
"kodakimg"
194 (if (equal ess-sas-submit-method
'sh
) "sdtimage"))
195 "*Default graphics image file viewer."
199 (defcustom ess-sas-submit-post-command
200 (if (equal ess-sas-submit-method
'sh
) "-rsasuser &"
201 (if ess-microsoft-p
"-rsasuser -icon"))
202 "*Command-line statement to post-modify SAS invocation, e.g. -rsasuser"
206 (defcustom ess-sas-submit-pre-command
207 (if (equal ess-sas-submit-method
'sh
)
208 ;; nice is tricky, higher numbers give you lower priorities
209 ;; if you are using csh/tcsh, the default priority is 4
210 ;; if you are using most other shells, the default priority is 10,
211 ;; and some implementations are higher, i.e. zsh unless you
212 ;; specify "setopt no_bg_nice" in your ~/.zshrc
213 ;; therefore, on the same machine, you can run at a higher or
214 ;; lower priority by changing shells, although, the command
216 ;; the following code should give you a priority of 10 regardless
217 ;; of which shell is in use, but it will default to the old
218 ;; behavior if csh or variant is not recognized
219 ;; this should avoid the necessity of each user needing to set this
220 ;; variable correctly based on the shell that they use and provide
221 ;; an environment where all shells are treated equally
222 (let* ((temp-shell (getenv "SHELL"))
223 (temp-char (string-match "/" temp-shell
)))
226 (setq temp-shell
(substring temp-shell
(+ 1 temp-char
)))
227 (setq temp-char
(string-match "/" temp-shell
)))
229 (cond ((or (equal temp-shell
"csh") (equal temp-shell
"tcsh"))
232 (if ess-microsoft-p
"start"))
233 "*Command-line statement to precede SAS invocation, e.g. start or nohup"
237 (defcustom ess-sas-suffix-1
"txt"
238 "*The first suffix to associate with SAS."
242 (defcustom ess-sas-suffix-2
"csv"
243 "*The second suffix to associate with SAS."
247 (defcustom ess-sas-suffix-regexp
248 (concat "[.]\\([sS][aA][sS]\\|[lL][oO][gG]\\|[lL][sS][tT]"
249 (if ess-sas-suffix-1
(concat
250 "\\|" (downcase ess-sas-suffix-1
) "\\|" (upcase ess-sas-suffix-1
)))
251 (if ess-sas-suffix-2
(concat
252 "\\|" (downcase ess-sas-suffix-2
) "\\|" (upcase ess-sas-suffix-2
)))
254 "*Regular expression for SAS suffixes."
258 (defcustom ess-sleep-for
(if ess-microsoft-p
5 0)
259 "*`ess-sas-submit-sh' may need to pause before sending output
260 to the shell on Windows when `ess-sas-submit-method' is 'sh."
264 (defvar ess-sas-tab-stop-alist
265 '(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)
266 "List of tab stop positions used by `tab-to-tab-stop' in ESS[SAS].")
268 (defcustom ess-sas-temp-root
"ess-temp"
269 "*The root of the temporary .sas file for `ess-sas-submit-region'."
273 ;;; Section 2: Function Definitions
276 (defun ess-ebcdic-to-ascii-search-and-replace ()
277 "*Search and replace EBCDIC text with ASCII equivalents."
279 (let ((ess-tmp-dd (executable-find "dd")) (ess-tmp-recode (executable-find "recode"))
280 (ess-tmp-util nil
) (ess-tmp-util-args nil
))
282 (if ess-tmp-dd
(progn
283 (setq ess-tmp-util ess-tmp-dd
)
284 (setq ess-tmp-util-args
"conv=ascii"))
286 (setq ess-tmp-util ess-tmp-recode
)
287 (setq ess-tmp-util-args
"EBCDIC..ISO-8859-1"))
290 (while (search-forward-regexp "[^\f\t\n -~][^\f\t\n -?A-JQ-Yb-jp-y]*[^\f\t\n -~]?" nil t
)
291 (call-process-region (match-beginning 0) (match-end 0)
292 ess-tmp-util t
(list t nil
) t ess-tmp-util-args
)))))
294 (defun ess-exit-notify-sh (string)
295 "Detect completion or failure of submitted job and notify the user."
296 (let* ((exit-done "\\[[0-9]+\\]\\ *\\+*\\ *\\(Exit\\|Done\\).*$")
297 (beg (string-match exit-done string
)))
299 (message (substring string beg
(match-end 0))))))
303 (defun ess-sas-append-log ()
304 "Append ess-temp.log to the current .log file."
306 (ess-sas-goto "log" 'revert
)
307 (goto-char (point-max))
308 (insert-file-contents (concat ess-sas-temp-root
".log"))
311 (defun ess-sas-append-lst ()
312 "Append ess-temp.lst to the current .lst file."
314 (ess-sas-goto "lst" 'revert
)
315 (goto-char (point-max))
316 (insert-file-contents (concat ess-sas-temp-root
".lst"))
319 (defun ess-sas-backward-delete-tab ()
320 "Moves the cursor to the previous tab-stop, deleting any characters
324 (let* (;; point of search
325 ;;(ess-sas-search-point nil)
327 ;;(ess-sas-search-column nil)
329 ;;(ess-sas-search-limit nil)
330 ;; text to be inserted after a back-tab, if any
331 ;;(ess-sas-end-text "end;")
333 (ess-sas-column (current-column))
334 ;; remainder of current-column and sas-indent-width
335 (ess-sas-remainder (% ess-sas-column sas-indent-width
)))
337 (if (not (= ess-sas-column
0))
339 (if (= ess-sas-remainder
0)
340 (setq ess-sas-remainder sas-indent-width
))
342 (let ((backward-delete-char-untabify-method 'nil
))
343 (backward-delete-char-untabify ess-sas-remainder t
)
344 (setq ess-sas-column
(- ess-sas-column ess-sas-remainder
))
345 (move-to-column ess-sas-column
)
346 (setq left-margin ess-sas-column
))
350 ;; this feature was far too complicated to perfect
351 ;; (if ess-sas-smart-back-tab (progn
353 ;; (setq ess-sas-search-point
354 ;; (search-backward-regexp "end" nil t))
356 ;; (if (and ess-sas-search-point
357 ;; (search-backward-regexp "%" (+ ess-sas-search-point -1) t))
358 ;; (setq ess-sas-search-point (+ ess-sas-search-point -1))
361 ;; (if (and ess-sas-search-point
362 ;; (not (equal ess-sas-column (current-column))))
363 ;; (setq ess-sas-search-point nil))
367 ;; (setq ess-sas-search-point
368 ;; (search-backward-regexp "do\\|select"
369 ;; ess-sas-search-point t))
371 ;; (setq ess-sas-search-column (current-column))
373 ;; (if ess-sas-search-point (progn
375 ;; (search-backward-regexp "^" nil t)
376 ;; (setq ess-sas-search-limit (point))
379 ;; (if (search-backward-regexp "if.*then\\|else" ess-sas-search-limit t)
380 ;; (setq ess-sas-search-point (point)))
382 ;; (if (search-backward-regexp "%" ess-sas-search-limit t) (progn
383 ;; (setq ess-sas-end-text "%end;")
384 ;; (setq ess-sas-search-point (point))
387 ;; (setq ess-sas-search-column (current-column))
389 ;; (if (not (equal ess-sas-column ess-sas-search-column))
390 ;; (setq ess-sas-search-point nil))
393 ;; (if ess-sas-search-point (insert ess-sas-end-text))
397 "Change directory, taking into account various issues with respect to
398 `ess-sas-file-path'."
401 (ess-sas-goto-shell t
)
402 (if (equal ess-sas-submit-method
'sh
)
403 (insert "cd " (car (last (split-string (file-name-directory ess-sas-file-path
)
404 "\\([a-zA-Z][a-zA-Z]:\\|]\\)"))))
405 (if (equal ess-sas-submit-method
'ms-dos
) (progn
406 (if (string-equal ":" (substring ess-sas-file-path
1 2)) (progn
407 (insert (substring ess-sas-file-path
0 2))
408 (comint-send-input)))
409 (insert "cd \"" (convert-standard-filename
410 (file-name-directory ess-sas-file-path
)) "\""))))
413 (defun ess-sas-create-local-variables-alist (&optional file-or-buffer
)
414 "Create an alist of local variables from file-or-buffer, use the
415 current buffer if nil."
417 (if file-or-buffer
(set-buffer (ess-get-file-or-buffer file-or-buffer
)))
419 (ess-change-alist 'ess-kermit-remote-directory ess-kermit-remote-directory nil
))
421 (defun ess-sas-data-view-fsview (&optional ess-sas-data
)
422 "Open a dataset for viewing with PROC FSVIEW."
424 (ess-save-and-set-local-variables)
426 (save-excursion (let ((ess-tmp-sas-data nil
)
427 (ess-tmp-sas-data-view-fsview-statement ess-sas-data-view-fsview-statement
)
429 "[ \t=]\\([a-zA-Z_][a-zA-Z_0-9]*[.][a-zA-Z_][a-zA-Z_0-9]*\\)\\(&.*\\)?[. ,()\t;]")
431 "^\\([wW][oO][rR][kK]\\|[fF][iI][rR][sS][tT]\\|[lL][aA][sS][tT]\\)[.]"))
433 (if ess-sas-data nil
(save-match-data
434 (search-backward-regexp "[ \t=]" nil t
)
437 (setq ess-tmp-sas-data
438 (ess-search-except ess-search-regexp ess-search-except
)))
440 (if (not ess-tmp-sas-data
)
441 (setq ess-tmp-sas-data
442 (ess-search-except ess-search-regexp ess-search-except t
)))
444 (setq ess-sas-data
(read-string "Permanent SAS Dataset: " ess-tmp-sas-data
))
446 (ess-sas-goto-shell t
)
449 (insert (concat ess-sas-submit-pre-command
" " ess-sas-submit-command
450 " -initstmt \"" ess-sas-data-view-libname ess-sas-data-view-fsview-command
451 ess-sas-data
";" ess-tmp-sas-data-view-fsview-statement
"; run;\" "
452 ess-sas-data-view-submit-options
" " ess-sas-submit-post-command
))
456 (defun ess-sas-data-view-insight (&optional ess-sas-data
)
457 "Open a dataset for viewing with PROC INSIGHT."
459 (ess-save-and-set-local-variables)
461 (save-excursion (let ((ess-tmp-sas-data nil
)
462 (ess-tmp-sas-data-view-insight-statement ess-sas-data-view-insight-statement
)
464 "[ \t=]\\([a-zA-Z_][a-zA-Z_0-9]*[.][a-zA-Z_][a-zA-Z_0-9]*\\)\\(&.*\\)?[. ,()\t;]")
466 "^\\([wW][oO][rR][kK]\\|[fF][iI][rR][sS][tT]\\|[lL][aA][sS][tT]\\)[.]"))
468 (if ess-sas-data nil
(save-match-data
469 (search-backward-regexp "[ \t=]" nil t
)
472 (setq ess-tmp-sas-data
473 (ess-search-except ess-search-regexp ess-search-except
)))
475 (if (not ess-tmp-sas-data
)
476 (setq ess-tmp-sas-data
477 (ess-search-except ess-search-regexp ess-search-except t
)))
479 (setq ess-sas-data
(read-string "Permanent SAS Dataset: " ess-tmp-sas-data
))
481 (ess-sas-goto-shell t
)
484 (insert (concat ess-sas-submit-pre-command
" " ess-sas-submit-command
485 " -initstmt \"" ess-sas-data-view-libname ess-sas-data-view-insight-command
486 ess-sas-data
";" ess-tmp-sas-data-view-insight-statement
"; run;\" "
487 ess-sas-data-view-submit-options
" " ess-sas-submit-post-command
))
491 (defun ess-sas-graph-view ()
492 "Open a GSASFILE for viewing."
494 ; (ess-sas-file-path)
495 (ess-sas-goto-log 'no-error-check
)
497 (save-excursion (let (
498 (ess-tmp-length (length ess-sas-graph-view-viewer-alist
))
501 (ess-tmp-graph-alist nil
)
503 (ess-tmp-graph-regexp
504 (concat "[ ]RECORDS[ ]WRITTEN[ ]TO[ ]\n?[ ]*\\(\\(\n\\|[^.]\\)*"
505 ess-sas-graph-view-suffix-regexp
"\\)")))
506 ; (concat "['\"]\\(.*" ess-sas-graph-suffix-regexp "\\)['\"]")))
509 (search-backward-regexp "[ \t=]" nil t
)
512 (setq ess-tmp-graph
(ess-search-except ess-tmp-graph-regexp
)))
514 (if (not ess-tmp-graph
)
515 (setq ess-tmp-graph
(ess-search-except ess-tmp-graph-regexp nil t
)))
517 (setq ess-tmp-graph
(read-string "GSASFILE: "
518 (or ess-tmp-graph ess-sas-file-path
)))
520 (if (fboundp 'ess-xemacs-insert-glyph
) (progn
521 (if (string-match "[.][gG][iI][fF]" ess-tmp-graph
)
522 (setq ess-tmp-glyph
'gif
)
524 (if (string-match "[.][jJ][pP][eE]?[gG]" ess-tmp-graph
)
525 (setq ess-tmp-glyph
'jpeg
)))))
527 ;;GNU Emacs graphics file image viewing mode loaded?
528 (if (and (boundp 'auto-image-file-mode
) auto-image-file-mode
529 (string-match "[.][jJ][pP][eE]?[gG]" ess-tmp-graph
))
530 (find-file ess-tmp-graph
)
531 ;;else XEmacs graphics file image viewing mode loaded?
532 (if (and (fboundp 'image-mode
)
533 (string-match "[.]\\([jJ][pP][eE]?[gG]\\|[gG][iI][fF]\\)"
535 (find-file ess-tmp-graph
)
536 ;;else XEmacs graphics file image viewing primitives loaded?
537 (if ess-tmp-glyph
(progn
538 (switch-to-buffer (file-name-nondirectory ess-tmp-graph
))
539 (ess-xemacs-insert-glyph
540 (make-glyph (vector ess-tmp-glyph
:file ess-tmp-graph
))))
542 ;;else use the appropriate graphics file image viewer
543 (while (< ess-tmp-counter ess-tmp-length
)
544 (setq ess-tmp-graph-alist
545 (nth ess-tmp-counter ess-sas-graph-view-viewer-alist
))
546 (setq ess-tmp-graph-regexp
(car ess-tmp-graph-alist
))
549 (concat "[.]" ess-tmp-graph-regexp
) ess-tmp-graph
)
551 (ess-sas-goto-shell t
)
552 (insert ess-sas-submit-pre-command
" "
553 (cdr ess-tmp-graph-alist
) " " ess-tmp-graph
554 (if (equal ess-sas-submit-method
'sh
) " &"))
555 (setq ess-tmp-glyph
'alist
)
556 (setq ess-tmp-counter ess-tmp-length
))
558 (setq ess-tmp-counter
(+ ess-tmp-counter
1))))
560 (if (not ess-tmp-glyph
) (progn
561 (ess-sas-goto-shell t
)
562 (insert ess-sas-submit-pre-command
" "
563 ess-sas-graph-view-viewer-default
" " ess-tmp-graph
564 (if (equal ess-sas-submit-method
'sh
) " &"))))
566 (comint-send-input))))))))
568 (defun ess-sas-file-path ()
569 "Define `ess-sas-file-path' to be the current buffer depending on suffix."
572 (save-match-data (let ((ess-sas-temp-file (expand-file-name (buffer-name))))
573 (if (string-match ess-sas-suffix-regexp ess-sas-temp-file
) ;;(progn
574 (setq ess-sas-file-path
575 (nth 0 (split-string ess-sas-temp-file
"[<]")))))))
576 ;; (setq ess-directory (file-name-directory ess-sas-file-path)))))))
578 (defun ess-sas-file-path-remote-host ()
579 "Return the remote host, if any, associated with `ess-sas-file-path'."
582 (let* ((temp-colon-pos (string-match ":" ess-sas-file-path
))
584 (if (or (not temp-colon-pos
) (> temp-colon-pos
2))
585 (if (equal ess-sas-file-path
".") nil
586 (split-string (file-name-directory ess-sas-file-path
)
588 (list ess-sas-file-path
)))
589 (temp-list-length (length temp-list
)))
590 (if (= temp-list-length
1) (setq temp-list nil
)
591 (if (= temp-list-length
2) (setq temp-list
(car temp-list
))
592 (setq temp-list
(nth 1 temp-list
))))
594 (if temp-list
(setq temp-list
595 (car (last (split-string temp-list
"/")))))
598 (defun ess-sas-goto (suffix &optional revert no-create
)
599 "Find a file associated with a SAS file by suffix and revert if necessary."
600 (let ((ess-temp-regexp (concat ess-sas-suffix-regexp
"\\(@.+\\)?")))
602 (if (or (string-match ess-temp-regexp
(expand-file-name (buffer-name)))
603 (string-match ess-temp-regexp ess-sas-file-path
))
607 (ess-sas-temp-file (replace-match (concat "." suffix
) t t
609 (ess-sas-temp-buff (find-buffer-visiting ess-sas-temp-file
))
610 (ess-temp-kermit-remote-directory ess-kermit-remote-directory
))
612 (if ess-sas-temp-buff
(switch-to-buffer ess-sas-temp-buff
)
614 (if no-create
(setq revert nil
) (find-file ess-sas-temp-file
)))
616 (if (and (not no-create
)
617 (or (string-equal suffix
"log")
618 (string-equal suffix
"lst")))
619 (ess-kermit-get (file-name-nondirectory ess-sas-temp-file
)
620 ess-temp-kermit-remote-directory
))
623 (if (and ess-sas-log-max
(string-equal suffix
"log")
624 (> (nth 7 (file-attributes ess-sas-temp-file
))
627 (insert-file-contents ess-sas-temp-file nil
0
631 (ess-revert-wisely)) nil
)))))))
633 ;;(defun ess-sas-file (suffix &optional revert)
634 ;; "Please use `ess-sas-goto' instead."
635 ;; (let* ((tail (downcase (car (split-string
636 ;; (car (last (split-string (buffer-name) "[.]"))) "[<]"))))
637 ;;(if (fboundp 'file-name-extension) (file-name-extension (buffer-name))
638 ;; (substring (buffer-name) -3)))
639 ;; (tail-in-tail-list (member tail (list "sas" "log" "lst"
640 ;; ess-sas-suffix-1 ess-sas-suffix-2)))
641 ;; (root (if tail-in-tail-list (expand-file-name (buffer-name))
642 ;; ess-sas-file-path))
643 ;; (ess-sas-arg (concat (file-name-sans-extension root) "." suffix))
644 ;; (ess-sas-buf (find-buffer-visiting ess-sas-arg)))
645 ;; (if (equal tail suffix) (if revert (ess-revert-wisely))
646 ;; (if (not ess-sas-buf) (find-file ess-sas-arg)
647 ;; (switch-to-buffer ess-sas-buf)
648 ;; (if revert (ess-revert-wisely))))))
651 (defun ess-sas-goto-file-1 ()
652 "Switch to ess-sas-file-1 and revert from disk."
654 (ess-sas-goto ess-sas-suffix-1
'revert
))
656 (defun ess-sas-goto-file-2 ()
657 "Switch to ess-sas-file-2 and revert from disk."
659 (ess-sas-goto ess-sas-suffix-2
'revert
))
661 (defun ess-sas-goto-log (&optional ess-tmp-no-error-check
)
662 "Switch to the .log file, revert from disk and search for error messages."
665 (let ((ess-sas-error (concat
666 "^ERROR [0-9]+-[0-9]+:\\|^ERROR:\\|_ERROR_=1 _N_=\\|_ERROR_=1[ ]?$"
667 "\\|NOTE: MERGE statement has more than one data set with repeats of BY values."
668 "\\|NOTE: Variable .* is uninitialized."
669 "\\|WARNING: Apparent symbolic reference .* not resolved."
670 "\\|NOTE 485-185: Informat .* was not found or could not be loaded."
671 "\\|WARNING: Length of character variable has already been set."
672 "\\|Bus Error In Task\\|Segmentation Violation In Task"
673 "\\|NOTE: Estimated G matrix is not positive definite."))
674 (ess-sas-save-point nil
))
676 (if (ess-sas-goto "log" 'revert
) (progn
677 (setq ess-sas-save-point
(point))
678 (goto-char (point-min)))
679 (setq ess-sas-save-point
(point)))
681 (if ess-tmp-no-error-check
(goto-char ess-sas-save-point
)
682 (if (or (search-forward-regexp ess-sas-error nil t
)
683 (and (goto-char (point-min))
684 (search-forward-regexp ess-sas-error nil t
)))
685 (if (and (boundp 'zmacs-regions
) zmacs-regions
)
687 (if ess-sas-pop-mark
(pop-mark)
688 (setq ess-sas-pop-mark t
))
689 (push-mark (match-beginning 0) t
)
690 (zmacs-activate-region)))
691 (goto-char ess-sas-save-point
)))))
693 (defun ess-sas-goto-lst ()
694 "Switch to the .lst file and revert from disk."
696 (ess-sas-goto "lst" 'revert
))
698 (defun ess-sas-goto-sas (&optional revert
)
699 "Switch to the .sas file."
701 (ess-sas-goto "sas" revert
))
703 (defun ess-sas-goto-shell (&optional set-buffer
)
704 "Set `ess-sas-file-path' and goto `ess-sas-shell-buffer'. If
705 optional argument is non-nil, then set-buffer rather than switch."
709 ; The following let* block is an attempt to deal with remote directories.
710 (let* ((temp-shell-buffer-remote-host
711 (or ess-sas-shell-buffer-remote-host
(ess-sas-file-path-remote-host)))
712 (temp-shell-buffer-remote-init ess-sas-shell-buffer-remote-init
)
714 (if temp-shell-buffer-remote-host
715 (concat "*" temp-shell-buffer-remote-host
"*")
716 ess-sas-shell-buffer
))
719 (if (get-buffer temp-shell-buffer
)
720 (if set-buffer
(set-buffer temp-shell-buffer
)
721 (switch-to-buffer temp-shell-buffer
))
723 (rename-buffer temp-shell-buffer
)
725 (if temp-shell-buffer-remote-host
(progn
727 temp-shell-buffer-remote-init
" " temp-shell-buffer-remote-host
))
731 (if (eq ess-sas-submit-method
'sh
)
732 (add-hook 'comint-output-filter-functions
'ess-exit-notify-sh
)) ;; 19.28
733 ;; nil t) works for newer emacsen
737 (goto-char (point-max))
738 ; (insert "cd " ess-temp-directory)
739 ; (comint-send-input))
742 (defun ess-sas-interactive ()
743 "And now for something completely different."
747 (let ((ess-temp-sas-file
749 (car (last (split-string ess-sas-file-path
"\\([a-zA-Z][a-zA-Z]:\\|]\\)"))) "[.]"))))
750 ;; (message "%s" ess-temp-sas-file)
751 (setq ess-sas-shell-buffer
"*iESS[SAS]*")
753 (insert (concat ess-sas-submit-command
" " ess-sas-submit-command-options
754 " -altlog " ess-temp-sas-file
".log -altprint "
755 ess-temp-sas-file
".lst -stdio < /dev/tty"))
757 (ess-add-ess-process)
759 (setq ess-sas-submit-method
'iESS
)
760 (setq ess-eval-visibly-p nil
)
762 ;;(defun ess-sas-interactive ()
764 ;; (ess-sas-file-path)
765 ;; (setq ess-sas-submit-method 'iESS)
767 ;; (let ((ess-temp-stderr " ") (ess-temp-stdout " ") (ess-temp-stdin " "))
768 ;; (setq ess-sas-shell-buffer "*LOG*")
769 ;; (ess-sas-goto-shell)
771 ;; (comint-send-input)
773 ;; (save-excursion (setq ess-temp-stderr (ess-search-except "\\(/dev/[a-z0-9/]+\\)" nil t)))
774 ;; (setq ess-sas-shell-buffer "*OUTPUT*")
775 ;; (ess-sas-goto-shell)
777 ;; (comint-send-input)
779 ;; (save-excursion (setq ess-temp-stdout (ess-search-except "\\(/dev/[a-z0-9/]+\\)" nil t)))
780 ;; (setq ess-sas-shell-buffer "*PROGRAM*")
781 ;; (ess-sas-goto-shell)
783 ;; (comint-send-input)
786 ;; (comint-send-input)
788 ;; (save-excursion (setq ess-temp-stdin (ess-search-except "\\(/dev/[a-z0-9/]+\\)" nil t)))
789 ;; (insert (concat ess-sas-submit-command " " ess-sas-submit-command-options " -stdio <"
790 ;; ess-temp-stdin " >1 " ess-temp-stdout " >2 " ess-temp-stderr))
791 ;; (comint-send-input)
792 ;; (ess-add-ess-process)
793 ;; (ess-sas-goto-sas)
796 (defun ess-sas-kill-buffers ()
797 "Kill all buffers related to a .sas file."
800 (ess-sas-goto "log" nil t
)
802 (ess-sas-goto "lst" nil t
)
804 (ess-sas-goto ess-sas-suffix-1 nil t
)
806 (ess-sas-goto ess-sas-suffix-2 nil t
)
808 (ess-sas-goto "sas" nil t
)
815 (require 'rtf-support
)
816 (when (featurep 'rtf-support
)
818 (defun ess-sas-rtf-portrait ()
819 "Creates an MS RTF portrait file from the current buffer."
824 ((ess-temp-rtf-file (replace-in-string ess-sas-file-path
"[.][^.]*$" ".rtf")))
825 ;(expand-file-name (buffer-name)) "[.][^.]*$" ".rtf")))
826 (rtf-export ess-temp-rtf-file
)
827 (ess-sas-goto "rtf" t
)
828 (goto-char (point-min))
829 (replace-regexp "\\\\fmodern .*;" "\\\\fmodern courier;" )
830 (goto-char (point-min))
832 (while (replace-regexp "\\\\fs[0-9]+" "\\\\fs18" ) nil
)
836 (defun ess-sas-rtf-us-landscape ()
837 "Creates an MS RTF US landscape file from the current buffer."
839 (ess-sas-rtf-portrait)
840 (ess-sas-goto "rtf" t
)
841 (goto-char (point-min))
843 (insert (concat "{\\*\\pgdsctbl\n"
844 "{\\pgdsc0\\pgdscuse195\\lndscpsxn\\pgwsxn15840\\pghsxn12240\\marglsxn1800\\margrsxn1800\\margtsxn1440\\margbsxn1440\\pgdscnxt0 Default;}}\n"
845 "\\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"))
848 (defun ess-sas-rtf-a4-landscape ()
849 "Creates an MS RTF A4 landscape file from the current buffer."
851 (ess-sas-rtf-portrait)
852 (ess-sas-goto "rtf" t
)
853 (goto-char (point-min))
855 (insert (concat "{\\*\\pgdsctbl\n"
856 "{\\pgdsc0\\pgdscuse195\\lndscpsxn\\pgwsxn16837\\pghsxn11905\\marglsxn1800\\margrsxn1800\\margtsxn1440\\margbsxn1440\\pgdscnxt0 Default;}}\n"
857 "\\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"))
862 (defun ess-sas-submit ()
863 "Save the .sas file and submit to shell using a function that
864 depends on the value of `ess-sas-submit-method'"
868 (ess-save-and-set-local-variables)
871 ((eq ess-sas-submit-method
'apple-script
)
872 (ess-sas-submit-mac ess-sas-submit-command
873 ess-sas-submit-command-options
))
874 ((eq ess-sas-submit-method
'ms-dos
)
875 (ess-sas-submit-windows ess-sas-submit-command
876 ess-sas-submit-command-options
))
877 ((eq ess-sas-submit-method
'iESS
)
878 (ess-sas-submit-iESS ess-sas-submit-command
879 ess-sas-submit-command-options
))
880 ((eq ess-sas-submit-method
'sh
)
881 (ess-sas-submit-sh ess-sas-submit-command
882 ess-sas-submit-command-options
))
883 (t (ess-sas-submit-sh ess-sas-submit-command
884 ess-sas-submit-command-options
)))
888 (defun ess-sas-submit-iESS (arg1 arg2
)
890 Submit a batch job in an inferior-ESS buffer. The buffer should
891 (1) have telnet access and be running a shell on a remote machine
893 (2) be running a shell on the local machine.
895 The user can telnet to the remote computer and then declare the
896 *telnet-buffer* to be an inferior ESS buffer with the `ess-add-ess-process'
897 command. When using a remote computer, the .sas file must live on the
898 remote computer and be accessed through `ange-ftp'. When
899 `ess-sas-submit' saves a file, it is therefore saved on the remote
900 computer. The various functions such as `ess-sas-goto-lst' retrieve
901 their files from the remote computer. Local copies of the .sas .lst
902 .log and others may be made manually with `write-buffer'."
903 ;; (ess-eval-linewise (concat "cd default-directory))
904 (ess-force-buffer-current "Process to load into: ")
906 (concat "cd " (car (last
907 (split-string (file-name-directory ess-sas-file-path
) "\\(:\\|]\\)")))))
908 (ess-eval-linewise (concat arg1
" " arg2
" " (buffer-name) " &")))
910 (defun ess-sas-submit-mac (arg1 arg2
)
911 "If you are using Mac SAS, then arg1, `ess-sas-submit-command', should be
912 the AppleScript command \"invoke SAS using program file\", and, if necessary,
913 arg2, `ess-sas-submit-command-options', is a string of the form
914 \"with options { \\\"option-1\\\", \\\"option-2\\\", etc.}\". If you are
915 using Windows SAS with the PC emulator Virtual PC, then `ess-sas-submit-command'
917 ;(ess-save-and-set-local-variables)
919 (do-applescript (concat arg1
" \""
920 (if (not ess-sas-submit-mac-virtual-pc
)
921 (unix-filename-to-mac default-directory
))
922 (buffer-name) "\"" arg2
)))
924 (defun ess-sas-submit-region ()
925 "Write region to temporary file, and submit to SAS."
928 (write-region (region-beginning) (region-end)
929 (concat ess-sas-temp-root
".sas"))
932 (ess-sas-goto-shell t
)
934 (if (and (w32-shell-dos-semantics)
935 (string-equal ":" (substring ess-sas-file-path
1 2)))
937 (insert (substring ess-sas-file-path
0 2))
941 (insert "cd \"" (convert-standard-filename
942 (file-name-directory ess-sas-file-path
)) "\"")
945 (insert (concat ess-sas-submit-pre-command
" " ess-sas-submit-command
946 " " ess-sas-temp-root
" " ess-sas-submit-post-command
))
951 (defun ess-sas-submit-sh (arg1 arg2
)
952 "Unix or bash in the *shell* buffer.
953 Multiple processing is supported on this platform.
954 SAS may not be found in your PATH. You can alter your PATH to include
955 SAS or you can specify the PATHNAME (PATHNAME can NOT contain spaces),
956 i.e. let arg1 be your local equivalent of
957 \"/usr/local/sas612/sas\"."
958 (if (string-equal (substring
959 (file-name-nondirectory ess-sas-file-path
) 0 1) ess-kermit-prefix
)
962 (ess-sas-goto-shell t
)
963 (insert ess-sas-submit-pre-command
" " arg1
" "
964 (substring (file-name-sans-extension
965 (file-name-nondirectory ess-sas-file-path
)) 1)
966 " " arg2
" " ess-sas-submit-post-command
))
968 (ess-sas-goto-shell t
)
969 ; (if ess-microsoft-p
970 ; (insert "cd " (file-name-directory ess-sas-file-path))
971 ; (insert "cd " (car (last (split-string
972 ; (file-name-directory ess-sas-file-path) "\\(:\\|]\\)")))))
973 (insert "cd " (car (last (split-string (file-name-directory ess-sas-file-path
)
974 "\\([a-zA-Z][a-zA-Z]:\\|]\\)"))))
976 (insert ess-sas-submit-pre-command
" " arg1
" "
977 (file-name-sans-extension (file-name-nondirectory ess-sas-file-path
))
978 " " arg2
" " ess-sas-submit-post-command
))
982 (defun ess-sas-submit-windows (arg1 arg2
)
983 "Windows using MS-DOS prompt in the *shell* buffer.
984 Multiple processing is supported on this platform.
985 On most Windows installations, SAS will not be found in your
986 PATH. You can set `ess-sas-submit-command' to
987 \"sas -icon -rsasuser\" and alter your PATH to include SAS, i.e.
989 SET PATH=%PATH%;C:\\Program Files\\SAS
991 Or you can specify the PATHNAME directly (you must escape
992 spaces by enclosing the string in \\\"'s), i.e. let
993 `ess-sas-submit-command' be \"\\\"C:\\Program Files\\SAS\\sas.exe\\\"\".
994 Keep in mind that the maximum command line length in MS-DOS is
995 127 characters so altering your PATH is preferable."
996 ;(ess-save-and-set-local-variables)
997 (ess-sas-goto-shell t
)
998 (if (string-equal ":" (substring ess-sas-file-path
1 2))
1000 (insert (substring ess-sas-file-path
0 2))
1004 (insert "cd \"" (convert-standard-filename
1005 (file-name-directory ess-sas-file-path
)) "\"")
1007 (insert ess-sas-submit-pre-command
" " arg1
" -sysin \""
1008 (file-name-sans-extension (file-name-nondirectory ess-sas-file-path
)) "\" "
1009 arg2
" " ess-sas-submit-post-command
)
1010 (comint-send-input))
1012 (defun ess-sas-tab-to-tab-stop ()
1013 "Tab to next tab-stop and set left margin."
1016 (setq left-margin
(current-column))
1019 (defun ess-sas-transcript (&optional strip
)
1020 "Comment .log messages to create a .sas program; use C-u to strip."
1023 (goto-char (point-min))
1025 (while (search-forward-regexp (concat
1026 "^\\(\\(1[ \t]+The SAS System\\|\f\\|NOTE\\|WARNING\\|ERROR\\|"
1027 "[ \t]+\\(\\(real\\|cpu\\) time\\|Licensed to\\|Engine:\\|"
1028 "Physical Name:\\|File Name=\\|Owner Name=\\|Group Name=\\|"
1029 "Access Permission=\\|File Size (bytes)=\\|Pipe command=\\|"
1030 "RECFM=[DFNPV],LRECL=\\|[0-9]+:[0-9]+[ /t]+[0-9]+:[0-9]+\\|"
1031 "[1-9][0-9]* at [0-9]+:[0-9]+[ /t]+[1-9][0-9]* at [0-9]+:[0-9]+\\)\\).*$"
1032 "\\|[0-9]+\\([ \t]+!\\)?\\|MPRINT([_A-Z]+):\\|"
1033 "[ \t]+\\(values at the places given by: (Line):(Column).\\|"
1034 "The m\\(in\\|ax\\)imum record length was [1-9][0-9]*.\\|"
1035 "One or more lines were truncated.\\|"
1036 "Each place is given by: (Number of times) at (Line):(Column).\\|"
1037 "[0-9][0-9]:[0-9][0-9] [MTWFS][aeioudhnrst]+day, [JFMASOND]"
1038 "[aeiouybcghlmnprstv]+ [1-9][0-9]?, 20[0-9][0-9]\\)\\)")
1039 nil t
) (replace-match (if strip
" " "/*\\&*/") t
))
1042 (defun ess-sas-toggle-sas-listing-mode (&optional force
)
1043 "Toggle SAS-listing-mode for .lst files."
1047 (if (equal (cdr (assoc "\\.[lL][sS][tT]\\'" auto-mode-alist
)) 'SAS-listing-mode
) (progn
1048 (setq auto-mode-alist
(delete '("\\.[lL][sS][tT]\\'" . SAS-listing-mode
) auto-mode-alist
))
1049 (setq buffer-read-only nil
)
1050 (ess-listing-minor-mode 0))
1051 (setq auto-mode-alist
(append '(("\\.[lL][sS][tT]\\'" . SAS-listing-mode
)) auto-mode-alist
))
1052 (setq buffer-read-only t
)
1053 (ess-listing-minor-mode 1)))
1055 (defun ess-sas-toggle-sas-log-mode ()
1056 "Toggle SAS-log-mode for .log files."
1058 (ess-sas-goto-log t
)
1060 (if (equal (cdr (assoc "\\.[lL][oO][gG]\\'" auto-mode-alist
)) 'SAS-log-mode
) (progn
1061 (setq auto-mode-alist
(delete '("\\.[lL][oO][gG]\\'" . SAS-log-mode
) auto-mode-alist
))
1062 (setq buffer-read-only nil
)
1063 (ess-transcript-minor-mode 0)
1065 (setq auto-mode-alist
(append '(("\\.[lL][oO][gG]\\'" . SAS-log-mode
)) auto-mode-alist
))
1066 (setq buffer-read-only t
)
1067 (ess-transcript-minor-mode 1)
1069 (font-lock-fontify-buffer)))
1072 "Put emacs to sleep for `ess-sleep-for' seconds.
1073 Sometimes its necessary to wait for a shell prompt."
1074 (if (featurep 'xemacs
) (sleep-for ess-sleep-for
)
1075 (sleep-for 0 (truncate (* ess-sleep-for
1000)))
1079 ;;; Section 3: Key Definitions
1082 (defun ess-sas-edit-keys-set (&optional arg
)
1083 "Set TAB/RET key in `SAS-mode'.
1085 TAB is `sas-indent-line' and
1086 RET is `newline-and-indent'.
1088 TAB is `ess-sas-tab-to-tab-stop',
1089 C-TAB is `ess-sas-backward-delete-tab' and
1095 (if (and (equal emacs-major-version
19) (equal emacs-minor-version
28))
1096 (define-key sas-mode-local-map
[C-tab
] 'ess-sas-backward-delete-tab
)
1098 (define-key sas-mode-local-map
[(control tab
)] 'ess-sas-backward-delete-tab
))
1099 (define-key sas-mode-local-map
[return] 'newline)
1100 (define-key sas-mode-local-map "\t" 'ess-sas-tab-to-tab-stop))
1102 (define-key sas-mode-local-map [return] 'newline-and-indent
)
1103 (define-key sas-mode-local-map
"\t" 'sas-indent-line
)))
1105 (defvar ess-sas-edit-keys-toggle nil
1106 "Toggle TAB/RET key in `SAS-mode'.
1107 nil binds TAB to `sas-indent-line' and RET to `newline-and-indent'.
1108 Non-nil binds TAB to `ess-sas-tab-to-tab-stop',
1109 C-TAB to `ess-sas-backward-delete-tab', and RET to `newline'.")
1111 (defun ess-sas-edit-keys-toggle (&optional arg
)
1112 "Toggle `ess-sas-edit-keys-toggle'. Optional arg is still
1113 accepted for backward compatibility, however, arg is ignored."
1116 (setq ess-sas-edit-keys-toggle
(not ess-sas-edit-keys-toggle
))
1117 (ess-sas-edit-keys-set ess-sas-edit-keys-toggle
)
1120 (defvar ess-sas-global-pc-keys nil
1121 "Non-nil if function keys use PC-like SAS key definitions in all modes.")
1123 (defun ess-sas-global-pc-keys ()
1124 "PC-like SAS key definitions"
1126 (when (featurep 'rtf-support
)
1127 (global-set-key [(control f1
)] 'ess-sas-rtf-portrait
)
1128 (global-set-key [(control f2
)] 'ess-sas-rtf-us-landscape
))
1129 (global-set-key (quote [f2]) 'ess-revert-wisely)
1130 (global-set-key (quote [f3]) 'ess-sas-goto-shell)
1131 (global-set-key (quote [f4]) 'ess-sas-goto-file-1)
1132 (global-set-key (quote [f5]) 'ess-sas-goto-sas)
1133 (global-set-key (quote [f6]) 'ess-sas-goto-log)
1134 (global-set-key [(control f6)] 'ess-sas-append-log)
1135 (global-set-key (quote [f7]) 'ess-sas-goto-lst)
1136 (global-set-key [(control f7)] 'ess-sas-append-lst)
1137 (global-set-key (quote [f8]) 'ess-sas-submit)
1138 (global-set-key [(control f8)] 'ess-sas-submit-region)
1139 (global-set-key (quote [f9]) 'ess-sas-data-view-fsview)
1140 (global-set-key [(control f9)] 'ess-sas-data-view-insight)
1141 (global-set-key (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1142 (global-set-key [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1143 (global-set-key (quote [f11]) 'ess-sas-goto-file-2)
1144 (global-set-key [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1145 (global-set-key (quote [f12]) 'ess-sas-graph-view)
1146 (if (and ess-sas-edit-keys-toggle
1147 (equal emacs-major-version 19) (equal emacs-minor-version 28))
1148 (global-set-key [C-tab] 'ess-sas-backward-delete-tab)
1150 (global-set-key [(control tab)] 'ess-sas-backward-delete-tab))
1151 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1152 (setq ess-sas-global-pc-keys t)
1153 (setq ess-sas-global-unix-keys nil)
1154 (setq ess-sas-local-pc-keys nil)
1155 (setq ess-sas-local-unix-keys nil)
1158 (defvar ess-sas-global-unix-keys nil
1159 "Non-nil if function keys use Unix-like SAS key definitions in all modes.")
1161 (defun ess-sas-global-unix-keys ()
1162 "Unix/Mainframe-like SAS key definitions"
1164 (when (featurep 'rtf-support)
1165 (global-set-key [(control f1)] 'ess-sas-rtf-portrait)
1166 (global-set-key [(control f2)] 'ess-sas-rtf-us-landscape))
1167 (global-set-key (quote [f2]) 'ess-revert-wisely
)
1168 (global-set-key (quote [f3]) 'ess-sas-submit)
1169 (global-set-key [(control f3)] 'ess-sas-submit-region)
1170 (global-set-key (quote [f4]) 'ess-sas-goto-sas)
1171 (global-set-key (quote [f5]) 'ess-sas-goto-log)
1172 (global-set-key [(control f5)] 'ess-sas-append-log)
1173 (global-set-key (quote [f6]) 'ess-sas-goto-lst)
1174 (global-set-key [(control f6)] 'ess-sas-append-lst)
1175 (global-set-key (quote [f7]) 'ess-sas-goto-file-1)
1176 (global-set-key (quote [f8]) 'ess-sas-goto-shell)
1177 (global-set-key (quote [f9]) 'ess-sas-data-view-fsview)
1178 (global-set-key [(control f9)] 'ess-sas-data-view-insight)
1179 (global-set-key (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1180 (global-set-key [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1181 (global-set-key (quote [f11]) 'ess-sas-goto-file-2)
1182 (global-set-key [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1183 (global-set-key (quote [f12]) 'ess-sas-graph-view)
1184 (if (and ess-sas-edit-keys-toggle
1185 (equal emacs-major-version 19) (equal emacs-minor-version 28))
1186 (global-set-key [C-tab] 'ess-sas-backward-delete-tab)
1188 (global-set-key [(control tab)] 'ess-sas-backward-delete-tab))
1189 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1190 (setq ess-sas-global-pc-keys nil)
1191 (setq ess-sas-global-unix-keys t)
1192 (setq ess-sas-local-pc-keys nil)
1193 (setq ess-sas-local-unix-keys nil)
1196 (defvar ess-sas-local-pc-keys nil
1197 "Non-nil if function keys use PC-like SAS key definitions
1198 in SAS-mode and related modes.")
1200 (defun ess-sas-local-pc-keys ()
1201 "PC-like SAS key definitions."
1203 (when (featurep 'rtf-support)
1204 (define-key sas-mode-local-map [(control f1)] 'ess-sas-rtf-portrait)
1205 (define-key sas-mode-local-map [(control f2)] 'ess-sas-rtf-us-landscape))
1206 (define-key sas-mode-local-map (quote [f2]) 'ess-revert-wisely)
1207 (define-key sas-mode-local-map (quote [f3]) 'ess-sas-goto-shell
)
1208 (define-key sas-mode-local-map
(quote [f4]) 'ess-sas-goto-file-1)
1209 (define-key sas-mode-local-map (quote [f5]) 'ess-sas-goto-sas)
1210 (define-key sas-mode-local-map (quote [f6]) 'ess-sas-goto-log)
1211 (define-key sas-mode-local-map [(control f6)] 'ess-sas-append-log)
1212 (define-key sas-mode-local-map (quote [f7]) 'ess-sas-goto-lst)
1213 (define-key sas-mode-local-map [(control f7)] 'ess-sas-append-lst)
1214 (define-key sas-mode-local-map (quote [f8]) 'ess-sas-submit)
1215 (define-key sas-mode-local-map [(control f8)] 'ess-sas-submit-region)
1216 (define-key sas-mode-local-map (quote [f9]) 'ess-sas-data-view-fsview)
1217 (define-key sas-mode-local-map [(control f9)] 'ess-sas-data-view-insight)
1218 (define-key sas-mode-local-map (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1219 (define-key sas-mode-local-map [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1220 (define-key sas-mode-local-map (quote [f11]) 'ess-sas-goto-file-2)
1221 (define-key sas-mode-local-map [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1222 (define-key sas-mode-local-map (quote [f12]) 'ess-sas-graph-view)
1223 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1224 (setq ess-sas-global-pc-keys nil)
1225 (setq ess-sas-global-unix-keys nil)
1226 (setq ess-sas-local-pc-keys t)
1227 (setq ess-sas-local-unix-keys nil)
1230 (defvar ess-sas-local-unix-keys nil
1231 "Non-nil if function keys use Unix-like SAS key definitions
1232 in SAS-mode and related modes.")
1234 (defun ess-sas-local-unix-keys ()
1235 "Unix/Mainframe-like SAS key definitions"
1237 (when (featurep 'rtf-support)
1238 (define-key sas-mode-local-map [(control f1)] 'ess-sas-rtf-portrait)
1239 (define-key sas-mode-local-map [(control f2)] 'ess-sas-rtf-us-landscape))
1240 (define-key sas-mode-local-map (quote [f2]) 'ess-revert-wisely)
1241 (define-key sas-mode-local-map (quote [f3]) 'ess-sas-submit)
1242 (define-key sas-mode-local-map [(control f3)] 'ess-sas-submit-region)
1243 (define-key sas-mode-local-map (quote [f4]) 'ess-sas-goto-sas
)
1244 (define-key sas-mode-local-map
(quote [f5]) 'ess-sas-goto-log)
1245 (define-key sas-mode-local-map [(control f5)] 'ess-sas-append-log)
1246 (define-key sas-mode-local-map (quote [f6]) 'ess-sas-goto-lst)
1247 (define-key sas-mode-local-map [(control f6)] 'ess-sas-append-lst)
1248 (define-key sas-mode-local-map (quote [f7]) 'ess-sas-goto-file-1)
1249 (define-key sas-mode-local-map (quote [f8]) 'ess-sas-goto-shell)
1250 (define-key sas-mode-local-map (quote [f9]) 'ess-sas-data-view-fsview)
1251 (define-key sas-mode-local-map [(control f9)] 'ess-sas-data-view-insight)
1252 (define-key sas-mode-local-map (quote [f10]) 'ess-sas-toggle-sas-log-mode)
1253 (define-key sas-mode-local-map [(control f10)] 'ess-sas-toggle-sas-listing-mode)
1254 (define-key sas-mode-local-map (quote [f11]) 'ess-sas-goto-file-2)
1255 (define-key sas-mode-local-map [(control f11)] 'ess-ebcdic-to-ascii-search-and-replace)
1256 (define-key sas-mode-local-map (quote [f12]) 'ess-sas-graph-view)
1257 ;(define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
1258 (setq ess-sas-global-pc-keys nil)
1259 (setq ess-sas-global-unix-keys nil)
1260 (setq ess-sas-local-pc-keys nil)
1261 (setq ess-sas-local-unix-keys t)
1266 \f ; Local variables section
1268 ;;; This file is automatically placed in Outline minor mode.
1269 ;;; The file is structured as follows:
1272 ;;; Subsections: ;;;*;;;
1273 ;;; Components: defuns, defvars, defconsts
1274 ;;; Random code beginning with a ;;;;* comment
1276 ;;; Local variables:
1277 ;;; mode: emacs-lisp
1278 ;;; outline-minor-mode: nil
1279 ;;; mode: outline-minor
1280 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
1283 ;;; essa-sas.el ends here