*** empty log message ***
[ess.git] / lisp / ess-noweb.el
blobe18fe70ab321c13be8fd138093be938604b86a3a
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)
40 \f ; Variables
42 (defvar ess-noweb-use-font-lock window-system
43 "Set to t if you want to use font-locking in ESS noweb buffers.")
45 ;; this helps with XEmacs barfing, sigh...
46 ;; but is *NOT* okay to do *globally*: (setq global-font-lock-mode t)
48 (if ess-noweb-use-font-lock
49 (require 'noweb-font-lock-mode))
51 \f ; Functions
53 ;;*;; Code Chunk evaluation.
55 (defun ess-eval-chunk (vis)
56 "Tangle the current chunk and send it to the inferior ESS process.
57 Arg has same meaning as for `ess-eval-region'."
58 (interactive "P")
59 (let ( (process-name ess-local-process-name)
60 new-process-name
61 (cbuf (current-buffer))
62 (temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
63 (noweb-tangle-chunk temp-buffer)
64 (set-buffer temp-buffer)
65 ;; When the temp buffer is created, it does not inherit any value
66 ;; of ess-local-process-name from the .Rnw buffer, so we have to set it
67 ;; here. If ess-local-process-name is not set in the .Rnw buffer,
68 ;; it will inherit the value that is chosen here.
69 (set (make-local-variable 'ess-local-process-name) process-name)
70 (ess-eval-region (point-min) (point-max) vis "Eval buffer")
71 (if process-name
72 (kill-buffer temp-buffer)
73 ;; if process-name was nil, source buffer did not have a local process
74 ;; so keep value from temp buffer before killing it.
75 (setq new-process-name ess-local-process-name)
76 (kill-buffer temp-buffer)
77 (set-buffer cbuf)
78 (set (make-local-variable 'ess-local-process-name) new-process-name))))
80 (defun ess-eval-chunk-and-go (vis)
81 "Tangle the current chunk, send to the ESS process, and go there.
82 Arg has same meaning as for `ess-eval-region'."
83 (interactive "P")
84 (ess-eval-chunk vis)
85 (ess-switch-to-ESS t))
87 ;;*;; Thread code chunk evaluation
89 ;;;
90 ;;; Threads are code chunks which fit into the same "buffer" (I'm (AJR)
91 ;;; abusing terminology, but what I mean is things like:
92 ;;; <<thing1>>=
93 ;;; code for thing1
94 ;;; @
95 ;;; Documentation
96 ;;; <<thing1>>=
97 ;;; continuing code for thing1
98 ;;; @
99 ;;;
101 (defun ess-eval-thread (vis)
102 "Tangle all chunks in the current chunk-thread and send to the ESS process.
103 Arg has same meaning as for `ess-eval-region'."
104 (interactive "P")
105 (let ((temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
106 (noweb-tangle-current-thread temp-buffer)
107 (set-buffer temp-buffer)
108 (ess-eval-region (point-min) (point-max) vis "Eval buffer")
109 (kill-buffer temp-buffer)))
111 (defun ess-eval-thread-and-go (vis)
112 "Tangle all chunks in the current chunk-thread, send to ESS process,
113 and go there. Arg has same meaning as for `ess-eval-region'."
114 (interactive "P")
115 (ess-eval-thread vis)
116 (ess-switch-to-ESS t))
118 \f ; Provide package
120 (provide 'ess-noweb)
122 \f ; Local variables section
124 ;;; This file is automatically placed in Outline minor mode.
125 ;;; The file is structured as follows:
126 ;;; Chapters: ^L ;
127 ;;; Sections: ;;*;;
128 ;;; Subsections: ;;;*;;;
129 ;;; Components: defuns, defvars, defconsts
130 ;;; Random code beginning with a ;;;;* comment
132 ;;; Local variables:
133 ;;; mode: emacs-lisp
134 ;;; outline-minor-mode: nil
135 ;;; mode: outline-minor
136 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
137 ;;; End:
139 ;;; ess-noweb.el ends here