yatex

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