;;; ess-s4-d.el --- S4 customization12;; Copyright (C) 1997--2004 A.J. Rossini, Richard M. Heiberger, Martin3;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.45;; Author: A.J. Rossini <[email protected]>6;; Created: 12 Jun 19977;; Maintainer: ESS-core <[email protected]>89;; Keywords: languages1011;; This file is part of ESS.1213;; This file is free software; you can redistribute it and/or modify14;; it under the terms of the GNU General Public License as published by15;; the Free Software Foundation; either version 2, or (at your option)16;; any later version.1718;; This file is distributed in the hope that it will be useful,19;; but WITHOUT ANY WARRANTY; without even the implied warranty of20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21;; GNU General Public License for more details.2223;; A copy of the GNU General Public License is available at24;; http://www.r-project.org/Licenses/252627;;; Commentary:2829;; DB contributed the changes from ess-s3-d.el to30;; ess-s4-d.el (removed the old ugly approach).31;; This file defines S4 customizations for ess-mode. Lots of thanks32;; to RMH and JMC for code and suggestions3334;;; Code:3536(autoload 'inferior-ess "ess-inf" "Run an ESS process.")3738(require 'ess-s-l)3940;; Some of this is based on files from:41;; Copyright (C) 1996, John M. Chambers.4243(defvar S4-customize-alist44(append45'((ess-local-customize-alist . 'S4-customize-alist)46(ess-dialect . "S4")47(ess-loop-timeout . ess-S-loop-timeout);fixme: dialect spec.48(ess-change-sp-regexp . ess-S-change-sp-regexp)49(ess-help-sec-keys-alist . ess-help-S3-sec-keys-alist)50(ess-object-name-db-file . "ess-s4-namedb.el")51(inferior-ess-program . inferior-S4-program-name)52(inferior-ess-objects-command . ".SmodeObs(%d, pattern=\"%s\")\n")53;;(inferior-ess-objects-pattern . ".*") ; for new s4 stuff54(inferior-ess-help-command . "help(\"%s\")\n")55(inferior-ess-help-filetype . nil)56(inferior-ess-search-list-command . ".SmodePaths()\n")57(ess-load-command . ".SmodeLoad(\"%s\")\n")58(inferior-ess-dump-command . ".SmodeDump(\"%s\", \"%s\")\n")5960(inferior-ess-start-file . nil) ;"~/.ess-S3")61(inferior-ess-start-args . "")62(ess-STERM . "iESS")63)64S+common-cust-alist); use S+ ones here; partly overwritten above!!6566"Variables to customize for S4.")6768;; For loading up the S code required for the above.69;;(add-hook 'ess-post-run-hook70;; (lambda ()71;; (ess-command72;; (concat73;; "if(exists(\"Sversion\")) library(emacs) else source(\""74;; ess-mode-run-file75;; "\")\n"))76;; (if ess-mode-run-file277;; (ess-command78;; (concat "source(\"" ess-mode-run-file2 "\")\n")))))798081(defun S4 ()82"Call 'S version 4', from Bell Labs. New way to do it."83(interactive)84(setq ess-customize-alist S4-customize-alist)85(ess-write-to-dribble-buffer86(format "\n(S4): ess-dialect=%s, buf=%s\n" ess-dialect (current-buffer)))87(inferior-ess)88(if inferior-ess-language-start89(ess-eval-linewise inferior-ess-language-start)))909192(defun S4-mode (&optional proc-name)93"Major mode for editing S4 source. See `ess-mode' for more help."94(interactive)95(setq ess-customize-alist S4-customize-alist)96(ess-mode S4-customize-alist proc-name)97(if ess-imenu-use-S (ess-imenu-S)))9899100;; From RMH: ALL THIS SHOULD BE INCORPORATED BY 5.0!101102;;; s4.el startup file103;;; Richard M. Heiberger104;;; [email protected]105;;106;;(load "S")107;;(setq inferior-S-program "/disk05/s4/betaJun96/S")108;;(setq S-plus nil) ;; needed for non S-plus109;;(add-to-list 'load-path "/disk05/s4/betaJun96") ;; S-namedb.el is here110;;(S)111;;(load-file "/disk05/s4/betaJun96/library/emacs/S-modeadds.el") ;; must come after (S)112;;113;;114;;;;; S4 __Help, no longer S3 .Help115;;(load "S-help")116;; ;; Must follow S-help117;;; S-help.file line 270118;;(defun S-get-help-files-list nil119;; (mapcar 'list120;; (apply 'append121;; (mapcar (lambda (dirname)122;; (if (file-directory-p dirname)123;; (directory-files dirname)))124;; (mapcar (lambda (str) (concat str "/__Help"))125;; (S-search-list))))))126;;127;;128;;;;; additional font-lock-keywords for S4129;;130;;;;*;; based on S-inf.el line 107131;;;;(add-to-list 'S-inf-font-lock-keywords132;;;; '("\\<\\(^Problem\\|^Warning\\|^Error\\|Debug ?\\|Browsing in frame of\\|Local Variables\\)\\>" . font-lock-reference-face) ; S-inf problems133;;;;)134;;;;(add-to-list 'S-inf-font-lock-keywords135;;;; '("^R>" . font-lock-keyword-face) ; debug prompt136;;;;)137;;(inferior-S-mode)138;;139;;; S-inf.el line 150140;;(setq inferior-S-search-list-command "searchPaths()\n")141;;142;;;; fontify S-transcript-mode143;;;; overwrites S-trans.el lines 60-69144;;;;(setq S-trans-font-lock-keywords S-inf-font-lock-keywords)145;;146;;(load "S-mode")147;; ;; Must follow S-mode148;;;;*;; based on S-mode.el line 219149;;(add-to-list 'S-mode-font-lock-keywords150;; '("\\<\\(setGeneric\\|removeGeneric\\|setMethod\\|unsetMethod\\|setReplaceGeneric\\|setReplaceMethod\\|standardGeneric\\|setIs\\|setClass\\|representation\\)\\>" . font-lock-function-name-face) ; S4 method functions151;;)152;;153;;154;;155;;;;; fix to S-load-file to make C-c C-l work with S4156;;157;;;When a file sourced into S4 by C-c C-l has a syntax error158;;;without the following changes, the system159;;;freezes until it is released with ^G. The reason is that the error160;;;messages, including the `Debug ?' request, go to the *S-errors*161;;;buffer. The *S-errors* buffer is not switched to, and couldn't accept162;;;a response if it were.163;;;164;;;The fix requires three modification to S-inf.el and two to S-mode.el.165;;;The correction to S-check-source noted in smode.cmt is also necessary.166;;;167;;168;;; S-inf.el line 92 NEW variable169;;(defvar inferior-S-debug-prompt "Debug \\? (y|n): "170;; "The expression S uses to offer to initiate debug tracing.")171;;172;;; S-inf.el line 458173;;(defun inferior-S-wait-for-prompt ()174;; "Wait until the S process is ready for input."175;; (let* ((cbuffer (current-buffer))176;; (sprocess (get-S-process S-current-process-name))177;; (sbuffer (process-buffer sprocess))178;; r179;; (timeout 0))180;; (set-buffer sbuffer)181;; (while (progn182;; (if (not (eq (process-status sprocess) 'run))183;; (S-error "S process has died unexpectedly.")184;; (if (> (setq timeout (1+ timeout)) S-loop-timeout)185;; (S-error "Timeout waiting for prompt. Check inferior-S-prompt or S-loop-timeout."))186;; (accept-process-output)187;; (goto-char (point-max))188;;(setq end (point))189;; (beginning-of-line)190;;(setq e (buffer-substring (point) end))191;;(if (equal e inferior-S-debug-prompt)192;; (S-error "Debug prompt"))193;; (setq r (looking-at inferior-S-prompt))194;; (not (or r (looking-at ".*\\?\\s *"))))))195;; (goto-char (point-max))196;; (set-buffer cbuffer)197;; (symbol-value r)))198;;199;;200;;201;;; S-mode.el line 204202;;(setq S-dump-error-re "Problem")203;;204;;;; S-mode.el line 655205;;(defun S-parse-errors (showerr)206;; "Jump to error in last loaded S source file.207;;With prefix argument, only shows the errors S reported."208;; (interactive "P")209;; (S-make-buffer-current)210;; (let ((errbuff (get-buffer S-error-buffer-name)))211;; (if (not errbuff)212;; (error "You need to do a load first!")213;; (set-buffer errbuff)214;; (goto-char (point-max))215;; (if216;; (re-search-backward ", file \"" nil t)217;; (let* ((beg-pos (progn (re-search-forward "\"" nil t) (point)))218;; (end-pos (progn (re-search-forward "\"" nil t) (- (point) 1)))219;; (filename (buffer-substring beg-pos end-pos))220;; (fbuffer (get-file-buffer filename))221;; (linenum (string-to-number222;; (progn (re-search-backward "," nil t)223;; (current-word))))224;; (end-pos (point))225;; (beg-pos (progn (goto-char (point-min))226;; (re-search-forward ":" nil t)227;; (1+ (point))))228;; (errmess (buffer-substring beg-pos end-pos))229;; )230;; (if showerr231;; (S-display-temp-buffer errbuff)232;; (if fbuffer nil233;; (setq fbuffer (find-file-noselect filename))234;; (save-excursion235;; (set-buffer fbuffer)236;; (S-mode)))237;; (pop-to-buffer fbuffer)238;; (goto-line linenum))239;; (princ errmess t))240;; (message "Not a syntax error.")241;; (S-display-temp-buffer errbuff)))))242;;243;;244;;245;;;; S-inf.el line 584246;;(defun S-prompt-wait (proc &optional start-of-output)247;; "Wait for a prompt to appear at BOL of current buffer248;;PROC is the S process. Does not change point"249;; (if start-of-output nil (setq start-of-output (point-min)))250;; (save-excursion251;; (while (progn252;; ;; get output if there is some ready253;; (accept-process-output proc 0 500)254;; (goto-char (marker-position (process-mark proc)))255;; (beginning-of-line)256;;257;; (if (re-search-forward inferior-S-debug-prompt nil t)258;; (if (equal (get-buffer S-error-buffer-name)259;; (get-buffer S-error-buffer-name))260;; (let* ((sprocess (get-S-process S-current-process-name))261;; (sbuffer (process-buffer sprocess)))262;; (set-buffer sbuffer)263;; (process-send-string sprocess "n\n")264;; (accept-process-output sprocess)265;; (beginning-of-line); delete inferior-S-debug-prompt266;; (kill-line)267;; (insert "> ")))268;;269;; (if (< (point) start-of-output) (goto-char start-of-output))270;; (not (looking-at inferior-S-primary-prompt)))))))271;;272273274275; Provide package276277(provide 'ess-s4-d)278279; Local variables section280281;;; This file is automatically placed in Outline minor mode.282;;; The file is structured as follows:283;;; Chapters: ^L ;284;;; Sections: ;;*;;285;;; Subsections: ;;;*;;;286;;; Components: defuns, defvars, defconsts287;;; Random code beginning with a ;;;;* comment288289;;; Local variables:290;;; mode: emacs-lisp291;;; outline-minor-mode: nil292;;; mode: outline-minor293;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"294;;; End:295296;;; ess-s4-d.el ends here297298299