Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexpkg.el @ 436:e78a87bc2c9e dev
current file treated as absolute path(YaTeX-preview-jump-line)
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 08 Jan 2016 08:18:54 +0859 |
parents | 92bab72bf4de |
children | 564510b9caca |
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] |
418 | 4 ;;; Last modified Fri Feb 13 22:45:46 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")) |
418 | 53 ("setspace" (env "spacing") (section "setstretch")) |
314
fae84a98372c
("crefrange") ("cpageref") ("labelcref") ("labelcpageref") for cleveref
HIROSE Yuuji <yuuji@gentei.org>
parents:
313
diff
changeset
|
54 ) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
55 "Default package vs. macro list. |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
56 Alists contains '(PACKAGENAME . MACROLIST) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
57 PACKAGENAME Basename of package(String). |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
58 MACROLIST List of '(TYPE . MACROS) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
59 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
|
60 MACROS List of macros |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
61 |
80 | 62 If TYPE is 'option, its cdr is alist of completion candidates for that |
63 package. Its cdr can be a symbol whose value is alist. | |
64 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
65 An good example is the value of YaTeX-package-alist-default.") |
78 | 66 |
80 | 67 (defvar YaTeX-package-graphics-driver-alist |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
68 '(("dvips") ("dvipsnames") ("usenames") |
333
30a8f68abe0a
Supply `dvipdfmx' completion instead of `dvipdf'
HIROSE Yuuji <yuuji@gentei.org>
parents:
314
diff
changeset
|
69 ("xdvi") ("dvipdfmx") ("pdftex") ("dvipsone") ("dviwindo") |
80 | 70 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin") |
71 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex")) | |
72 "Drivers alist of graphics/color stylefile's supporting deveces. | |
73 This list is taken from | |
74 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz | |
75 %% Copyright (C) 1995 1996 1997 1998 David Carlisle | |
76 as of 2004/1/19. Thanks.") | |
77 | |
78 | 78 (defvar YaTeX-package-alist-private nil |
79 "*User defined package vs. macro list. See also YaTeX-package-alist-default") | |
80 | |
81 (defun YaTeX-package-lookup (macro &optional type) | |
82 "Look up a package which contains a definition of MACRO. | |
83 Optional second argument TYPE limits the macro type. | |
84 TYPE is a symbol, one of 'env, 'section, 'maketitle." | |
85 (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
|
86 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
|
87 (setq origlist list) |
78 | 88 (while list |
89 (setq element (car list) | |
90 pkg (car element) | |
91 element (cdr element)) | |
304
a57f4c74179a
(yatexpkg)YaTeX-package-lookup sees 'same-as entry.
HIROSE Yuuji <yuuji@gentei.org>
parents:
303
diff
changeset
|
92 (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
|
93 (setq element (cdr (assoc (cdr sameas) origlist)))) |
78 | 94 (if (setq r (catch 'found |
95 (while element | |
80 | 96 (setq x (car element) |
97 val (cdr x)) | |
98 (if (symbolp val) (setq val (symbol-value val))) | |
99 (and (or (null type) | |
78 | 100 (eq type (car x))) |
80 | 101 (YaTeX-member macro val) |
78 | 102 (throw 'found (car x))) ;car x is type |
103 (setq element (cdr element))))) | |
104 (setq pkglist (cons (cons pkg r) pkglist))) | |
105 (setq list (cdr list))) | |
106 pkglist)) | |
107 | |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
108 (defun YaTeX-package-option-lookup (pkg &optional key) |
80 | 109 "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
|
110 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
|
111 (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
|
112 (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
|
113 (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
|
114 (cond |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
115 (recur (YaTeX-package-option-lookup recur key)) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
116 ((symbolp l) (symbol-value l)) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
117 (t l)))) |
80 | 118 |
78 | 119 (defvar YaTeX-package-resolved-list nil |
120 "List of macros whose package is confirmed to be loaded.") | |
121 | |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
122 (defun YaTeX-package-auto-usepackage (macro type &optional autopkg autoopt) |
78 | 123 "(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
|
124 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
|
125 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
|
126 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
|
127 a \\usepackage line." |
78 | 128 (let ((cb (current-buffer)) |
129 (wc (current-window-configuration)) | |
130 (usepackage (concat YaTeX-ec "usepackage")) | |
80 | 131 (pkglist (YaTeX-package-lookup macro type)) |
78 | 132 (usepkgrx (concat |
133 YaTeX-ec-regexp | |
134 "\\(usepackage\\|include\\)\\b")) | |
353
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
346
diff
changeset
|
135 (register (function |
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
346
diff
changeset
|
136 (lambda () (set-buffer cb) |
78 | 137 (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
|
138 (cons macro YaTeX-package-resolved-list))))) |
78 | 139 (begdoc (concat YaTeX-ec "begin{document}")) |
80 | 140 pb pkg optlist (option "") mb0 uspkgargs) |
78 | 141 (if (or (YaTeX-member macro YaTeX-package-resolved-list) |
142 (null pkglist)) | |
143 nil ;nothing to do | |
144 ;; Search `usepackage' into main-file | |
145 (YaTeX-visit-main t) ;set buffer to parent file | |
146 (setq pb (current-buffer)) | |
147 (save-excursion | |
148 (save-restriction | |
149 (if (catch 'found | |
150 (goto-char (point-min)) | |
151 (YaTeX-search-active-forward ;if search fails, goto eob | |
152 begdoc YaTeX-comment-prefix nil 1) | |
80 | 153 (while ;(YaTeX-re-search-active-backward |
154 ;usepkgrx YaTeX-comment-prefix nil t) | |
155 ;;allow commented out \usepackages 2004/3/16 | |
156 (re-search-backward usepkgrx nil t) | |
78 | 157 (setq mb0 (match-beginning 0)) |
158 (skip-chars-forward "^{") | |
80 | 159 (setq uspkgargs (YaTeX-buffer-substring |
160 (point) | |
161 (progn | |
162 ;;(forward-list 1) is more precise, | |
163 ;; but higher risk. | |
164 (skip-chars-forward "^}\n")(point)))) | |
78 | 165 (let ((pl pkglist)) |
166 (while pl ;(car pl)'s car is package, cdr is type | |
80 | 167 (if (string-match |
168 (concat "[{,]\\s *" | |
169 (regexp-quote (car (car pl))) | |
170 "\\>") | |
171 uspkgargs) | |
78 | 172 (throw 'found t)) |
173 (setq pl (cdr pl))) | |
174 (goto-char mb0)))) | |
175 ;;corresponding \usepackage found | |
176 (funcall register) | |
177 ;; 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
|
178 (if (or |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
179 autopkg |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
180 (y-or-n-p |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
181 (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
|
182 macro))) |
78 | 183 (progn |
80 | 184 (require 'yatexadd) |
78 | 185 (setq pkg |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
186 (or autopkg |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
187 (completing-read |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
188 "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
|
189 pkglist nil nil |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
190 ;;initial input |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
191 (if (= (length pkglist) 1) |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
192 (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
|
193 (if YaTeX-emacs-19 (cons w 0) w))))) |
80 | 194 optlist |
195 (YaTeX-package-option-lookup pkg)) | |
196 (if optlist | |
197 (let ((minibuffer-completion-table optlist) | |
303
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
198 (delim ",") (w (car (car optlist))) |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
199 (dflt (YaTeX-package-option-lookup |
13a62b7c8354
(yatexpkg)Add default option for package completion.
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
200 pkg 'default-option))) |
80 | 201 (setq option |
356
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
202 (or |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
203 autoopt |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
204 (read-from-minibuffer |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
205 (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
|
206 (let ((v (or dflt |
af0bd0f86b27
Now YaTeX-package-auto-usepackage can insert aline full-automaticaly
HIROSE Yuuji <yuuji@gentei.org>
parents:
353
diff
changeset
|
207 (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
|
208 (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
|
209 YaTeX-minibuffer-completion-map)) |
80 | 210 option (if (string< "" option) |
211 (concat "[" option "]") | |
212 "")))) | |
78 | 213 (set-buffer pb) |
214 (goto-char (point-min)) | |
215 (if (YaTeX-re-search-active-forward | |
216 (concat YaTeX-ec-regexp | |
217 "document\\(style\\|class\\){") | |
218 YaTeX-comment-prefix nil t) | |
219 (forward-line 1)) | |
220 (if (YaTeX-search-active-forward | |
221 begdoc YaTeX-comment-prefix nil t) | |
222 (goto-char (match-beginning 0))) | |
223 (insert | |
224 usepackage | |
80 | 225 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n" |
226 option pkg macro)) | |
78 | 227 (funcall register)) |
120
8772bd5d1f02
Do not ask again when user answer n to usepackage addition.
yuuji@gentei.org
parents:
80
diff
changeset
|
228 (funcall register) |
78 | 229 (message "Don't forget to put \\usepackage{%s} yourself later" |
230 (car (car pkglist)))) ;doing car car is negligence... | |
231 )))))) |