Klimi's new dotfiles with stow.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

1460 líneas
64 KiB

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