1 ;; Copyright (C) 2005 David Whiting, A.J. Rossini, Rich M. Heiberger, Martin
2 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
4 ;; Original Author: David Whiting <david.whiting@ncl.ac.uk>
5 ;; Created: 15 April 2005
6 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
8 ;; Keywords: Noweb, Literate Statistical Practice, Sweave
10 ;; This file is part of ESS.
12 ;; This file is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This file is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;; Some simple functions for ESS and Sweave
30 ;; david.whiting at ncl.ac.uk
31 ;; Wed Sep 1 14:55:52 CEST 2004
33 ;; I have written some very simple elisp functions that I have found
34 ;; useful and thought others might like to see. I dabble with elisp
35 ;; occasionally at best so there are probably better ways to do what I
36 ;; have done, but so far this seems to work for me. There are several
37 ;; things that are hard-coded, I use Linux and I think that this would
38 ;; probably not work in Windows (not as it is now anyway).
40 ;; With these functions and key bindings all I need to do is open a .Rnw
41 ;; file and, assuming R is running, I press:
43 ;; M-n s to Sweave the file, then
44 ;; M-n l to run latex on the results of Sweave, then
45 ;; M-n p to make and display a postscript file , or
46 ;; M-n P to make and display a PDF version.
48 ;; David Whiting to Anthony Rossini, Mar 30
49 ;; On Wed, Mar 30, 2005 at 11:51:26AM +0200, A.J. Rossini wrote:
50 ;; > I'm going to go ahead and add this stuff to the distribution tonight
51 ;; > if you don't mind. I'd forgotten about it!
52 ;; It would make me very happy indeed.
53 ;; > (however, need permission to do so).
54 ;; Permission granted!
59 ;; School of Clinical Medical Sciences, The Medical School
60 ;; University of Newcastle upon Tyne, NE2 4HH, UK.
65 ;;; 1. I want to be able to send ess-makeLatex a parameter to tell it
66 ;;; the number of times to run LaTeX (to get references updated
69 ;;; 2. Also need to add ess-makeBibtex.
71 ;;; 3. Might be good to have a way to chain commands.
74 ;;; Autoloads and Requires
78 (defun ess-makeSweave ()
79 "Run Sweave on the current .Rnw file."
82 ;; Make sure tools is loaded.
84 (setq ess-command
(format "library(tools)"))
85 (ess-execute ess-command
)
86 (message "Sweaving %S" (buffer-file-name))
87 (setq ess-command
(format "Sweave(%S)" (buffer-file-name)))
88 (ess-execute ess-command
'buffer nil nil
))))
91 (defun ess-makeLatex ()
92 "Run LaTeX on the product of Sweave()ing the current file."
95 (let* ((thisbuffer (buffer-name))
96 (namestem (substring (buffer-name) 0 (search ".Rnw" (buffer-name))))
97 (latex-filename (concat namestem
".tex")))
98 (message "Running LaTeX ..." )
99 (switch-to-buffer "*tex-output*")
100 (call-process "latex" nil
"*tex-output*" 1 latex-filename
)
101 (switch-to-buffer thisbuffer
)
102 (message "Finished running LaTeX" ))))
106 "Create a postscript file from a dvi file (name based on the current
107 Sweave file buffer name) and display it with gv."
109 (let* ((namestem (substring (buffer-name) 0 (search ".Rnw" (buffer-name))))
110 (dvi-filename (concat namestem
".dvi")))
111 (shell-command (concat "dvips -o temp.ps " dvi-filename
))
112 (shell-command "gv temp.ps & ")))
115 (defun ess-makePDF ()
116 "Create a PDF file and display it with acroread."
118 (let* ((namestem (substring (buffer-name) 0 (search ".Rnw" (buffer-name))))
119 (tex-filename (concat namestem
".tex")))
120 (shell-command (concat "pdflatex " tex-filename
))
121 (shell-command (concat "acroread " namestem
".pdf &"))))
123 (defun ess-insert-Sexpr ()
124 "Insert Sexpr{} into the buffer at point."
130 ;;; Now bind some keys.
131 (define-key noweb-minor-mode-map
"\M-ns" 'ess-makeSweave
)
132 (define-key noweb-minor-mode-map
"\M-nl" 'ess-makeLatex
)
133 (define-key noweb-minor-mode-map
"\M-np" 'ess-makePS
)
134 (define-key noweb-minor-mode-map
"\M-nP" 'ess-makePDF
)
135 (define-key noweb-minor-mode-map
"\M-nx" 'ess-insert-Sexpr
)
142 \f ; Local variables section
144 ;;; This file is automatically placed in Outline minor mode.
145 ;;; The file is structured as follows:
148 ;;; Subsections: ;;;*;;;
149 ;;; Components: defuns, defvars, defconsts
150 ;;; Random code beginning with a ;;;;* comment
154 ;;; outline-minor-mode: nil
155 ;;; mode: outline-minor
156 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
159 ;;; ess-swv.el ends here