-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmp.texi
More file actions
1844 lines (1611 loc) · 57.3 KB
/
mp.texi
File metadata and controls
1844 lines (1611 loc) · 57.3 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo
@set NAME mp
@set VERSION 0.2
@set UPDATED January 3, 2022
@setfilename @value{NAME}
@finalout
@c %**start of header
@settitle @value{NAME} @value{VERSION}
@syncodeindex pg cp
@c %**end of header
@copying
This manual is for @value{NAME}, version @value{VERSION}
Copyright @copyright{} 2018-2022 - Chris Dardis
@quotation
@end quotation
@end copying
@dircategory R, Sweave, knitr, latex, noweb, org
@direntry
* @value{NAME} (@value{NAME}).Make pdfs.
* install-info: (@value{NAME})
Invoking install-info.
...
...
@end direntry
@titlepage
@title @value{NAME}
@subtitle for version @value{VERSION}, @value{UPDATED}
@author C. Dardis <christopherdardis@@gmail.com>
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top @value{NAME}
This manual is for @value{NAME} version @value{VERSION}, @value{UPDATED}
@end ifnottex
@menu
* Preamble::
* defgroup::
* defun::
* defcustom::
* defvar::
* defconst::
* defvar-local::
* Other symbolic expressions::
* Index::
@end menu
@node Preamble
@chapter Preamble
@cindex Preamble
@code{lexical binding} is @code{t}.@*
@strong{Copyright}: 2018-2022 - Chris Dardis @*
@strong{Author}: C. Dardis <christopherdardis@@gmail.com> @*
@strong{URL}: @uref{http://github.com/dardisco/mp} @*
@strong{Version}: 0.2 @*
@strong{Keywords}: R, Sweave, knitr, latex, noweb, org @*
@strong{Package-Requires}: ((ess) (org) (org-element) (tex)) @*
@strong{Commentary}: Makes a pdf from the materials in the `default-directory'
(or will search up the directory tree for
the appropriate file type).
These may include .R, .tex, .Rnw, .org, .Rmd and .bib files.
Support is provided for indexes, glossaries and table of contents.
Installation:
This package can be installed using
(package-install-from-file "/path/to/mp.el")
Or place the folliwng in your init.el file
(add-to-list 'load-path "~/path/to/directory")
(require 'mp)
Usage:
To generate a .pdf file use the `mp-mp' command.
`M-x mp-mp RET'
This command can be called within the directory used to produce
the .pdf. It can also be called from one of the files used to
produce the .pdf. In the latter case, the file will first be
saved if there are any changes.
There are a number of addition commands which you may wish
to call independently:
- `mp-customize-common' - Set common customizable variables
- `mp-example' - Generate an example .pdf
- `mp-custom-example' - Call both commands above, in sequence
- `mp-customize-all' - Set all customizable variables
- `mp-customize-skeleton-string' - Set all customizable
skeleton strings for the package (strings used by skeletons)
- `mp-clean' - Delete files in which have `mp-clean-extensions'
- `mp-tex-new' - Make a new .tex file
- `mp-chunk-new' - Insert a new chunk
You may wish to define a shortcut for calling
`mp-chunk-new'.
`f8' is suggested as there are 8 characters in these prefixes.
That is, "## ---- " is 8 characters in length.
The prefixes follow the conventions established by knitr.
If so, also place something like this in your init.el file:
```
(global-set-key
(kbd "<f8>")
(lambda ()
(interactive)
(mp-chunk-new)))
```
or, for example, if using ESS and `bind-key':
```
(bind-key
(kbd "<f8>")
(lambda ()
(interactive)
(mp-chunk-new))
ess-mode-map)
```
Details:
The purpose of `mp-mp' is to move from an R file or an
intermediary file (.Rnw, .Rmd, .org, .bib, .tex) to a .pdf
with a single command. This is done by selecting an entwiner
(named after the conventions of 'weaving' with Sweave or 'knitting'
with knitr; the default is knitr).
The simplest way to see this in action is to call `mp-example'.
This will generate a new directory in the current
`default-directory' for the files used to generate the final .pdf.
This may also be a good way to start a new project.
Assuming we start with an .R file, `mp-mp' generates an
intermediary file, as appropriate, then uses the entwiner to
generate a .tex file from the intermediary, then uses latexmk
to generate a .pdf from the .tex file, which is then displayed.
Alternatively, we may start with an intermediary e.g. a .Rnw file.
A .R file is generated from this before making the .tex file,
as above.
We may also start directly with a .tex file. In this case,
no intermediary or .R file is created; we proceed directly
to .pdf. Similarly in the case of a .bib file. Note that
a .pdf will *not* be generated from a .bib file without a
corresponding .tex file in the same directory.
Output from the various steps in compiling the .pdf appears in
the '*make-pdf*' buffer, which (by default) will by used to
display the .pdf once complete. Alternative .pdf viewers are
supported. If another viewer is used, this output will remain
visible in the '*make-pdf*' buffer.
Note that all code in the .R file is run via Rscript, to ensure
there are no errors with this and in case this modifies another
file in the workign directory e.g. a .bib file as is the case
when running `mp-example'.
Updating R code chunks:
An advantage of `mp-mp' is that code can be updated in either
the .R file or the intermediary. Whichever has been more recently
modified will be used as the source and the other as the destination.
This allows for editing of code in either the .R file or the
intermediary.
That is, when `mp-mp' is called from an .R file or an intermediary,
a corresponding .R or intermediary will be created or
updated, as appropriate.
This starts by reading the chunks from the working file.
This is the buffer currently open (if it has unsaved changes).
This will be an .R file, or an entwiner file (.Rnw, .Rmd, .org).
For example, when working with an .R file, if there is *no*
entwiner file (.Rnw, .org) with the same file name prefix in
the same directory, this file will be *created* before generating
a .tex file from this entwiner.
If an entwiner file *already exists*, this is *deleted*.
A new entwiner file is created after reading the code chunks
in the .R file.
As above, note that changes to a .tex file do *not* update the
corresponding intermediary. Thus free text (outside .R code chunks)
should generally be updated in the intermediary file, unless
no further changes to the .R code is planned.
Customization:
To avoid errors, it is best to set the following customizable
variables once at the start of a project:
- `mp-entwiner'
- `mp-latex'
- `mp-bib'
If these are changed mid-way through, it may be necessary to
first delete the intermediary, .tex and .pdf files before starting
afresh from the .R file in the directory.
This package contains a variety of defaults which may be modified.
For example, the preamble for a LaTeX document, which varies
depending on whether LaTeX or XeTeX/LuaLaTeX is used to generate
the .pdf.
Multiple plots per chunk:
All of the entwiners will save graphical output in one or more
separate files, then include some these in the final .pdf.
Only knitr supports multiple plots per chunk by default.
By default, both Sweave and Org will include only the first
plot/graph/figure produced.
They both use the TeX command `\includegraphics' for this.
The function `mp-tex-to-pdf' will replace instances of this
command with `\includepdf[pages=-, width=0.9\linewidth]',
so that all plots/pages are included.
An alternative is to save each plot as a separate
file and then output the TeX command to include all of them.
An example of a code block using this approach follows below.
```
for(i in 1:4){
file=paste("f", i, ".eps", sep="")
postscript(file=file, paper="special", width=8, height=8)
plot(rnorm(100)+i)
dev.off()
cat(" \\includegraphics{", file, "}\n", sep="")
}
```
In Sweave, we would wrap the code above in:
```
<<plots, results=tex, strip.white=false>>=
**code**
@@
```
In Org, we would wrap the code above in:
```
#+NAME: plots2
#+begin_src R :session *org-R-session* :exports both :results output :results verbatim :results latex
**code**
#+end_src
```
History/goals:
This package was initially developed in 2012 to help to
speed up the process of scientific writing. At that time,
there was no easy was to tranistion quickly from a .R file to
a .pdf and knitr was relatively new and was not being used
routinely e.g. to generate package documentation.
The range of options has expanded dramatically since.
In particulary, .Rmd appears to have become the most popular
choice for performing this type of work.
Dependencies:
The following should be installed and on your path:
- R, including the packages knitr and rmarkdown
- LaTeX
- pandoc
- bash commands: locate, grep
The following emacs packages are also recommended:
- org
- ess
- tex, bibtex
- doc-view
- markdown-mode
- polymode, poly-R
This is designed for Emacs on debian linux with bash.
It has not been evaluated on other systems.
For developers:
Function-local/temporary variables are named using
as name1 e.g. `v1', `buffer1'. @*
@node defgroup
@chapter defgroup
@cindex defgroup
Documentation for @code{defgroup}: @*
Declare SYMBOL as a customization group containing MEMBERS.
SYMBOL does not need to be quoted.
Third argument DOC is the group documentation. This should be a short
description of the group, beginning with a capital and ending with
a period. Words other than the first should not be capitalized, if they
are not usually written so.
MEMBERS should be an alist of the form ((NAME WIDGET)...) where
NAME is a symbol and WIDGET is a widget for editing that symbol.
Useful widgets are ‘custom-variable’ for editing variables,
‘custom-face’ for editing faces, and ‘custom-group’ for editing groups.
The remaining arguments should have the form
[KEYWORD VALUE]...
For a list of valid keywords, see the common keywords listed in
‘defcustom’.
See Info node ‘(elisp) Customization’ in the Emacs Lisp manual
for more information.@*
A table of all @code{defgroup}s follows:
@ftable @code
@item mp
@item mp-common
@end ftable
Details of each @code{defgroup} follow below: @*
@cindex mp
@unnumberedsec mp
@deffn defgroup mp
@table @var
@item group-documentation
Make Pdf.
This is a series of variables and functions to simplity
the process of pdf creation using R, LaTeX and
the intermediaries (entwiners)
knitr, Sweave and Org (`org-mode').
@item custom-prefix
mp-
@item custom-version
0.2
@item custom-group
((mp custom-group) (mp-common custom-group) (mp-example-file-name custom-variable) (mp-timeout custom-variable) (mp-file-name-extensions custom-variable) (mp-function-sequence custom-variable) (mp-entwiner custom-variable) (mp-R-chunks-new-R custom-variable) (mp-chunk-name-prefix-R custom-variable) (mp-chunk-format-prefix-R custom-variable) (mp-chunk-content-suffix-R custom-variable) (mp-chunk-heading-level custom-variable) (mp-R-chunk-defaults-R-pkg custom-variable) (mp-chunk-format-default-R-pkg custom-variable) (mp-chunk-format-default-sweave custom-variable) (mp-chunk-format-default-org custom-variable) (mp-bib custom-variable) (mp-preamble-bib custom-variable) (mp-preamble-biblatex custom-variable) (mp-doc-class-tex custom-variable) (mp-preamble-knitr custom-variable) (mp-preamble-sweave custom-variable) (mp-preamble-org custom-variable) (mp-latex custom-variable) (mp-latex-font custom-variable) (mp-xetex-font custom-variable) (mp-preamble-tex custom-variable) (mp-add-preamble-tex-extra custom-variable) (mp-preamble-tex-extra custom-variable) (mp-tex-beginning custom-variable) (mp-bibtex-style custom-variable) (mp-tex-end custom-variable) (mp-sentinel-sleep custom-variable) (mp-latex-options custom-variable) (mp-latexmkrc custom-variable) (mp-bib-default custom-variable) (mp-pdf-viewer custom-variable) (mp-clean custom-variable) (mp-clean-extensions custom-variable) (mp-clean-others custom-variable) (mp-skeleton-string custom-group))
@end table
@end deffn
@cindex mp-common
@unnumberedsec mp-common
@deffn defgroup mp-common
@table @var
@item group-documentation
Options that the user is most likely to wish to change.
This group is part of `mp'.
@item custom-group
((mp-timeout custom-variable) (mp-entwiner custom-variable) (mp-chunk-heading-level custom-variable) (mp-bib custom-variable) (mp-clean custom-variable))
@end table
@end deffn
@node defun
@chapter defun
@cindex defun
Documentation for @code{defun}: @*
Define NAME as a function.
The definition is (lambda ARGLIST [DOCSTRING] BODY...).
See also the function ‘interactive’.
DECL is a declaration, optional, of the form (declare DECLS...) where
DECLS is a list of elements of the form (PROP . VALUES). These are
interpreted according to ‘defun-declarations-alist’.
The return value is undefined.
(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)@*
A table of all @code{defun}s follows:
@ftable @code
@item mp-custom-example
Run ‘mp-customize-common’ then ‘mp-example’.
@item mp-example
Generate and run an example.
@item mp-initialize
Set the following ‘defvar’s to their staring value:
@item mp-set-mp-dd
Set the value of ‘mp-dd’.
@item mp-valid-file-name-p
Return t is STRING is a valid filename.
@item mp-run
Run the appropriate list of functions from ‘mp-function-sequence’.
@item mp-R-entwiner
Convert R to an entwiner or vice versa.
@item mp-bib
Check if there is a file named ‘mp-fnb’.bib in ‘mp-dd’.
@item mp-R-new
Make an .R file.
@item mp-chunk-update-format
Update the format of a CHUNK, per the value of ‘mp-entwiner’.
@item mp-R-chunk-R-citations
Return a string which is R code that writes a bibliography file.
@item mp-file-display
Displays FILE-NAME.
@item mp-file-open
Open FILE-NAME in a buffer; set buffer to appropriate mode.
@item mp-chunk-set-adfixes
Set the prefixes and suffixes for chunks.
@item mp-set-mode
Set the appropriate mode for a file.
@end ftable
Details of each @code{defun} follow below: @*
@cindex mp-custom-example
@unnumberedsec mp-custom-example
@defun mp-custom-example
Command ? @emph{yes} @*
Arguments: @emph{none} @*
Documentation: Run ‘mp-customize-common’ then ‘mp-example’.
@smallformat @verbatim
((interactive)
(mp-customize-common)
(mp-example))
@end verbatim
@end smallformat
@end defun
@cindex mp-example
@unnumberedsec mp-example
@defun mp-example
Command ? @emph{yes} @*
Arguments: @emph{none} @*
Documentation: Generate and run an example.
Calls ‘mp-mp’, in the subdirectory ‘mp-example-file-name’.
@smallformat @verbatim
((interactive)
(mp-set-mp-dd)
(let
((d1
(concat mp-dd mp-example-file-name "/")))
(delete-directory d1 t)
(mkdir d1 t)
(cd d1)
(setq mp-dd d1 mp-fnb mp-example-file-name mp-fne "R")
(mp-initialize)
(message
(concat "mp-example ... running in "
(print mp-dd))))
(mp-run mp-fne))
@end verbatim
@end smallformat
@end defun
@cindex mp-initialize
@unnumberedsec mp-initialize
@defun mp-initialize
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Set the following ‘defvar’s to their staring value:
- ‘mp-df’
- ‘mp-fn’
- ‘mp-chunks’
Called by ‘mp-example’ and ‘mp-mp’.
@smallformat @verbatim
((while
(get-buffer-window "*make-pdf*")
(delete-window
(get-buffer-window "*make-pdf*")))
(if
(get-buffer "*make-pdf*")
(progn
(kill-buffer "*make-pdf*")))
(balance-windows)
(setq mp-df
(sort
(directory-files mp-dd nil
(mapconcat
#'(lambda
(x)
(concat "\\." x "$"))
mp-file-name-extensions "\\|")
t)
#'file-newer-than-file-p)
mp-fn
(car mp-df)
mp-chunks 'nil mp-exiting nil))
@end verbatim
@end smallformat
@end defun
@cindex mp-set-mp-dd
@unnumberedsec mp-set-mp-dd
@defun mp-set-mp-dd
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Set the value of ‘mp-dd’.
If ‘mp-fnb’ is an empty string, also set this to the same
value as ‘mp-dd’.
@smallformat @verbatim
((setq mp-dd
(cond
((buffer-file-name)
(file-name-directory buffer-file-name))
((equal major-mode 'dired-mode)
dired-directory)
(t
(shell-command-to-string "printf '%s' $HOME/")))
default-directory mp-dd)
(message
(concat "mp-set-mp-dd ... mp-dd set to "
(print mp-dd)))
(if
(equalp "" mp-fnb)
(progn
(setq mp-fnb
(file-name-nondirectory
(directory-file-name mp-dd)))
(message
(concat "mp-set-mp-dd ... mp-fnb set to "
(print mp-fnb))))))
@end verbatim
@end smallformat
@end defun
@cindex mp-valid-file-name-p
@unnumberedsec mp-valid-file-name-p
@defun mp-valid-file-name-p
Command ? @emph{yes} @*
Arguments: @var{STRING} @*
Documentation: Return t is STRING is a valid filename.
Uses ‘file-name-invalid-regexp’, which depends on the ‘system-type’.
An example of an invalid filename is "\0".
See also the following for additional restrictions on Windows:
URL ‘https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file’.
@smallformat @verbatim
((interactive "FFilename: ")
(not
(string-match file-name-invalid-regexp STRING)))
@end verbatim
@end smallformat
@end defun
@cindex mp-run
@unnumberedsec mp-run
@defun mp-run
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Run the appropriate list of functions from ‘mp-function-sequence’.
This is given by ‘mp-fne’.
@smallformat @verbatim
((let
((seq1
(catch '--cl-block-nil--
(let
((--dolist-tail-- mp-function-sequence))
(while --dolist-tail--
(let
((x
(car --dolist-tail--)))
(if
(string-match
(car x)
mp-fne)
(progn
(throw '--cl-block-nil--
(eval
(cdr x)))))
(setq --dolist-tail--
(cdr --dolist-tail--))))))))
(message
(concat "mp-run, with "
(car mp-entwiner)
" and "
(cdr mp-entwiner)
", starting with ." mp-fne " file ..."))
(let
((--dolist-tail-- seq1))
(while --dolist-tail--
(let
((x
(car --dolist-tail--)))
(funcall x)
(setq --dolist-tail--
(cdr --dolist-tail--))))))
(mp-exit "mp-run... done"))
@end verbatim
@end smallformat
@end defun
@cindex mp-R-entwiner
@unnumberedsec mp-R-entwiner
@defun mp-R-entwiner
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Convert R to an entwiner or vice versa.
Calls ‘mp-chunks-read’ to get code chunks from the current file.
If this is an .R file and an ’entwiner’ file already exists,
this is deleted and replaced.
update the *least recently used* file
i.e. the .R or the entwiner, using, as appropriate
‘mp-update-entwiner-from-R’ or ‘mp-update-R-from-entwiner’.
If no such file exists, make one with ‘mp-entwiner-new’.
@smallformat @verbatim
((let
((rf1
(car
(cl-member
(concat mp-fnb ".R")
mp-df :test #'equalp)))
(ef1
(car
(cl-member
(concat mp-fnb "."
(car mp-entwiner))
mp-df :test #'equalp))))
(message "mp-R-entwiner ...")
(if
(not rf1)
(progn
(mp-R-new)
(if
(mp-empty-string-to-nil ef1)
nil
(mp-entwiner-new)))
(if ef1
(if
(file-newer-than-file-p rf1 ef1)
(mp-update-entwiner-from-R)
(mp-update-R-from-entwiner))
(progn
(mp-file-display
(concat mp-fnb ".R"))
(mp-chunks-read)
(mp-entwiner-new)))))
(if mp-bib
(progn
(mp-bib)))
(mp-shell-sentinel "mp-Rscript-run")
(message "mp-R-entwiner ... done"))
@end verbatim
@end smallformat
@end defun
@cindex mp-bib
@unnumberedsec mp-bib
@defun mp-bib
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Check if there is a file named ‘mp-fnb’.bib in ‘mp-dd’.
If not, make one by calling ‘mp-bib-skeleton’.
See also the variable ‘mp-bib’.
@smallformat @verbatim
((if
(directory-files mp-dd nil
(concat mp-fnb ".bib$"))
nil
(mp-file-display
(concat mp-fnb ".bib"))
(mp-bib-skeleton)
(save-buffer)
(kill-buffer)
(delete-window)))
@end verbatim
@end smallformat
@end defun
@cindex mp-R-new
@unnumberedsec mp-R-new
@defun mp-R-new
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Make an .R file.
If ‘mp-chunks’ is not an empty list, use these,
otherwise use ‘mp-R-chunks-new-R’.
Called by ‘mp-R-entwiner’ and ‘mp-update-R-from-entwiner’.
@smallformat @verbatim
((if
(equalp 'nil mp-chunks)
(progn
(if mp-bib
(progn
(setq mp-chunks
(cons
(list "R citations" ""
(mp-R-chunk-R-citations))
mp-chunks))))
(let
((--dolist-tail--
(reverse
(copy-tree mp-R-chunks-new-R))))
(while --dolist-tail--
(let
((x
(car --dolist-tail--)))
(setq mp-chunks
(cons x mp-chunks))
(setq --dolist-tail--
(cdr --dolist-tail--)))))
(if
(string-match "^R-pkg-"
(cdr mp-entwiner))
(progn
(setq mp-chunks
(cons
(copy-tree mp-R-chunk-defaults-R-pkg)
mp-chunks))))))
(let
((--dolist-tail-- mp-chunks))
(while --dolist-tail--
(let
((x
(car --dolist-tail--)))
(mp-chunk-update-format x)
(setq --dolist-tail--
(cdr --dolist-tail--)))))
(setq mp-fne "R")
(let
((fn1
(concat mp-fnb ".R")))
(if
(get-buffer fn1)
nil
(mp-file-display fn1))
(save-current-buffer
(set-buffer fn1)
(goto-char
(point-min))
(mapc #'mp-chunk-insert mp-chunks)
(goto-char
(point-max)))
(save-buffer)
(kill-buffer)
(delete-window)))
@end verbatim
@end smallformat
@end defun
@cindex mp-chunk-update-format
@unnumberedsec mp-chunk-update-format
@defun mp-chunk-update-format
Command ? @emph{no} @*
Arguments: @var{CHUNK} @*
Documentation: Update the format of a CHUNK, per the value of ‘mp-entwiner’.
The format is the second element of CHUNK, a string.
@smallformat @verbatim
((if
(equalp ""
(car
(cdr CHUNK)))
(progn
(setcar
(cdr CHUNK)
(mp-chunk-format)))))
@end verbatim
@end smallformat
@end defun
@cindex mp-R-chunk-R-citations
@unnumberedsec mp-R-chunk-R-citations
@defun mp-R-chunk-R-citations
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Return a string which is R code that writes a bibliography file.
This file is named ’‘mp-fnb’.bib.’.
A citation appears therein for each loaded R package.
Adds a handle to each citation, if necessary.
This is added to ‘mp-chunks’ when ‘mp-bib’ is non-nil.
Called by ‘mp-R-new’.
@smallformat @verbatim
((concat "print(.packages())\n## vector for citations\nvc1 <- unlist(sapply(X=rev(.packages()),\n FUN=function(x)\n utils::toBibtex(utils::citation(x))))\nvc1 <- vc1[!vc1=='']\n## names for citations\nn1 <- vc1[which(grepl(pattern='.year', x=vc1))]\nn1 <- paste0(\n sub(pattern='\\\\.year$', replacement='', x=names(n1)),\n regmatches(x=n1, m=regexpr(pattern='[0123456789]+', text=n1)))\n## group as list\nl1 <- vector(mode='list', length=length(n1))\nnames(l1) <- n1\nend1 <- which(grepl(pattern='\\\\}$', x=vc1))\n## remove trailing comma from last item in .bib entry, if necessary\nvc1[end1-1] <- sub(pattern=',$', replacement='', x=vc1[end1-1])\nend1 <- c(0, end1)\nfor (i in seq.int(length.out=length(l1)))\n l1[[i]] <- unname(vc1[seq.int(from=(end1[i] + 1L), to=end1[i+1])])\nl1 <- l1[!duplicated(l1)]\n## add a handle, if necessary\nfor (i in seq.int(length.out=length(l1)))\n if (grepl(pattern='\\\\{,$', x=l1[[i]][1]))\n l1[[i]][1] <- sub(pattern=',$', \n replacement=paste0(names(l1[i]), ','),\n x=l1[[i]][1])\nif (!'mp-example.bib' %in% dir())\n write(x='', file='" mp-dd mp-fnb ".bib')\nbib1 <- readLines('" mp-dd mp-fnb ".bib')\nfor (i in seq.int(length.out=length(l1)))\n if (!(l1[[i]][1] %in% bib1))\n write(x=l1[[i]], file='" mp-dd mp-fnb ".bib', append=TRUE)"))
@end verbatim
@end smallformat
@end defun
@cindex mp-file-display
@unnumberedsec mp-file-display
@defun mp-file-display
Command ? @emph{no} @*
Arguments: @var{FILE-NAME} @*
Documentation: Displays FILE-NAME.
If the file is already open if a buffer, calls ‘pop-to-buffer’.
If not, calls ‘mp-file-open’.
Finally, calls ‘mp-set-mode’ and ‘mp-chunk-set-adfixes’.
@smallformat @verbatim
((setq mp-fne
(file-name-extension FILE-NAME))
(let
((default-directory mp-dd)
(bn1
(car
(member FILE-NAME
(mapcar 'buffer-name
(buffer-list))))))
(if bn1
(pop-to-buffer bn1)
(mp-file-open FILE-NAME)))
(mp-set-mode)
(mp-chunk-set-adfixes))
@end verbatim
@end smallformat
@end defun
@cindex mp-file-open
@unnumberedsec mp-file-open
@defun mp-file-open
Command ? @emph{no} @*
Arguments: @var{FILE-NAME} @*
Documentation: Open FILE-NAME in a buffer; set buffer to appropriate mode.
Return buffer.
This function is derived from a combination of the functions
‘find-file-noselect’ and ‘find-file-noselect-1’.
Called by ‘mp-file-display’.
@smallformat @verbatim
((let*
((default-directory mp-dd)
(truename1
(abbreviate-file-name
(file-truename FILE-NAME)))
(buf1 nil))
(if
(featurep 'uniquify)
(let
((uniquify-managed
(progn
(make-local-variable 'uniquify-managed)
nil)))
(setq buf1
(create-file-buffer FILE-NAME)))
(setq buf1
(create-file-buffer FILE-NAME)))
(pop-to-buffer buf1 nil t)
(set-buffer buf1)
(set-buffer-multibyte t)
(if
(and
(=
(buffer-size buf1)
0)
(directory-files mp-dd nil
(concat "^" FILE-NAME "$")))
(progn
(insert-file-contents-literally truename1 t)))
(setq buffer-file-truename truename1 buffer-file-name
(expand-file-name buffer-file-truename)
buffer-file-number
(nthcdr 10
(file-attributes truename1)))))
@end verbatim
@end smallformat
@end defun
@cindex mp-chunk-set-adfixes
@unnumberedsec mp-chunk-set-adfixes
@defun mp-chunk-set-adfixes
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Set the prefixes and suffixes for chunks.
These depend on the ‘file-name-extension’ of the curent buffer,
if applicable, otherwise on ‘mp-fne’.
The following file-local variables are set:
- ‘mp-chunk-heading-level-prefix’
- ‘mp-chunk-heading-level-suffix’
- ‘mp-chunk-name-prefix’
- ‘mp-chunk-name-suffix’
- ‘mp-chunk-format-prefix’
- ‘mp-chunk-content-suffix’
Called by ‘mp-file-display’.
@smallformat @verbatim
((let
((fe1
(car
(cl-member
(file-name-extension
(buffer-file-name))
'("R" "Rnw" "org" "Rmd")
:test #'equalp))))
(if fe1 nil
(setq fe1 mp-fne))
(cond
((equalp "R" fe1)
(setq mp-chunk-name-prefix mp-chunk-name-prefix-R mp-chunk-format-prefix mp-chunk-format-prefix-R mp-chunk-name-suffix "" mp-chunk-content-suffix mp-chunk-content-suffix-R))
((equalp "Rnw" fe1)
(setq mp-chunk-heading-level-prefix
(elt mp-chunk-heading-level 0)
mp-chunk-heading-level-suffix "}" mp-chunk-name-prefix mp-chunk-name-prefix-Rnw mp-chunk-name-suffix mp-chunk-name-suffix-Rnw mp-chunk-format-prefix mp-chunk-format-prefix-Rnw mp-chunk-content-suffix mp-chunk-content-suffix-Rnw))
((equalp "org" fe1)
(setq mp-chunk-heading-level-prefix
(elt mp-chunk-heading-level 1)
mp-chunk-heading-level-suffix "" mp-chunk-name-prefix mp-chunk-name-prefix-org mp-chunk-format-prefix mp-chunk-format-prefix-org mp-chunk-name-suffix "" mp-chunk-content-suffix mp-chunk-content-suffix-org))
((equalp "Rmd" fe1)
(setq mp-chunk-heading-level-prefix
(elt mp-chunk-heading-level 2)
mp-chunk-heading-level-suffix "" mp-chunk-name-prefix mp-chunk-name-prefix-Rmd mp-chunk-name-suffix mp-chunk-name-suffix-Rmd mp-chunk-format-prefix mp-chunk-format-prefix-Rmd mp-chunk-content-suffix mp-chunk-content-suffix-Rmd)))
(message
(concat "mp-chunk-set-adfixes... set per for ." fe1 " file extension"))))
@end verbatim
@end smallformat
@end defun
@cindex mp-set-mode
@unnumberedsec mp-set-mode
@defun mp-set-mode
Command ? @emph{no} @*
Arguments: @emph{none} @*
Documentation: Set the appropriate mode for a file.
@smallformat @verbatim
((cond
((equalp "R" mp-fne)
(R-mode))
((equalp "Rnw" mp-fne)
(Rnw-mode))
((equalp "org" mp-fne)
(org-mode))
((equalp "Rmd" mp-fne)
(markdown-mode)
(if poly-markdown+r-mode nil
(poly-markdown+r-mode)))
((equalp "tex" mp-fne)
(tex-mode))
((equalp "bib" mp-fne)
(bibtex-mode))
(t
(fundamental-mode))))
@end verbatim
@end smallformat
@end defun
@node defcustom
@chapter defcustom
@cindex defcustom
Documentation for @code{defcustom}: @*
Declare SYMBOL as a customizable variable.
SYMBOL is the variable name; it should not be quoted.
STANDARD is an expression specifying the variable’s standard
value. It should not be quoted. It is evaluated once by
‘defcustom’, and the value is assigned to SYMBOL if the variable
is unbound. The expression itself is also stored, so that
Customize can re-evaluate it later to get the standard value.
DOC is the variable documentation.
This macro uses ‘defvar’ as a subroutine, which also marks the
variable as "special", so that it is always dynamically bound
even when ‘lexical-binding’ is t.
The remaining arguments to ‘defcustom’ should have the form
[KEYWORD VALUE]...
The following keywords are meaningful:
:type VALUE should be a widget type for editing the symbol’s value.
Every ‘defcustom’ should specify a value for this keyword.
:options VALUE should be a list of valid members of the widget type.
:initialize
VALUE should be a function used to initialize the
variable. It takes two arguments, the symbol and value
given in the ‘defcustom’ call. The default is
‘custom-initialize-reset’.
:set VALUE should be a function to set the value of the symbol
when using the Customize user interface. It takes two arguments,
the symbol to set and the value to give it. The function should
not modify its value argument destructively. The default choice
of function is ‘set-default’.
:get VALUE should be a function to extract the value of symbol.
The function takes one argument, a symbol, and should return
the current value for that symbol. The default choice of function
is ‘default-value’.
:require
VALUE should be a feature symbol. If you save a value
for this option, then when your init file loads the value,
it does (require VALUE) first.
:set-after VARIABLES
Specifies that SYMBOL should be set after the list of variables
VARIABLES when both have been customized.
:risky Set SYMBOL’s ‘risky-local-variable’ property to VALUE.
:safe Set SYMBOL’s ‘safe-local-variable’ property to VALUE.