yatex

diff yatexpkg.el @ 84:73cba5ddd111

Converted from RCS of yatex
author yuuji
date Sun, 27 Sep 2009 13:04:14 +0000
parents 0734be649cb8
children 8772bd5d1f02
line diff
     1.1 --- a/yatexpkg.el	Thu Dec 25 04:10:32 2003 +0000
     1.2 +++ b/yatexpkg.el	Sun Sep 27 13:04:14 2009 +0000
     1.3 @@ -1,10 +1,13 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; YaTeX package manager
     1.6  ;;; yatexpkg.el
     1.7 -;;; (c)2003 by HIROSE, Yuuji [yuuji@yatex.org]
     1.8 -;;; Last modified Thu Aug 28 18:24:33 2003 on firestorm
     1.9 +;;; (c)2003-2006 by HIROSE, Yuuji [yuuji@yatex.org]
    1.10 +;;; Last modified Sun Dec 24 15:13:29 2006 on firestorm
    1.11  ;;; $Id$
    1.12  
    1.13 +(defvar YaTeX-package-ams-envs
    1.14 +  (mapcar 'car YaTeX-ams-env-table))
    1.15 +
    1.16  (defvar YaTeX-package-alist-default
    1.17    '(("version"	(env "comment")		;by tsuchiya@pine.kuee.kyoto-u.ac.jp
    1.18       		(section "includeversion" "excludeversion"))
    1.19 @@ -14,6 +17,7 @@
    1.20      ("url"	(section "url"))	;by fujieda@jaist.ac.jp
    1.21  
    1.22      ("fancybox"	(section "shadowbox" "doublebox" "ovalbox" "Ovalbox"))
    1.23 +    ("slashbox"	(section "slashbox" "backslashbox"))
    1.24      ("pifont"	(section "ding"))
    1.25      ("longtable" (env "longtable"))
    1.26      ("ascmac"	(env "screen" "boxnote" "shadebox" "itembox")
    1.27 @@ -21,10 +25,20 @@
    1.28       		(section "keytop") ("mask") ("maskbox"))
    1.29      ("bm"	(section "bm"))		;by aoyama@le.chiba-u.ac.jp
    1.30  
    1.31 -    ("graphicx"	(section "includegraphics"))
    1.32      ("alltt"	(env "alltt"))
    1.33      ("misc"	(section "verbfile" "listing"))
    1.34 -    ("eclbkbox"	(env "breakbox")))
    1.35 +    ("eclbkbox"	(env "breakbox"))
    1.36 +    ("supertabular" (env "supertabular"))
    1.37 +    ("amsmath"	(env . YaTeX-package-ams-envs)
    1.38 +     		(section "tag" "tag*"))
    1.39 +    ("graphicx" (section "includegraphics"
    1.40 +			 "rotatebox" "scalebox" "resizebox" "reflectbox")
    1.41 +     		(option . YaTeX-package-graphics-driver-alist))
    1.42 +    ("color"	(section "textcolor" "colorbox" "pagecolor" "color")
    1.43 +     		(option . YaTeX-package-graphics-driver-alist))
    1.44 +    ("ulem"	(section "uline" "uuline" "uwave")
    1.45 +		(option ("normalem")))
    1.46 +    ("multicol"	(env "multicols")))
    1.47    "Default package vs. macro list.
    1.48  Alists contains '(PACKAGENAME . MACROLIST)
    1.49  PACKAGENAME     Basename of package(String).
    1.50 @@ -32,8 +46,21 @@
    1.51  TYPE	One of 'env, 'section or 'maketitle according to completion-type
    1.52  MACROS	List of macros
    1.53  
    1.54 +If TYPE is 'option, its cdr is alist of completion candidates for that
    1.55 +package.  Its cdr can be a symbol whose value is alist.
    1.56 +
    1.57  An good example is the value of YaTeX-package-alist-default.")
    1.58  
    1.59 +(defvar YaTeX-package-graphics-driver-alist
    1.60 +  '(("dvips") ("xdvi") ("dvipdf") ("pdftex") ("dvipsone") ("dviwindo")
    1.61 +    ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin")
    1.62 +    ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex"))
    1.63 +  "Drivers alist of graphics/color stylefile's supporting deveces.
    1.64 +This list is taken from
    1.65 +%% graphics.dtx Copyright (C) 1994      David Carlisle Sebastian Rahtz
    1.66 +%%              Copyright (C) 1995 1996 1997 1998 David Carlisle
    1.67 +as of 2004/1/19.  Thanks.")
    1.68 +
    1.69  (defvar YaTeX-package-alist-private nil
    1.70    "*User defined package vs. macro list. See also YaTeX-package-alist-default")
    1.71  
    1.72 @@ -42,23 +69,33 @@
    1.73  Optional second argument TYPE limits the macro type.
    1.74  TYPE is a symbol, one of 'env, 'section, 'maketitle."
    1.75    (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
    1.76 -	element x pkg pkglist r)
    1.77 +	element x val pkg pkglist r)
    1.78      (while list
    1.79        (setq element (car list)
    1.80  	    pkg (car element)
    1.81  	    element (cdr element))
    1.82        (if (setq r (catch 'found
    1.83  		    (while element
    1.84 -		      (setq x (car element))
    1.85 -		      (and (YaTeX-member macro (cdr x))
    1.86 -			   (or (null type)
    1.87 +		      (setq x (car element)
    1.88 +			    val (cdr x))
    1.89 +		      (if (symbolp val) (setq val (symbol-value val)))
    1.90 +		      (and (or (null type)
    1.91  			       (eq type (car x)))
    1.92 +			   (YaTeX-member macro val)
    1.93  			   (throw 'found (car x)))	;car x is type
    1.94  		      (setq element (cdr element)))))
    1.95  	  (setq pkglist (cons (cons pkg r) pkglist)))
    1.96        (setq list (cdr list)))
    1.97      pkglist))
    1.98  
    1.99 +(defun YaTeX-package-option-lookup (pkg)
   1.100 +  "Look up options for specified pkg and returne them in alist form.
   1.101 +Just only accocing against the alist of YaTeX-package-alist-*"
   1.102 +  (let ((l (cdr (assq 'option
   1.103 +		      (assoc pkg (append YaTeX-package-alist-private
   1.104 +					 YaTeX-package-alist-default))))))
   1.105 +    (if (symbolp l) (symbol-value l) l)))
   1.106 +
   1.107  (defvar YaTeX-package-resolved-list nil
   1.108    "List of macros whose package is confirmed to be loaded.")
   1.109  
   1.110 @@ -68,7 +105,7 @@
   1.111    (let ((cb (current-buffer))
   1.112  	(wc (current-window-configuration))
   1.113  	(usepackage (concat YaTeX-ec "usepackage"))
   1.114 -	(pkglist (YaTeX-package-lookup macro))
   1.115 +	(pkglist (YaTeX-package-lookup macro type))
   1.116  	(usepkgrx (concat
   1.117  		   YaTeX-ec-regexp
   1.118  		   "\\(usepackage\\|include\\)\\b"))
   1.119 @@ -76,7 +113,7 @@
   1.120  		     (set (make-local-variable 'YaTeX-package-resolved-list)
   1.121  			  (cons macro YaTeX-package-resolved-list))))
   1.122  	(begdoc (concat YaTeX-ec "begin{document}"))
   1.123 -	pb pkg mb0)
   1.124 +	pb pkg optlist (option "") mb0 uspkgargs)
   1.125      (if (or (YaTeX-member macro YaTeX-package-resolved-list)
   1.126  	    (null pkglist))
   1.127  	nil				;nothing to do
   1.128 @@ -89,14 +126,25 @@
   1.129  		(goto-char (point-min))
   1.130  		(YaTeX-search-active-forward	;if search fails, goto eob
   1.131  		 begdoc YaTeX-comment-prefix nil 1)
   1.132 -		(while (YaTeX-re-search-active-backward
   1.133 -			usepkgrx YaTeX-comment-prefix nil t)
   1.134 +		(while ;(YaTeX-re-search-active-backward
   1.135 +			;usepkgrx YaTeX-comment-prefix nil t)
   1.136 +		    ;;allow commented out \usepackages 2004/3/16
   1.137 +		    (re-search-backward usepkgrx nil t)
   1.138  		  (setq mb0 (match-beginning 0))
   1.139  		  (skip-chars-forward "^{")
   1.140 -		  (forward-char 1)
   1.141 +		  (setq uspkgargs (YaTeX-buffer-substring
   1.142 +				   (point)
   1.143 +				   (progn
   1.144 +				     ;;(forward-list 1) is more precise,
   1.145 +				     ;; but higher risk.
   1.146 +				     (skip-chars-forward "^}\n")(point))))
   1.147  		  (let ((pl pkglist))
   1.148  		    (while pl		;(car pl)'s car is package, cdr is type
   1.149 -		      (if (looking-at (regexp-quote (car (car pl))))
   1.150 +		      (if (string-match
   1.151 +			   (concat "[{,]\\s *"
   1.152 +				   (regexp-quote (car (car pl)))
   1.153 +				   "\\>")
   1.154 +			   uspkgargs)
   1.155  			  (throw 'found t))
   1.156  		      (setq pl (cdr pl)))
   1.157  		    (goto-char mb0))))
   1.158 @@ -106,6 +154,7 @@
   1.159  	    (if (y-or-n-p
   1.160  		 (format "`%s' requires package. Put \\usepackage now?" macro))
   1.161  		(progn
   1.162 +		  (require 'yatexadd)
   1.163  		  (setq pkg
   1.164  			(completing-read
   1.165  			 "Load which package?(TAB for list): "
   1.166 @@ -113,7 +162,21 @@
   1.167  			 ;;initial input
   1.168  			 (if (= (length pkglist) 1)
   1.169  			     (let ((w (car (car pkglist))))
   1.170 -			       (if YaTeX-emacs-19 (cons w 0) w)))))
   1.171 +			       (if YaTeX-emacs-19 (cons w 0) w))))
   1.172 +			optlist
   1.173 +			(YaTeX-package-option-lookup pkg))
   1.174 +		  (if optlist
   1.175 +		      (let ((minibuffer-completion-table optlist)
   1.176 +			    (delim ",") (w (car (car optlist))))
   1.177 +			(setq option
   1.178 +			      (read-from-minibuffer
   1.179 +			       (format "Any option for {%s}?: " pkg)
   1.180 +			       (if (= (length optlist) 1)
   1.181 +				   (if YaTeX-emacs-19 (cons w 0) w))
   1.182 +			       YaTeX-minibuffer-completion-map)
   1.183 +			      option (if (string< "" option)
   1.184 +					 (concat "[" option "]")
   1.185 +				       ""))))
   1.186  		  (set-buffer pb)
   1.187  		  (goto-char (point-min))
   1.188  		  (if (YaTeX-re-search-active-forward
   1.189 @@ -126,8 +189,8 @@
   1.190  		      (goto-char (match-beginning 0)))
   1.191  		  (insert
   1.192  		   usepackage
   1.193 -		   (format "{%s}\t%% required for `\\%s' (yatex added)\n"
   1.194 -			   pkg macro))
   1.195 +		   (format "%s{%s}\t%% required for `\\%s' (yatex added)\n"
   1.196 +			   option pkg macro))
   1.197  		  (funcall register))
   1.198  	      (message "Don't forget to put \\usepackage{%s} yourself later"
   1.199  		       (car (car pkglist)))) ;doing car car is negligence...