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