yatex

view yatexpkg.el @ 79:0734be649cb8

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