Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexpkg.el @ 395:5aa8208fbef0 dev
Change header lines.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 16 Jan 2015 10:39:19 +0900 |
parents | 8ee8514e06ed |
children | 92bab72bf4de |
rev | line source |
---|---|
395 | 1 ;;; yatexpkg.el --- YaTeX package manager -*- coding: sjis -*- |
287 | 2 ;;; |
395 | 3 ;;; (c)2003-2015 by HIROSE, Yuuji [yuuji@yatex.org] |
4 ;;; Last modified Fri Jan 16 10:33:26 2015 on firestorm | |
368 | 5 ;;; $Id$ |
78 | 6 |
287 | 7 ;;; Code: |
80 | 8 (defvar YaTeX-package-ams-envs |
9 (mapcar 'car YaTeX-ams-env-table)) | |
10 | |
78 | 11 (defvar YaTeX-package-alist-default |
193 | 12 '(("version" (env "comment") ;by tsuchiya<at>pine.kuee.kyoto-u.ac.jp |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
13 (section "includeversion" "excludeversion")) |
78 | 14 |
193 | 15 ("plext" (section "bou")) ;by yas.axis<at>ma.mni.ne.jp |
78 | 16 |
193 | 17 ("url" (section "url")) ;by fujieda<at>jaist.ac.jp |
78 | 18 |
19 ("fancybox" (section "shadowbox" "doublebox" "ovalbox" "Ovalbox")) | |
80 | 20 ("slashbox" (section "slashbox" "backslashbox")) |
78 | 21 ("pifont" (section "ding")) |
22 ("longtable" (env "longtable")) | |
23 ("ascmac" (env "screen" "boxnote" "shadebox" "itembox") | |
24 (maketitle "return" "Return" "yen") | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
25 (section "keytop") ("mask") ("maskbox")) |
193 | 26 ("bm" (section "bm")) ;by aoyama<at>le.chiba-u.ac.jp |
78 | 27 |
28 ("alltt" (env "alltt")) | |
29 ("misc" (section "verbfile" "listing")) | |
80 | 30 ("eclbkbox" (env "breakbox")) |
31 ("supertabular" (env "supertabular")) | |
32 ("amsmath" (env . YaTeX-package-ams-envs) | |
33 (section "tag" "tag*")) | |
134 | 34 ("amssymb" (maketitle "leqq" "geqq" "mathbb" "mathfrak" |
305
53709ee88448
Add \because and \therefore to math-image completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
304
diff
changeset
|
35 "fallingdotseq" "therefore" "because" |
134 | 36 "lll" "ggg")) ;very few. Please tell us! |
80 | 37 ("graphicx" (section "includegraphics" |
38 "rotatebox" "scalebox" "resizebox" "reflectbox") | |
39 (option . YaTeX-package-graphics-driver-alist)) | |
40 ("color" (section "textcolor" "colorbox" "pagecolor" "color") | |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
41 (option . YaTeX-package-graphics-driver-alist) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
42 (default-option . "usenames,dvipsnames")) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
43 ("xcolor" (same-as . "color")) |
80 | 44 ("ulem" (section "uline" "uuline" "uwave") |
45 (option ("normalem"))) | |
312 | 46 ("multicol" (env "multicols")) |
314
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
47 ("cref" (section "cleveref")) |
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
48 ("crefrange" (same-as . "cref")) |
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
49 ("cpageref" (same-as . "cref")) |
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
50 ("labelcref" (same-as . "cref")) |
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
51 ("labelcpageref" (same-as . "cref")) |
346 | 52 ("wrapfig" (env "wrapfigure" "wraptable")) |
314
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
53 ) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
54 "Default package vs. macro list. |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
55 Alists contains '(PACKAGENAME . MACROLIST) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
56 PACKAGENAME Basename of package(String). |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
57 MACROLIST List of '(TYPE . MACROS) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
58 TYPE One of 'env, 'section or 'maketitle according to completion-type |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
59 MACROS List of macros |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
60 |
80 | 61 If TYPE is 'option, its cdr is alist of completion candidates for that |
62 package. Its cdr can be a symbol whose value is alist. | |
63 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
64 An good example is the value of YaTeX-package-alist-default.") |
78 | 65 |
80 | 66 (defvar YaTeX-package-graphics-driver-alist |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
67 '(("dvips") ("dvipsnames") ("usenames") |
333
30a8f68abe0a
Supply `dvipdfmx' completion instead of `dvipdf'
HIROSE Yuuji <yuuji@gentei.org>
parents:
314
diff
changeset
|
68 ("xdvi") ("dvipdfmx") ("pdftex") ("dvipsone") ("dviwindo") |
80 | 69 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin") |
70 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex")) | |
71 "Drivers alist of graphics/color stylefile's supporting deveces. | |
72 This list is taken from | |
73 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz | |
74 %% Copyright (C) 1995 1996 1997 1998 David Carlisle | |
75 as of 2004/1/19. Thanks.") | |
76 | |
78 | 77 (defvar YaTeX-package-alist-private nil |
78 "*User defined package vs. macro list. See also YaTeX-package-alist-default") | |
79 | |
80 (defun YaTeX-package-lookup (macro &optional type) | |
81 "Look up a package which contains a definition of MACRO. | |
82 Optional second argument TYPE limits the macro type. | |
83 TYPE is a symbol, one of 'env, 'section, 'maketitle." | |
84 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default)) | |
304
a57f4c74179a
(yatexpkg)YaTeX-package-lookup sees 'same-as entry.
HIROSE Yuuji <yuuji@gentei.org>
parents:
303
diff
changeset
|
85 origlist element x sameas val pkg pkglist r) |
a57f4c74179a
(yatexpkg)YaTeX-package-lookup sees 'same-as entry.
HIROSE Yuuji <yuuji@gentei.org>
parents:
303
diff
changeset
|
86 (setq origlist list) |
78 | 87 (while list |
88 (setq element (car list) | |
89 pkg (car element) | |
90 element (cdr element)) | |
304
a57f4c74179a
(yatexpkg)YaTeX-package-lookup sees 'same-as entry.
HIROSE Yuuji <yuuji@gentei.org>
parents:
303
diff
changeset
|
91 (if (setq sameas (assq 'same-as element)) ;non-recursive retrieval |
a57f4c74179a
(yatexpkg)YaTeX-package-lookup sees 'same-as entry.
HIROSE Yuuji <yuuji@gentei.org>
parents:
303
diff
changeset
|
92 (setq element (cdr (assoc (cdr sameas) origlist)))) |
78 | 93 (if (setq r (catch 'found |
94 (while element | |
80 | 95 (setq x (car element) |
96 val (cdr x)) | |
97 (if (symbolp val) (setq val (symbol-value val))) | |
98 (and (or (null type) | |
78 | 99 (eq type (car x))) |
80 | 100 (YaTeX-member macro val) |
78 | 101 (throw 'found (car x))) ;car x is type |
102 (setq element (cdr element))))) | |
103 (setq pkglist (cons (cons pkg r) pkglist))) | |
104 (setq list (cdr list))) | |
105 pkglist)) | |
106 | |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
107 (defun YaTeX-package-option-lookup (pkg &optional key) |
80 | 108 "Look up options for specified pkg and returne them in alist form. |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
109 Just only associng against the alist of YaTeX-package-alist-*" |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
110 (let*((list (append YaTeX-package-alist-private YaTeX-package-alist-default)) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
111 (l (cdr (assq (or key 'option) (assoc pkg list)))) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
112 (recur (cdr (assq 'same-as (assoc pkg list))))) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
113 (cond |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
114 (recur (YaTeX-package-option-lookup recur key)) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
115 ((symbolp l) (symbol-value l)) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
116 (t l)))) |
80 | 117 |
78 | 118 (defvar YaTeX-package-resolved-list nil |
119 "List of macros whose package is confirmed to be loaded.") | |
120 | |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
121 (defun YaTeX-package-auto-usepackage (macro type &optional autopkg autoopt) |
78 | 122 "(Semi)Automatically add the \\usepackage line to main-file. |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
123 Search the usepackage for MACRO of the TYPE. |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
124 Optional second and third argument AUTOPKG, AUTOOPT are selected |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
125 without query. Thus those two argument (Full)automatically add |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
126 a \\usepackage line." |
78 | 127 (let ((cb (current-buffer)) |
128 (wc (current-window-configuration)) | |
129 (usepackage (concat YaTeX-ec "usepackage")) | |
80 | 130 (pkglist (YaTeX-package-lookup macro type)) |
78 | 131 (usepkgrx (concat |
132 YaTeX-ec-regexp | |
133 "\\(usepackage\\|include\\)\\b")) | |
353
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
346
diff
changeset
|
134 (register (function |
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
346
diff
changeset
|
135 (lambda () (set-buffer cb) |
78 | 136 (set (make-local-variable 'YaTeX-package-resolved-list) |
353
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
346
diff
changeset
|
137 (cons macro YaTeX-package-resolved-list))))) |
78 | 138 (begdoc (concat YaTeX-ec "begin{document}")) |
80 | 139 pb pkg optlist (option "") mb0 uspkgargs) |
78 | 140 (if (or (YaTeX-member macro YaTeX-package-resolved-list) |
141 (null pkglist)) | |
142 nil ;nothing to do | |
143 ;; Search `usepackage' into main-file | |
144 (YaTeX-visit-main t) ;set buffer to parent file | |
145 (setq pb (current-buffer)) | |
146 (save-excursion | |
147 (save-restriction | |
148 (if (catch 'found | |
149 (goto-char (point-min)) | |
150 (YaTeX-search-active-forward ;if search fails, goto eob | |
151 begdoc YaTeX-comment-prefix nil 1) | |
80 | 152 (while ;(YaTeX-re-search-active-backward |
153 ;usepkgrx YaTeX-comment-prefix nil t) | |
154 ;;allow commented out \usepackages 2004/3/16 | |
155 (re-search-backward usepkgrx nil t) | |
78 | 156 (setq mb0 (match-beginning 0)) |
157 (skip-chars-forward "^{") | |
80 | 158 (setq uspkgargs (YaTeX-buffer-substring |
159 (point) | |
160 (progn | |
161 ;;(forward-list 1) is more precise, | |
162 ;; but higher risk. | |
163 (skip-chars-forward "^}\n")(point)))) | |
78 | 164 (let ((pl pkglist)) |
165 (while pl ;(car pl)'s car is package, cdr is type | |
80 | 166 (if (string-match |
167 (concat "[{,]\\s *" | |
168 (regexp-quote (car (car pl))) | |
169 "\\>") | |
170 uspkgargs) | |
78 | 171 (throw 'found t)) |
172 (setq pl (cdr pl))) | |
173 (goto-char mb0)))) | |
174 ;;corresponding \usepackage found | |
175 (funcall register) | |
176 ;; not found, insert it. | |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
177 (if (or |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
178 autopkg |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
179 (y-or-n-p |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
180 (format "`%s' requires package. Put \\usepackage now?" |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
181 macro))) |
78 | 182 (progn |
80 | 183 (require 'yatexadd) |
78 | 184 (setq pkg |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
185 (or autopkg |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
186 (completing-read |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
187 "Load which package?(TAB for list): " |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
188 pkglist nil nil |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
189 ;;initial input |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
190 (if (= (length pkglist) 1) |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
191 (let ((w (car (car pkglist)))) |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
192 (if YaTeX-emacs-19 (cons w 0) w))))) |
80 | 193 optlist |
194 (YaTeX-package-option-lookup pkg)) | |
195 (if optlist | |
196 (let ((minibuffer-completion-table optlist) | |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
197 (delim ",") (w (car (car optlist))) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
198 (dflt (YaTeX-package-option-lookup |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
199 pkg 'default-option))) |
80 | 200 (setq option |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
201 (or |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
202 autoopt |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
203 (read-from-minibuffer |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
204 (format "Any option for {%s}?: " pkg) |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
205 (let ((v (or dflt |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
206 (and (= (length optlist) 1) w)))) |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
207 (and v (if YaTeX-emacs-19 (cons v 0) v))) |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
208 YaTeX-minibuffer-completion-map)) |
80 | 209 option (if (string< "" option) |
210 (concat "[" option "]") | |
211 "")))) | |
78 | 212 (set-buffer pb) |
213 (goto-char (point-min)) | |
214 (if (YaTeX-re-search-active-forward | |
215 (concat YaTeX-ec-regexp | |
216 "document\\(style\\|class\\){") | |
217 YaTeX-comment-prefix nil t) | |
218 (forward-line 1)) | |
219 (if (YaTeX-search-active-forward | |
220 begdoc YaTeX-comment-prefix nil t) | |
221 (goto-char (match-beginning 0))) | |
222 (insert | |
223 usepackage | |
80 | 224 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n" |
225 option pkg macro)) | |
78 | 226 (funcall register)) |
120
8772bd5d1f02
Do not ask again when user answer n to usepackage addition.
yuuji@gentei.org
parents:
80
diff
changeset
|
227 (funcall register) |
78 | 228 (message "Don't forget to put \\usepackage{%s} yourself later" |
229 (car (car pkglist)))) ;doing car car is negligence... | |
230 )))))) |