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