Initial Commit
[packages] / xemacs-packages / ess / lisp / ess.el
1 ;;; ess.el --- Emacs Speaks Statistics: statistical programming within Emacs
2
3 ;; Copyright (C) 1989--1996 Bates, Kademan, Ritter and Smith
4 ;; Copyright (C) 1997--2005 A.J. Rossini, Rich M. Heiberger, Martin
5 ;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
7 ;; Original Authors: Doug Bates, Ed Kademan, Frank Ritter, David Smith
8 ;; Created: October 14, 1991
9 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
10
11 ;; Keywords: statistical support
12 ;; Summary: general functions for ESS
13
14 ;; This file is part of ESS
15
16 ;; This file is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; any later version.
20 ;;
21 ;; This file is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 ;; GNU General Public License for more details.
25 ;;
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING.  If not, write to
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;;
30 ;; In short: you may use this code any way you like, as long as you
31 ;; don't charge money for it, remove this notice, or hold anyone liable
32 ;; for its results.
33
34 ;;; Commentary:
35
36 ;;; PURPOSE
37 ;;;
38 ;;; Interface to the S, SAS, and XLisp dialects of statistical
39 ;;; programming languages, with potential extensions to other
40 ;;; languages.  Designed to be extendable to most other interactive
41 ;;; statistical programming situations.
42
43 ;;; BRIEF OVERVIEW
44 ;;;
45 ;;; Supports structured editing of S, SAS, and XLisp (statistics
46 ;;; programming languages) functions that are integrated with a
47 ;;; running process in a buffer.
48
49 ;;; THE ESS MAILING LIST
50 ;;;
51 ;;; There is an informal mailing list for discussions of ESS. Alpha
52 ;;; and beta releases of ESS are also announced here. Send mail
53 ;;; to ess-request@stat.math.ethz.ch to join.
54
55 ;;; OVERVIEW OF ESS
56 ;;;
57 ;;; S is a statistics programming language developed at Bell Labs
58 ;;; particularly suited for descriptive and exploratory statistics.
59 ;;; s-mode is built on top of comint (the general command interpreter
60 ;;; mode written by Olin Shivers), and so comint.el (or comint.elc)
61 ;;; should be either loaded or in your load path when you invoke it.
62 ;;;
63 ;;; Aside from the general features offered by comint such as
64 ;;; command history editing and job control, inferior S mode
65 ;;; allows you to dump and load S objects into and from external
66 ;;; files, and to display help on functions.  It also provides
67 ;;; name completion while you do these.  For more detailed
68 ;;; information see the documentation strings for inferior-ess,
69 ;;; inferior-ess-mode, ess-mode, and comint-mode.  There are also
70 ;;; many variables and hooks available for customizing (see
71 ;;; the variables below that have document strings that start
72 ;;; with an "*").
73
74 ;;; INSTALLATION
75 ;;; See README and S-site for details.
76
77 ;;; GETTING RELEASES OF ESS
78 ;;; ===> http://ess.r-project.org
79 ;;;
80
81 ;;; CREDITS.
82 ;;; Thanks to shiba@shun.isac.co.jp (Ken'ichi "Modal" Shibayama) for
83 ;;;   the indenting code.
84 ;;; Thanks also to maechler@stat.math.ethz.ch (Martin Maechler) for
85 ;;;   suggestions and bug fixes.
86 ;;; ess-eval-line-and-step is based on a function by Rod Ball
87 ;;;   (rod@marcam.dsir.govt.nz)
88 ;;; Also thanks from David Smith to the previous authors for all their
89 ;;; help and suggestions.
90 ;;; And thanks from Richard M. Heiberger, Kurt Hornik, Martin
91 ;;; Maechler, and A.J. Rossini to David Smith.
92
93 ;;; BUG REPORTS
94 ;;; Please report bugs to ess-bugs@stat.math.ethz.ch
95 ;;; Comments, suggestions, words of praise and large cash donations
96 ;;; are also more than welcome, but should generally be split between
97 ;;; all authors :-).
98
99 ;;; Code:
100
101 \f;;*;; Requires and autoloads
102 ;;;=====================================================
103 ;;;
104
105 (require 'easymenu)
106 (if (or window-system
107         noninteractive ; compilation!
108         )
109     (require 'font-lock))
110
111 (require 'ess-emcs)
112
113 (eval-and-compile
114   (require 'ess-cust))
115
116 \f ; ess-mode: editing S/R/XLS/SAS source
117
118 (autoload 'inferior-ess "ess-inf"
119   "Run [inferior-ess-program], an ess process, in an Emacs buffer" t)
120
121 (autoload 'ess-dump-object-into-edit-buffer "ess-mode"
122   "Edit an S object." t)
123
124 (autoload 'ess-parse-errors "ess-mode"
125   "Jump to the last error generated from a sourced file." t)
126
127 (autoload 'ess-load-file "ess-inf" "Source a file into S.")
128
129 (autoload 'ess-inside-string-or-comment-p "ess-utils"
130   "Non-nil, if inside string or comment." t)
131 (autoload 'ess-inside-string-p "ess-utils" "Non-nil if inside string." t)
132
133 (autoload 'ess-do-auto-fill "ess-utils" "substitute for \\[do-auto-fill]." t)
134
135 (autoload 'ess-rep-regexp "ess-utils" "Replace, but not in string/comment." t)
136
137 (autoload 'ess-time-string "ess-utils" "Return time-stamp string." t)
138
139 (autoload 'ess-nuke-trailing-whitespace "ess-utils"
140   "Maybe get rid of trailing blanks." t)
141
142 \f ; ess-transcript-mode: editing ``outputs'
143
144 (autoload 'ess-transcript-mode "ess-trns"
145   "Major mode for editing S transcript files." t)
146
147 (autoload 'ess-display-help-on-object "ess-help"
148   "Display help on an S object." t)
149
150 (defalias 'ess-help 'ess-display-help-on-object)
151
152 (autoload 'ess-goto-info "ess-help"
153   "Jump to the relevant section in the `ess-mode' manual." t)
154
155 (autoload 'ess-submit-bug-report "ess-help"
156   "Submit a bug report on the `ess-mode' package." t)
157
158 ;;==> ess-inf.el  has its OWN autoload's !
159
160
161 \f ; Set up for menus, if necessary
162 ;;;
163 ;;;     nn.     Set up the keymaps for the simple-menus
164 ;;;
165
166 ;;(if ess-use-menus
167 ;;    (require 'ess-menu))
168
169
170 ;;; Function Menu (func-menu) for XEmacs:
171 ;;(defvar fume-function-name-regexp-smode
172 ;;  " "
173 ;;  "Expression to get function names")
174 ;;
175 ;;(append
176 ;; '((s-mode  . fume-function-name-regexp-smode)
177 ;;   (r-mode  . fume-function-name-regexp-smode))
178 ;; fume-function-name-regexp-alist)
179
180 ;;; Imenu for Emacs...
181
182
183 ;;; Completion and Database code
184
185 (defun ess-load-object-name-db-file ()
186   "Load object database file if present, mention if not."
187   (if (string= ess-language "S")
188       (progn
189         (make-local-variable 'ess-object-name-db)
190         (condition-case ()
191             (load ess-object-name-db-file)
192           (error
193            ;;(message "%s does not exist.  Consider running ess-create-object-name-db."
194                 ;;    ess-object-name-db-file)
195 ;;            (ding)
196               (sit-for 1))))))
197
198
199
200 \f ; Buffer local customization stuff
201
202 ;; Parse a line into its constituent parts (words separated by
203 ;; whitespace).    Return a list of the words.
204 ;; Taken from rlogin.el, from the comint package, from XEmacs 20.3.
205 (defun ess-line-to-list-of-words (line)
206   (let ((list nil)
207         (posn 0))
208         ;; (match-data (match-data)))
209     (while (string-match "[^ \t\n]+" line posn)
210       (setq list (cons (substring line (match-beginning 0) (match-end 0))
211                        list))
212       (setq posn (match-end 0)))
213     (store-match-data (match-data))
214     (nreverse list)))
215
216 (defun ess-write-to-dribble-buffer (text)
217   "Write TEXT to dribble buffer."
218   (save-excursion
219     (if (not (buffer-live-p ess-dribble-buffer))
220         ;; ESS dribble buffer must be re-created.
221         (setq ess-dribble-buffer (get-buffer-create "*ESS*")))
222     (set-buffer ess-dribble-buffer)
223     (goto-char (point-max))
224     (insert-string text)))
225
226 (defun ess-setq-vars-local (alist &optional buf)
227   "Set language variables from ALIST, in buffer BUF, if desired."
228   (if buf (set-buffer buf))
229   (mapcar (lambda (pair)
230             (make-local-variable (car pair))
231             (if (cdr pair)
232                 (set (car pair) (eval (cdr pair)))))
233           alist)
234   (ess-write-to-dribble-buffer
235    (format "(ess-setq-vars-LOCAL): language=%s, dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
236            ess-language ess-dialect buf comint-process-echoes comint-input-sender)))
237
238 (defun ess-setq-vars-default (alist &optional buf)
239   "Set language variables from ALIST, in buffer BUF, if desired."
240   (ess-write-to-dribble-buffer
241    (format "ess-setq-vars-default 0: ess-language=%s, -dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
242            ess-language ess-dialect buf comint-process-echoes comint-input-sender))
243   (if buf (set-buffer buf))
244   (mapcar (lambda (pair)
245             (set-default (car pair) (eval (cdr pair))))
246           alist)
247   (ess-write-to-dribble-buffer
248    (format "ess-setq-vars-default 1: ess-language=%s, -dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
249            ess-language ess-dialect buf comint-process-echoes comint-input-sender))
250 )
251
252 ;;--- emacs 19.34 compatibility [MM]:
253 (if (not (fboundp 'functionp))
254     ;; take the definition from emacs 20.4  lisp/subr.el:
255  (defun functionp (object)
256   "Non-nil if OBJECT is a type of object that can be called as a function."
257   (or (subrp object) (byte-code-function-p object)
258       (eq (car-safe object) 'lambda)
259       (and (symbolp object) (fboundp object))))
260 )
261
262 ;;-- more emacs 19 back compatibility
263 (if (not (fboundp 'cadr)); could (require 'cl) but that is too big
264  (defun cadr (list) (car (cdr list))))
265
266
267 ;;; versions thanks to Barry Margolin <barmar@bbnplanet.com>.
268 ;;; unfortunately, requires 'cl.  Whoops.
269 ;;(defun ess-setq-vars (var-alist &optional buf)
270 ;;  "Set language variables from alist, in buffer `buf', if desired."
271 ;;  (if buf (set-buffer buf))
272 ;;  (dolist (pair var-alist)
273 ;;    (set (car pair) (eval (cdr pair))))
274 ;;  (ess-write-to-dribble-buffer
275 ;;    (format "(ess-setq-vars): ess-language=%s, buf=%s \n"
276 ;;         ess-language buf)))
277 ;;(defun ess-setq-vars-default (var-alist &optional buf)
278 ;;  "Set language variables from alist, in buffer `buf', if desired."
279 ;;  (if buf (set-buffer buf))
280 ;;  (dolist (pair var-alist)
281 ;;    (set-default (car pair) (eval (cdr pair))))
282 ;;  (ess-write-to-dribble-buffer
283 ;;    (format "(ess-setq-vars-default): ess-language=%s, buf=%s \n"
284 ;;         ess-language buf)))
285
286 ;; Toby Speight <Toby.Speight@ansa.co.uk>
287 ;;> ;; untested
288 ;;> (let ((l R-customize-alist))            ; or whatever
289 ;;>   (while l
290 ;;>     (set (car (car l)) (cdr (car l)))   ; set, not setq!
291 ;;>     (setq l (cdr l))))
292 ;;
293 ;;
294 ;;If they are to be buffer-local, you may need to
295 ;;
296 ;;>     ;; untested
297 ;;>     (set (make-local-variable (car (car l))) (cdr (car l)))
298 ;;
299
300
301 ;; Erik Naggum <erik@naggum.no>
302 ;;
303 ;;(mapcar (lambda (pair) (set (car pair) (cdr pair)))
304 ;;        R-customize-alist)
305 ;;
306 ;;if you want to evaluate these things along the way, which it appears that
307 ;;you want, try:
308 ;;
309 ;;(mapcar (lambda (pair) (set (car pair) (eval (cdr pair))))
310 ;;        R-customize-alist)
311
312 ;; jsa@alexandria.organon.com (Jon S Anthony)
313 ;;(mapcar #'(lambda (x)
314 ;;          (set-variable (car x) (cdr x)))
315 ;;      R-customize-alist)
316
317
318
319 ; Run load hook and provide package
320
321 (run-hooks 'ess-mode-load-hook)
322
323 (provide 'ess)
324
325 \f ; Local variables section
326
327 ;;; This file is automatically placed in Outline minor mode.
328 ;;; The file is structured as follows:
329 ;;; Chapters:     ^L ;
330 ;;; Sections:    ;;*;;
331 ;;; Subsections: ;;;*;;;
332 ;;; Components:  defuns, defvars, defconsts
333 ;;;              Random code beginning with a ;;;;* comment
334
335 ;;; Local variables:
336 ;;; mode: emacs-lisp
337 ;;; mode: outline-minor
338 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
339 ;;; End:
340
341 ;;; ess.el ends here