~ubuntu-branches/ubuntu/maverick/ess/maverick

« back to all changes in this revision

Viewing changes to lisp/essa-sas.el

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2010-03-03 06:25:04 UTC
  • mfrom: (1.2.13 upstream) (3.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100303062504-rtei3p11s1gmcj4r
Tags: 5.8-1
New upstream version released this morning

Show diffs side-by-side

added added

removed removed

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