(ess-r-args-get): Do not use zap-to-char within defun,
[ess.git] / lisp / ess.el
blobc4e4ad6e4708e5b97b1eb7b173df034485d3de26
1 ;;; ess.el --- Emacs Speaks Statistics: statistical programming within Emacs
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.
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>
11 ;; Keywords: statistical support
12 ;; Summary: general functions for ESS
14 ;; This file is part of ESS
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.
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.
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.
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.
34 ;;; Commentary:
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.
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.
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.
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 "*").
74 ;;; INSTALLATION
75 ;;; See README and S-site for details.
77 ;;; GETTING RELEASES OF ESS
78 ;;; ===> http://ess.r-project.org
79 ;;;
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.
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 :-).
99 ;;; Code:
101 \f;;*;; Requires and autoloads
102 ;;;=====================================================
105 (require 'easymenu)
106 (if (or window-system
107 noninteractive ; compilation!
109 (require 'font-lock))
111 (require 'ess-emcs)
113 (eval-and-compile
114 (require 'ess-cust))
116 \f ; ess-mode: editing S/R/XLS/SAS source
118 (autoload 'inferior-ess "ess-inf"
119 "Run [inferior-ess-program], an ess process, in an Emacs buffer" t)
121 (autoload 'ess-dump-object-into-edit-buffer "ess-mode"
122 "Edit an S object." t)
124 (autoload 'ess-parse-errors "ess-mode"
125 "Jump to the last error generated from a sourced file." t)
127 (autoload 'ess-load-file "ess-inf" "Source a file into S.")
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)
133 (autoload 'ess-do-auto-fill "ess-utils" "substitute for \\[do-auto-fill]." t)
135 (autoload 'ess-rep-regexp "ess-utils" "Replace, but not in string/comment." t)
137 (autoload 'ess-time-string "ess-utils" "Return time-stamp string." t)
139 (autoload 'ess-nuke-trailing-whitespace "ess-utils"
140 "Maybe get rid of trailing blanks." t)
142 \f ; ess-transcript-mode: editing ``outputs'
144 (autoload 'ess-transcript-mode "ess-trns"
145 "Major mode for editing S transcript files." t)
147 (autoload 'ess-display-help-on-object "ess-help"
148 "Display help on an S object." t)
150 (defalias 'ess-help 'ess-display-help-on-object)
152 (autoload 'ess-goto-info "ess-help"
153 "Jump to the relevant section in the `ess-mode' manual." t)
155 (autoload 'ess-submit-bug-report "ess-help"
156 "Submit a bug report on the `ess-mode' package." t)
158 ;;==> ess-inf.el has its OWN autoload's !
161 \f ; Set up for menus, if necessary
163 ;;; nn. Set up the keymaps for the simple-menus
166 ;;(if ess-use-menus
167 ;; (require 'ess-menu))
170 ;;; Function Menu (func-menu) for XEmacs:
171 ;;(defvar fume-function-name-regexp-smode
172 ;; " "
173 ;; "Expression to get function names")
175 ;;(append
176 ;; '((s-mode . fume-function-name-regexp-smode)
177 ;; (r-mode . fume-function-name-regexp-smode))
178 ;; fume-function-name-regexp-alist)
180 ;;; Imenu for Emacs...
183 ;;; Completion and Database code
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))))))
200 ;;; Running these must be done "every time" before use, since
201 ;;; they depend on a customizable variable.
203 ;; trying different viewers; thanks to an original patch for
204 ;; ess-swv.el from Leo <sdl@web.de> :
205 (defun ess-get-ps-viewer ()
206 "Get external PostScript viewer to be used from ESS.
207 Use `ess-ps-viewer-pref' when that is executably found by \\[executable-find].
208 Otherwise try a list of fixed known viewers."
209 (file-name-nondirectory
210 (or (and ess-ps-viewer-pref ; -> ./ess-cust.el
211 (executable-find ess-ps-viewer-pref))
212 (executable-find "gv")
213 (executable-find "evince")
214 (executable-find "kghostview"))))
216 (defun ess-get-pdf-viewer ()
217 "Get external PDF viewer to be used from ESS.
218 Use `ess-pdf-viewer-pref' when that is executably found by \\[executable-find].
219 Otherwise try a list of fixed known viewers."
220 (file-name-nondirectory
221 (or (and ess-pdf-viewer-pref ; -> ./ess-cust.el
222 (executable-find ess-pdf-viewer-pref))
223 (car (ess-get-words-from-vector
224 "getOption(\"pdfviewer\")\n"))
225 (executable-find "evince")
226 (executable-find "kpdf")
227 (executable-find "xpdf")
228 (executable-find "acroread"))))
232 \f ; Buffer local customization stuff
234 ;; Parse a line into its constituent parts (words separated by
235 ;; whitespace). Return a list of the words.
236 ;; Taken from rlogin.el, from the comint package, from XEmacs 20.3.
237 (defun ess-line-to-list-of-words (line)
238 (let ((list nil)
239 (posn 0))
240 ;; (match-data (match-data)))
241 (while (string-match "[^ \t\n]+" line posn)
242 (setq list (cons (substring line (match-beginning 0) (match-end 0))
243 list))
244 (setq posn (match-end 0)))
245 (store-match-data (match-data))
246 (nreverse list)))
248 (defun ess-write-to-dribble-buffer (text)
249 "Write TEXT to dribble buffer."
250 (save-excursion
251 (if (not (buffer-live-p ess-dribble-buffer))
252 ;; ESS dribble buffer must be re-created.
253 (setq ess-dribble-buffer (get-buffer-create "*ESS*")))
254 (set-buffer ess-dribble-buffer)
255 (goto-char (point-max))
256 (insert text)))
258 (defun ess-setq-vars-local (alist &optional buf)
259 "Set language variables from ALIST, in buffer BUF, if desired."
260 (if buf (set-buffer buf))
261 (mapcar (lambda (pair)
262 (make-local-variable (car pair))
263 (if (cdr pair)
264 (set (car pair) (eval (cdr pair)))))
265 alist)
266 (ess-write-to-dribble-buffer
267 (format "(ess-setq-vars-LOCAL): language=%s, dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
268 ess-language ess-dialect buf comint-process-echoes comint-input-sender)))
270 (defun ess-setq-vars-default (alist &optional buf)
271 "Set language variables from ALIST, in buffer BUF, if desired."
272 (ess-write-to-dribble-buffer
273 (format "ess-setq-vars-default 0: ess-language=%s, -dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
274 ess-language ess-dialect buf comint-process-echoes comint-input-sender))
275 (if buf (set-buffer buf))
276 (mapcar (lambda (pair)
277 (set-default (car pair) (eval (cdr pair))))
278 alist)
279 (ess-write-to-dribble-buffer
280 (format "ess-setq-vars-default 1: ess-language=%s, -dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
281 ess-language ess-dialect buf comint-process-echoes comint-input-sender))
284 ;;; versions thanks to Barry Margolin <barmar@bbnplanet.com>.
285 ;;; unfortunately, requires 'cl. Whoops.
286 ;;(defun ess-setq-vars (var-alist &optional buf)
287 ;; "Set language variables from alist, in buffer `buf', if desired."
288 ;; (if buf (set-buffer buf))
289 ;; (dolist (pair var-alist)
290 ;; (set (car pair) (eval (cdr pair))))
291 ;; (ess-write-to-dribble-buffer
292 ;; (format "(ess-setq-vars): ess-language=%s, buf=%s \n"
293 ;; ess-language buf)))
294 ;;(defun ess-setq-vars-default (var-alist &optional buf)
295 ;; "Set language variables from alist, in buffer `buf', if desired."
296 ;; (if buf (set-buffer buf))
297 ;; (dolist (pair var-alist)
298 ;; (set-default (car pair) (eval (cdr pair))))
299 ;; (ess-write-to-dribble-buffer
300 ;; (format "(ess-setq-vars-default): ess-language=%s, buf=%s \n"
301 ;; ess-language buf)))
303 ;; Toby Speight <Toby.Speight@ansa.co.uk>
304 ;;> ;; untested
305 ;;> (let ((l R-customize-alist)) ; or whatever
306 ;;> (while l
307 ;;> (set (car (car l)) (cdr (car l))) ; set, not setq!
308 ;;> (setq l (cdr l))))
311 ;;If they are to be buffer-local, you may need to
313 ;;> ;; untested
314 ;;> (set (make-local-variable (car (car l))) (cdr (car l)))
318 ;; Erik Naggum <erik@naggum.no>
320 ;;(mapcar (lambda (pair) (set (car pair) (cdr pair)))
321 ;; R-customize-alist)
323 ;;if you want to evaluate these things along the way, which it appears that
324 ;;you want, try:
326 ;;(mapcar (lambda (pair) (set (car pair) (eval (cdr pair))))
327 ;; R-customize-alist)
329 ;; jsa@alexandria.organon.com (Jon S Anthony)
330 ;;(mapcar #'(lambda (x)
331 ;; (set-variable (car x) (cdr x)))
332 ;; R-customize-alist)
336 ; Run load hook and provide package
338 (run-hooks 'ess-mode-load-hook)
340 (provide 'ess)
342 \f ; Local variables section
344 ;;; This file is automatically placed in Outline minor mode.
345 ;;; The file is structured as follows:
346 ;;; Chapters: ^L ;
347 ;;; Sections: ;;*;;
348 ;;; Subsections: ;;;*;;;
349 ;;; Components: defuns, defvars, defconsts
350 ;;; Random code beginning with a ;;;;* comment
352 ;;; Local variables:
353 ;;; mode: emacs-lisp
354 ;;; mode: outline-minor
355 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
356 ;;; End:
358 ;;; ess.el ends here