(ess-quit-r): Default response (if RET pressed on its own) is that
[ess.git] / lisp / ess-inf.el
blob0372b7c8365ce274c991bc7d616d6351acb4f4ad
1 ;;; ess-inf.el --- Support for running S as an inferior Emacs process
3 ;; Copyright (C) 1989-1994 Bates, Kademan, Ritter and Smith
4 ;; Copyright (C) 1997-1999 A.J. Rossini <rossini@u.washington.edu>,
5 ;; Martin Maechler <maechler@stat.math.ethz.ch>.
6 ;; Copyright (C) 2000--2005 A.J. Rossini, Rich M. Heiberger, Martin
7 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
9 ;; Original Author: David Smith <dsmith@stats.adelaide.edu.au>
10 ;; Created: 7 Jan 1994
11 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
13 ;; This file is part of ESS
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.
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.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to
27 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;;; Commentary:
31 ;; Code for handling running ESS processes.
33 ;;; Code:
35 \f ; Requires and autoloads
37 ;;*;; Requires
38 (require 'ess-site)
40 ;; Byte-compiler, SHUT-UP!
41 (eval-and-compile
42 (require 'comint)
43 (require 'ess-utils))
45 ;;*;; Autoloads
46 (autoload 'ess-parse-errors "ess-mode" "(autoload)." t)
47 (autoload 'ess-dump-object-into-edit-buffer "ess-mode" "(autoload)." t)
48 (autoload 'ess-beginning-of-function "ess-mode" "(autoload)." t)
49 (autoload 'ess-end-of-function "ess-mode" "(autoload)." t)
50 (autoload 'ess-extract-word-name "ess-utils" "(autoload)." t)
51 (autoload 'ess-uniq-list "ess-utils" "(autoload)." t)
53 (autoload 'ess-transcript-send-command-and-move "ess-trns" "(autoload)." t)
55 \f ;;*;; Process handling
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 ;;;; In this section:
59 ;;;;
60 ;;;; * User commands for starting an ESS process
61 ;;;; * Functions called at startup
62 ;;;; * Process handling code
63 ;;;; * Multiple process implementation
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 ;;*;; Starting a process
69 (defun ess-proc-name (n name)
70 "Return name of process N, as a string, with NAME prepended."
71 (if ess-plain-first-buffername
72 (if (> n 1)
73 (concat name ":" (number-to-string n))
74 (concat name))
75 (concat name ":" (number-to-string n))))
77 (defun inferior-ess (&optional ess-start-args)
78 "Start inferior ESS process.
80 Without a prefix argument, starts a new ESS process, or switches
81 to the ESS process associated with the current buffer.
82 With a prefix, starts the process with those args.
83 The current buffer is used if it is an `inferior-ess-mode'
84 or `ess-transcript-mode' buffer.
86 If `ess-ask-about-transfile' is non-nil, you will be asked for a
87 transcript file to use. If there is no transcript file, the buffer
88 name will be like *S* or *S2*.
90 Takes the program name from the variable `inferior-ess-program'.
91 An initialization file (dumped into the process) is specified by
92 `inferior-ess-start-file', and `inferior-ess-start-args' is used to
93 accompany the call for `inferior-ess-program'.
95 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
97 ;; Use the current buffer if it is in inferior-ess-mode or ess-trans-mode
98 ;; If not, maybe ask about starting directory and/or transcript file.
99 ;; If no transfile, use buffer *S*
101 ;; This function is primarily used to figure out the Process and
102 ;; buffer names to use for inferior-ess.
104 ;; Once, long ago, it was used for switching buffers, but we don't
105 ;; do that any more (at least not from here).
107 (interactive)
109 (ess-write-to-dribble-buffer
110 (format "(inferior-ess 0): ess-start-args=%s \n" ess-start-args))
112 ;; set up for current language (need here, to get ess-language, etc).
114 ;; Couldn't we rather set all the default values or Local values now ?
115 ;;>>> (ess-setq-vars-default ess-customize-alist (current-buffer))
116 ;;>>> (ess-setq-vars-local ess-customize-alist (current-buffer))
117 ;;; AJR sez: I think we should set them later; don't want to nuke if
118 ;;; I don't have to.
119 ;;- MM: We shouldn't have to use ess-setq-vars-default _at all_ ;
120 ;; only do the buffer local ...-vars-local ones
121 (let ((temp-ess-dialect (eval (cdr (assoc 'ess-dialect
122 ess-customize-alist))))
123 (temp-ess-lang (eval (cdr (assoc 'ess-language
124 ess-customize-alist)))))
125 (save-excursion
126 ;;- Is this needed? (no, but it's useful to see them there [MM])
127 (set-buffer ess-dribble-buffer)
128 ;; Hack to work around the following "default" (global) setting of vars:
129 ;; make sure our comint-... hack doesn't affect anything else
130 (make-variable-buffer-local 'comint-use-prompt-regexp-instead-of-fields)
131 ;; now the abomination:
132 (ess-setq-vars-default ess-customize-alist)
134 (setq-default comint-use-prompt-regexp-instead-of-fields nil); re set HACK!
135 ;;>> Doesn't set ess-language,
136 ;;>> => comint-input-sender is not set to 'ess-input- ==> no input echo!
137 ;;>> => that's why things fail:
138 ;;>> (ess-setq-vars-local ess-customize-alist (current-buffer))
139 ;; ======
140 ;;MM --- why set them here again when already "(let ..)" above ?
141 ;; --> trying without (comment the following 4 lines):
142 ;; (setq temp-ess-dialect
143 ;; (eval(cdr(assoc 'ess-dialect ess-customize-alist))))
144 ;; (setq temp-ess-lang
145 ;; (eval(cdr(assoc 'ess-language ess-customize-alist))))
148 ;; run hooks now, to overwrite the above!
149 (run-hooks 'ess-pre-run-hook)
150 (ess-write-to-dribble-buffer
151 (format "(inf-ess 1): lang=%s, dialect=%s, tmp-dialect=%s, buf=%s\n"
152 ess-language ess-dialect temp-ess-dialect (current-buffer)))
153 (let* ((process-environment process-environment)
154 (defdir (or (and ess-directory-function (funcall ess-directory-function))
155 ess-directory default-directory))
156 (temp-dialect temp-ess-dialect)
157 (temp-lang temp-ess-lang)
158 (procname (let ((ntry 0) ;; find a non-existent process
159 (done nil))
160 (while (not done)
161 (setq ntry (1+ ntry)
162 done (not
163 (get-process (ess-proc-name
164 ntry
165 temp-dialect)))))
166 (ess-proc-name ntry temp-dialect)))
167 (startdir nil)
168 (buf nil)
169 (buf-name-str (concat "*" procname "*")))
171 (ess-write-to-dribble-buffer
172 (format "(inf-ess 1.1): procname=%s temp-dialect=%s, buf-name=%s \n"
173 procname
174 temp-dialect
175 buf-name-str))
176 (cond
177 ;; Since it's a new or terminated process, try to use current buffer
178 ((and (not buf)
179 (not (comint-check-proc (current-buffer)))
180 (memq major-mode '(inferior-ess-mode)))
181 (setq startdir
182 (if ess-ask-for-ess-directory
183 (ess-get-directory (directory-file-name defdir))
184 defdir))
185 (setq buf (current-buffer))
186 (ess-write-to-dribble-buffer
187 (format "(inferior-ess) Method #1 start=%s buf=%s\n" startdir buf)))
189 ;; Not an ESS buffer yet
190 ((and (not buf)
191 (get-buffer buf-name-str))
192 (setq buf (get-buffer buf-name-str))
193 (ess-write-to-dribble-buffer
194 (format "(inferior-ess) Method #2 buf=%s\n" buf)))
196 ;; Ask for transcript file and startdir
197 ;; FIXME -- this should be in ess-get-transfile
198 ;; AJR: Why? I'm not clear about the logic, i.e. when would it
199 ;; be used again, to justify?
200 ((not buf)
201 (setq startdir
202 (if ess-ask-for-ess-directory
203 (ess-get-directory (directory-file-name defdir))
204 defdir))
205 (if ess-ask-about-transfile
206 (let ((transfilename (read-file-name
207 "Use transcript file (default none):"
208 startdir "")))
209 (setq buf (if (string= transfilename "")
210 (get-buffer-create buf-name-str)
211 (find-file-noselect (expand-file-name
212 transfilename)))))
213 (setq buf (get-buffer-create buf-name-str)))
214 (ess-write-to-dribble-buffer
215 (format "(inferior-ess) Method #3 start=%s buf=%s\n" startdir buf))))
217 (set-buffer buf)
218 ;; Now that we have the buffer, set buffer-local variables.
219 (ess-setq-vars-local ess-customize-alist); buf)
220 (if ess-start-args (setq inferior-ess-start-args ess-start-args))
221 ;; Was: if not, set to null.
222 ;;(setq inferior-ess-start-args "")) ;; AJR: Errors with XLS?
223 ;; I think I might have solved this?
225 ;; Write out debug info
226 (ess-write-to-dribble-buffer
227 (format "(inf-ess 2.1): ess-language=%s, ess-dialect=%s buf=%s \n"
228 ess-language
229 ess-dialect
230 (current-buffer)))
231 (ess-write-to-dribble-buffer
232 (format "(inf-ess 2.2): start args = %s, inf-ess-start-args=%s \n"
233 ess-start-args
234 inferior-ess-start-args))
235 (ess-write-to-dribble-buffer
236 (format "(inf-ess finish [%s(%s), %s(%s,%s)]\n"
237 ess-language
238 ess-dialect
239 inferior-ess-program
240 ess-current-process-name
241 ess-local-process-name))
243 ;; Start from the "right" directory
244 (if startdir (setq default-directory startdir))
245 ;; Set up history
246 (setq-default ess-history-file
247 (concat "." ess-dialect "history"))
248 ;; initialize.
249 (let ((ess-directory (if startdir default-directory ess-directory)))
250 (ess-multi procname buf inferior-ess-start-args)))))
253 (defvar inferior-ess-objects-command nil
254 "The language/dialect specific command for listing objects.
255 It is initialized from the corresponding inferior-<lang>-objects-command
256 and then made buffer local."); and the *-<lang>-* ones are customized!
257 (make-variable-buffer-local 'inferior-ess-objects-command)
259 (defvar ess-save-lastvalue-command nil
260 "The command to save the last value. See S section for more details.
261 Default depends on the ESS language/dialect and hence made buffer local")
262 (make-variable-buffer-local 'ess-save-lastvalue-command)
264 (defvar ess-retr-lastvalue-command nil
265 "The command to retrieve the last value. See S section for more details.
266 Default depends on the ESS language/dialect and hence made buffer local")
267 (make-variable-buffer-local 'ess-retr-lastvalue-command)
269 ;;; A note on multiple processes: the following variables
270 ;;; ess-local-process-name
271 ;;; ess-search-list
272 ;;; ess-sl-modtime-alist
273 ;;; ess-sp-change
274 ;;; ess-prev-load-dir/file
275 ;;; ess-directory
276 ;;; ess-object-list
277 ;;; are specific to each ess-process and are buffer-local variables
278 ;;; local to the ESS process buffer. If required, these variables should
279 ;;; be accessed with the function ess-get-process-variable
281 (defun ess-multi (name &optional buffer inf-ess-start-args)
282 "Start or switch to ESS process named NAME in the buffer BUFFER.
283 BUFFER is only needed if process NAME is not running. BUFFER must
284 exist. Default-directory is the ESS starting directory. BUFFER may be
285 visiting a file.
287 If ess-process NAME is running, switch to it. If not, use COMINT to
288 start up a new process, using NAME and BUFFER (which is needed if
289 there is no process NAME)."
291 (let* ((proc-name name)
292 (special-display-regexps nil)
293 (special-display-frame-alist inferior-ess-frame-alist)
294 (proc (get-process proc-name)))
295 (if inferior-ess-own-frame
296 (setq special-display-regexps '(".")))
297 ;; If ESS process NAME is running, switch to it
298 (if (and proc (comint-check-proc (process-buffer proc)))
299 (pop-to-buffer (process-buffer proc))
300 ;; Otherwise, crank up a new process
301 (let* ((symbol-string
302 (concat "inferior-" inferior-ess-program "-args"))
303 (switches-symbol (intern-soft symbol-string))
304 (switches
305 (if (and switches-symbol (boundp switches-symbol))
306 (symbol-value switches-symbol)))
307 (buf-name-str (buffer-name buffer)))
308 (ess-write-to-dribble-buffer
309 (format "(ess-multi 0): inf-ess-start-args=%s, comint-..echoes=%s\n"
310 inf-ess-start-args comint-process-echoes))
311 (set-buffer buffer)
312 (inferior-ess-mode)
313 (ess-write-to-dribble-buffer
314 (format "(ess-multi post inf-ess: start-args=%s, comint-echoes=%s\n"
315 inf-ess-start-args comint-process-echoes))
316 (setq ess-local-process-name proc-name)
317 (goto-char (point-max))
318 ;; load past history
319 (setq comint-input-ring-file-name
320 (expand-file-name ess-history-file ess-directory))
321 (comint-read-input-ring)
322 ;; create and run process.
323 (ess-write-to-dribble-buffer
324 (format "(ess-multi 1): start-args=%s \n"
325 inf-ess-start-args))
326 (set-buffer
327 (if switches
328 (inferior-ess-make-comint buf-name-str
329 proc-name
330 inf-ess-start-args
331 switches)
332 (inferior-ess-make-comint buf-name-str
333 proc-name
334 inf-ess-start-args)))
335 ;; Set the process sentinel to save the history
336 (set-process-sentinel (get-process proc-name) 'ess-process-sentinel)
337 ;; Add this process to ess-process-name-list, if needed
338 (let ((conselt (assoc proc-name ess-process-name-list)))
339 (if conselt nil
340 (setq ess-process-name-list
341 (cons (cons proc-name nil) ess-process-name-list))))
342 (ess-make-buffer-current)
343 (inferior-ess-wait-for-prompt)
344 (goto-char (point-max))
345 (setq ess-sl-modtime-alist nil)
346 ;; Get search list when needed
347 (setq ess-sp-change t)
348 (run-hooks 'ess-post-run-hook))
349 (if (and inferior-ess-same-window (not inferior-ess-own-frame))
350 (switch-to-buffer (process-buffer (get-process proc-name)))
351 (pop-to-buffer (process-buffer (get-process proc-name)))))))
354 (defun ess-process-sentinel (proc message)
355 "Sentinel for use with ESS processes.
356 This marks the process with a message, at a particular time point."
357 (save-excursion
358 (setq message (substring message 0 -1)) ; strip newline
359 (set-buffer (process-buffer proc))
360 (comint-write-input-ring)
361 (goto-char (point-max))
362 (insert-before-markers
363 (format "\nProcess %s %s at %s\n"
364 (process-name proc) message (current-time-string)))))
366 (defun inferior-ess-make-comint (bufname
367 procname
368 inferior-ess-start-args
369 &rest switches)
370 "Make an S comint process in buffer BUFNAME with process PROCNAME.
371 This was rewritten by KH in April 1996."
372 ;;; This function is a modification of make-comint from the comint.el
373 ;;; code of Olin Shivers.
374 (let* ((buffer (get-buffer-create bufname))
375 (proc (get-process procname)))
376 ;; If no process, or nuked process, crank up a new one and put buffer in
377 ;; comint mode. Otherwise, leave buffer and existing process alone.
378 (cond ((or (not proc) (not (memq (process-status proc) '(run stop))))
379 (save-excursion
380 (set-buffer buffer)
381 (if ess-directory (setq default-directory ess-directory))
382 (if (eq (buffer-size) 0) nil
383 (goto-char (point-max))
384 (insert "\^L\n"))) ; page boundaries = Interactive sessions
385 (let ((process-environment
386 (nconc
387 (list "STATATERM=emacs"
388 (format "PAGER=%s" inferior-ess-pager))
389 process-environment)))
390 (ess-write-to-dribble-buffer "Making Process...")
391 (ess-write-to-dribble-buffer
392 (format "Buf %s, Proc %s, Prog %s\n Start File=%s, Args= %s.\n"
393 buffer
394 procname
395 inferior-ess-program
396 inferior-ess-start-file
397 inferior-ess-start-args))
398 (comint-exec buffer
399 procname
400 inferior-ess-program
401 inferior-ess-start-file
402 (ess-line-to-list-of-words
403 inferior-ess-start-args)))))
404 buffer))
407 ;;*;; Requester functions called at startup
409 ;(defun ess-get-directory-ORIG (default)
410 ; "Request and return S starting directory."
411 ; (let ((the-dir
412 ; (expand-file-name
413 ; (file-name-as-directory
414 ; (read-file-name
415 ; (format "ESS [%s(%s): %s] starting data directory? "
416 ; ess-language ess-dialect inferior-ess-program)
417 ; (file-name-as-directory default)
418 ; (file-name-as-directory default) t nil)))))
419 ; (if (file-directory-p the-dir) nil
420 ; (error "%s is not a valid directory" the-dir))
421 ; the-dir))
423 (defun ess-get-directory (default)
424 (ess-prompt-for-directory
425 default
426 (format "ESS [%s(%s): %s] starting data directory? "
427 ess-language ess-dialect inferior-ess-program)))
429 (defun ess-prompt-for-directory (default prompt)
430 "`prompt' for a directory, using `default' as the usual."
431 (let ((the-dir
432 (expand-file-name
433 (file-name-as-directory
434 (if (fboundp 'read-directory-name)
435 ;; use XEmacs' read-directory-name if exists.
436 (read-directory-name prompt
437 (file-name-as-directory default)
438 (file-name-as-directory default) t nil)
439 (read-file-name prompt
440 (file-name-as-directory default)
441 (file-name-as-directory default) t nil))))))
442 (if (file-directory-p the-dir) nil
443 (error "%s is not a valid directory" the-dir))
444 the-dir))
447 ;;*;; General process handling code
449 (defun get-ess-process (name)
450 "Return the ESS process named by NAME."
451 (update-ess-process-name-list)
452 (if (null name)
453 (error "No ESS process is associated with this buffer now.")
454 (if (assoc name ess-process-name-list)
455 (get-process name)
456 (error "Process %s is not running." name))))
458 (defun inferior-ess-wait-for-prompt ()
459 "Wait until the ESS process is ready for input."
460 (let* ((cbuffer (current-buffer))
461 (sprocess (get-ess-process ess-current-process-name))
462 (sbuffer (process-buffer sprocess))
463 (r nil)
464 (timeout 0))
465 (set-buffer sbuffer)
466 (while (progn
467 (if (not (eq (process-status sprocess) 'run))
468 (ess-error "ESS process has died unexpectedly.")
469 (if (> (setq timeout (1+ timeout)) ess-loop-timeout)
470 (ess-error "Timeout waiting for prompt. Check inferior-ess-prompt or ess-loop-timeout."))
471 (accept-process-output)
472 (goto-char (point-max))
473 (beginning-of-line); bol ==> no need for "^" in *-prompt! (MM?)
474 ;; above, except for Stata, which has "broken" i/o,
475 ;; sigh... (AJR)
476 (setq r (looking-at inferior-ess-prompt))
477 (not (or r (looking-at ".*\\?\\s *"))))))
478 (goto-char (point-max))
479 (set-buffer cbuffer)
480 (symbol-value r)))
482 ;;--- Unfinished idea (ESS-help / R-help ) -- probably not worth it...
483 ;;- (defun ess-set-inferior-program-name (filename)
484 ;;- "Allows to set or change `inferior-ess-program', the program (file)name."
485 ;;- (interactive "fR executable (script) file: ")
486 ;;- ;; "f" : existing file {file name completion} !
487 ;;- (setq inferior-ess-program filename))
488 ;; the inferior-ess-program is initialized in the customize..alist,
489 ;; e.g. from inferior-R-program-name ... --> should change rather these.
490 ;; However these really depend on the current ess-language!
491 ;; Plan: 1) must know and use ess-language
492 ;; 2) change the appropriate inferior-<ESSlang>-program-name
493 ;; (how?) in R/S : assign(paste("inferior-",ESSlang,"-p...."), filename))
495 ;;*;; Multiple process handling code
497 (defun ess-make-buffer-current nil
498 "Make the process associated with the current buffer the current ESS process.
499 Returns the name of the process, or nil if the current buffer has none."
500 (update-ess-process-name-list)
501 (if ess-local-process-name
502 (setq ess-current-process-name ess-local-process-name))
503 ess-local-process-name)
505 (defun ess-get-process-variable (name var)
506 "Return the variable VAR (symbol) local to ESS process called NAME (string)."
507 (save-excursion
508 (set-buffer (process-buffer (get-ess-process name)))
509 (symbol-value var)))
511 (defun ess-set-process-variable (name var val)
512 "Set variable VAR (symbol) local to ESS process called NAME (string) to VAL."
513 (save-excursion
514 (set-buffer (process-buffer (get-ess-process name)))
515 (set var val)))
517 (defun ess-request-a-process (message &optional noswitch)
518 "Ask for a process, and make it the current ESS process.
519 Also switches to the process buffer unless NOSWITCH is non-nil. Interactively,
520 NOSWITCH can be set by giving a prefix argument.
521 Returns the name of the selected process."
522 (interactive
523 (list "Switch to which ESS process? " current-prefix-arg)) ;prefix sets 'noswitch
524 (update-ess-process-name-list)
525 (if (eq (length ess-process-name-list) 0)
526 (error "No ESS processes running."))
527 (let ((proc (completing-read message
528 ess-process-name-list
529 nil ; predicate
530 'require-match
531 ;; If in S buffer, don't offer current process
532 (if (eq major-mode 'inferior-ess-mode)
533 ess-language
534 ess-current-process-name
535 ;; maybe ess-local-process-name IF exists?
536 ))))
537 (save-excursion
538 (set-buffer (process-buffer (get-process proc)))
539 (ess-make-buffer-current))
540 (if noswitch
542 (ess-show-buffer (buffer-name (process-buffer (get-process proc))) t))
543 proc))
545 (defun ess-force-buffer-current (prompt &optional force)
546 "Make sure the current buffer is attached to an ESS process.
547 If not, or FORCE (prefix argument) is non-nil,
548 prompt for a process name with PROMPT.
549 `ess-local-process-name' is set to the name of the process selected.
550 `ess-dialect' is set to the dialect associated with the process selected."
551 (interactive
552 (list (concat ess-dialect " process to use: ") current-prefix-arg))
553 (if (and (not force) (ess-make-buffer-current))
554 nil ; do nothing
555 ;; Make sure the source buffer is attached to a process
556 (if (and ess-local-process-name (not force))
557 (error "Process %s has died." ess-local-process-name)
558 ;; ess-local-process-name is nil -- which process to attach to
559 (save-excursion
560 (let ((proc (ess-request-a-process prompt 'no-switch))
561 dialect)
562 (save-excursion
563 (set-buffer (process-buffer (get-process proc)))
564 (setq dialect ess-dialect))
565 (setq ess-local-process-name proc)
566 (setq ess-dialect dialect))))))
568 (defun ess-switch-process ()
569 "Force a switch to a new underlying process."
570 (interactive)
571 (ess-force-buffer-current "Process to use: " t))
573 ;;*;;; Commands for switching to the process buffer
575 (defun ess-switch-to-ESS (eob-p)
576 "Switch to the current inferior ESS process buffer.
577 With (prefix) EOB-P non-nil, positions cursor at end of buffer.
578 This function should follow the description in `ess-show-buffer'
579 for showing the iESS buffer, except that the iESS buffer is also
580 made current."
581 (interactive "P")
582 (ess-make-buffer-current)
583 (if (and ess-current-process-name (get-process ess-current-process-name))
584 (progn
585 ;; Display the buffer, but don't select it yet.
586 (ess-show-buffer
587 (buffer-name (process-buffer (get-process ess-current-process-name)))
589 (if eob-p (goto-char (point-max))))
590 (message "No inferior ESS process")
591 (ding)))
593 (defun ess-switch-to-end-of-ESS ()
594 "Switch to the end of the inferior ESS process buffer."
595 (interactive)
596 (ess-switch-to-ESS t))
598 (defun get-ess-buffer (name)
599 "Return the buffer associated with the ESS process named by NAME."
600 (process-buffer (get-ess-process name)))
602 (defun update-ess-process-name-list ()
603 "Remove names with no process."
604 (let (defunct)
605 (mapcar
606 '(lambda (conselt)
607 (let ((proc (get-process (car conselt))))
608 (if (and proc (eq (process-status proc) 'run)) nil
609 (setq defunct (cons conselt defunct)))))
610 ess-process-name-list)
611 (mapcar
612 '(lambda (pointer)
613 (setq ess-process-name-list (delq pointer ess-process-name-list)))
614 defunct))
615 (if (eq (length ess-process-name-list) 0)
616 (setq ess-current-process-name nil)))
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 ;; ess-show-buffer
620 ;; Something like this almost works, but problems with XEmacs and Emacs
621 ;; differing implementations of the args to display-buffer make this
622 ;; too tough to pursue. The longer version below works.
623 ;; (defun ess-show-buffer (buf)
624 ;; "Display the buffer BUF, a string, but do not select it.
625 ;; Returns the window corresponding to the buffer."
626 ;; ;; On XEmacs, I get an error if third arg to display-buffer is t and
627 ;; ;; the BUF is in another frame. Emacs does not have this problem.
628 ;; (if (featurep 'xemacs)
629 ;; (display-buffer buf nil (get-frame-for-buffer buf))
630 ;; (display-buffer buf nil t)))
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
632 (defun ess-show-buffer (buf &optional visit)
633 "Ensure the ESS buffer BUF is visible.
634 The buffer, specified as a string, is typically an iESS (e.g. *R*) buffer.
636 This handles several cases:
638 1. If BUF is visible in the current frame, nothing is done.
639 2. If BUF is visible in another frame, then we ensure that frame is
640 visible (it may have been iconified).
641 3. If buffer is not visible in any frame, simply show it in another window
642 in the current frame.
644 Iff VISIT is non-nil, as well as making BUF visible, we also select it
645 as the current buffer."
646 (let ( (frame))
647 (if (ess-buffer-visible-this-frame buf)
648 ;;1. Nothing to do, BUF visible in this frame; just return window
649 ;; where this buffer is.
652 ;; 2. Maybe BUF visible in another frame.
653 (setq frame (ess-buffer-visible-other-frame buf))
654 (if frame
655 ;; BUF is visible in frame, so just check frame is raised.
656 (if (not (eq (frame-visible-p frame) t))
657 ;; frame is not yet visible, so raise it.
658 (raise-frame frame))
659 ;; 3. else BUF not visible in any frame, so show it (but do
660 ;; not select it) in another window in current frame.
661 (display-buffer buf)))
662 ;; At this stage, the buffer should now be visible on screen,
663 ;; although it won't have been made current.
664 (if visit
665 (progn
666 ;; Need to select the buffer.
668 ;; First of all, check case 2 if buffer is in another frame
669 ;; but that frame may not be selected.
670 (if (and frame (not (featurep 'xemacs)))
671 (progn
672 ;; need to select the frame
673 (select-frame frame)
674 ;; reposition mouse to make frame active.
675 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
676 (select-window (get-buffer-window buf 0))))))
679 ;; The next few functions are copied from my (SJE) iswitchb library.
680 (defun ess-get-bufname (win)
681 "Used by `ess-get-buffers-in-frames' to walk through all windows."
682 (let ((buf (buffer-name (window-buffer win))))
683 (if (not (member buf ess-bufs-in-frame))
684 ;; Only add buf if it is not already in list.
685 ;; This prevents same buf in two different windows being
686 ;; put into the list twice.
687 (setq ess-bufs-in-frame
688 (cons buf ess-bufs-in-frame)))))
690 (defun ess-get-buffers-in-frames (&optional current)
691 "Return the list of buffers that are visible in the current frame.
692 If optional argument CURRENT is given, restrict searching to the
693 current frame, rather than all frames."
694 (let ((ess-bufs-in-frame nil))
695 (walk-windows 'ess-get-bufname nil (if current nil 0))
696 ess-bufs-in-frame))
698 (defun ess-buffer-visible-this-frame (buf)
699 "Return t if BUF is visible in current frame."
700 (member buf (ess-get-buffers-in-frames t)))
702 (defun ess-buffer-visible-other-frame (buf)
703 "Return t if BUF is visible in another frame.
704 Assumes that buffer has not already been in found in current frame."
705 (if (member buf (ess-get-buffers-in-frames))
706 (window-frame (get-buffer-window buf 0))
707 nil))
710 \f ; Functions for evaluating code
712 (defun ess-ddeclient-p ()
713 "Returns t if the ess-local-process-name is associated with an
714 inferior-ess-ddeclient, and nil if the ess-process is running as an
715 ordinary inferior process. Alway nil on Unix machines."
716 (interactive)
717 (if ess-microsoft-p
718 (not (equal (ess-get-process-variable
719 ess-local-process-name 'inferior-ess-ddeclient)
720 (default-value 'inferior-ess-ddeclient)))))
722 (defun ess-prompt-wait (proc &optional start-of-output sleep)
723 "Wait for a prompt to appear at BOL of current buffer.
724 PROC is the ESS process. Does not change point"
725 (if sleep (sleep-for sleep)); we sleep here, *and* wait below
726 (if start-of-output nil (setq start-of-output (point-min)))
727 (save-excursion
728 (while (progn
729 ;; get output if there is some ready
731 ;; (if (and ess-microsoft-p ess-ms-slow)
732 ;; (accept-process-output proc 0 1500) ; Microsoft is slow
733 (accept-process-output proc 0 500)
734 ;; )
735 (goto-char (marker-position (process-mark proc)))
736 (beginning-of-line)
737 (if (< (point) start-of-output) (goto-char start-of-output))
738 (not (looking-at inferior-ess-primary-prompt))))))
740 (defun ordinary-insertion-filter (proc string)
741 (let ((old-buffer (current-buffer)))
742 (unwind-protect
743 (let (moving)
744 (set-buffer (process-buffer proc))
745 (setq moving (= (point) (process-mark proc)))
746 (save-excursion
747 ;; Insert the text, moving the process-marker.
748 (goto-char (process-mark proc))
749 (insert string)
750 (set-marker (process-mark proc) (point)))
751 (if moving (goto-char (process-mark proc))))
752 (set-buffer old-buffer))))
754 (defun ess-command (com &optional buf sleep)
755 "Send the ESS process command COM and delete the output
756 from the ESS process buffer. If an optional second argument BUF exists
757 save the output in that buffer. BUF is erased before use.
758 COM should have a terminating newline.
759 Guarantees that the value of .Last.value will be preserved.
760 When optional third arg SLEEP is non-nil, `(sleep-for (* a SLEEP))'
761 will be used in a few places where `a' is proportional to `ess-cmd-delay'."
762 ;; Use this function when you need to evaluate some S code, and the
763 ;; result is needed immediately. Waits until the output is ready
764 (let* ((sprocess (get-ess-process ess-current-process-name))
765 sbuffer
766 do-sleep end-of-output
767 oldpb oldpf oldpm
768 my-retr-cmd my-save-cmd)
769 (if sprocess nil
770 (error "Process %s is not running!" ess-current-process-name))
771 (setq sbuffer (process-buffer sprocess))
772 (save-excursion
773 (set-buffer sbuffer)
774 (setq do-sleep ; only now when in sprocess buffer
775 (progn
776 (if sleep (if (numberp sleep) nil (setq sleep 1))); t means 1
777 (and ess-cmd-delay sleep)))
778 (if do-sleep (setq sleep (* sleep ess-cmd-delay)))
779 (save-excursion
780 (goto-char (marker-position (process-mark sprocess)))
781 (beginning-of-line)
782 (if (looking-at inferior-ess-primary-prompt) nil
783 (ess-error
784 "ESS process not ready. Finish your command before trying again.")))
785 (if buf nil (setq buf (get-buffer-create " *ess-command-output*")))
786 (setq oldpf (process-filter sprocess))
787 (setq oldpb (process-buffer sprocess))
788 (setq oldpm (marker-position (process-mark sprocess)))
789 ;; need the buffer-local values in result buffer "buf":
790 (setq my-retr-cmd ess-retr-lastvalue-command)
791 (setq my-save-cmd ess-save-lastvalue-command)
792 (unwind-protect
793 (progn
794 (set-process-buffer sprocess buf)
795 (set-process-filter sprocess 'ordinary-insertion-filter)
796 ;; Output is now going to BUF:
797 (save-excursion
798 (set-buffer buf)
799 (erase-buffer)
800 (set-marker (process-mark sprocess) (point-min))
801 (process-send-string sprocess my-save-cmd)
803 (ess-prompt-wait sprocess nil (and do-sleep (* 0.05 sleep)))
804 (erase-buffer)
805 (process-send-string sprocess com)
807 ;; need time for ess-create-object-name-db on PC
808 (ess-prompt-wait sprocess nil (and do-sleep (* 0.4 sleep)));MS: 4
809 ;;(if do-sleep (sleep-for (* 0.0 sleep))); microsoft: 0.5
810 (goto-char (point-max))
811 (save-excursion
812 (beginning-of-line) ; so prompt will be deleted
813 (setq end-of-output (point)))
814 (process-send-string sprocess my-retr-cmd)
816 (ess-prompt-wait sprocess end-of-output
817 (and do-sleep (* 0.05 sleep))); microsoft: 0.5)
819 ;; Get rid out output from last assign
820 (delete-region end-of-output (point-max))))
821 ;; Restore old values for process filter
822 (set-process-buffer sprocess oldpb)
823 (set-process-filter sprocess oldpf)
824 (set-marker (process-mark sprocess) oldpm)))))
826 (defun ess-replace-in-string (str regexp newtext &optional literal)
827 "Replace all matches in STR for REGEXP with NEWTEXT string.
828 Optional LITERAL non-nil means do a literal replacement.
829 Otherwise treat \\ in NEWTEXT string as special:
830 \\& means substitute original matched text,
831 \\N means substitute match for \(...\) number N,
832 \\\\ means insert one \\."
833 (if (not (stringp str))
834 (error "(replace-in-string): First argument must be a string: %s" str))
835 (if (stringp newtext)
837 (error "(replace-in-string): 3rd arg must be a string: %s"
838 newtext))
839 (let ((rtn-str "")
840 (start 0)
841 (special)
842 match prev-start)
843 (while (setq match (string-match regexp str start))
844 (setq prev-start start
845 start (match-end 0)
846 rtn-str
847 (concat
848 rtn-str
849 (substring str prev-start match)
850 (cond (literal newtext)
851 (t (mapconcat
852 (function
853 (lambda (c)
854 (if special
855 (progn
856 (setq special nil)
857 (cond ((eq c ?\\) "\\")
858 ((eq c ?&)
859 (substring str
860 (match-beginning 0)
861 (match-end 0)))
862 ((and (>= c ?0) (<= c ?9))
863 (if (> c (+ ?0 (length
864 (match-data))))
865 ;; Invalid match num
866 (error "(replace-in-string) Invalid match num: %c" c)
867 (setq c (- c ?0))
868 (substring str
869 (match-beginning c)
870 (match-end c))))
871 (t (char-to-string c))))
872 (if (eq c ?\\) (progn (setq special t) nil)
873 (char-to-string c)))))
874 newtext ""))))))
875 (concat rtn-str (substring str start))))
879 ;;*;; Evaluating lines, paragraphs, regions, and buffers.
881 ;;--- The two basic building blocks [called by all other ess-eval..] are
882 ;; (ess-eval-linewise ....)
883 ;; and
884 ;; (ess-eval-region ....)
886 (defun ess-eval-linewise (text-withtabs &optional invisibly eob even-empty)
887 ;; RDB 28/8/92 added optional arg eob
888 ;; AJR 971022: text-withtabs was text.
889 "Evaluate TEXT-WITHTABS in the ESS process buffer as if typed in w/o tabs.
890 Waits for prompt after each line of input, so won't break on large texts.
892 If optional second arg INVISIBLY is non-nil, don't echo commands. If it
893 is a string, just include that string. If optional third arg
894 EOB is non-nil go to end of ESS process buffer after evaluation. If optional
895 4th arg EVEN-EMPTY is non-nil, also send empty text (e.g. an empty line)."
896 ;; Use this to evaluate some code, but don't wait for output.
897 (let* ((cbuffer (current-buffer))
898 (sprocess (get-ess-process ess-current-process-name))
899 (sbuffer (process-buffer sprocess))
900 (text (ess-replace-in-string text-withtabs "\t" " "))
901 start-of-output
902 com pos txt-gt-0)
904 ;;(message "'ess-eval-linewise: sbuffer = %s" sbuffer)
905 (set-buffer sbuffer)
907 ;; the following is required to make sure things work!
908 (if (string= ess-language "STA")
909 (setq invisibly t))
910 ;; dbg:
911 ;; dbg(ess-write-to-dribble-buffer
912 ;; dbg (format "(eval-visibly 1): lang %s (invis=%s, eob=%s, even-empty=%s)\n"
913 ;; dbg ess-language invisibly eob even-empty))
915 (goto-char (marker-position (process-mark sprocess)))
916 (if (stringp invisibly)
917 (insert-before-markers (concat "*** " invisibly " ***\n")))
918 ;; dbg:
919 ;; dbg (ess-write-to-dribble-buffer
920 ;; dbg (format "(eval-visibly 2): text[%d]= «%s»\n" (length text) text))
921 (while (or (setq txt-gt-0 (> (length text) 0))
922 even-empty)
923 (if even-empty (setq even-empty nil))
924 (if txt-gt-0
925 (progn
926 (setq pos (string-match "\n\\|$" text))
927 (setq com (concat (substring text 0 pos) "\n"))
928 (setq text (substring text (min (length text) (1+ pos)))))
929 ;; else 0-length text
930 (setq com "\n")
932 (goto-char (marker-position (process-mark sprocess)))
933 (if (not invisibly)
934 ;; Terrible kludge -- need to insert after all markers *except*`
935 ;; the process mark
936 (let ((dokludge (eq (point)
937 (marker-position (process-mark sprocess)))))
938 (insert com)
939 (if dokludge (set-marker (process-mark sprocess) (point)))))
940 (setq start-of-output (marker-position (process-mark sprocess)))
941 ;; A kludge to prevent the delay between insert and process output
942 ;; affecting the display. A case for a comint-send-input-hook?
943 ;; (save-excursion
944 ;; ;; comint-postoutput-scroll-to-bottom can change
945 ;; ;; current-buffer. Argh.
946 ;; (let ((functions comint-output-filter-functions))
947 ;; (while functions
948 ;; (funcall (car functions) com)
949 ;; (setq functions (cdr functions)))))
950 (process-send-string sprocess com)
951 ;; Don't hang around waiting for the prompt after the last
952 ;; line of input
953 (if (eq (length text) 0)
955 (while (progn
956 (accept-process-output nil 0 100)
957 (goto-char (marker-position (process-mark sprocess)))
958 (beginning-of-line)
959 (if (< (point) start-of-output)
960 (goto-char start-of-output))
961 (not (looking-at inferior-ess-prompt))))))
962 (goto-char (marker-position (process-mark sprocess)))
963 (if eob
964 (progn
965 (ess-show-buffer (buffer-name sbuffer) nil)
966 ;; Once SBUFFER is visible, we can then move the point in that
967 ;; window to the end of the buffer.
968 (set-window-point (get-buffer-window sbuffer t)
969 (with-current-buffer sbuffer (point-max))))
970 (set-buffer cbuffer))
973 ;;;*;;; Evaluate only
975 (defun ess-eval-region (start end toggle &optional message)
976 "Send the current region to the inferior ESS process.
977 With prefix argument, toggle meaning of `ess-eval-visibly-p'."
978 (interactive "r\nP")
979 ;;(untabify (point-min) (point-max))
980 ;;(untabify start end); do we really need to save-excursion?
981 (ess-force-buffer-current "Process to load into: ")
982 (message "Starting evaluation...")
983 (let ((visibly (if toggle (not ess-eval-visibly-p) ess-eval-visibly-p)))
984 (if visibly
985 (ess-eval-linewise (buffer-substring start end))
986 (if ess-synchronize-evals
987 (ess-eval-linewise (buffer-substring start end)
988 (or message "Eval region"))
989 ;; else [almost always!]
990 (let ((sprocess (get-ess-process ess-current-process-name)))
991 (process-send-region sprocess start end)
992 (process-send-string sprocess "\n")))))
993 (message "Finished evaluation"))
995 (defun ess-eval-buffer (vis)
996 "Send the current buffer to the inferior ESS process.
997 Arg has same meaning as for `ess-eval-region'."
998 (interactive "P")
999 ;; already in eval-region:
1000 ;; (ess-force-buffer-current "Process to load into: ")
1001 (ess-eval-region (point-min) (point-max) vis "Eval buffer"))
1003 (defun ess-eval-function (vis)
1004 "Send the current function to the inferior ESS process.
1005 Arg has same meaning as for `ess-eval-region'."
1006 (interactive "P")
1007 ;; already in eval-region:
1008 ;; (ess-force-buffer-current "Process to load into: ")
1009 (save-excursion
1010 (let* ((beg-end (ess-end-of-function))
1011 (beg (nth 0 beg-end))
1012 (end (nth 1 beg-end))
1013 name)
1014 (goto-char beg)
1015 (setq name (ess-extract-word-name))
1016 (princ (concat "Loading: " name) t)
1017 (ess-eval-region beg end vis
1018 (concat "Eval function " name)))))
1020 ;; This is from Mary Lindstrom <lindstro@Biostat.Wisc.Edu>
1021 ;; 31 Aug 1995 14:11:43 To: S-mode@stat.math.ethz.ch
1022 (defun ess-eval-paragraph (vis)
1023 "Send the current paragraph to the inferior ESS process.
1024 Prefix arg VIS toggles visibility of ess-code as for `ess-eval-region'."
1025 (interactive "P")
1026 (ess-force-buffer-current "Process to load into: ")
1027 (save-excursion
1028 (forward-paragraph)
1029 (let ((end (point)))
1030 (backward-paragraph)
1031 (ess-eval-region (point) end vis "Eval paragraph"))))
1033 (defun ess-eval-line (vis)
1034 "Send the current line to the inferior ESS process.
1035 Arg has same meaning as for `ess-eval-region'."
1036 (interactive "P")
1037 (ess-force-buffer-current "Process to load into: ")
1038 (save-excursion
1039 (end-of-line)
1040 (let ((end (point)))
1041 (beginning-of-line)
1042 (princ (concat "Loading line: " (ess-extract-word-name) " ...") t)
1043 (ess-eval-region (point) end vis "Eval line"))))
1047 ;; Contributed by Stephen Eglen <stephen@anc.ed.ac.uk> {idea from octave int.}
1048 (defun ess-next-code-line (&optional arg)
1049 "Move ARG lines of code forward (backward if ARG is negative).
1050 Skips past all empty and comment lines. Default for ARG is 1.
1052 On success, return 0. Otherwise, go as far as possible and return -1."
1053 (interactive "p")
1054 (or arg (setq arg 1))
1055 (beginning-of-line)
1056 (let ((n 0)
1057 (inc (if (> arg 0) 1 -1)))
1058 (while (and (/= arg 0) (= n 0))
1059 (setq n (forward-line inc)); n=0 is success
1060 (while (and (= n 0)
1061 (looking-at "\\s-*\\($\\|\\s<\\)"))
1062 (setq n (forward-line inc)))
1063 (setq arg (- arg inc)))
1066 (defun ess-eval-line-and-step (&optional simple-next even-empty invisibly)
1067 "Evaluate the current line visibly and step to the \"next\" line.
1068 \"next\" = the next line with non-comment code _unless_ SIMPLE-NEXT is non-nil,
1069 possibly via prefix arg. If 2nd arg EVEN-EMPTY [prefix as well],
1070 also send empty lines. When the variable `ess-eval-empty' is non-nil
1071 both SIMPLE-NEXT and EVEN-EMPTY are interpreted as true."
1072 ;; From an idea by Rod Ball (rod@marcam.dsir.govt.nz)
1073 (interactive "P\nP"); prefix sets BOTH !
1074 (ess-force-buffer-current "Process to load into: ")
1075 (save-excursion
1076 (end-of-line)
1077 (let ((end (point)))
1078 (beginning-of-line)
1079 ;; go to end of process buffer so user can see result
1080 (ess-eval-linewise (buffer-substring (point) end)
1081 invisibly 'eob (or even-empty ess-eval-empty))))
1082 (if (or simple-next ess-eval-empty)
1083 (forward-line 1)
1084 (ess-next-code-line 1)))
1086 (defun ess-eval-line-and-step-invisibly (&optional simple-next even-empty)
1087 "Evaluate the current line invisibly and step to the next line.
1088 Evaluate all comments and empty lines."
1089 (interactive)
1090 (ess-eval-line-and-step t t t))
1092 ;; goes to the real front, in case you do double function definition
1093 ;; 29-Jul-92 -FER
1094 ;; don't know why David changed it.
1096 ;; FER's versions don't work properly with nested functions. Replaced
1097 ;; mine. DMS 16 Nov 92
1099 ;;;*;;; Evaluate and switch to S
1101 (defun ess-eval-region-and-go (start end vis)
1102 "Send the current region to the inferior S and switch to the process buffer.
1103 Arg has same meaning as for `ess-eval-region'."
1104 (interactive "r\nP")
1105 (ess-eval-region start end vis)
1106 (ess-switch-to-ESS t))
1108 (defun ess-eval-buffer-and-go (vis)
1109 "Send the current buffer to the inferior S and switch to the process buffer.
1110 Arg has same meaning as for `ess-eval-region'."
1111 (interactive "P")
1112 (ess-eval-buffer vis)
1113 (ess-switch-to-ESS t))
1115 (defun ess-eval-function-and-go (vis)
1116 "Send the current function to the inferior ESS process and switch to
1117 the process buffer. Arg has same meaning as for `ess-eval-region'."
1118 (interactive "P")
1119 (ess-eval-function vis)
1120 (ess-switch-to-ESS t))
1122 (defun ess-eval-line-and-go (vis)
1123 "Send the current line to the inferior ESS process and switch to the
1124 process buffer. Arg has same meaning as for `ess-eval-region'."
1125 (interactive "P")
1126 (ess-eval-line vis)
1127 (ess-switch-to-ESS t))
1129 ;;; Related to the ess-eval-* commands, there are the ess-load
1130 ;;; commands. Need to add appropriate stuff...
1132 (defun ess-load-file (filename)
1133 "Load an S source file into an inferior ESS process."
1134 (interactive (list
1136 (and (eq major-mode 'ess-mode)
1137 (buffer-file-name))
1138 (expand-file-name
1139 (read-file-name "Load S file: " nil nil t)))))
1140 (ess-make-buffer-current)
1141 (let ((source-buffer (get-file-buffer filename)))
1142 (if (ess-check-source filename)
1143 (error "Buffer %s has not been saved" (buffer-name source-buffer))
1144 ;; Find the process to load into
1145 (if source-buffer
1146 (save-excursion
1147 (set-buffer source-buffer)
1148 (ess-force-buffer-current "Process to load into: ")
1149 (ess-check-modifications))))
1150 (let ((errbuffer (ess-create-temp-buffer ess-error-buffer-name))
1151 error-occurred nomessage)
1152 (ess-command (format inferior-ess-load-command filename) errbuffer);sleep ?
1153 (save-excursion
1154 (set-buffer errbuffer)
1155 (goto-char (point-max))
1156 (setq error-occurred (re-search-backward ess-dump-error-re nil t))
1157 (setq nomessage (= (buffer-size) 0)))
1158 (if error-occurred
1159 (message "Errors: Use %s to find error."
1160 (substitute-command-keys
1161 "\\<inferior-ess-mode-map>\\[ess-parse-errors]"))
1162 ;; Load did not cause an error
1163 (if nomessage (message "Load successful.")
1164 ;; There was a warning message from S
1165 (ess-display-temp-buffer errbuffer))
1166 ;; Consider deleting the file
1167 (let ((skdf (if source-buffer
1168 (save-excursion
1169 (set-buffer source-buffer)
1170 ess-keep-dump-files)
1171 ess-keep-dump-files))) ;; global value
1172 (cond
1173 ((null skdf)
1174 (delete-file filename))
1175 ((memq skdf '(check ask))
1176 (let ((doit (y-or-n-p (format "Delete %s " filename))))
1177 (if doit (delete-file filename))
1178 (and source-buffer
1179 (local-variable-p 'ess-keep-dump-files source-buffer)
1180 (save-excursion
1181 (set-buffer source-buffer)
1182 (setq ess-keep-dump-files doit)))))))
1183 (ess-switch-to-ESS t)))))
1185 \f ; Inferior S mode
1186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1187 ;;;; In this section:
1188 ;;;;
1189 ;;;; * The major mode inferior-ess-mode
1190 ;;;; * Process handling code
1191 ;;;; * Completion code
1192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1194 ;;*;; Major mode definition
1196 (if inferior-ess-mode-map
1199 (cond ((featurep 'xemacs)
1200 ;; Code for XEmacs
1201 (setq inferior-ess-mode-map (make-keymap))
1202 (set-keymap-parent inferior-ess-mode-map comint-mode-map))
1203 ((not (featurep 'xemacs))
1204 ;; Code for GNU Emacs
1205 (setq inferior-ess-mode-map (cons 'keymap comint-mode-map))))
1207 ;; Use syntax valid *both* for GNU emacs and XEmacs :
1208 (define-key inferior-ess-mode-map "\r" 'inferior-ess-send-input)
1209 (define-key inferior-ess-mode-map "\C-a" 'comint-bol)
1210 (define-key inferior-ess-mode-map "\M-\r" 'ess-transcript-send-command-and-move)
1211 (define-key inferior-ess-mode-map "\C-c\C-l" 'ess-load-file)
1212 ;; the above OVERRIDES comint-dynamic-list-input-ring --> re-assign:
1213 (define-key inferior-ess-mode-map "\C-c\M-l" 'comint-dynamic-list-input-ring)
1214 (define-key inferior-ess-mode-map "\C-c`" 'ess-parse-errors)
1215 (define-key inferior-ess-mode-map "\C-c\C-d" 'ess-dump-object-into-edit-buffer)
1216 (define-key inferior-ess-mode-map "\C-c\C-v" 'ess-display-help-on-object)
1217 (define-key inferior-ess-mode-map "\C-c\C-q" 'ess-quit)
1218 (define-key inferior-ess-mode-map "\C-c\C-t" 'ess-execute)
1219 (define-key inferior-ess-mode-map "\C-c\C-s" 'ess-execute-search)
1220 (define-key inferior-ess-mode-map "\C-c\C-x" 'ess-execute-objects)
1221 ;;(define-key inferior-ess-mode-map "\C-c\C-a" 'ess-execute-attach)
1222 (define-key inferior-ess-mode-map "\C-c\034" 'ess-abort) ; \C-c\C-backslash
1223 (define-key inferior-ess-mode-map "\C-c\C-z" 'ess-abort) ; mask comint map
1224 (define-key inferior-ess-mode-map "\C-d" 'delete-char) ; EOF no good in S
1225 (define-key inferior-ess-mode-map "\t" 'comint-dynamic-complete)
1226 (define-key inferior-ess-mode-map "\C-c\t" 'ess-complete-object-name)
1227 (define-key inferior-ess-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
1228 (define-key inferior-ess-mode-map "\M-?" 'ess-list-object-completions)
1229 (define-key inferior-ess-mode-map "\C-c\C-k" 'ess-request-a-process))
1231 (easy-menu-define
1232 inferior-ess-mode-menu inferior-ess-mode-map
1233 "Menu for use in Inferior S mode"
1234 '("iESS"
1235 ["What is this? (beta)" ess-mouse-me t]
1236 ["Resynch S completions" ess-resynch t]
1237 ["Quit S" ess-quit t]
1238 ["Display search list" ess-execute-search t]
1239 ["Display object list" ess-execute-objects t]
1240 ["Get help on S object" ess-display-help-on-object t]
1241 ["Enter S command" ess-execute t]
1242 ["Attach directory" ess-execute-attach t]
1243 "------"
1244 ["Send and move" ess-transcript-send-command-and-move t]
1245 ["Copy command" comint-copy-old-input t]
1246 ["Send command" inferior-ess-send-input t]
1247 "------"
1248 ["Jump to Error" ess-parse-errors t]
1249 ;; need a toggle switch for above, AJR.
1250 ["Load source file" ess-load-file t]
1251 ["Edit S Object" ess-dump-object-into-edit-buffer t]
1252 "------"
1253 ["Describe" describe-mode t]
1254 ["About" (ess-goto-info "Entering Commands") t]
1255 ["Send bug report" ess-submit-bug-report t]
1259 (defun inferior-ess-mode-xemacs-menu ()
1260 "Hook to install `ess-mode' menu for XEmacs (w/ easymenu)."
1261 (if 'inferior-ess-mode
1262 (easy-menu-add inferior-ess-mode-menu)
1263 (easy-menu-remove inferior-ess-mode-menu)))
1265 (if (string-match "XEmacs" emacs-version)
1266 (add-hook 'inferior-ess-mode-hook 'inferior-ess-mode-xemacs-menu))
1268 (if ess-mode-minibuffer-map nil
1270 (cond ((featurep 'xemacs)
1271 ;; Code for XEmacs
1272 (setq ess-mode-minibuffer-map (make-keymap))
1273 (set-keymap-parent ess-mode-minibuffer-map minibuffer-local-map)))
1275 (cond ((not (featurep 'xemacs))
1276 ;; Code for Emacs
1277 (setq ess-mode-minibuffer-map (cons 'keymap minibuffer-local-map))))
1279 (define-key ess-mode-minibuffer-map "\t" 'ess-complete-object-name)
1280 (define-key ess-mode-minibuffer-map "\C-c\C-s" 'ess-execute-search)
1281 (define-key ess-mode-minibuffer-map "\C-c\C-x" 'ess-execute-objects))
1283 (defun inferior-ess-mode ()
1284 "Major mode for interacting with an inferior ESS process.
1285 Runs an S interactive job as a subprocess of Emacs, with I/O through an
1286 Emacs buffer. Variable `inferior-ess-program' controls which S
1287 is run.
1289 Commands are sent to the ESS process by typing them, and pressing
1290 \\[inferior-ess-send-input]. Pressing \\[complete-dynamic-complete]
1291 completes known object names or filenames, as appropriate. Other
1292 keybindings for this mode are:
1294 \\{inferior-ess-mode-map}
1296 When editing S objects, the use of \\[ess-load-file] is advocated.
1297 `ess-load-file' keeps source files (if `ess-keep-dump-files' is non-nil) in
1298 the directory specified by `ess-source-directory', with the
1299 filename chosen according to `ess-dump-filename-template'. When a file is
1300 loaded, `ess-mode' parses error messages and jumps to the appropriate file
1301 if errors occur. The ess-eval- commands do not do this.
1303 Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
1304 `inferior-ess-mode-hook' (in that order).
1306 You can send text to the inferior ESS process from other buffers containing
1307 S source. The key bindings of these commands can be found by typing
1308 C-h m (help for mode) in the other buffers.
1309 `ess-eval-region' sends the current region to the ESS process.
1310 `ess-eval-buffer' sends the current buffer to the ESS process.
1311 `ess-eval-function' sends the current function to the ESS process.
1312 `ess-eval-line' sends the current line to the ESS process.
1313 `ess-beginning-of-function' and `ess-end-of-function' move the point to
1314 the beginning and end of the current S function.
1315 `ess-switch-to-ESS' switches the current buffer to the ESS process buffer.
1316 `ess-switch-to-end-of-ESS' switches the current buffer to the ESS process
1317 buffer and puts point at the end of it.
1319 `ess-eval-region-and-go', `ess-eval-buffer-and-go',
1320 `ess-eval-function-and-go', and `ess-eval-line-and-go' switch to the S
1321 process buffer after sending their text.
1322 `ess-dump-object-into-edit-buffer' moves an S object into a temporary file
1323 and buffer for editing
1324 `ess-load-file' sources a file of commands to the ESS process.
1326 Commands:
1327 Return after the end of the process' output sends the text from the
1328 end of process to point.
1329 Return before the end of the process' output copies the sexp ending at point
1330 to the end of the process' output, and sends it.
1331 Delete converts tabs to spaces as it moves back.
1332 C-M-q does Tab on each line starting within following expression.
1333 Paragraphs are separated only by blank lines. Crosshatches start comments.
1334 If you accidentally suspend your process, use \\[comint-continue-subjob]
1335 to continue it."
1336 (interactive)
1337 ;;(message " at very beg. of (inferior-ess-mode): inf.-ess-prompt= %s"
1338 ;; inferior-ess-prompt)
1339 (comint-mode)
1342 ;; SJE: is this the proper place for setting inferior-ess-prompt,
1343 ;; rather than within ess-multi? Tony - have you remembered yet
1345 ;; about the setq-default, as I changed it back to setq.
1346 (setq inferior-ess-prompt
1347 ;; shouldn't be setq-default! And I've
1348 ;; forgotten why! (AJR)
1349 ;; Do not anchor to bol with `^'
1350 (concat "\\("
1351 inferior-ess-primary-prompt
1352 "\\|"
1353 inferior-ess-secondary-prompt
1354 "\\)"))
1355 (setq comint-prompt-regexp (concat "^" inferior-ess-prompt))
1356 (setq major-mode 'inferior-ess-mode)
1357 (setq mode-name "iESS") ;(concat "iESS:" ess-dialect))
1358 (setq mode-line-process
1359 '(" [" ess-local-process-name "]: %s"))
1360 (use-local-map inferior-ess-mode-map)
1361 (if ess-mode-syntax-table
1362 (set-syntax-table ess-mode-syntax-table)
1363 ; FIXME: need to do something if not set! Get from the proper place!
1365 (add-hook 'comint-input-filter-functions 'ess-search-path-tracker)
1366 (setq comint-get-old-input 'inferior-ess-get-old-input)
1368 (ess-write-to-dribble-buffer
1369 (format "(i-ess 1): buf=%s, lang=%s, comint..echo=%s, comint..sender=%s,\n"
1370 (current-buffer) ess-language
1371 comint-process-echoes comint-input-sender))
1373 (make-local-variable 'comint-process-echoes)
1374 (make-local-variable 'comint-input-sender)
1375 (make-local-variable 'process-connection-type)
1376 (setq process-connection-type t)
1378 ;; Configuration for SAS/XLispStat input handling
1379 ;; We set comint-process-echoes to t because inferior-ess-input-sender
1380 ;; recopies the input. If comint-process-echoes was *meant* to be t ...
1382 ;; except that XLS doesn't like it. This is an ugly hack that ought
1383 ;; to go into the dialect configuration...
1384 (if (or (string= ess-language "SAS")
1385 (string= ess-language "XLS"))
1386 (setq comint-process-echoes nil)
1387 (setq comint-process-echoes t))
1389 ;; Configuration for S/R input handling
1390 ;; AJR: add KH's fix. This is ugly, change to do it right.
1391 ;; i.e. put it as a buffer local var, in S or R defuns...
1392 (if (or (string= ess-language "S"))
1393 (cond
1394 ((string= ess-dialect "R")
1395 (setq comint-input-sender 'inferior-R-input-sender))
1396 ((or (string= ess-dialect "S3") ;; S dialects
1397 (string= ess-dialect "S4")
1398 (string= ess-dialect "S+3")
1399 (string= ess-dialect "S+4")
1400 (string= ess-dialect "S+5")
1401 (string= ess-dialect "S+6")
1402 (string= ess-dialect "S"))
1403 (setq comint-input-sender 'inferior-ess-input-sender))))
1405 ;; Configuration for Stata input handling
1406 ;; AJR: Stata is hell. This is the primary configuration point.
1407 (if (string= ess-language "STA")
1408 (progn
1409 (setq comint-input-sender 'inferior-ess-input-sender) ; was STA
1410 (setq comint-process-echoes t)))
1412 ;; Configuration for Omegahat input handling
1413 (if (string= ess-language "OMG")
1414 (progn
1415 ; the following doesn't exist (until needed?)
1416 ;(setq comint-input-sender 'inferior-OMG-input-sender)
1417 (setq comint-process-echoes nil)))
1419 (ess-write-to-dribble-buffer
1420 (format "(i-ess 2): buf=%s, lang=%s, comint..echo=%s, comint..sender=%s,\n"
1421 (current-buffer) ess-language
1422 comint-process-echoes comint-input-sender))
1423 ;; Font-lock support
1424 ;; AJR: This (the following local-var is already the case!
1425 ;; KH sez: only in XEmacs :-(.
1426 (make-local-variable 'font-lock-defaults)
1427 (setq font-lock-defaults
1428 '(inferior-ess-font-lock-keywords nil nil ((?' . "."))))
1430 (ess-setq-vars-local ess-customize-alist); (current-buffer))
1432 (ess-write-to-dribble-buffer
1433 (format "(i-ess 3): curr-buf=%s, comint..echo=%s, comint..sender=%s,\n"
1434 (current-buffer) comint-process-echoes comint-input-sender))
1436 ;; Completion support
1437 ;; SJE: comint-dynamic-complete-functions is regarded as a hook, rather
1438 ;; than a regular variable.
1439 (add-hook 'comint-dynamic-complete-functions
1440 'ess-complete-object-name nil 'local)
1441 (add-hook 'comint-dynamic-complete-functions
1442 'comint-replace-by-expanded-history 'append 'local)
1443 (add-hook 'comint-dynamic-complete-functions
1444 'ess-complete-filename 'append 'local)
1448 ;; (setq comint-completion-addsuffix nil) ; To avoid spaces after filenames
1449 ;; KH: next 2 lines solve.
1450 (make-local-variable 'comint-completion-addsuffix)
1451 (setq comint-completion-addsuffix (cons "/" ""))
1453 (setq comint-input-autoexpand t) ; Only for completion, not on input.
1455 ;;; Keep <tabs> out of the code.
1456 (make-local-variable 'indent-tabs-mode)
1457 (setq indent-tabs-mode nil)
1459 (make-local-variable 'paragraph-start)
1460 (setq paragraph-start (concat inferior-ess-primary-prompt "\\|\^L"))
1461 (make-local-variable 'paragraph-separate)
1462 (setq paragraph-separate "\^L")
1464 ;; SJE Tue 28 Dec 2004: do not attempt to load object name db.
1465 ;; (ess-load-object-name-db-file)
1466 ;; (sleep-for 0.5)
1467 (make-local-variable 'kill-buffer-hook)
1468 (add-hook 'kill-buffer-hook 'ess-kill-buffer-function)
1469 (run-hooks 'inferior-ess-mode-hook)
1470 (message
1471 (concat (substitute-command-keys
1472 "Type \\[describe-mode] for help on ESS version ")
1473 ess-version)))
1475 ;;*;; Commands used exclusively in inferior-ess-mode
1477 ;;;*;;; Main user commands
1479 (defun inferior-ess-input-sender (proc string)
1480 (ess-eval-linewise (concat string "\n") nil nil ess-eval-empty))
1482 (defun inferior-STA-input-sender (proc string)
1483 (ess-eval-linewise (concat string "\n") t t))
1485 ;;> <PD writes>:
1486 ;;> Also, invoking help() from the command line may lead to confusing
1487 ;;> output, somewhat worse with R than with S. You're not really supposed
1488 ;;> to do that (use C-c C-v to invoke ess-display-help-on-object), but it's
1489 ;;> an obvious newcomer's mistake.
1491 ;;> (I wonder: could the elisp-code not quite easily recognize help
1492 ;;> calls (at least in the ?xxx form) and do the right thing automagically?)
1494 ;;> As promised, here is a quick hack:
1495 ;; ___hack much improved by MM___ , both help(.) and ?... now work
1496 ;; FIXME: Note that '??' nicely works in *R*, but
1497 ;; 'type ? topic' doesn't use ess-help {but display in *R*}
1498 (defconst inferior-R-1-input-help (format "help *(%s)" ess-help-arg-regexp))
1499 (defconst inferior-R-2-input-help (format "^ *\\? *%s" ess-help-arg-regexp))
1500 (defconst inferior-R-page (format "^ *page *(%s)" ess-help-arg-regexp))
1502 (defun inferior-R-input-sender (proc string)
1503 ;; REALLY only for debugging: this S_L_O_W_S D_O_W_N [here AND below]
1504 ;;(ess-write-to-dribble-buffer (format "(inf..-R-..): string=«%s»; " string))
1505 ;; rmh: 2002-01-12 catch page() in R
1506 (let ((help-string (or (string-match inferior-R-1-input-help string)
1507 (string-match inferior-R-2-input-help string)))
1508 (page-string (string-match inferior-R-page string)))
1509 (if (or help-string page-string)
1510 (let* ((string2 (match-string 2 string))
1511 (string2-rt (concat string2 ".rt")))
1512 ;; (ess-write-to-dribble-buffer (format " new string=«%s»\n" string2))
1513 (beginning-of-line)
1514 (if (looking-at inferior-ess-primary-prompt)
1515 (progn
1516 (end-of-line)
1517 (insert-before-markers string)) ;; emacs 21.0.105 and older
1518 (delete-backward-char 1)) ;; emacs 21.0.106 and newer
1519 (if page-string
1520 (progn
1521 (ess-command (concat string2 "\n")
1522 (get-buffer-create (concat string2 ".rt")))
1523 (ess-eval-linewise "\n")
1524 (switch-to-buffer-other-window string2-rt)
1525 (R-transcript-mode))
1526 (ess-display-help-on-object
1527 (if (string= string2 "") "help" string2))
1528 (ess-eval-linewise "\n")))
1529 ;; else: normal command
1530 (inferior-ess-input-sender proc string))))
1533 (defun inferior-ess-send-input ()
1534 "Sends the command on the current line to the ESS process."
1535 (interactive)
1536 (ess-make-buffer-current)
1537 (run-hooks 'ess-send-input-hook)
1538 (comint-send-input)
1539 (setq ess-object-list nil)) ;; Will be reconstructed from cache if needs be
1541 (defun inferior-ess-get-old-input ()
1542 "Return the ESS command surrounding point."
1543 (save-excursion
1544 (beginning-of-line)
1545 (if (not (looking-at inferior-ess-prompt))
1546 (ess-error "No command on this line."))
1547 (if (looking-at inferior-ess-primary-prompt) nil
1548 (re-search-backward (concat "^" inferior-ess-primary-prompt)))
1549 (comint-skip-prompt)
1550 (let (command
1551 (beg (point)))
1552 (end-of-line)
1553 (setq command (buffer-substring beg (point)))
1554 (forward-line 1)
1555 (while (looking-at inferior-ess-secondary-prompt)
1556 (comint-skip-prompt)
1557 (setq beg (point))
1558 (end-of-line)
1559 (setq command (concat command "\n" (buffer-substring beg (point))))
1560 (forward-line 1))
1561 (forward-line -1)
1562 (setq ess-temp-point (point))
1563 command)))
1565 ;;;*;;; Hot key commands
1567 (defun ess-execute-objects (posn)
1568 "Send the objects() command to the ESS process.
1569 By default, gives the objects at position 1.
1570 A prefix argument toggles the meaning of `ess-execute-in-process-buffer'.
1571 A prefix argument of 2 or more means get objects for that position.
1572 A negative prefix argument gets the objects for that position
1573 and toggles `ess-execute-in-process-buffer' as well."
1574 (interactive "P")
1575 (ess-make-buffer-current)
1576 (let* ((num-arg (if (listp posn)
1577 (if posn -1 1)
1578 (prefix-numeric-value posn)))
1579 (the-posn (if (< num-arg 0) (- num-arg) num-arg))
1580 (invert (< num-arg 0))
1581 (the-command (format inferior-ess-objects-command the-posn ".*"))
1582 (the-message (concat ">>> Position "
1583 (number-to-string the-posn)
1584 " ("
1585 (nth (1- the-posn) (ess-search-list))
1586 ")\n")))
1587 (ess-execute the-command invert "S objects" the-message)))
1589 ;;;; S4 Version
1590 ;;;; soup-up the interactive usage: allow modifications to a default pattern
1591 ;;(defun ess-execute-objects (posn)
1592 ;; "Send the `inferior-ess-objects-command' to the ESS process.
1593 ;;No prefix argument uses position 1 and pattern inferior-ess-objects-pattern.
1594 ;;A nonnegative prefix gets objects for that position and prompts for
1595 ;; the pattern.
1596 ;;A negative prefix also toggles ess-execute-in-process-buffer."
1597 ;; (interactive "P")
1598 ;; (ess-make-buffer-current)
1599 ;; (let* ((num-arg (if (listp posn) 1
1600 ;; (prefix-numeric-value posn)))
1601 ;; (the-posn (if (< num-arg 0) (- num-arg) num-arg))
1602 ;; (invert (< num-arg 0))
1603 ;; (pattern (if current-prefix-arg (read-string "Pattern (.*): ")
1604 ;; inferior-ess-objects-pattern))
1605 ;; (pattern (if (string= pattern "") ".*" pattern))
1606 ;; (the-command (format inferior-ess-objects-command the-posn pattern))
1607 ;; (the-message (concat ">>> Position "
1608 ;; the-posn
1609 ;; " ("
1610 ;; (nth (1- the-posn) (ess-search-list))
1611 ;; ") (pattern = "
1612 ;; pattern
1613 ;; ")\n")))
1614 ;; (ess-execute the-command invert "S objects" the-message)))
1616 (defun ess-execute-search (invert)
1617 "Send the `inferior-ess-search-list-command' command to the `ess-language' process.
1618 [search(..) in S]"
1619 (interactive "P")
1620 (ess-execute inferior-ess-search-list-command invert "S search list"))
1622 (defun ess-execute-attach (dir &optional posn)
1623 "Attach a directory in the `ess-language' process with the attach() command.
1624 When used interactively, user is prompted for DIR to attach and
1625 prefix argument is used for POSN (or 2, if absent.)
1626 Doesn't work for data frames."
1627 (interactive "DAttach directory: \nP")
1628 (ess-execute (concat "attach(\""
1629 (directory-file-name (expand-file-name dir))
1630 "\""
1631 (if posn (concat "," (number-to-string
1632 (prefix-numeric-value posn))))
1633 ")") 'buffer)
1634 (setq ess-sp-change t))
1636 (defun ess-execute-screen-options ()
1637 "Cause S to set the \"width\" option to 1 less than the frame width.
1638 Also sets the \"length\" option to 99999.
1639 This is a good thing to put in `ess-post-run-hook' --- for the S dialects."
1640 (interactive)
1641 (if (string= ess-language "S")
1642 (ess-eval-linewise (format "options(width=%d,length=99999)"
1643 (1- (frame-width))))))
1645 (defun ess-execute (command &optional invert buff message)
1646 "Send a command to the ESS process.
1647 A newline is automatically added to COMMAND. Prefix arg (or second arg
1648 INVERT) means invert the meaning of
1649 `ess-execute-in-process-buffer'. If INVERT is 'buffer, output is
1650 forced to go to the process buffer. If the output is going to a
1651 buffer, name it *BUFF*. This buffer is erased before use. Optional
1652 fourth arg MESSAGE is text to print at the top of the buffer (defaults
1653 to the command if BUFF is not given.)"
1654 (interactive (list
1655 (read-from-minibuffer "Execute> "
1657 ess-mode-minibuffer-map)
1658 current-prefix-arg))
1659 (ess-make-buffer-current)
1660 (let ((the-command (concat command "\n"))
1661 (buff-name (concat "*" (or buff "ess-output") "*"))
1662 (in-pbuff (if invert (or (eq invert 'buffer)
1663 (not ess-execute-in-process-buffer))
1664 ess-execute-in-process-buffer)))
1665 (if in-pbuff
1666 (ess-eval-linewise the-command)
1667 (let ((buff (ess-create-temp-buffer buff-name)))
1668 (save-excursion
1669 (set-buffer buff)
1670 (ess-command the-command (get-buffer buff-name));; sleep?
1671 (goto-char (point-min))
1672 (if message (insert message)
1673 (if buff nil
1674 ;; Print the command in the buffer if it has not been
1675 ;; given a special name
1676 (insert "> " the-command)))
1677 ;;(make-local-variable 'ess-local-process-name)
1678 (setq ess-local-process-name ess-current-process-name))
1679 (ess-display-temp-buffer buff)))))
1681 ;;;*;;; Quitting
1683 (defun ess-quit (dont-cleanup)
1684 "Issue an exiting command to the inferior process.
1685 By default, you will be asked if you wish to delete all buffers
1686 associated with the current buffer; if you specify a prefix
1687 arg (with C-u), this step will be omitted."
1688 (interactive "P")
1689 (if (string-equal ess-dialect "R")
1690 (ess-quit-r dont-cleanup)
1691 (ess-force-buffer-current "Process to quit: ")
1692 (ess-make-buffer-current)
1693 (let ((sprocess (get-ess-process ess-current-process-name)))
1694 (if (not sprocess) (error "No ESS process running."))
1695 (when (yes-or-no-p (format "Really quit ESS process %s? " sprocess))
1696 (if dont-cleanup nil (ess-cleanup))
1697 (goto-char (marker-position (process-mark sprocess)))
1698 (insert inferior-ess-exit-command)
1699 (process-send-string sprocess inferior-ess-exit-command)
1700 ;;SJE - suggest no need to rename buffer upon exit.
1701 ;;(rename-buffer (concat (buffer-name) "-exited") t)
1702 ))))
1704 (defun ess-quit-r (dont-cleanup)
1705 "Issue an exiting command to an inferior R process, and optionally clean up.
1706 This version is for killing *R* processes; it asks the extra question
1707 regarding whether the workspace image should be saved."
1708 (ess-force-buffer-current "Process to quit: ")
1709 (ess-make-buffer-current)
1710 (let (response cmd
1711 (sprocess (get-ess-process ess-current-process-name)))
1712 (if (not sprocess) (error "No ESS process running."))
1713 (setq response (completing-read "Save workspace image? "
1714 '( ( "yes".1) ("no" . 1) ("cancel" . 1))
1715 nil t))
1716 (if (string-equal response "")
1717 (setq response "no")) ;default = do not save workspace.
1718 (unless (string-equal response "cancel")
1719 (if dont-cleanup nil (ess-cleanup))
1720 (setq cmd (format "q(\"%s\")\n" response))
1721 (goto-char (marker-position (process-mark sprocess)))
1722 (process-send-string sprocess cmd)
1723 ;;(rename-buffer (concat (buffer-name) "-exited") t)
1726 (defun ess-abort ()
1727 "Kill the ESS process, without executing .Last or terminating devices.
1728 If you want to finish your session, use \\[ess-quit] instead."
1729 ;;; Provided as a safety measure over the default binding of C-c C-z in
1730 ;;; comint-mode-map.
1731 (interactive)
1732 (ding)
1733 (message "WARNING: \\[inferior-ess-exit-command] will not be executed and graphics devices won't finish properly!")
1734 (sit-for 2)
1735 (if (yes-or-no-p "Still abort? ")
1736 (comint-quit-subjob)
1737 (message "Good move.")))
1739 (defun ess-cleanup ()
1740 "Kill (or offer to kill) all buffers associated with this ESS process.
1741 Leaves you in the ESS process buffer. It's a good idea to run this
1742 before you quit. It is run automatically by \\[ess-quit]."
1743 (interactive)
1744 (let ((the-procname (or (ess-make-buffer-current) ess-local-process-name)))
1745 (if the-procname nil
1746 (error "I don't know which ESS process to clean up after!"))
1747 (if (y-or-n-p
1748 (format
1749 "Delete all buffers associated with process %s? " the-procname))
1750 (save-excursion
1751 (mapcar '(lambda (buf)
1752 (set-buffer buf)
1753 ;; Consider buffers for which
1754 ;; ess-local-process-name is the same as
1755 ;; the-procname
1756 (if (and (not (get-buffer-process buf))
1757 ess-local-process-name
1758 (equal ess-local-process-name the-procname))
1759 (kill-buffer buf)))
1760 (buffer-list))))
1761 (ess-switch-to-ESS nil)))
1763 (defun ess-kill-buffer-function nil
1764 "Function run just before an ESS process buffer is killed."
1765 ;; This simply deletes the buffers process to avoid an Emacs bug
1766 ;; where the sentinel is run *after* the buffer is deleted
1767 (let ((proc (get-buffer-process (current-buffer))))
1768 (if proc (delete-process proc))))
1770 ;;*;; Object name completion
1772 ;;;*;;; The user completion command
1773 (defun ess-complete-object-name (&optional listcomp)
1774 "Perform completion on `ess-language' object preceding point.
1775 The object is compared against those objects known by
1776 `ess-get-object-list' and any additional characters up to ambiguity are
1777 inserted. Completion only works on globally-known objects (including
1778 elements of attached data frames), and thus is most suitable for
1779 interactive command-line entry, and not so much for function editing
1780 since local objects (e.g. argument names) aren't known.
1782 Use \\[ess-resynch] to re-read the names of the attached directories.
1783 This is done automatically (and transparently) if a directory is
1784 modified (S only!), so the most up-to-date list of object names is always
1785 available. However attached dataframes are *not* updated, so this
1786 command may be necessary if you modify an attached dataframe.
1788 If ARG is non-nil, no completion is attempted, but the available
1789 completions are listed [__UNIMPLEMENTED__]."
1790 (interactive "P");; FIXME : the `listcomp' argument is NOT used
1791 (ess-make-buffer-current)
1792 (if (memq (char-syntax (preceding-char)) '(?w ?_))
1793 (let* ((comint-completion-addsuffix nil)
1794 (end (point))
1795 (buffer-syntax (syntax-table))
1796 (beg (unwind-protect
1797 (save-excursion
1798 (set-syntax-table ess-mode-syntax-table)
1799 (backward-sexp 1)
1800 (point))
1801 (set-syntax-table buffer-syntax)))
1802 (full-prefix (buffer-substring beg end))
1803 (pattern full-prefix)
1804 ;; See if we're indexing a list with `$'
1805 (listname (if (string-match "\\(.+\\)\\$\\(\\(\\sw\\|\\s_\\)*\\)$"
1806 full-prefix)
1807 (progn
1808 (setq pattern
1809 (if (not (match-beginning 2)) ""
1810 (substring full-prefix
1811 (match-beginning 2)
1812 (match-end 2))))
1813 (substring full-prefix (match-beginning 1)
1814 (match-end 1)))))
1815 ;; are we trying to get a slot via `@' ?
1816 (classname (if (string-match "\\(.+\\)@\\(\\(\\sw\\|\\s_\\)*\\)$"
1817 full-prefix)
1818 (progn
1819 (setq pattern
1820 (if (not (match-beginning 2)) ""
1821 (substring full-prefix
1822 (match-beginning 2)
1823 (match-end 2))))
1824 (ess-write-to-dribble-buffer
1825 (format "(ess-C-O-Name : slots..) : patt=%s"
1826 pattern))
1827 (substring full-prefix (match-beginning 1)
1828 (match-end 1)))))
1829 (components (if listname
1830 (ess-object-names listname)
1831 (if classname
1832 (ess-slot-names classname)
1833 (ess-get-object-list ess-current-process-name)))))
1834 ;; always return a non-nil value to prevent history expansions
1835 (or (comint-dynamic-simple-complete pattern components) 'none))))
1837 (defun ess-list-object-completions nil
1838 "List all possible completions of the object name at point."
1839 (interactive)
1840 (ess-complete-object-name t));; FIXME: NOT WORKING since argument is unused!
1842 ;;;*;;; Support functions
1843 (defun ess-extract-onames-from-alist (alist posn &optional force)
1844 "Return the object names in position POSN of ALIST.
1845 ALIST is an alist like `ess-sl-modtime-alist'. POSN should be in 1 .. (length
1846 ALIST). If optional third arg FORCE is t, the corresponding element
1847 of the search list is re-read. Otherwise it is only re-read if it's a
1848 directory and has been modified since it was last read."
1849 (let* ((entry (nth (1- posn) alist))
1850 (dir (car entry))
1851 (timestamp (car (cdr entry)))
1852 (new-modtime (ess-dir-modtime dir)))
1853 ;; Refresh the object listing if necessary
1854 (if (or force (not (equal new-modtime timestamp)))
1855 (setcdr (cdr entry) (ess-object-names dir posn)))
1856 (cdr (cdr entry))))
1858 (defun ess-dir-modtime (dir)
1859 "Return the last modtime if DIR is a directory, and nil otherwise."
1860 (and ess-filenames-map
1861 (file-directory-p dir)
1862 (nth 5 (file-attributes dir))))
1864 (defun ess-object-modtime (object)
1865 "Return the modtime of the S object OBJECT (a string).
1866 Searches along the search list for a file named OBJECT and returns its modtime
1867 Returns nil if that file cannot be found, i.e., for R or any non-S language!"
1868 (let ((path (ess-search-list))
1869 result)
1870 (while (and (not result) path)
1871 (setq result (file-attributes
1872 (concat (file-name-as-directory (car path))
1873 object)))
1874 (setq path (cdr path)))
1875 (nth 5 result)))
1877 (defun ess-modtime-gt (mod1 mod2)
1878 "Return t if MOD1 is later than MOD2."
1879 (and mod1
1880 (or (> (car mod1) (car mod2))
1881 (and (= (car mod1) (car mod2))
1882 (> (car (cdr mod1)) (car (cdr mod2)))))))
1884 (defun ess-get-object-list (name)
1885 "Return a list of current S object names associated with process NAME,
1886 using `ess-object-list' if that is non-nil."
1887 (or ess-object-list
1888 (save-excursion
1889 (set-buffer (process-buffer (get-ess-process name)))
1890 (ess-make-buffer-current)
1891 (ess-write-to-dribble-buffer (format "(get-object-list %s) .." name))
1892 (if (or (not ess-sl-modtime-alist) ess-sp-change)
1893 (progn (ess-write-to-dribble-buffer "--> (ess-get-modtime-list)\n")
1894 (ess-get-modtime-list))
1895 ;;else
1896 (ess-write-to-dribble-buffer " using existing ess-*-alist\n")
1898 (let* ((alist ess-sl-modtime-alist)
1899 (i 2)
1900 (n (length alist))
1901 result)
1902 ;; Always force a re-read of position 1 :
1903 (setq result (ess-extract-onames-from-alist alist 1 'force))
1904 ;; Re-read remaining directories if necessary.
1905 (while (<= i n)
1906 (setq result
1907 (append result
1908 (ess-extract-onames-from-alist alist i)))
1909 (setq i (1+ i)))
1910 (setq ess-object-list (ess-uniq-list result))))))
1912 (defun ess-get-words-from-vector (command)
1913 "Evaluate the S command COMMAND, which returns a character vector.
1914 Return the elements of the result of COMMAND as an alist of strings.
1915 A newline is automatically added to COMMAND."
1916 (let ((tbuffer (get-buffer-create
1917 " *ess-names-list*")); initial space: disable-undo
1918 names)
1919 (save-excursion
1920 (set-buffer tbuffer)
1921 (ess-command command tbuffer 'sleep)
1922 (goto-char (point-min))
1923 (if ess-verbose (ess-write-to-dribble-buffer "ess-get-words-.. "))
1924 (if (not (looking-at "\\s-*\\[1\\]"))
1925 (progn (if ess-verbose
1926 (ess-write-to-dribble-buffer "not seeing \"[1]\".. "))
1927 (setq names nil)
1929 (goto-char (point-max))
1930 (while (re-search-backward "\"\\([^\"]*\\)\"" nil t)
1931 (setq names (cons (buffer-substring (match-beginning 1)
1932 (match-end 1)) names))))
1933 ;;DBG, do *not* (i.e., comment):
1934 (kill-buffer tbuffer)
1936 (if ess-verbose
1937 (ess-write-to-dribble-buffer
1938 (if (> (length names) 5)
1939 (format " |-> (length names)= %d\n" (length names))
1940 (format " |-> names= «%s»\n" names))))
1941 names))
1943 (defun ess-compiled-dir (dir)
1944 "Return non-nil if DIR is an S object directory with special files.
1945 I.e. if the filenames in DIR are not representative of the objects in DIR."
1946 (or (file-exists-p (concat (file-name-as-directory dir) "___nonfile"))
1947 (file-exists-p (concat (file-name-as-directory dir) "__BIGIN"))
1948 (file-exists-p (concat (file-name-as-directory dir) "___NONFI"))))
1950 (defun ess-object-names (obj &optional pos)
1951 "Return alist of S object names in directory (or object) OBJ.
1952 If OBJ is a directory name (begins with `/') returns a listing of that dir.
1953 This may use the search list position POS if necessary.
1954 If OBJ is an object name, returns result of S command names(OBJ).
1955 If OBJ is nil or not a directory, POS must be supplied, and objects(POS) is returned.
1956 In all cases, the value is an list of object names."
1958 ;; FIXME: in both cases below, use the same fallback "objects(POS)" -- merge!
1959 (if (and obj (file-accessible-directory-p obj))
1960 ;; Check the pre-compiled object list in ess-object-name-db first
1962 ;; FIXME: If used at all, ess-object-name-db should not only
1963 ;; ----- be used in the directory case !!
1964 (or (cdr-safe (assoc obj ess-object-name-db))
1965 ;; Take a directory listing
1966 (and ess-filenames-map
1967 ;; first try .Data subdirectory:
1968 ;;FIXME: move ".Data" or ``this function'' to essd-sp6.el etc:
1969 (let ((dir (concat (file-name-as-directory obj) ".Data")))
1970 (if (not (file-accessible-directory-p dir))
1971 (setq dir obj))
1972 (and (not (ess-compiled-dir dir))
1973 (directory-files dir))))
1974 ;; Get objects(pos) instead
1975 (and (or (ess-write-to-dribble-buffer
1976 (format "(ess-object-names ..): directory %s not used\n" obj))
1979 (ess-get-words-from-vector
1980 (format inferior-ess-objects-command pos))))
1981 ;; "else" should really give an error!
1982 ;; would need pos = which(obj = search())
1984 ;; else
1985 (or (and obj ;; want names(obj)
1986 (or (ess-write-to-dribble-buffer
1987 (format "(ess-object-names obj=%s): no directory - trying names\n"
1988 obj))
1990 (ess-get-words-from-vector
1991 (format inferior-ess-names-command obj)))
1992 (and nil; must return nil
1993 (ess-write-to-dribble-buffer
1994 (format "(ess-object-names obj=%s): no dir.; -> objects()\n" obj)))
1995 ;; get objects(pos)
1996 (ess-get-words-from-vector
1997 (format inferior-ess-objects-command pos))))) ; had 2nd arg ".*"
1998 ; s4 needs 2
1999 ; args, rest only need 1 ?
2000 ; changes needed to allow for
2001 ; pattern argument to
2002 ; .SmodeObs
2004 (defun ess-slot-names (obj)
2005 "Return alist of S4 slot names of S4 object OBJ."
2006 (ess-get-words-from-vector (format "slotNames(%s)\n" obj)))
2009 ;;; SJE: Wed 29 Dec 2004 --- remove this function.
2010 ;;; rmh: Wed 5 Jan 2005 --- bring it back for use on Windows
2011 (defun ess-create-object-name-db ()
2012 "Create a database of object names in standard S directories. This
2013 database is saved in the file specified by `ess-object-name-db-file',
2014 and is loaded when `ess-mode' is loaded. It defines the variable
2015 `ess-object-name-db', which is used for completions.
2017 Before you call this function, modify the S search list so that it contains
2018 all the non-changing (i.e. system) S directories. All positions of the search
2019 list except for position 1 are searched and stored in the database.
2021 After running this command, you should move ess-namedb.el to a directory in
2022 the `load-path'."
2023 (interactive)
2024 (setq ess-object-name-db nil)
2025 (let ((search-list (cdr (ess-search-list)))
2026 (pos 2)
2027 name
2028 (buffer (get-buffer-create " *ess-db*"))
2029 (temp-object-name-db nil)
2030 (temp-object-name-db-file ess-object-name-db-file))
2032 (ess-write-to-dribble-buffer
2033 (format "(object db): search-list=%s \n " search-list))
2034 (while search-list
2035 (message "Searching %s" (car search-list))
2036 (setq temp-object-name-db (cons (cons (car search-list)
2037 (ess-object-names nil pos))
2038 temp-object-name-db))
2039 (setq search-list (cdr search-list))
2040 (ess-write-to-dribble-buffer
2041 (format "(object db): temp-obj-name-db=%s \n pos=%s"
2042 temp-object-name-db pos))
2043 (setq pos (1+ pos)))
2045 (save-excursion
2046 (set-buffer buffer)
2047 (erase-buffer)
2048 (insert "(setq ess-object-name-db '")
2049 (prin1 temp-object-name-db (current-buffer))
2050 (insert ")\n")
2051 (setq name (expand-file-name ess-object-name-db-file))
2052 (write-region (point-min) (point-max) name)
2053 (message "Wrote %s" name))
2054 (kill-buffer buffer)
2055 (setq ess-object-name-db temp-object-name-db)))
2057 (defun ess-resynch nil
2058 "Reread all directories/objects in variable `ess-search-list' to
2059 form completions."
2060 (interactive)
2061 (if (ess-make-buffer-current) nil
2062 (error "Not an ESS process buffer"))
2063 (setq ess-sl-modtime-alist nil)
2064 (setq ess-object-list nil)
2065 (setq ess-object-name-db nil) ; perhaps it would be better to reload?
2066 (setq ess-sp-change t)
2067 (ess-get-modtime-list))
2070 (defun ess-complete-filename nil
2071 ;; Do file completion only within strings, or when the ! call is being used
2072 (if (comint-within-quotes
2073 (1- (process-mark (get-buffer-process (current-buffer)))) (point))
2074 ;; (- comint-last-input-start 1) (point)) <- from S4 modeadds.
2075 ;; changed on 4/12/96 (dxsun)
2076 ;; This is sensible, but makes it hard to use history refs
2077 ;; (or
2078 ;; (save-excursion
2079 ;; (goto-char comint-last-input-start)
2080 ;; (looking-at "\\s-*!"))
2081 ;; (comint-within-quotes comint-last-input-start (point)))
2082 (progn
2083 (comint-replace-by-expanded-filename)
2084 ;; always return t if in a string
2085 t)))
2087 (defun ess-after-pathname-p nil
2088 ;; Heuristic: after partial pathname if it looks like we're in a
2089 ;; string, and that string looks like a pathname. Not the best for
2090 ;; use with unix() (or it's alias, !). Oh well.
2091 (save-excursion
2092 (save-match-data
2093 (let ((opoint (point)))
2094 (and (re-search-backward "\\(\"\\|'\\)[~/#$.a-zA-Z0-9][^ \t\n\"']*"
2095 nil t)
2096 (eq opoint (match-end 0)))))))
2098 ;;*;; Functions handling the search list
2100 (defun ess-search-list ()
2101 "Return the current search list as a list of strings.
2102 Elements which are apparently directories are expanded to full dirnames.
2103 Is *NOT* used by \\[ess-execute-search],
2104 but by \\[ess-resynch], \\[ess-get-object-list], \\[ess-get-modtime-list],
2105 \\[ess-execute-objects], \\[ess-object-modtime], \\[ess-create-object-name-db],
2106 and (indirectly) by \\[ess-get-help-files-list]."
2107 (save-excursion
2108 (let ((result nil))
2109 (set-buffer (get-ess-buffer ess-current-process-name));to get *its* local vars
2110 (if (and ess-search-list (not ess-sp-change))
2111 ;; use cache:
2112 ess-search-list
2113 ;; else, re-compute:
2114 (let ((tbuffer (get-buffer-create " *search-list*"))
2115 (homedir ess-directory)
2116 (my-search-cmd inferior-ess-search-list-command); from ess-buffer
2117 elt)
2118 (save-excursion
2119 (set-buffer tbuffer)
2120 ;; guaranteed by the initial space in its name: (buffer-disable-undo)
2121 (ess-command my-search-cmd tbuffer 0.2); <- sleep; does (erase-buffer)
2122 (goto-char (point-min))
2123 (while (re-search-forward "\"\\([^\"]*\\)\"" nil t)
2124 (setq elt (buffer-substring (match-beginning 1) (match-end 1)))
2125 ;;Dbg: (ess-write-to-dribble-buffer (format " .. elt= %s \t" elt))
2126 (if (and (string-match "^[^/]" elt)
2127 (file-directory-p (concat ess-directory elt)))
2128 (progn
2129 ;;Dbg: (ess-write-to-dribble-buffer "*IS* directory\n")
2130 (setq elt (concat homedir elt)))
2131 ;;else
2132 ;;dbg
2133 ;;- (ess-write-to-dribble-buffer "not dir.\n")
2135 (setq result (append result (list elt))))
2136 (kill-buffer tbuffer)))
2137 (setq ess-search-list result)
2138 (setq ess-sp-change nil)
2139 result))))
2141 ;;; ess-sl-modtime-alist is a list with elements as follows:
2142 ;;; * key (directory or object name)
2143 ;;; * modtime (list of 2 integers)
2144 ;;; * name, name ... (accessible objects in search list posn labeled by key)
2145 ;;; It is a buffer-local variable (belonging to e.g. *R*, *S+6*, .. etc)
2146 ;;; and has the same number of elements and is in the same order as the
2147 ;;; S search list
2149 (defun ess-get-modtime-list ()
2150 "Record the modification times of the directories in the search list,
2151 and the objects in those directories.
2152 The result is stored in `ess-sl-modtime-alist'."
2153 ;; Operation applies to process of current buffer
2154 (let* ((searchlist (ess-search-list))
2155 (index 1)
2156 posn
2157 newalist)
2158 (while searchlist
2159 (setq posn (car searchlist))
2160 (setq newalist
2161 (append
2162 newalist
2163 (list (or (assoc posn ess-sl-modtime-alist)
2164 (append
2165 (list posn (ess-dir-modtime posn))
2166 (prog2
2167 (message "Forming completions for %s..." posn)
2168 (ess-object-names posn index)
2169 (message "Forming completions for %s...done" posn)
2170 ))))))
2171 (setq index (1+ index))
2172 (setq searchlist (cdr searchlist)))
2173 ;;DBG:
2174 (ess-write-to-dribble-buffer
2175 (format "ess-get-modtime-list: new alist of length %d\n"
2176 (length newalist)));; todo : also give length of components!
2178 (setq ess-sl-modtime-alist newalist)))
2181 (defun ess-search-path-tracker (str)
2182 "Check if input STR changed the search path.
2183 This function monitors user input to the inferior ESS process so that
2184 Emacs can keep the variable `ess-search-list' up to date. `completing-read' in
2185 \\[ess-read-object-name] uses this list indirectly when it prompts for help or
2186 for an object to dump."
2187 (if (string-match ess-change-sp-regexp str)
2188 (setq ess-sp-change t)))
2190 \f ; Miscellaneous routines
2192 ;;;*;;; Routines for reading object names
2194 (defun ess-read-object-name (p-string)
2195 "Read an S object name from the minibuffer with completion, and return it.
2196 P-STRING is the prompt string."
2197 (let* ((default (ess-read-object-name-dump))
2198 (prompt-string (if default
2199 (format "%s(default %s) " p-string default)
2200 p-string))
2201 (object-list (mapcar 'list (ess-get-object-list ess-local-process-name)))
2202 (spec (completing-read prompt-string object-list)))
2203 (list (cond
2204 ((string= spec "") default)
2205 (t spec)))))
2207 (defun ess-read-object-name-default ()
2208 "Return the object name at point, or nil if none."
2209 (condition-case ()
2210 (save-excursion
2211 ;; The following line circumvents an 18.57 bug in following-char
2212 (if (eobp) (backward-char 1)) ; Hopefully buffer is not empty!
2213 ;; Get onto a symbol
2214 (catch 'nosym ; bail out if there's no symbol at all before point
2215 (while (/= (char-syntax (following-char)) ?w)
2216 (if (bobp) (throw 'nosym nil) (backward-char 1)))
2217 (let*
2218 ((end (progn (forward-sexp 1) (point)))
2219 (beg (progn (backward-sexp 1) (point))))
2220 (buffer-substring beg end))))
2221 (error nil)))
2223 (defun ess-read-object-name-dump ()
2224 "Return the object name at point, or \"Temporary\" if none."
2225 (condition-case ()
2226 (save-excursion
2227 ;; The following line circumvents an 18.57 bug in following-char
2228 (if (eobp) (backward-char 1)) ; Hopefully buffer is not empty!
2229 ;; Get onto a symbol
2230 (catch 'nosym ; bail out if there's no symbol at all before point
2231 (while (/= (char-syntax (following-char)) ?w)
2232 (if (bobp) (throw 'nosym nil) (backward-char 1)))
2233 (let*
2234 ((end (progn (forward-sexp 1) (point)))
2235 (beg (progn (backward-sexp 1) (point)))
2236 (object-name (buffer-substring beg end)))
2237 (or object-name "Temporary"))))
2238 (error nil)))
2241 ;;*;; Temporary buffer handling
2243 ;(defun ess-create-temp-buffer (name)
2244 ; "Create an empty buffer called NAME, but doesn't display it."
2245 ; (let ((buff (get-buffer-create name)))
2246 ; (save-excursion
2247 ; (set-buffer buff)
2248 ; (erase-buffer))
2249 ; buff))
2252 ;; Ed Kademan's version:
2253 ;From: Ed Kademan <kademan@phz.com>
2254 ;Subject: Re: ess-mode 5.1.16; search list
2255 ;To: rossini@biostat.washington.edu (A.J. Rossini)
2256 ;Cc: Martin Maechler <maechler@stat.math.ethz.ch>, ess-bugs@stat.math.ethz.ch
2257 ;Date: 26 Jul 2000 16:12:12 -0400
2259 ;Dear Tony Rossini,
2261 ;I was having trouble looking at the search list under ess. When I
2262 ;started up multiple inferior processes---each for a different
2263 ;dialect---ess-mode would issue the wrong variant of the "search"
2264 ;command when I typed C-c C-s. In case it is useful let me tell you
2265 ;what I did to get it to work for me.
2267 ;I added the component:
2268 ; (inferior-ess-search-list-command . "search()\n")
2269 ;to S+3-customize-alist and R-customize-alist, and then I redefined the
2270 ;ess-create-temp-buffer function as follows:
2271 (defun ess-create-temp-buffer (name)
2272 "Create an empty buffer called NAME."
2273 (let ((buff (get-buffer-create name))
2274 (elca (eval ess-local-customize-alist)))
2275 (save-excursion
2276 (set-buffer buff)
2277 (erase-buffer)
2278 (ess-setq-vars-local elca buff))
2279 buff))
2280 ;;These two steps seem to insure that the temporary buffer in which the
2281 ;;search results appear has the correct version of the local variables.
2282 ;;I am not that well acquainted with the ess code and don't know whether
2283 ;;this is a good fundamental way of fixing the problem, or even whether
2284 ;;or not this breaks some other feature of ess-mode that I never use.
2285 ;;Thanks for listening.
2286 ;;Ed K.
2287 ;;--
2288 ;;Ed Kademan 508.651.3700
2289 ;;PHZ Capital Partners 508.653.1745 (fax)
2290 ;;321 Commonwealth Road <kademan@phz.com>
2291 ;;Wayland, MA 01778
2295 (defun ess-display-temp-buffer (buff)
2296 "Display the buffer BUFF using `temp-buffer-show-function'."
2297 (funcall (or temp-buffer-show-function 'display-buffer) buff))
2299 ;;*;; Error messages
2301 (defun ess-error (msg)
2302 "Something bad has happened.
2303 Display the S buffer, and cause an error displaying MSG."
2304 (display-buffer (process-buffer (get-ess-process ess-current-process-name)))
2305 (error msg))
2307 \f ; Provide package
2309 (provide 'ess-inf)
2311 \f ; Local variables section
2313 ;;; This file is automatically placed in Outline minor mode.
2314 ;;; The file is structured as follows:
2315 ;;; Chapters: ^L ;
2316 ;;; Sections: ;;*;;
2317 ;;; Subsections: ;;;*;;;
2318 ;;; Components: defuns, defvars, defconsts
2319 ;;; Random code beginning with a ;;;;* comment
2321 ;;; Local variables:
2322 ;;; mode: emacs-lisp
2323 ;;; outline-minor-mode: nil
2324 ;;; mode: outline-minor
2325 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
2326 ;;; End:
2328 ;;; ess-inf.el ends here