Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexpkg.el @ 91:801593454c59 current start-branch-for-1.75
MVER=1.74 (but not used recently)
author | yuuji@gentei.org |
---|---|
date | Mon, 28 Sep 2009 12:18:36 +0900 |
parents | 9b4354af748c |
children | 8772bd5d1f02 |
rev | line source |
---|---|
78 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX package manager | |
3 ;;; yatexpkg.el | |
80 | 4 ;;; (c)2003-2006 by HIROSE, Yuuji [yuuji@yatex.org] |
5 ;;; Last modified Sun Dec 24 15:13:29 2006 on firestorm | |
78 | 6 ;;; $Id$ |
7 | |
80 | 8 (defvar YaTeX-package-ams-envs |
9 (mapcar 'car YaTeX-ams-env-table)) | |
10 | |
78 | 11 (defvar YaTeX-package-alist-default |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
12 '(("version" (env "comment") ;by tsuchiya@pine.kuee.kyoto-u.ac.jp |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
13 (section "includeversion" "excludeversion")) |
78 | 14 |
15 ("plext" (section "bou")) ;by yas.axis@ma.mni.ne.jp | |
16 | |
17 ("url" (section "url")) ;by fujieda@jaist.ac.jp | |
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")) |
78 | 26 ("bm" (section "bm")) ;by aoyama@le.chiba-u.ac.jp |
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*")) | |
34 ("graphicx" (section "includegraphics" | |
35 "rotatebox" "scalebox" "resizebox" "reflectbox") | |
36 (option . YaTeX-package-graphics-driver-alist)) | |
37 ("color" (section "textcolor" "colorbox" "pagecolor" "color") | |
38 (option . YaTeX-package-graphics-driver-alist)) | |
39 ("ulem" (section "uline" "uuline" "uwave") | |
40 (option ("normalem"))) | |
41 ("multicol" (env "multicols"))) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
42 "Default package vs. macro list. |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
43 Alists contains '(PACKAGENAME . MACROLIST) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
44 PACKAGENAME Basename of package(String). |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
45 MACROLIST List of '(TYPE . MACROS) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
46 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
|
47 MACROS List of macros |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
48 |
80 | 49 If TYPE is 'option, its cdr is alist of completion candidates for that |
50 package. Its cdr can be a symbol whose value is alist. | |
51 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
52 An good example is the value of YaTeX-package-alist-default.") |
78 | 53 |
80 | 54 (defvar YaTeX-package-graphics-driver-alist |
55 '(("dvips") ("xdvi") ("dvipdf") ("pdftex") ("dvipsone") ("dviwindo") | |
56 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin") | |
57 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex")) | |
58 "Drivers alist of graphics/color stylefile's supporting deveces. | |
59 This list is taken from | |
60 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz | |
61 %% Copyright (C) 1995 1996 1997 1998 David Carlisle | |
62 as of 2004/1/19. Thanks.") | |
63 | |
78 | 64 (defvar YaTeX-package-alist-private nil |
65 "*User defined package vs. macro list. See also YaTeX-package-alist-default") | |
66 | |
67 (defun YaTeX-package-lookup (macro &optional type) | |
68 "Look up a package which contains a definition of MACRO. | |
69 Optional second argument TYPE limits the macro type. | |
70 TYPE is a symbol, one of 'env, 'section, 'maketitle." | |
71 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default)) | |
80 | 72 element x val pkg pkglist r) |
78 | 73 (while list |
74 (setq element (car list) | |
75 pkg (car element) | |
76 element (cdr element)) | |
77 (if (setq r (catch 'found | |
78 (while element | |
80 | 79 (setq x (car element) |
80 val (cdr x)) | |
81 (if (symbolp val) (setq val (symbol-value val))) | |
82 (and (or (null type) | |
78 | 83 (eq type (car x))) |
80 | 84 (YaTeX-member macro val) |
78 | 85 (throw 'found (car x))) ;car x is type |
86 (setq element (cdr element))))) | |
87 (setq pkglist (cons (cons pkg r) pkglist))) | |
88 (setq list (cdr list))) | |
89 pkglist)) | |
90 | |
80 | 91 (defun YaTeX-package-option-lookup (pkg) |
92 "Look up options for specified pkg and returne them in alist form. | |
93 Just only accocing against the alist of YaTeX-package-alist-*" | |
94 (let ((l (cdr (assq 'option | |
95 (assoc pkg (append YaTeX-package-alist-private | |
96 YaTeX-package-alist-default)))))) | |
97 (if (symbolp l) (symbol-value l) l))) | |
98 | |
78 | 99 (defvar YaTeX-package-resolved-list nil |
100 "List of macros whose package is confirmed to be loaded.") | |
101 | |
102 (defun YaTeX-package-auto-usepackage (macro type) | |
103 "(Semi)Automatically add the \\usepackage line to main-file. | |
104 Search the usepackage for MACRO of the TYPE." | |
105 (let ((cb (current-buffer)) | |
106 (wc (current-window-configuration)) | |
107 (usepackage (concat YaTeX-ec "usepackage")) | |
80 | 108 (pkglist (YaTeX-package-lookup macro type)) |
78 | 109 (usepkgrx (concat |
110 YaTeX-ec-regexp | |
111 "\\(usepackage\\|include\\)\\b")) | |
112 (register '(lambda () (set-buffer cb) | |
113 (set (make-local-variable 'YaTeX-package-resolved-list) | |
114 (cons macro YaTeX-package-resolved-list)))) | |
115 (begdoc (concat YaTeX-ec "begin{document}")) | |
80 | 116 pb pkg optlist (option "") mb0 uspkgargs) |
78 | 117 (if (or (YaTeX-member macro YaTeX-package-resolved-list) |
118 (null pkglist)) | |
119 nil ;nothing to do | |
120 ;; Search `usepackage' into main-file | |
121 (YaTeX-visit-main t) ;set buffer to parent file | |
122 (setq pb (current-buffer)) | |
123 (save-excursion | |
124 (save-restriction | |
125 (if (catch 'found | |
126 (goto-char (point-min)) | |
127 (YaTeX-search-active-forward ;if search fails, goto eob | |
128 begdoc YaTeX-comment-prefix nil 1) | |
80 | 129 (while ;(YaTeX-re-search-active-backward |
130 ;usepkgrx YaTeX-comment-prefix nil t) | |
131 ;;allow commented out \usepackages 2004/3/16 | |
132 (re-search-backward usepkgrx nil t) | |
78 | 133 (setq mb0 (match-beginning 0)) |
134 (skip-chars-forward "^{") | |
80 | 135 (setq uspkgargs (YaTeX-buffer-substring |
136 (point) | |
137 (progn | |
138 ;;(forward-list 1) is more precise, | |
139 ;; but higher risk. | |
140 (skip-chars-forward "^}\n")(point)))) | |
78 | 141 (let ((pl pkglist)) |
142 (while pl ;(car pl)'s car is package, cdr is type | |
80 | 143 (if (string-match |
144 (concat "[{,]\\s *" | |
145 (regexp-quote (car (car pl))) | |
146 "\\>") | |
147 uspkgargs) | |
78 | 148 (throw 'found t)) |
149 (setq pl (cdr pl))) | |
150 (goto-char mb0)))) | |
151 ;;corresponding \usepackage found | |
152 (funcall register) | |
153 ;; not found, insert it. | |
154 (if (y-or-n-p | |
155 (format "`%s' requires package. Put \\usepackage now?" macro)) | |
156 (progn | |
80 | 157 (require 'yatexadd) |
78 | 158 (setq pkg |
159 (completing-read | |
160 "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
|
161 pkglist nil nil |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
162 ;;initial input |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
163 (if (= (length pkglist) 1) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
164 (let ((w (car (car pkglist)))) |
80 | 165 (if YaTeX-emacs-19 (cons w 0) w)))) |
166 optlist | |
167 (YaTeX-package-option-lookup pkg)) | |
168 (if optlist | |
169 (let ((minibuffer-completion-table optlist) | |
170 (delim ",") (w (car (car optlist)))) | |
171 (setq option | |
172 (read-from-minibuffer | |
173 (format "Any option for {%s}?: " pkg) | |
174 (if (= (length optlist) 1) | |
175 (if YaTeX-emacs-19 (cons w 0) w)) | |
176 YaTeX-minibuffer-completion-map) | |
177 option (if (string< "" option) | |
178 (concat "[" option "]") | |
179 "")))) | |
78 | 180 (set-buffer pb) |
181 (goto-char (point-min)) | |
182 (if (YaTeX-re-search-active-forward | |
183 (concat YaTeX-ec-regexp | |
184 "document\\(style\\|class\\){") | |
185 YaTeX-comment-prefix nil t) | |
186 (forward-line 1)) | |
187 (if (YaTeX-search-active-forward | |
188 begdoc YaTeX-comment-prefix nil t) | |
189 (goto-char (match-beginning 0))) | |
190 (insert | |
191 usepackage | |
80 | 192 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n" |
193 option pkg macro)) | |
78 | 194 (funcall register)) |
195 (message "Don't forget to put \\usepackage{%s} yourself later" | |
196 (car (car pkglist)))) ;doing car car is negligence... | |
197 )))))) |