-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrnw2pdf.elc
198 lines (172 loc) · 24.5 KB
/
rnw2pdf.elc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
;ELC
;;; Compiled
;;; in Emacs version 26.2
;;; with all optimizations.
;;; This file uses dynamic docstrings, first added in Emacs 19.29.
;;; This file does not contain utf-8 non-ASCII characters,
;;; and so can be loaded in Emacs versions earlier than 23.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#@205 Path to Rscript executable. It can be the absolute path of the executable or its name if it can be found in the search path. In the latter case see also `rnw2pdf-search-path'.
It defaults to `Rscript'.
(defvar rnw2pdf-r-path nil (#$ . 409))
#@232 Path to PDF viewer. In Windows defaults to MiKTeX `texworks' or alternatively to the default PDF application. In Linux defaults to the default PDF application. For other systems or when there is no suitable application, it is nil.
(defvar rnw2pdf-viewer (byte-code "\301=\2036 \302\303!\203 \303\207\304\305!\306\307\"A@\262\211\2055 \304\310P!\262\306\307\"A@\262\306\311\"A@\211\262\207\312=\203I \302\313!\203I \304\314!\315\316O\207\317\207" [system-type windows-nt executable-find "texworks" shell-command-to-string "cmd /c assoc .pdf" split-string "=" "cmd /c ftype " "\"" gnu/linux "xdg-open" "basename $(xdg-mime query default application/pdf) .desktop" 0 -1 nil] 4) (#$ . 659))
#@282 Directory path or list directory paths to search for excutables such as latexmk, pdflatex. If nil, the enviroment variable PATH is used; otherwise the added paths are sought before. This variable is also used to find the R executable when `rnw2pdf-r-path' is not an absolute path.
(defvar rnw2pdf-search-path nil (#$ . 1364))
#@27 Temporary file directory.
(defvar rnw2pdf-aux "aux-files" (#$ . 1696))
#@198 If non-nil, the latexmk ".fls" file in the Rnw document directory is deleted at the end of the build.
Note that if `rnw2pdf-aux' is non-nil, a copy of this file is available in the aux directory.
(defvar rnw2pdf-clean-fls t (#$ . 1774))
#@418 If your system is Windows, nil unsets Emacs "HOME" environment variable for called subprocesses.
In Windows, there is no systen set "HOME" variable. Some progrmas set themselves the value of this variable, unless the user has already done so. R and Emacs set different values for it. When we call R as an Emacs subprocess, it will inherit the wrong value. For this reason it is better to disable "HOME" inheritance.
(defvar rnw2pdf/inherit-home nil (#$ . 2019))
#@105 Command template to process (knit) Rnw file.
`%string' are expanded according to `rnw2pdf/expand-list'.
(defvar rnw2pdf/r-cmd "%r %k %R" (#$ . 2489))
#@98 Command template to process TeX file.
`%string' are expanded according to `rnw2pdf/expand-list'.
(defvar rnw2pdf/tex-cmd "%l -interaction=nonstopmode -pdf -shell-escape -silent -g %f" (#$ . 2645))
#@95 Command template to view PDF file.
`%string' are expanded according to `rnw2pdf/expand-list'.
(defvar rnw2pdf/view-cmd "%v %p" (#$ . 2848))
#@90 Used to restore `exec-path' value after adding the directories in `rnw2pdf-search-path'.
(defconst rnw2pdf/original-exec-path exec-path (#$ . 2994))
#@53 List of sub-jobs involved involved in Rnw building.
(defconst rnw2pdf/job-seq (list 'knit 'latex 'view 'dispose) (#$ . 3149))
#@105 Alist associating Rnw document paths to the process buffers (receiving the input of building commands).
(defvar rnw2pdf/rnw-alist nil (#$ . 3282))
#@72 Full path of system shell. Under Windows normally it is `cmdproxy.exe'
(defvar rnw2pdf/sys-shell (byte-code "\302=\203 \207\303\207" [system-type shell-file-name windows-nt "/bin/sh"] 2) (#$ . 3435))
#@301 List "expansion strings" and associated hook functions for rnw2pdf command strings.
Before running a command string, expansion strings are expanded with the output of the hook functions.
Hook functions should be added as one-argument lambdas. Always add the argument to lambdas, even if it is unused
(defvar rnw2pdf/expand-list '(("%f" (lambda (rnw-path-sans) (shell-quote-argument rnw-path-sans))) ("%R" (lambda (rnw-path-sans) (shell-quote-argument (concat rnw-path-sans ".Rnw")))) ("%p" (lambda (rnw-path-sans) (shell-quote-argument (concat rnw-path-sans ".pdf")))) ("%k" (lambda (rnw-path-sans) (shell-quote-argument (rnw2pdf/set-r2p-path rnw-path-sans)))) ("%r" (lambda (dummy) (rnw2pdf/r-path))) ("%l" (lambda (dummy) "latexmk")) ("%v" (lambda (dummy) (shell-quote-argument rnw2pdf-viewer)))) (#$ . 3645))
#@113 Rnw absolute document path.
Note that the process buffer is not associated to a file unless the user saves it.
(defvar associated-rnw-path nil (#$ . 4464))
(make-variable-buffer-local 'associated-rnw-path)
(defvar next-job "Next job to carry out. Can be: 'knit, 'latex or 'dispose. The latter involves resetting process buffer local variables" nil)
(make-variable-buffer-local 'next-job)
#@118 Nil if no build is happening, so no process is running and local variables are reset for the related process buffer.
(defvar is-active nil (#$ . 4860))
(make-variable-buffer-local 'is-active)
#@57 Non-nil if an error has been detected during the build.
(defvar error-p nil (#$ . 5058))
(make-variable-buffer-local 'error-p)
#@54 The beginning line of the error `error-file' or nil.
(defvar error-line-beg nil (#$ . 5191))
(make-variable-buffer-local 'error-line-beg)
#@76 The ending line of the error `error-file' or nil.
Not used for TeX errors
(defvar error-line-end nil (#$ . 5335))
(make-variable-buffer-local 'error-line-end)
#@36 File with the build errors or nil.
(defvar error-file nil (#$ . 5501))
(make-variable-buffer-local 'error-file)
#@293 Convert the Rnw document in the current buffer in a PDF a display it with the TeXworks viewer, unless a different one is configured.
The file is automatically saved if it is associated to a file, otherwise the user is asked to save it.
It is required for the file to have a ".Rnw" extension.
(defalias 'rnw2pdf #[0 "\300 \301\3022% \303\304!\210\305 \210\306 \210\307!\210\310!\210\311!\210\312!\210\313\314!0\262\303\301!\210\211\2052 \313!\207" [buffer-file-name nil rnw2pdf/main rnw2pdf/set-exec-path t rnw2pdf/distro-test rnw2pdf/file-save rnw2pdf/active-job\? rnw2pdf/make-proc-buf rnw2pdf/make-knit-script rnw2pdf/next-job message "Processing..."] 4 (#$ . 5620) nil])
#@328 Execute the job set by the variable `next-job' local to the process buffer identified by RNW-PATH.
`rnw2pdf/command-sentinel' updates `next-job' and re-call this function until the local variable is empty.
Depending on the job, `rnw2pdf/r-cmd' or `rnw2pdf/tex-cmd' command patterns are (exapndend and) executed.
(fn RNW-PATH)
(defalias 'rnw2pdf/next-job #[257 "\306!\307\300\"\310\211\211\211q\210\311\312!!\210\313\267\202, \314\202- \315\202- \316\202- \317\202- \310\262\320\267\202E \202F \n\202F \202F \321\202F \310\262\322\"\262\323\"\262\324\325\326\261\210db\210\327\330!\f\331=\205n ?/\332!/\203} \333\330!\210\334\267\202\274 \335!\210\202\322 \336 \337\"\312!\3400!\341!Q\342\343#\266\3441\310\345\310\346\f&\210\347\300!\210\350\351 !\210\202\322 \352 1\346%\262\353\354\"\210\355\356\"\210\333\330\"\210\211\211/\266\203)\207" [next-job rnw2pdf/r-cmd rnw2pdf/tex-cmd rnw2pdf/view-cmd system-type rnw2pdf/inherit-home rnw2pdf/get-pbuf buffer-local-value nil cd file-name-directory #s(hash-table size 4 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (knit 28 latex 32 view 36 dispose 40)) "Knitting" "Latexing" "Viewing" "Finished processing" #s(hash-table size 4 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (knit 53 latex 57 view 61 dispose 65)) "rnw2pdf" rnw2pdf/customise-template rnw2pdf/command-expand " " " with:\n" "\n\n" getenv "HOME" windows-nt file-truename setenv #s(hash-table size 2 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (dispose 131 view 139)) rnw2pdf/dispose-job rnw2pdf/change-ext ".pdf" file-name-as-directory file-name-nondirectory copy-file t call-process 0 "-c" make-local-variable dispose rnw2pdf/next-job start-process set-process-filter ordinary-insertion-filter set-process-sentinel rnw2pdf/command-sentinel default-directory rnw2pdf-aux rnw2pdf/sys-shell] 16 (#$ . 6307)])
#@184 If ADD is non-nil, add the directories in `rnw2pdf-search-path', if any, to `exec-path'. If ADD is nil, restore original search path stored in `rnw2pdf/original-exec-path'.
(fn ADD)
(defalias 'rnw2pdf/set-exec-path #[257 "<\203 \202 C\203 \211\203 \304\305\"\210\304\306\"\210 \307=\204) \310\311\"\262\2034 \312\n\"\2025 \211\207" [rnw2pdf-search-path system-type exec-path rnw2pdf/original-exec-path mapc #[257 "\211;?\205\f \300\301\302\"!\207" [rnw2pdf/ret format "ERROR: In `rnw2pdf-search-path'\n%s is not a string."] 5 "\n\n(fn PATH)"] #[257 "\300!?\205 \301\302\303Q!\207" [file-directory-p rnw2pdf/ret "ERROR: In `rnw2pdf-search-path'\n" "\nnot found."] 5 "\n\n(fn PATH)"] windows-nt mapcar #[257 "\300!\207" [shell-quote-argument] 3 "\n\n(fn PATH)"] append] 5 (#$ . 8243)])
#@37 Test needed binaries are available.
(defalias 'rnw2pdf/distro-test #[0 "\203 \302!\204% \303\304\305Q!\210\202% \306\307!\204% \310 \211\204% \303\311!\210 \2040 \303\312!\210\202C \313\232\204C \306 !\204C \303\314\315 \"!\210\306\316!\203O \306\317!\204S \303\320!\210\321\207" [rnw2pdf-r-path rnw2pdf-viewer file-exists-p rnw2pdf/ret "ERROR: " "\ndoes not exist or is not executable" executable-find "Rscript" rnw2pdf-find-r-win "ERROR: Cannot find R executable. \nMake sure Rscript executable is in your path or set `rnw2pdf-r-path' variable." "ERROR: Please set the variable `rnw2pdf-viewer' to the path of a PDF viewer." "start" format "ERROR: Cannot find PDF viewer executable \n%s\n set by the variable `rnw2pdf-viewer'." "tex" "latexmk" "ERROR: Cannot find a working TeX distribution with latexmk.\nMake sure latexmk and common TeX binaries are found in your PATH environment variable." t] 4 (#$ . 9055)])
#@142 Save Rnw document in the current buffer and create knitting script.
If the current buffer is not associated to a file stop and ask to save.
(defalias 'rnw2pdf/file-save #[0 "\204\f \301\302\303 \304Q!\210\305 \210\306\307!\207" [buffer-file-name rnw2pdf/ret "ERROR: " buffer-name " is not associated to any file. Please, save it using the extension \".Rnw\"." save-buffer message "Saved and processing..."] 4 (#$ . 9984)])
#@249 Check if there a process buffer associated to RNW-PATH with active build jobs.
If so ask whether to kill the process or abort the request.
The variable `is-active', local to process buffer , is set to nil when the build is finished.
(fn RNW-PATH)
(defalias 'rnw2pdf/active-job\? #[257 "\300!\301!\302\203<