yatex

view yatexpkg.el @ 78:5b19f901fa16

Initial revision
author yuuji
date Fri, 02 May 2003 11:23:59 +0000
parents
children 0734be649cb8
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX package manager
3 ;;; yatexpkg.el
4 ;;; (c )2003 by HIROSE, Yuuji [yuuji@yatex.org]
5 ;;; Last modified Fri May 2 20:13:49 2003 on firestorm
6 ;;; $Id$
8 (defvar YaTeX-package-alist-default
9 '(("version" (env "comment")) ;by tsuchiya@pine.kuee.kyoto-u.ac.jp
11 ("plext" (section "bou")) ;by yas.axis@ma.mni.ne.jp
13 ("url" (section "url")) ;by fujieda@jaist.ac.jp
15 ("fancybox" (section "shadowbox" "doublebox" "ovalbox" "Ovalbox"))
16 ("pifont" (section "ding"))
17 ("longtable" (env "longtable"))
18 ("ascmac" (env "screen" "boxnote" "shadebox" "itembox")
19 (maketitle "return" "Return" "yen")
20 (section "keytop"))
21 ("bm" (section "bm")) ;by aoyama@le.chiba-u.ac.jp
23 ("graphicx" (section "includegraphics"))
24 ("alltt" (env "alltt"))
25 ("misc" (section "verbfile" "listing"))
26 ("eclbkbox" (env "breakbox")))
27 "Default package vs. macro list")
29 (defvar YaTeX-package-alist-private nil
30 "*User defined package vs. macro list. See also YaTeX-package-alist-default")
32 (defun YaTeX-package-lookup (macro &optional type)
33 "Look up a package which contains a definition of MACRO.
34 Optional second argument TYPE limits the macro type.
35 TYPE is a symbol, one of 'env, 'section, 'maketitle."
36 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
37 element x pkg pkglist r)
38 (while list
39 (setq element (car list)
40 pkg (car element)
41 element (cdr element))
42 (if (setq r (catch 'found
43 (while element
44 (setq x (car element))
45 (and (YaTeX-member macro (cdr x))
46 (or (null type)
47 (eq type (car x)))
48 (throw 'found (car x))) ;car x is type
49 (setq element (cdr element)))))
50 (setq pkglist (cons (cons pkg r) pkglist)))
51 (setq list (cdr list)))
52 pkglist))
54 (defvar YaTeX-package-resolved-list nil
55 "List of macros whose package is confirmed to be loaded.")
57 (defun YaTeX-package-auto-usepackage (macro type)
58 "(Semi)Automatically add the \\usepackage line to main-file.
59 Search the usepackage for MACRO of the TYPE."
60 (let ((cb (current-buffer))
61 (wc (current-window-configuration))
62 (usepackage (concat YaTeX-ec "usepackage"))
63 (pkglist (YaTeX-package-lookup macro))
64 (usepkgrx (concat
65 YaTeX-ec-regexp
66 "\\(usepackage\\|include\\)\\b"))
67 (register '(lambda () (set-buffer cb)
68 (set (make-local-variable 'YaTeX-package-resolved-list)
69 (cons macro YaTeX-package-resolved-list))))
70 (begdoc (concat YaTeX-ec "begin{document}"))
71 pb pkg mb0)
72 (if (or (YaTeX-member macro YaTeX-package-resolved-list)
73 (null pkglist))
74 nil ;nothing to do
75 ;; Search `usepackage' into main-file
76 (YaTeX-visit-main t) ;set buffer to parent file
77 (setq pb (current-buffer))
78 (save-excursion
79 (save-restriction
80 (if (catch 'found
81 (goto-char (point-min))
82 (YaTeX-search-active-forward ;if search fails, goto eob
83 begdoc YaTeX-comment-prefix nil 1)
84 (while (YaTeX-re-search-active-backward
85 usepkgrx YaTeX-comment-prefix nil t)
86 (setq mb0 (match-beginning 0))
87 (skip-chars-forward "^{")
88 (let ((pl pkglist))
89 (while pl ;(car pl)'s car is package, cdr is type
90 (if (looking-at (regexp-quote (car (car pl))))
91 (throw 'found t))
92 (setq pl (cdr pl)))
93 (goto-char mb0))))
94 ;;corresponding \usepackage found
95 (funcall register)
96 ;; not found, insert it.
97 (if (y-or-n-p
98 (format "`%s' requires package. Put \\usepackage now?" macro))
99 (progn
100 (setq pkg
101 (completing-read
102 "Load which package?(TAB for list): "
103 pkglist))
104 (set-buffer pb)
105 (goto-char (point-min))
106 (if (YaTeX-re-search-active-forward
107 (concat YaTeX-ec-regexp
108 "document\\(style\\|class\\){")
109 YaTeX-comment-prefix nil t)
110 (forward-line 1))
111 (if (YaTeX-search-active-forward
112 begdoc YaTeX-comment-prefix nil t)
113 (goto-char (match-beginning 0)))
114 (insert
115 usepackage
116 (format "{%s}\t%% required for `\\%s' (yatex added)\n"
117 pkg macro))
118 (funcall register))
119 (message "Don't forget to put \\usepackage{%s} yourself later"
120 (car (car pkglist)))) ;doing car car is negligence...
121 ))))))