Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-noweb.el --- support for Literate Data Analysis
2
3
;; Copyright (C) 1999 Mark Lunt
4
;; Copyright (C) 1999--2004 A.J. Rossini, Richard M. Heiberger, Martin
5
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
7
;; Author: Mark Lunt <[email protected]>
8
;; A.J. Rossini <[email protected]>
9
;; Created: April 18, 1999
10
;; Maintainer: ESS-core <[email protected]>
11
12
;; Keywords: statistics, languages
13
;; Summary: Noweb support for ESS
14
15
;; This file is part of ESS
16
17
;; This file is free software; you can redistribute it and/or modify
18
;; it under the terms of the GNU General Public License as published by
19
;; the Free Software Foundation; either version 2, or (at your option)
20
;; any later version.
21
22
;; This file is distributed in the hope that it will be useful,
23
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
;; GNU General Public License for more details.
26
27
;; A copy of the GNU General Public License is available at
28
;; http://www.r-project.org/Licenses/
29
30
;;; Commentary:
31
32
;; Code for ESS and Literate Data Analysis.
33
34
;;; Code:
35
36
; Requires and autoloads
37
38
(require 'ess-noweb-mode)
39
;; still needed when user turns font-lock-mode *on* (from initial off):
40
(autoload 'ess-noweb-font-lock-mode "ess-noweb-font-lock-mode")
41
42
; Variables
43
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.")
46
47
;; this helps with XEmacs barfing, sigh...
48
;; but is *NOT* okay to do *globally*: (setq global-font-lock-mode t)
49
50
(if ess-noweb-use-font-lock
51
(require 'ess-noweb-font-lock-mode))
52
53
; Functions
54
55
;;*;; Code Chunk evaluation.
56
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
(save-excursion
66
(ess-noweb-tangle-chunk temp-buffer)
67
(set-buffer temp-buffer)
68
;; When the temp buffer is created, it does not inherit any value
69
;; of ess-local-process-name from the .Rnw buffer, so we have to set it
70
;; here. If ess-local-process-name is not set in the .Rnw buffer,
71
;; it will inherit the value that is chosen here.
72
(set (make-local-variable 'ess-local-process-name) process-name)
73
(ess-eval-region (point-min) (point-max) vis "Eval Chunk")
74
(if process-name
75
(kill-buffer temp-buffer)
76
;; if process-name was nil, source buffer did not have a local process
77
;; so keep value from temp buffer before killing it.
78
(setq new-process-name ess-local-process-name)
79
(kill-buffer temp-buffer)
80
(set-buffer cbuf)
81
(set (make-local-variable 'ess-local-process-name) new-process-name)))))
82
83
84
(defun ess-eval-chunk-and-step (&optional vis)
85
"Tangle the current chunk and send it to the inferior ESS process and
86
step to the next chunk"
87
(interactive)
88
(ess-eval-chunk vis)
89
(ess-noweb-next-code-chunk 1))
90
91
(defun ess-eval-chunk-and-go (vis)
92
"Tangle the current chunk, send to the ESS process, and go there.
93
Arg has same meaning as for `ess-eval-region'."
94
(interactive "P")
95
(ess-eval-chunk vis)
96
(ess-switch-to-ESS t))
97
98
;;*;; Thread code chunk evaluation
99
100
;;;
101
;;; Threads are code chunks which fit into the same "buffer" (I'm (AJR)
102
;;; abusing terminology, but what I mean is things like:
103
;;; <<thing1>>=
104
;;; code for thing1
105
;;; @
106
;;; Documentation
107
;;; <<thing1>>=
108
;;; continuing code for thing1
109
;;; @
110
;;;
111
112
(defun ess-eval-thread (vis)
113
"Tangle all chunks in the current chunk-thread and send to the ESS process.
114
Arg has same meaning as for `ess-eval-region'."
115
(interactive "P")
116
(let ((temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
117
(ess-noweb-tangle-current-thread temp-buffer)
118
(set-buffer temp-buffer)
119
(ess-eval-region (point-min) (point-max) vis "Eval buffer")
120
(kill-buffer temp-buffer)))
121
122
(defun ess-eval-thread-and-go (vis)
123
"Tangle all chunks in the current chunk-thread, send to ESS process,
124
and go there. Arg has same meaning as for `ess-eval-region'."
125
(interactive "P")
126
(ess-eval-thread vis)
127
(ess-switch-to-ESS t))
128
129
; Provide package
130
131
(provide 'ess-noweb)
132
133
; Local variables section
134
135
;;; This file is automatically placed in Outline minor mode.
136
;;; The file is structured as follows:
137
;;; Chapters: ^L ;
138
;;; Sections: ;;*;;
139
;;; Subsections: ;;;*;;;
140
;;; Components: defuns, defvars, defconsts
141
;;; Random code beginning with a ;;;;* comment
142
143
;;; Local variables:
144
;;; mode: emacs-lisp
145
;;; outline-minor-mode: nil
146
;;; mode: outline-minor
147
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
148
;;; End:
149
150
;;; ess-noweb.el ends here
151
152