ESS[SAS]: somebody forgot about the SUM statement (probably me)
[ess.git] / lisp / ess-noweb.el
blob54a0a41edf5b1816e8e8a83229fe97100f1a8718
1 ;;; ess-noweb.el : support for Literate Data Analysis
3 ;; Copyright (C) 1999 Mark Lunt
4 ;; Copyright (C) 1999--2004 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Authors: Mark Lunt <mark.lunt@mrc-bsu.cam.ac.uk>
8 ;; A.J. Rossini <rossini@u.washington.edu>
9 ;; Created: April 18, 1999
10 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
12 ;; Keywords: statistical support
13 ;; Summary: Noweb support for ESS
16 ;; This file is part of ESS
18 ;; This file is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; any later version.
23 ;; This file is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
32 ;;; Commentary:
34 ;; Code for ESS and Literate Data Analysis.
36 \f ; Requires and autoloads
38 (require 'noweb-mode)
39 ;; still needed when user turns font-lock-mode *on* (from initial off):
40 (autoload 'noweb-font-lock-mode "noweb-font-lock-mode")
42 \f ; Variables
44 (defvar ess-noweb-use-font-lock font-lock-mode
45 "Set to t if you want to use font-locking in ESS noweb buffers.")
47 ;; this helps with XEmacs barfing, sigh...
48 ;; but is *NOT* okay to do *globally*: (setq global-font-lock-mode t)
50 (if ess-noweb-use-font-lock
51 (require 'noweb-font-lock-mode))
53 \f ; Functions
55 ;;*;; Code Chunk evaluation.
57 (defun ess-eval-chunk (vis)
58 "Tangle the current chunk and send it to the inferior ESS process.
59 Arg has same meaning as for `ess-eval-region'."
60 (interactive "P")
61 (let ( (process-name ess-local-process-name)
62 new-process-name
63 (cbuf (current-buffer))
64 (temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
65 (noweb-tangle-chunk temp-buffer)
66 (set-buffer temp-buffer)
67 ;; When the temp buffer is created, it does not inherit any value
68 ;; of ess-local-process-name from the .Rnw buffer, so we have to set it
69 ;; here. If ess-local-process-name is not set in the .Rnw buffer,
70 ;; it will inherit the value that is chosen here.
71 (set (make-local-variable 'ess-local-process-name) process-name)
72 (ess-eval-region (point-min) (point-max) vis "Eval buffer")
73 (if process-name
74 (kill-buffer temp-buffer)
75 ;; if process-name was nil, source buffer did not have a local process
76 ;; so keep value from temp buffer before killing it.
77 (setq new-process-name ess-local-process-name)
78 (kill-buffer temp-buffer)
79 (set-buffer cbuf)
80 (set (make-local-variable 'ess-local-process-name) new-process-name))))
82 (defun ess-eval-chunk-and-go (vis)
83 "Tangle the current chunk, send to the ESS process, and go there.
84 Arg has same meaning as for `ess-eval-region'."
85 (interactive "P")
86 (ess-eval-chunk vis)
87 (ess-switch-to-ESS t))
89 ;;*;; Thread code chunk evaluation
91 ;;;
92 ;;; Threads are code chunks which fit into the same "buffer" (I'm (AJR)
93 ;;; abusing terminology, but what I mean is things like:
94 ;;; <<thing1>>=
95 ;;; code for thing1
96 ;;; @
97 ;;; Documentation
98 ;;; <<thing1>>=
99 ;;; continuing code for thing1
100 ;;; @
103 (defun ess-eval-thread (vis)
104 "Tangle all chunks in the current chunk-thread and send to the ESS process.
105 Arg has same meaning as for `ess-eval-region'."
106 (interactive "P")
107 (let ((temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
108 (noweb-tangle-current-thread temp-buffer)
109 (set-buffer temp-buffer)
110 (ess-eval-region (point-min) (point-max) vis "Eval buffer")
111 (kill-buffer temp-buffer)))
113 (defun ess-eval-thread-and-go (vis)
114 "Tangle all chunks in the current chunk-thread, send to ESS process,
115 and go there. Arg has same meaning as for `ess-eval-region'."
116 (interactive "P")
117 (ess-eval-thread vis)
118 (ess-switch-to-ESS t))
120 \f ; Provide package
122 (provide 'ess-noweb)
124 \f ; Local variables section
126 ;;; This file is automatically placed in Outline minor mode.
127 ;;; The file is structured as follows:
128 ;;; Chapters: ^L ;
129 ;;; Sections: ;;*;;
130 ;;; Subsections: ;;;*;;;
131 ;;; Components: defuns, defvars, defconsts
132 ;;; Random code beginning with a ;;;;* comment
134 ;;; Local variables:
135 ;;; mode: emacs-lisp
136 ;;; outline-minor-mode: nil
137 ;;; mode: outline-minor
138 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
139 ;;; End:
141 ;;; ess-noweb.el ends here