Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-sas-d.el --- SAS customization
2
3
;; Copyright (C) 1997--2001 Richard M. Heiberger and A. J. Rossini
4
;; Copyright (C) 2002--2004 A.J. Rossini, Richard M. Heiberger, Martin
5
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
7
;; Author: Richard M. Heiberger <[email protected]>
8
;; Created: 20 Aug 1997
9
;; Maintainer: ESS-core <[email protected]>
10
11
;; Keywords: languages
12
13
;; This file is part of ESS.
14
15
;; This file is free software; you can redistribute it and/or modify
16
;; it under the terms of the GNU General Public License as published by
17
;; the Free Software Foundation; either version 2, or (at your option)
18
;; any later version.
19
20
;; This file is distributed in the hope that it will be useful,
21
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
;; GNU General Public License for more details.
24
25
;; A copy of the GNU General Public License is available at
26
;; http://www.r-project.org/Licenses/
27
28
;;; Commentary:
29
30
;; This file defines all the SAS customizations for ESS behaviors. See
31
;; ess-sas-l and ess-sas-a for the underlying general modifications.
32
33
;;; Code:
34
35
;;; Autoloads:
36
37
(ess-message "[ess-sas-d:] require 'comint & 'shell ...")
38
(require 'comint)
39
(require 'shell)
40
(require 'executable)
41
42
;;(ess-message "[ess-sas-d:] require 'ess-sas-a ...")
43
;;(require 'ess-sas-a)
44
(ess-message "[ess-sas-d:] require 'ess-sas-l ...")
45
(require 'ess-sas-l)
46
(ess-message "[ess-sas-d:] (autoload ..) (def** ..) ...")
47
48
(autoload 'inferior-ess "ess-inf" no-doc t)
49
(autoload 'ess-mode "ess-mode" no-doc t)
50
(autoload 'ess-proc-name "ess-inf" no-doc nil)
51
52
(defvar inferior-SAS-args "-stdio -linesize 80 -noovp -nosyntaxcheck"
53
"*Arguments to use for starting SAS.")
54
55
(defvar inferior-SAS-args-temp nil
56
"Hack variable, needed for args preprocessing.
57
Better logic needed! (see 2 uses, in this file).")
58
59
(defun ess-SAS-pre-run-hook (temp-ess-dialect)
60
"Set up log and list files for interactive SAS."
61
62
(let* ((ess-shell-buffer-name-flag (get-buffer "*shell*"))
63
ess-shell-buffer-name
64
;; isn't pretty yet.
65
;; ess-local-process-name is defined after this function.
66
;; it needs to be defined prior to this function.
67
(tmp-procname (let ((ntry 0)
68
(done nil))
69
;; find a non-existent process
70
(while (not done)
71
(setq ntry (1+ ntry)
72
done (not
73
(get-process (ess-proc-name
74
ntry
75
temp-ess-dialect)))))
76
(ess-proc-name ntry temp-ess-dialect)))
77
;; Following was tmp-local-process-name. Stolen from inferior-ess
78
(ess-sas-lst-bufname (concat "*" tmp-procname ".lst*"))
79
(ess-sas-log-bufname (concat "*" tmp-procname ".log*"))
80
(explicit-shell-file-name "/bin/sh")
81
inferior-SAS-redirect-args
82
ess-sas-lst
83
ess-sas-log)
84
85
(ess-write-to-dribble-buffer
86
(format "(ess-SAS-pre-run-hook 1): ess-lang=%s, ess-dialect=%s, temp-dialect=%s, buf=%s \n"
87
ess-language
88
ess-dialect
89
temp-ess-dialect
90
(current-buffer)))
91
;; If someone is running a *shell* buffer, rename it to avoid
92
;; inadvertent nuking.
93
(if ess-shell-buffer-name-flag
94
(save-excursion
95
(set-buffer "*shell*")
96
(setq ess-shell-buffer-name
97
(rename-buffer "*ess-shell-regular*" t))))
98
99
;; Construct the LST buffer for output
100
(if (get-buffer ess-sas-lst-bufname)
101
nil
102
(shell)
103
(accept-process-output (get-buffer-process (current-buffer)))
104
(sleep-for 2) ; need to wait, else working too fast!
105
(setq ess-sas-lst (ess-insert-accept "tty"))
106
(SAS-listing-mode)
107
(shell-mode)
108
(ess-listing-minor-mode t)
109
(rename-buffer ess-sas-lst-bufname t))
110
111
;; Construct the LOG buffer for output
112
(if (get-buffer ess-sas-log-bufname)
113
nil
114
(shell)
115
(accept-process-output (get-buffer-process (current-buffer)))
116
(sleep-for 2) ; need to wait, else working too fast!
117
(setq ess-sas-log (ess-insert-accept "tty"))
118
;(SAS-log-mode)
119
(shell-mode)
120
(ess-transcript-minor-mode t)
121
(rename-buffer ess-sas-log-bufname t))
122
123
(setq inferior-SAS-redirect-args (concat " "
124
ess-sas-lst
125
" "
126
ess-sas-log
127
" ")
128
inferior-SAS-args-temp (concat inferior-SAS-redirect-args
129
inferior-SAS-args))
130
131
;; Restore the *shell* buffer
132
(if ess-shell-buffer-name-flag
133
(save-excursion
134
(set-buffer ess-shell-buffer-name)
135
(rename-buffer "*shell*")))
136
137
(delete-other-windows)
138
(split-window-vertically)
139
(split-window-vertically)
140
(switch-to-buffer (nth 2 (buffer-list)))
141
(other-window 2)
142
(switch-to-buffer ess-sas-log-bufname)
143
(split-window-vertically)
144
(other-window 1)
145
(switch-to-buffer ess-sas-lst-bufname)
146
(other-window 2)
147
148
;;workaround
149
(setq inferior-SAS-program-name
150
(concat (file-name-as-directory ess-etc-directory)
151
"ess-sas-sh-command"))
152
(setq inferior-ess-program inferior-SAS-program-name)))
153
154
(defun ess-insert-accept (command)
155
"Submit command to process, get next line."
156
(interactive)
157
(goto-char (point-max))
158
(insert command)
159
(comint-send-input)
160
(accept-process-output (get-buffer-process (current-buffer)))
161
(forward-line -1)
162
(let* ((beg (point))
163
(ess-tty-name (progn (end-of-line) (buffer-substring beg (point)))))
164
(goto-char (point-max))
165
ess-tty-name))
166
167
168
(defvar SAS-customize-alist
169
'((ess-local-customize-alist . 'SAS-customize-alist)
170
(ess-language . "SAS")
171
(ess-dialect . "SAS")
172
(ess-mode-editing-alist . SAS-editing-alist) ; from ess-sas-l.el
173
(ess-mode-syntax-table . SAS-syntax-table)
174
(inferior-ess-program . inferior-SAS-program-name)
175
(ess-help-sec-regex . "^[A-Z. ---]+:$")
176
(ess-help-sec-keys-alist . " ")
177
(ess-object-name-db-file . "ess-sas-namedb.el")
178
(inferior-ess-objects-command . "objects(%d)");;FIXME
179
(inferior-ess-help-command . "help(\"%s\",pager=\"cat\",window=F)\n");;FIXME
180
(inferior-ess-exit-command . "endsas;\n")
181
(ess-loop-timeout . 500000 )
182
(inferior-ess-primary-prompt . "^")
183
(inferior-ess-secondary-prompt . "^")
184
(comint-use-prompt-regexp . t)
185
(inferior-ess-start-file . nil) ;"~/.ess-SAS")
186
(inferior-ess-start-args . inferior-SAS-args-temp)
187
(inferior-ess-font-lock-defaults . SAS-mode-font-lock-defaults)
188
;; (ess-pre-run-hook . 'ess-SAS-pre-run-hook)
189
;; (ess-local-process-name . nil)
190
)
191
"Variables to customize for SAS")
192
193
;;; The functions of interest (mode, inferior mode)
194
195
(defvar sas-mode-local-map nil "contains modified local keymap for SAS")
196
197
(defun SAS-mode (&optional proc-name)
198
"Major mode for editing SAS source. See ess-mode for more help."
199
(interactive)
200
(setq ess-customize-alist SAS-customize-alist)
201
(ess-mode SAS-customize-alist proc-name)
202
203
;; Local map settings, AFTER initialization (only if not yet defined)
204
(if sas-mode-local-map
205
nil
206
(setq sas-mode-local-map (copy-keymap (current-local-map)))
207
(ess-sas-edit-keys-set ess-sas-edit-keys-toggle)
208
(if ess-sas-local-unix-keys (ess-sas-local-unix-keys))
209
(if ess-sas-local-pc-keys (ess-sas-local-pc-keys))
210
(if ess-sas-global-unix-keys (ess-sas-global-unix-keys))
211
(if ess-sas-global-pc-keys (ess-sas-global-pc-keys)))
212
(define-key sas-mode-local-map "\C-ci" 'ess-eval-line-and-step-invisibly)
213
(define-key sas-mode-local-map ";" 'ess-electric-run-semicolon)
214
215
;; this is a mess
216
;; interactive and batch commands share sas-mode-local-map,
217
;; but the associated commands are very different
218
;; what would be better is two maps like
219
;; sas-batch-mode-local-map and sas-interactive-mode-local-map
220
;; or smart function definitions that would do the appropriate
221
;; thing for either batch or interactive sessions
222
;; however, neither of these solutions are planned
223
;; therefore, no key definitions can be shared between
224
;; batch and interactive at this time, hence the lines that
225
;; are commented below: uncomment at your own risk
226
;; (define-key sas-mode-local-map "\C-c\C-p" 'ess-sas-file-path)
227
;; (define-key sas-mode-local-map "\C-c\C-b" 'ess-sas-submit)
228
;; (define-key sas-mode-local-map "\C-c\C-r" 'ess-sas-submit-region)
229
;; (define-key sas-mode-local-map "\C-c\C-x" 'ess-sas-goto-log)
230
;; (define-key sas-mode-local-map "\C-c\C-y" 'ess-sas-goto-lst)
231
232
(use-local-map sas-mode-local-map)
233
234
(set (make-local-variable 'font-lock-defaults)
235
;; KEYWORDS KEYWORDS-ONLY CASE-FOLD .....
236
'(SAS-mode-font-lock-defaults nil t))
237
;; ^^ this *should* set
238
;; font-lock-keywords-case-fold-search, but it fails for Emacs 22.[23]
239
;; hence :
240
(setq font-lock-keywords-case-fold-search t)
241
(run-hooks 'SAS-mode-hook))
242
243
244
245
;; rmh Jul 10 2003
246
(defun ess-electric-run-semicolon (arg)
247
"Insert character. If the line contains \"run;\" or \"quit;\" and nothing else then indent line."
248
(interactive "P")
249
(if ess-sas-edit-keys-toggle (insert ";") (let (insertpos)
250
(if (and (not arg)
251
(eolp)
252
(save-excursion
253
(skip-chars-backward " \t")
254
(backward-word 1)
255
(and (looking-at "run\\|quit")
256
(progn
257
(skip-chars-backward " \t")
258
(bolp)))))
259
(progn
260
(insert last-command-event)
261
(ess-indent-line)
262
(save-excursion
263
(if insertpos (goto-char (1+ insertpos)))
264
(delete-char -1))))
265
(if insertpos
266
(save-excursion
267
(goto-char insertpos)
268
(self-insert-command (prefix-numeric-value arg)))
269
(self-insert-command (prefix-numeric-value arg))))))
270
271
(defun SAS ()
272
"Call 'SAS', from SAS Institute."
273
(interactive)
274
(setq-default ess-customize-alist SAS-customize-alist)
275
(let* ((temp-dialect "SAS")) ;(cdr (rassoc ess-dialect SAS-customize-alist))))
276
(ess-write-to-dribble-buffer
277
(format "(SAS): ess-dial=%s, temp-dial=%s\n"
278
ess-dialect
279
temp-dialect))
280
(ess-SAS-pre-run-hook temp-dialect)
281
(inferior-ess)
282
(save-excursion
283
(set-buffer "*SAS*")
284
(use-local-map sas-mode-local-map))))
285
286
287
(defun ess-multi-frame-SAS ()
288
"Put running SAS buffers into separate frames.
289
Load this function M-x load-file essx-sas.el RET.
290
Then find-file myfile.sas. If myfile.sas is already in a buffer, kill-buffer
291
it and then find-file it again.
292
Place the cursor in a myfile.sas buffer. Run SAS with M-x SAS,
293
Return the cursor to the myfile.sas buffer,
294
then enter C-c C-w to put *SAS* *SAS.log* *SAS.lst* buffers into
295
their own frames."
296
(interactive)
297
(delete-other-windows)
298
(save-excursion
299
(set-buffer "*SAS*")
300
(make-frame)
301
(set-buffer "*SAS.log*")
302
(make-frame)
303
(set-buffer "*SAS.lst*")
304
(make-frame)))
305
306
307
(add-hook 'ess-mode-hook
308
(lambda ()
309
(when (string= ess-language "SAS") ;; e.g. not for R-only users
310
(local-set-key "\C-c\C-w" 'ess-multi-frame-SAS))))
311
312
; Provide package
313
314
(provide 'ess-sas-d)
315
316
; Local variables section
317
318
;;; This file is automatically placed in Outline minor mode.
319
;;; The file is structured as follows:
320
;;; Chapters: ^L ;
321
;;; Sections: ;;*;;
322
;;; Subsections: ;;;*;;;
323
;;; Components: defuns, defvars, defconsts
324
;;; Random code beginning with a ;;;;* comment
325
326
;;; Local variables:
327
;;; mode: emacs-lisp
328
;;; outline-minor-mode: nil
329
;;; mode: outline-minor
330
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
331
;;; End:
332
333
;;; ess-sas-d.el ends here
334
335