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