yatex

changeset 82:d84447b92eca

1.73
author yuuji
date Sun, 24 Dec 2006 06:24:55 +0000
parents dacfb49eec6e
children 680d92784c1a
files yatex.el
diffstat 1 files changed, 340 insertions(+), 137 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Sun Dec 24 06:21:09 2006 +0000
     1.2 +++ b/yatex.el	Sun Dec 24 06:24:55 2006 +0000
     1.3 @@ -1,15 +1,15 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; Yet Another tex-mode for emacs - //野鳥//
     1.6 -;;; yatex.el rev. 1.72
     1.7 -;;; (c)1991-2003 by HIROSE Yuuji.[yuuji@yatex.org]
     1.8 -;;; Last modified Thu Dec 25 13:10:42 2003 on firestorm
     1.9 +;;; yatex.el rev. 1.73
    1.10 +;;; (c)1991-2006 by HIROSE Yuuji.[yuuji@yatex.org]
    1.11 +;;; Last modified Sun Dec 24 15:12:43 2006 on firestorm
    1.12  ;;; $Id$
    1.13  ;;; The latest version of this software is always available at;
    1.14  ;;; http://www.yatex.org/
    1.15  
    1.16  (require 'comment)
    1.17  (require 'yatexlib)
    1.18 -(defconst YaTeX-revision-number "1.72"
    1.19 +(defconst YaTeX-revision-number "1.73"
    1.20    "Revision number of running yatex.el")
    1.21  
    1.22  ;---------- Local variables ----------
    1.23 @@ -108,10 +108,6 @@
    1.24    Remember Demacs's call-process function is not oriented for interactive
    1.25  process.")
    1.26  
    1.27 -(defvar latex-message-kanji-code 2
    1.28 -  "*Kanji coding system latex command types out.
    1.29 -1 = Shift JIS, 2 = JIS, 3 = EUC.")
    1.30 -
    1.31  (defvar NTT-jTeX nil
    1.32    "*T for using NTT-jTeX for latex command.
    1.33  More precisely, setting t to this variables inhibits inter-word break on
    1.34 @@ -207,6 +203,9 @@
    1.35  			       (not YaTeX-use-font-lock))
    1.36    "*Use hilit19 to highlight buffer or not.")
    1.37  
    1.38 +(defvar YaTeX-tabular-indentation 4
    1.39 +  "*Indentation column-depth of continueing line in tabular environment.")
    1.40 +
    1.41  ;;-- Math mode values --
    1.42  
    1.43  (defvar YaTeX-math-key-list-default
    1.44 @@ -249,13 +248,15 @@
    1.45       ("footnote") ("footnotetext") ("index")
    1.46       ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite")
    1.47       ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption")
    1.48 +     ("arabic")
    1.49 +     ("newcounter")
    1.50       ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2)
    1.51       ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2)
    1.52       ("newcommand" 2) ("renewcommand" 2)
    1.53 -     ("setcounter" 2) ("newenvironment" 3) ("newtheorem" 2)
    1.54 +     ("newenvironment" 3) ("newtheorem" 2)
    1.55       ("cline") ("framebox") ("savebox" 2) ("sbox" 2) ("newsavebox") ("usebox")
    1.56 -     ("date") ("put") ("ref") ("pageref")
    1.57 -     ("multicolumn" 3) ("shortstack")
    1.58 +     ("date") ("put") ("ref") ("pageref") ("tabref") ("figref") ("raisebox" 2)
    1.59 +     ("multicolumn" 3) ("shortstack") ("parbox" 2)
    1.60       ;; for mathmode accent
    1.61       ("tilde") ("hat") ("check") ("bar") ("dot") ("ddot") ("vec")
    1.62       ("widetilde") ("widehat") ("overline") ("overrightarrow")
    1.63 @@ -269,9 +270,10 @@
    1.64  	 ("textrm") ("textsc") ("textsf") ("textsl") ("texttt") ("textup")
    1.65  	 ("mathbf") ("mathcal") ("mathit") ("mathnormal") ("mathrm")
    1.66  	 ("mathsf") ("mathtt")
    1.67 +	 ("textcircled")
    1.68  	 ("scalebox" 1) ;is faking of argument position
    1.69 -	 ("rotatebox" 2) ("resizebox" 2) ("reflectbox")
    1.70 -	 ("colorbox" 2) ("fcolorbox" 3) ("textcolor" 2) ("color")
    1.71 +	 ("rotatebox" 2) ("resizebox" 3) ("reflectbox")
    1.72 +	 ("colorbox" 2) ("fcolorbox" 3) ("textcolor" 2) ("color") ("pagecolor")
    1.73  	 ("includegraphics") ("includegraphics*")
    1.74  	 ("bou")			;defined in plext
    1.75  	 ("url")			;defined in url
    1.76 @@ -280,11 +282,33 @@
    1.77  	 ("keytop") ("mask" 2) ("maskbox" 5) ;defined in ascmac
    1.78  	 ("bm")				;deined in bm
    1.79  	 ("verbfile") ("listing")	;defined in misc
    1.80 -	 )))
    1.81 +	 ("slashbox" 2) ("backslashbox" 2) ;defined in slashbox
    1.82 +	 ))
    1.83 +   (if YaTeX-use-AMS-LaTeX
    1.84 +       '(("DeclareMathOperator" 2) ("boldsymbol") ("pmb") ("eqref")
    1.85 +	 ("tag") ("tag*"))))
    1.86    "Default completion table for section-type completion.")
    1.87  
    1.88  (defvar user-section-table nil)
    1.89  (defvar tmp-section-table nil)
    1.90 +(defvar YaTeX-ams-math-begin-alist
    1.91 +  '(("align") ("align*") ("multline") ("multline*") ("gather") ("gather*")
    1.92 +    ("alignat") ("alignat*") ("xalignat") ("xalignat*")
    1.93 +    ("xxalignat") ("xxalignat*") ("flalign") ("flalign*") ("equation*")))
    1.94 +(defvar YaTeX-ams-math-gathering-alist
    1.95 +  '(("matrix") ("pmatrix") ("bmatrix") ("Bmatrix") ("vmatrix") ("Vmatrix")
    1.96 +    ("split") ("split*") ("aligned") ("aligned*") ("alignedat") ("gathered")
    1.97 +    ("smallmatrix") ("cases") ("subequations")))
    1.98 +;; Prepare list(not alist) for YaTeX::ref in yatexadd.el
    1.99 +(defvar YaTeX-math-begin-list
   1.100 +  (mapcar 'car YaTeX-ams-math-begin-alist))
   1.101 +(defvar YaTeX-math-gathering-list	;used in yatexadd.el#yatex::ref
   1.102 +  (mapcar 'car YaTeX-ams-math-gathering-alist))
   1.103 +
   1.104 +
   1.105 +(defvar YaTeX-ams-env-table
   1.106 +  (append YaTeX-ams-math-begin-alist YaTeX-ams-math-gathering-alist)
   1.107 +  "*Standard AMS-LaTeX(2e) environment completion table.")
   1.108  
   1.109  ; Set tex-environment possible completion
   1.110  (defvar env-table
   1.111 @@ -296,13 +320,16 @@
   1.112       ("eqnarray") ("figure") ("equation") ("abstract") ("array")
   1.113       ("thebibliography") ("theindex") ("flushleft") ("flushright")
   1.114       ("minipage")
   1.115 +     ("supertabular")
   1.116       )
   1.117     (if YaTeX-use-LaTeX2e
   1.118         '(("comment")			;defined in version
   1.119  	 ("longtable")			;defined in longtable
   1.120 -	 ("screen") ("boxnote") ("shadebox") ("itembox") ;in ascmac
   1.121 +	 ("screen") ("boxnote") ("shadebox") ;; ("itembox") ;in ascmac
   1.122  	 ("alltt")			;defined in alltt
   1.123 -	 ("breakbox"))))			;defined in eclbkbox
   1.124 +	 ("multicols")			;defined in multicol
   1.125 +	 ("breakbox")))			;defined in eclbkbox
   1.126 +   (if YaTeX-use-AMS-LaTeX YaTeX-ams-env-table))
   1.127    "Default completion table for begin-type completion.")
   1.128  
   1.129  (defvar user-env-table nil)
   1.130 @@ -344,6 +371,7 @@
   1.131       ("footnotemark") ("verb") ("verb*")
   1.132       ("linebreak") ("pagebreak") ("noindent") ("indent")
   1.133       ("left") ("right") ("dots") ("smallskip") ("medskip") ("bigskip")
   1.134 +     ("displaystyle")
   1.135       )
   1.136     (if YaTeX-greek-by-maketitle-completion
   1.137         '(("alpha") ("beta") ("gamma") ("delta") ("epsilon")
   1.138 @@ -354,7 +382,8 @@
   1.139  	 ("Gamma") ("Delta") ("Theta") ("Lambda")("Xi") ("Pi")
   1.140  	 ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")))
   1.141     (if YaTeX-use-LaTeX2e
   1.142 -       '(("return") ("Return") ("yen"))))	;defined in ascmac
   1.143 +       '(("return") ("Return") ("yen")))	;defined in ascmac
   1.144 +   )
   1.145    "Default completion table for maketitle-type completion.")
   1.146  
   1.147  (defvar user-singlecmd-table nil)
   1.148 @@ -469,16 +498,12 @@
   1.149    (YaTeX-define-key "d" 'YaTeX-display-hierarchy)
   1.150    (YaTeX-define-key "x" YaTeX-user-extensional-map)
   1.151    (YaTeX-define-key "n"
   1.152 -    '(lambda () (interactive) (insert "\\\\")))
   1.153 +    '(lambda () (interactive)
   1.154 +       (insert "\\" (if (YaTeX-on-section-command-p "o?oalign") "crcr" "\\"))))
   1.155    (if YaTeX-dos
   1.156        (define-key YaTeX-prefix-map "\C-r"
   1.157  	'(lambda () (interactive)
   1.158 -	   (set-screen-height YaTeX-saved-screen-height) (recenter))))
   1.159 -  (mapcar
   1.160 -   (function
   1.161 -    (lambda (key)
   1.162 -      (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)))
   1.163 -   YaTeX-math-key-list))
   1.164 +	   (set-screen-height YaTeX-saved-screen-height) (recenter)))))
   1.165  
   1.166  (defvar YaTeX-section-completion-map nil
   1.167    "*Key map used at YaTeX completion in the minibuffer.")
   1.168 @@ -498,8 +523,13 @@
   1.169    "*Key map used at YaTeX reading arguments in the minibuffer.")
   1.170  (if YaTeX-recursive-map nil
   1.171    (setq YaTeX-recursive-map (copy-keymap global-map))
   1.172 -  (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map))
   1.173 -
   1.174 +  (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map)
   1.175 +  (mapcar
   1.176 +   (function
   1.177 +    (lambda (key)
   1.178 +      (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)
   1.179 +      (define-key YaTeX-recursive-map (car key) 'YaTeX-math-insert-sequence)))
   1.180 +   YaTeX-math-key-list))
   1.181  ;---------- Define other variable ----------
   1.182  (defvar YaTeX-env-name "document" "*Initial tex-environment completion")
   1.183  (defvar YaTeX-section-name
   1.184 @@ -623,6 +653,7 @@
   1.185  	 (setq buffer-file-coding-system
   1.186  	       (or (and (fboundp 'set-auto-coding) buffer-file-name
   1.187  			(save-excursion
   1.188 +			  (goto-char (point-min))
   1.189  			  (set-auto-coding buffer-file-name (buffer-size))))
   1.190  		   YaTeX-coding-system)))
   1.191  	((featurep 'mule)
   1.192 @@ -675,9 +706,11 @@
   1.193  (defvar YaTeX-struct-name-regexp "[^}]+"
   1.194    "Environment name regexp.")
   1.195  (defvar YaTeX-TeX-token-regexp
   1.196 -  (cond (YaTeX-japan "[A-Za-z*あ-ん亜-龠]+")
   1.197 +  (cond (YaTeX-japan "[A-Za-z*ぁ-ん亜-龠]+")
   1.198  	(t "[A-Za-z*]+"))
   1.199    "Regexp of characters which can be a member of TeX command's name.")
   1.200 +(defvar YaTeX-kanji-regexp "[ぁ-ん亜-龠]"
   1.201 +  "Generic regexp of Japanese Kanji (and symbol) characters.")
   1.202  (defvar YaTeX-command-token-regexp YaTeX-TeX-token-regexp
   1.203    "Regexp of characters which can be a member of current mark up language's command name.")
   1.204  
   1.205 @@ -825,7 +858,7 @@
   1.206  	  (if YaTeX-use-LaTeX2e "documentclass" "documentstyle"))
   1.207  	 ((progn
   1.208  	    (if (= (char-after (1- (point))) ?~) (forward-char -1))
   1.209 -	    (forward-char -1) (looking-at "表\\|図\\|式"))
   1.210 +	    (forward-char -1) (looking-at "表\\|図\\|式\\|第"))
   1.211  	  "ref")
   1.212  	 ((and (looking-at "[a-z \t]")
   1.213  	       (progn (skip-chars-backward "a-z \t")
   1.214 @@ -895,7 +928,24 @@
   1.215  	   (title "")
   1.216  	   (j 1)
   1.217  	   (after-change-functions nil)	;inhibit font-locking temporarily
   1.218 -	   (enable-recursive-minibuffers t));;let
   1.219 +	   (enable-recursive-minibuffers t)
   1.220 +	   (mkarg-func
   1.221 +	    (function
   1.222 +	     (lambda (n)
   1.223 +	       (while (<= j n)
   1.224 +		 (insert
   1.225 +		  (concat		;to allow nil return value
   1.226 +		   "{"
   1.227 +		   (setq title
   1.228 +			 (cond
   1.229 +			  (addin-args (funcall arg-reader j))
   1.230 +			  (YaTeX-skip-default-reader "")
   1.231 +			  (t
   1.232 +			   (read-string
   1.233 +			    (format "Argument %d of %s: " j section)))))
   1.234 +		   "}"))
   1.235 +		 (setq j (1+ j))))))
   1.236 +	   );;let
   1.237  	(setq YaTeX-section-name section)
   1.238  	(if beg
   1.239  	    (let*((e (make-marker))
   1.240 @@ -905,7 +955,10 @@
   1.241  	      (insert "}")
   1.242  	      (set-marker e (point))
   1.243  	      (goto-char beg)
   1.244 -	      (insert YaTeX-ec YaTeX-section-name "{")
   1.245 +	      (insert YaTeX-ec YaTeX-section-name
   1.246 +		      (YaTeX-addin YaTeX-section-name))
   1.247 +	      (if (> numarg 1) (funcall mkarg-func (1- numarg)))
   1.248 +	      (insert "{")
   1.249  	      (if arp (funcall ar2 (point) e))
   1.250  	      (goto-char e)
   1.251  	      (set-marker e nil))
   1.252 @@ -913,17 +966,8 @@
   1.253  	  (if (= numarg 0) (YaTeX-make-singlecmd YaTeX-section-name)
   1.254  	    (progn (insert YaTeX-ec YaTeX-section-name)
   1.255  		   (insert (YaTeX-addin YaTeX-section-name))))
   1.256 -	  (while (<= j numarg)
   1.257 -	    (insert
   1.258 -	     "{"
   1.259 -	     (setq title
   1.260 -		   (cond
   1.261 -		    (addin-args (funcall arg-reader j))
   1.262 -		    (YaTeX-skip-default-reader "")
   1.263 -		    (t
   1.264 -		     (read-string (format "Argument %d of %s: " j section)))))
   1.265 -	     "}")
   1.266 -	    (setq j (1+ j))))
   1.267 +	  ;;read arguments with add-in
   1.268 +	  (funcall mkarg-func numarg))
   1.269  	(YaTeX-update-table
   1.270  	 (if (/= numarg 1) (list section numarg)
   1.271  	   (list section))
   1.272 @@ -1076,7 +1120,7 @@
   1.273  	    (ding))
   1.274  	   ((eq completion t) (message "Sole completion."))
   1.275  	   ((not (string= completion pattern))
   1.276 -	    (kill-region begin end)
   1.277 +	    (delete-region begin end)
   1.278  	    (insert completion)
   1.279  	    )
   1.280  	   (t
   1.281 @@ -1483,7 +1527,13 @@
   1.282    If optional second argument OTHERWIN is non-nil, move to other window."
   1.283  
   1.284    (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
   1.285 -	(refcommands "label\\|\\(page\\)?ref\\|cite\\|bibitem")
   1.286 +	(refcommands "label\\|\\(page\\|eq\\)?ref\\|cite\\|bibitem")
   1.287 +	(foundmsg (format "Type %s %c to return to original position."
   1.288 +			  (key-description
   1.289 +			   (car
   1.290 +			    (or (where-is-internal 'register-to-point)
   1.291 +				(where-is-internal 'jump-to-register))))
   1.292 +			  YaTeX-current-position-register))
   1.293  	(func (function (lambda (string sfunc)
   1.294  			  (or
   1.295  			   (funcall sfunc string nil t)
   1.296 @@ -1492,16 +1542,31 @@
   1.297  				    string nil t))))))
   1.298      (cond
   1.299       ((YaTeX-on-section-command-p refcommands)
   1.300 -      (setq scmd (cdr (assoc (YaTeX-match-string 1)
   1.301 -			     '(("label" . "\\(page\\)?ref") ("ref" . "label")
   1.302 -			       ("pageref" . "label")
   1.303 -			       ("cite" . "bibitem\\(\\[[^]]+\\]\\)?")
   1.304 -			       ("bibitem" . "cite\\(\\[[^]]+\\]\\)?")))))
   1.305 +      (setq scmd
   1.306 +	    (cdr
   1.307 +	     (assoc
   1.308 +	      (YaTeX-match-string 1)
   1.309 +	      '(("label" . "\\\\\\(page\\|eq\\)?ref{%k}")
   1.310 +		("ref" . "\\\\label{%k}")
   1.311 +		("eqref" . "\\\\label{%k}")
   1.312 +		("pageref" . "\\\\label{%k}")
   1.313 +		("cite" .
   1.314 +		 "\\\\bibitem\\(\\[[^]]+\\]\\)?{%k}\\|^\\s *@[a-z]+{%k,")
   1.315 +		("bibitem" . "\\\\cite\\(\\[[^]]+\\]\\)?")))))
   1.316        (goto-char (match-end 0))
   1.317        (let ((label (buffer-substring 
   1.318 -		    (1- (point)) (progn (backward-list 1) (1+ (point))))))
   1.319 +		    (1- (point)) (progn (backward-list 1) (1+ (point)))))
   1.320 +	    (fp (make-marker))fl fn
   1.321 +	    (goother (function (lambda (buffer point)
   1.322 +				 (goto-char point)
   1.323 +				 (if (one-window-p)
   1.324 +				     (split-window-calculate-height
   1.325 +				      YaTeX-default-pop-window-height))
   1.326 +				 (select-window (get-lru-window))
   1.327 +				 (switch-to-buffer buffer)))))
   1.328  	;(setq string (concat "\\" scmd "{" label "}"))
   1.329 -	(setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
   1.330 +	;(setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
   1.331 +	(setq string (YaTeX-replace-format scmd "k" (regexp-quote label)))
   1.332  	(setq direc (if (string-match "ref\\|cite" scmd)
   1.333  			're-search-forward 're-search-backward))
   1.334  	(if YaTeX-current-position-register
   1.335 @@ -1510,52 +1575,65 @@
   1.336  				    're-search-backward 're-search-forward)))
   1.337  	(if (funcall func string direc)	;label/ref found!
   1.338  	    (progn
   1.339 -	      (if otherwin
   1.340 -		  (progn
   1.341 -		    (goto-char p)
   1.342 -		    (if (one-window-p)
   1.343 -			(split-window-calculate-height
   1.344 -			 YaTeX-default-pop-window-height))
   1.345 -		    (select-window (get-lru-window))
   1.346 -		    (switch-to-buffer cb)))
   1.347 +	      (if otherwin (funcall goother cb p))
   1.348  	      (goto-char (match-beginning 0))
   1.349  	      (push-mark p))
   1.350  	  ;;if label/ref not found, search through all yatex buffers.
   1.351  	  (goto-char p)			;resume position of current buffer
   1.352 -	  (setq blist (YaTeX-yatex-buffer-list))
   1.353  	  (catch 'found
   1.354 +	    (setq blist (YaTeX-yatex-buffer-list))
   1.355  	    (while blist
   1.356 +	      ;; search for corresponding keyword
   1.357  	      (set-buffer (car blist))
   1.358  	      (if (YaTeX-on-section-command-p refcommands)
   1.359  		  (goto-char (match-beginning 0)))
   1.360 -	      (if (funcall func string direc)
   1.361 -		  (progn
   1.362 -		    (cond
   1.363 -		     (otherwin
   1.364 -		      (set-buffer cb)
   1.365 -		      (goto-char p)
   1.366 -		      (if (one-window-p)
   1.367 -			  (split-window-calculate-height
   1.368 -			   YaTeX-default-pop-window-height))
   1.369 -		      (select-window (get-lru-window))
   1.370 -		      (switch-to-buffer (car blist)))
   1.371 -		     ((or (get-buffer-window (car blist))
   1.372 -			  (and YaTeX-emacs-19
   1.373 -			       (get-buffer-window (car blist) t)))
   1.374 -		      (goto-buffer-window (car blist)))
   1.375 -		     (t
   1.376 -		      (switch-to-buffer (car blist))
   1.377 -		      (message
   1.378 -		       (format "Type %s %c to return to original position."
   1.379 -			       (key-description
   1.380 -				(car
   1.381 -				 (or (where-is-internal 'register-to-point)
   1.382 -				     (where-is-internal 'jump-to-register))))
   1.383 -			       YaTeX-current-position-register))))
   1.384 -		    (goto-char (match-beginning 0))
   1.385 -		    (throw 'found t)))
   1.386 -	      (setq blist (cdr blist)))))
   1.387 -	)
   1.388 +	      (cond
   1.389 +	       ; cond1
   1.390 +	       ((funcall func string direc)
   1.391 +		(cond
   1.392 +		 (otherwin
   1.393 +		  (set-buffer cb)
   1.394 +		  (funcall goother (car blist) p))
   1.395 +		 ((or (get-buffer-window (car blist))
   1.396 +		      (and YaTeX-emacs-19
   1.397 +			   (get-buffer-window (car blist) t)))
   1.398 +		  (goto-buffer-window (car blist)))
   1.399 +		 (t
   1.400 +		  (switch-to-buffer (car blist))
   1.401 +		  (message foundmsg)))
   1.402 +		(goto-char (match-beginning 0))
   1.403 +		(throw 'found t))
   1.404 +	       ; cond2
   1.405 +	       ((and
   1.406 +		 (string-match "bibitem" scmd)
   1.407 +		 (catch 'found2
   1.408 +		   (save-excursion
   1.409 +		     (goto-char (point-min))
   1.410 +		     (while (YaTeX-re-search-active-forward
   1.411 +			     "\\\\bibliography{\\([^}]*\\)}" "%" nil t)
   1.412 +		       (setq fl (YaTeX-split-string (YaTeX-match-string 1) ","))
   1.413 +		       (while fl
   1.414 +			 (if (or (file-exists-p (setq fn (car fl)))
   1.415 +				 (file-exists-p (setq fn (concat fn ".bib"))))
   1.416 +			     (progn
   1.417 +			       (set-buffer (find-file-noselect fn))
   1.418 +			       (save-excursion
   1.419 +				 (goto-char (point-min))
   1.420 +				 (if (YaTeX-re-search-active-forward
   1.421 +				      string "%" nil t)
   1.422 +				     (throw 'found2
   1.423 +					    (set-marker fp (point)))))))
   1.424 +			 (setq fl (cdr fl)))))))
   1.425 +		(if otherwin
   1.426 +		    (funcall goother (marker-buffer fp) fp)
   1.427 +		  (switch-to-buffer (marker-buffer fp))
   1.428 +		  (goto-char fp))
   1.429 +		(set-marker fp nil)
   1.430 +		(message foundmsg)
   1.431 +		(throw 'found t)))
   1.432 +	      (setq blist (cdr blist)))
   1.433 +	    ;; search for bibliography
   1.434 +	    )))
   1.435        (if YaTeX-emacs-19
   1.436  	  (setq regexp-search-ring
   1.437  		(cons string (delete string regexp-search-ring)))
   1.438 @@ -1722,23 +1800,31 @@
   1.439    "Check if point is on the LaTeX command: COMMAND(regexp).
   1.440  Return nil if point is not on it.  Otherwise return the
   1.441  number of argument position.
   1.442 -Section command name is stored in match-data #1."
   1.443 -  (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0))
   1.444 +Section command name is stored in match-data #1.
   1.445 +Parsing information is stored to plist.
   1.446 +Macros name stored to propname 'command.
   1.447 +Macro's argument number stored to propname 'argc."
   1.448 +  (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0)
   1.449 +	(ec+command (concat YaTeX-ec-regexp "\\(" command "\\)")))
   1.450 +    (setplist 'YaTeX-on-section-command-p nil)
   1.451      (while (setq i (string-match "\\\\(" command i))
   1.452        (setq grouping (1+ grouping) i (+ i 2)))
   1.453      (save-excursion
   1.454 -      (if (looking-at (concat YaTeX-ec-regexp command)) nil
   1.455 +      (if (looking-at ec+command) nil
   1.456  	(catch 'found			;caught value has no meaning
   1.457  	  ;;(1) looking at current position
   1.458 -	  (if (looking-at command)
   1.459 -	      (progn
   1.460 -		(while (and (not (bobp)) (looking-at command))
   1.461 -		  (forward-char -1))
   1.462 -		(throw 'found t)))
   1.463 +	  (and (looking-at command)
   1.464 +	       (save-excursion
   1.465 +		 (while (and (not (bobp)) (looking-at command))
   1.466 +		   (forward-char -1))
   1.467 +		 (looking-at ec+command))
   1.468 +	       (goto-char (match-beginning 0))
   1.469 +	       (throw 'found t))
   1.470  	  ;;(2) search command directly
   1.471  	  (skip-chars-forward "^{}[]")
   1.472  	  (and (YaTeX-re-search-active-backward
   1.473 -		(concat YaTeX-ec-regexp command) YaTeX-comment-prefix nil t)
   1.474 +		ec+command
   1.475 +		YaTeX-comment-prefix nil t)
   1.476  	       (>= p (match-beginning 0))
   1.477  	       (throw 'found (goto-char (match-beginning 0))))
   1.478  	  ;;(3) search token
   1.479 @@ -1753,8 +1839,8 @@
   1.480  	    (skip-chars-backward (concat "^ \t\r\n{}[]" YaTeX-ec-regexp))
   1.481  	    (or (bobp) (forward-char -1)))))
   1.482        (if (and
   1.483 -	   (looking-at (concat YaTeX-ec-regexp "\\(" command "\\)"
   1.484 -			       "\\(\\(\\[[^]]+\\]\\)*\\)"	;optional arg
   1.485 +	   (looking-at (concat ec+command
   1.486 +			       "\\(\\(\\[[^]]+\\]\\|([0-9,]+)\\)*\\)"	;optional arg
   1.487  			       ;"[ \t\n\r]*{[^}]+}")) ;arg braces
   1.488  			       "[ \t\n\r]*{[^}]*}")) ;arg braces
   1.489  	   (not (YaTeX-lookup-table
   1.490 @@ -1766,6 +1852,8 @@
   1.491  	    (setq argc
   1.492  		  (or (car (cdr (YaTeX-lookup-table word 'section)))
   1.493  		      argc))
   1.494 +	    (put 'YaTeX-on-section-command-p 'argc argc)
   1.495 +	    (put 'YaTeX-on-section-command-p 'command argc)
   1.496  	    (while (and (>= (setq argc (1- argc)) 0)
   1.497  			(progn (skip-chars-forward " \t\n\r")
   1.498  			       (looking-at "{")))
   1.499 @@ -1806,7 +1894,10 @@
   1.500  	    (if (equal (char-after (1- (point)))
   1.501  		       (string-to-char YaTeX-ec))
   1.502  		(forward-char -1))))
   1.503 -      (beginning-of-line))
   1.504 +      ;(beginning-of-line)
   1.505 +      (if (equal (char-after (point)) ?\\) nil	;stay here
   1.506 +	(skip-chars-backward "^\n\\\\")
   1.507 +	(or (bolp) (forward-char -1))))
   1.508      (re-search-forward
   1.509       ;;"\\\\begin{\\([^}]+\\)}\\|\\\\end{\\([^}]+\\)}"
   1.510       (concat
   1.511 @@ -1857,7 +1948,7 @@
   1.512       ((YaTeX-goto-corresponding-BEGIN-END))
   1.513       ((and (setq mm (YaTeX-in-math-mode-p))
   1.514  	   (YaTeX-goto-corresponding-leftright)))
   1.515 -     ((and mm YaTeX-use-AMS-LaTeX
   1.516 +     ((and ;;mm YaTeX-use-AMS-LaTeX
   1.517  	   (YaTeX-goto-corresponding-paren)))
   1.518       ;;((and (string-match
   1.519       ;;	  YaTeX-equation-env-regexp	;to delay loading
   1.520 @@ -2012,9 +2103,11 @@
   1.521        t)))
   1.522  
   1.523  (defun YaTeX-kill-section-command (point kill-all)
   1.524 -  "Kill section-type command at POINT leaving its argument.
   1.525 -Non-nil for the second argument kill its argument too."
   1.526 -  (let (beg (end (make-marker)))
   1.527 +  "Kill section-type command at POINT leaving its last argument.
   1.528 +Non-nil for the second argument kill its last argument too."
   1.529 +  (let ((cmd (get 'YaTeX-on-section-command-p 'command))
   1.530 +	(argc (get 'YaTeX-on-section-command-p 'argc))
   1.531 +	beg (end (make-marker)))
   1.532      (save-excursion
   1.533        (goto-char point)
   1.534        (or (looking-at YaTeX-ec-regexp)
   1.535 @@ -2023,12 +2116,22 @@
   1.536  	    (forward-char -1)))
   1.537        (setq beg (point))
   1.538        (skip-chars-forward "^{")
   1.539 +      (while (> (setq argc (1- argc)) 0)
   1.540 +	(skip-chars-forward "^{")
   1.541 +	(forward-list 1))
   1.542 +      (kill-region beg (point))
   1.543        (forward-list 1)
   1.544        (set-marker end (point))
   1.545 -      (if kill-all (kill-region beg end)
   1.546 +      (if kill-all
   1.547 +	  (progn
   1.548 +	    (kill-append (buffer-substring beg end) nil)
   1.549 +	    (delete-region beg end))
   1.550  	(goto-char beg)
   1.551 -	(kill-region
   1.552 -	 (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
   1.553 +	(kill-append
   1.554 +	 (buffer-substring
   1.555 +	  (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
   1.556 +	 nil)
   1.557 +	(delete-region beg (1+ (point)))
   1.558  	(goto-char end)
   1.559  	(set-marker end nil)
   1.560  	(kill-append (buffer-substring (point) (1- (point))) nil)
   1.561 @@ -2265,11 +2368,11 @@
   1.562    "Parse current line and call suitable function."
   1.563    (interactive)
   1.564    (cond
   1.565 +   ((YaTeX-change-parentheses))
   1.566     ((YaTeX-change-environment))
   1.567     ((YaTeX-change-section))
   1.568     ((YaTeX-change-fontsize))
   1.569     ((YaTeX-change-math-image))
   1.570 -   ((YaTeX-change-parentheses))
   1.571     (t (message "I don't know what to change."))))
   1.572  
   1.573  ;;;
   1.574 @@ -2397,20 +2500,26 @@
   1.575  	(if (/= (char-after (1- (match-beginning 0))) ?\\ )
   1.576  	    (replace-match "\\1"))))))
   1.577  
   1.578 +(defvar YaTeX-itemize-withlabel-max-indent-depth 8)
   1.579  (defun YaTeX-get-item-info (&optional recent thisenv)
   1.580    "Return the list of the beginning of \\item and column of its item.
   1.581  If it seems to be outside of itemizing environment, just return nil.
   1.582  Non-nil for optional argument RECENT refers recent \\item.
   1.583  Optional second argument THISENV omits calling YaTeX-inner-environment."
   1.584    (save-excursion
   1.585 -    (let* ((p (point)) env e0 c
   1.586 +    (let* ((p (point)) env e0 c cc md
   1.587  	   (bndry (and (setq env (or thisenv (YaTeX-inner-environment t)))
   1.588 -		       (get 'YaTeX-inner-environment 'point)
   1.589 -		       )))
   1.590 +		       (get 'YaTeX-inner-environment 'point))))
   1.591        (end-of-line)
   1.592        (if (if recent
   1.593 -	      (YaTeX-re-search-active-backward
   1.594 -	       YaTeX-item-regexp YaTeX-comment-prefix bndry t)
   1.595 +	      (catch 'found
   1.596 +		(while (YaTeX-re-search-active-backward
   1.597 +			YaTeX-item-regexp YaTeX-comment-prefix bndry t)
   1.598 +		  (setq md (match-data))
   1.599 +		  (YaTeX-inner-environment t)
   1.600 +		  (store-match-data md)
   1.601 +		  (if (= bndry (get 'YaTeX-inner-environment 'point))
   1.602 +		      (throw 'found t))))
   1.603  	    (goto-char bndry)
   1.604  	    (YaTeX-re-search-active-forward
   1.605  	     YaTeX-item-regexp YaTeX-comment-prefix p t))
   1.606 @@ -2419,8 +2528,13 @@
   1.607  	    ;(setq c (current-column))
   1.608  	    (if (string-match "desc" env)
   1.609  		(setq c 6)
   1.610 +	      (setq cc (current-column))
   1.611  	      (if (equal (following-char) ?\[) (forward-list 1))
   1.612 -	      (setq c 0))
   1.613 +	      (if (< (- (current-column) cc)
   1.614 +		     YaTeX-itemize-withlabel-max-indent-depth)
   1.615 +		  (setq c 0)
   1.616 +		(move-to-column cc)
   1.617 +		(setq c YaTeX-itemize-withlabel-max-indent-depth)))
   1.618  	    (skip-chars-forward " \t" (point-end-of-line))
   1.619  	    (list (point-beginning-of-line) (+ c (current-column))))))))
   1.620  
   1.621 @@ -2486,10 +2600,19 @@
   1.622     ((YaTeX-in-math-mode-p) nil)
   1.623     (t
   1.624      (save-excursion
   1.625 -      (let ((verbrex (concat YaTeX-ec-regexp
   1.626 +      (let*((verbrex (concat YaTeX-ec-regexp
   1.627  			     "\\(" YaTeX-verb-regexp "\\)" ;match#1
   1.628  			     "\\(.\\).*\\(\\2\\)")) ;match #2 and #3
   1.629 -	    (p (point)) ii end poslist spacelist (fill-prefix fill-prefix))
   1.630 +	    (tilderex (concat "\\("
   1.631 +			      YaTeX-kanji-regexp "~"
   1.632 +			      "\\)" YaTeX-ec-regexp
   1.633 +			      "\\|\\("
   1.634 +			      "~" YaTeX-kanji-regexp
   1.635 +			      "\\)"))
   1.636 +	    (p (point)) ii end poslist spacelist lenlist b e n
   1.637 +	    (fill-prefix fill-prefix)
   1.638 +	    (inenv (or (YaTeX-inner-environment t) "document"))
   1.639 +	    (border (get 'YaTeX-inner-environment 'point)))
   1.640  	(cond
   1.641  	 ((save-excursion (beginning-of-line) ;if point is on the first
   1.642  			  (setq end (point))  ;non-whitespace char
   1.643 @@ -2497,8 +2620,7 @@
   1.644  			  (equal (point) p))
   1.645  	  (setq fill-prefix (buffer-substring p end)))
   1.646  	 ((and ;;(not YaTeX-emacs-19)
   1.647 -	       (string-match YaTeX-itemizing-env-regexp
   1.648 -			     (or (YaTeX-inner-environment t) "document"))
   1.649 +	       (string-match YaTeX-itemizing-env-regexp inenv)
   1.650  	       (setq ii (YaTeX-get-item-info)))
   1.651  	  (save-excursion
   1.652  	    (beginning-of-line)
   1.653 @@ -2506,10 +2628,30 @@
   1.654  	    (setq fill-prefix
   1.655  		  (buffer-substring (point) (point-beginning-of-line)))
   1.656  	    (delete-region (point) (progn (beginning-of-line) (point))))))
   1.657 -        (mark-paragraph)
   1.658 +	(cond
   1.659 +	 ((string-match "tabular" inenv)
   1.660 +	  (let ((b (point-beginning-of-line))
   1.661 +		(e (point-end-of-line)))
   1.662 +	    (if (re-search-backward
   1.663 +		 "&\\|\\\\\\\\\\|\\\\\\(begin\\|end\\){" border t)
   1.664 +		(setq b (if (match-beginning 1)
   1.665 +			    (progn (forward-line 1) (point))
   1.666 +			  (point-beginning-of-line))))
   1.667 +	    (goto-char p)
   1.668 +	    (if (re-search-forward
   1.669 +		 "&\\|\\\\\\\\\\|\\\\\\(end\\|begin\\){" nil t)
   1.670 +		(setq e (if (match-beginning 1)
   1.671 +			    (progn (forward-line -1)
   1.672 +				   (point-end-of-line))
   1.673 +			  (match-beginning 0))))
   1.674 +	    (set-mark e)
   1.675 +	    (goto-char b)))
   1.676 +	 (t
   1.677 +	  (mark-paragraph)))
   1.678  	(save-restriction
   1.679  	  (narrow-to-region (region-beginning) (region-end))
   1.680  	  (YaTeX-remove-trailing-comment (point-min) (point-max))
   1.681 +	  ;; First, replace spaces in verb to _ temporarily.
   1.682  	  (goto-char (point-min))
   1.683  	  (while (YaTeX-re-search-active-forward
   1.684  		  verbrex YaTeX-comment-prefix (point-max) t)
   1.685 @@ -2517,21 +2659,39 @@
   1.686  	    (goto-char (match-beginning 2))
   1.687  	    (while (re-search-forward "\\s " end t)
   1.688  	      (setq poslist (cons (make-marker) poslist)
   1.689 -		    spacelist (cons (preceding-char) spacelist))
   1.690 +		    spacelist (cons (preceding-char) spacelist)
   1.691 +		    lenlist (cons 1 lenlist))
   1.692  	      (replace-match "_")
   1.693  	      (set-marker (car poslist) (match-beginning 0))))
   1.694 +	  ;; Second, replace "表~\ref{...}" to "\\\ref{...}"
   1.695 +	  (goto-char (point-min))
   1.696 +	  (while (YaTeX-re-search-active-forward
   1.697 +		  tilderex YaTeX-comment-prefix (point-max) t)
   1.698 +	    (if (match-beginning 1)
   1.699 +		(setq b (match-beginning 1) e (match-end 1) n 1)
   1.700 +	      (setq b (match-beginning 2) e (match-end 2) n 2))
   1.701 +	    (setq poslist (cons (make-marker) poslist)
   1.702 +		  spacelist (cons (YaTeX-match-string n) spacelist)
   1.703 +		  lenlist (cons 2 lenlist))
   1.704 +	    (goto-char (match-beginning 0))
   1.705 +	    (delete-region (point) e)
   1.706 +	    (insert YaTeX-ec YaTeX-ec)	;set-marker should be here
   1.707 +	    (set-marker (car poslist) b))
   1.708  	  ;;(fill-paragraph arg)
   1.709  	  (fill-region-as-paragraph (point-min) (point-max) arg)
   1.710  	  (while spacelist
   1.711  	    (goto-char (car poslist))
   1.712  	    (set-marker (car poslist) nil)
   1.713 -	    (delete-char 1)
   1.714 +	    (and (eolp) (skip-chars-forward "\n\t "))
   1.715 +	    (delete-char (car lenlist))
   1.716  	    (insert (car spacelist))
   1.717 -	    (setq spacelist (cdr spacelist) poslist (cdr poslist)))
   1.718 +	    (setq spacelist (cdr spacelist)
   1.719 +		  poslist (cdr poslist)
   1.720 +		  lenlist (cdr lenlist)))
   1.721  	  (goto-char (point-min))
   1.722  	  (forward-word 1)
   1.723  	  (beginning-of-line)
   1.724 -	  (while (re-search-forward "\\\\\\(\\(page\\)?ref\\|cite\\){" nil t)
   1.725 +	  (while (re-search-forward "\\\\\\([a-z]*ref\\|cite\\){" nil t)
   1.726  	    (if (< (point-end-of-line)
   1.727  		   (save-excursion (forward-char -1) (forward-list 1) (point)))
   1.728  		(progn (end-of-line)
   1.729 @@ -2539,6 +2699,12 @@
   1.730  			     (backward-word 1)
   1.731  			     (looking-at "[^0-9A-z!-)]"))
   1.732  			   (insert YaTeX-comment-prefix)))))
   1.733 +	  ;; Nonbreak space `~'
   1.734 +	  (goto-char (point-min))
   1.735 +	  (while (YaTeX-re-search-active-forward
   1.736 +		  "~\\(\\s *\\)$" YaTeX-comment-prefix (point-max) t)
   1.737 +	    (delete-region (match-beginning 1) (match-end 1))
   1.738 +	    (insert YaTeX-comment-prefix))
   1.739  	  (goto-char (point-min))
   1.740  	  (if (and NTT-jTeX (looking-at "[ \t]\\|^$"))
   1.741  	      (progn
   1.742 @@ -2631,6 +2797,9 @@
   1.743      (skip-chars-forward " \t")
   1.744      (current-column)))
   1.745  
   1.746 +(defvar YaTeX-noindent-env-regexp "verbatim\\*?\\|alltt"
   1.747 +  "*Regexp of environment names that should begin with no indentation.
   1.748 +All verbatime-like environment name should match with.")
   1.749  (defun YaTeX-indent-line ()
   1.750    "Indent corrent line referrin current environment."
   1.751    (interactive)
   1.752 @@ -2641,7 +2810,7 @@
   1.753  	     (+ (YaTeX-current-indentation)
   1.754  		(or additional 0)
   1.755  		YaTeX-environment-indent)))))
   1.756 -	sect depth iteminfo (p (point)) pp (peol (point-end-of-line))
   1.757 +	sect depth iteminfo (p (point)) pp (peol (point-end-of-line)) begend
   1.758  	;;inenv below is sometimes defined in YaTeX-indent-new-comment-line
   1.759  	(inenv (or (and (boundp 'inenv) inenv) (YaTeX-inner-environment t))))
   1.760      ;;(if NTT-jTeX		;;Do you need this section?
   1.761 @@ -2658,15 +2827,32 @@
   1.762      ;;	  (kill-line))))))
   1.763      (or inenv (setq inenv "document"))	;is the default environment
   1.764      (cond
   1.765 -     ((and (YaTeX-on-begin-end-p)
   1.766 -	   (or
   1.767 -	    (match-beginning 2)		;if \end
   1.768 -	    (and (match-beginning 3)	;if \) \]
   1.769 -		 (= (char-syntax (char-after (1+ (match-beginning 3)))) ?\)))))
   1.770 +     ((and
   1.771 +       (prog1 (YaTeX-on-begin-end-p)
   1.772 +	 (setq begend (match-beginning 0)))
   1.773 +       (or (match-beginning 2)		;if \end
   1.774 +	   (and (match-beginning 3)	;if \) \]
   1.775 +		(= (char-syntax (char-after (1+ (match-beginning 3)))) ?\)))))
   1.776        (YaTeX-reindent
   1.777         (save-excursion
   1.778  	 (YaTeX-goto-corresponding-environment)
   1.779  	 (current-column))))
   1.780 +     ;; on the begining of verbatime line, remove all indentation
   1.781 +     ((and begend ;; match-beginning 0 of \begin
   1.782 +	   YaTeX-noindent-env-regexp
   1.783 +	   (stringp YaTeX-noindent-env-regexp)
   1.784 +	   (save-excursion
   1.785 +	     (and ;; if the \begin is the first declaration of this line
   1.786 +	      (progn (beginning-of-line) (skip-chars-forward " \t")
   1.787 +		     (= begend (point)))
   1.788 +	      (progn
   1.789 +		(goto-char begend)
   1.790 +		(looking-at
   1.791 +		 (concat YaTeX-ec-regexp
   1.792 +			 "begin{\\(" YaTeX-noindent-env-regexp "\\)}"))))))
   1.793 +      (save-excursion
   1.794 +	(goto-char begend)
   1.795 +	(delete-region (point) (point-beginning-of-line))))
   1.796       ((string-match YaTeX-equation-env-regexp inenv)
   1.797        (YaTeX-indent-line-equation))	;autoload-ed from yatexenv
   1.798       (;(YaTeX-in-environment-p '("itemize" "enumerate" "description" "list"))
   1.799 @@ -2687,7 +2873,7 @@
   1.800  			((looking-at "sub")	1)
   1.801  			(t			0)))))
   1.802  	    (funcall indent-relative depth))
   1.803 -	(YaTeX-reindent (or (car (cdr (YaTeX-get-item-info nil inenv)))
   1.804 +	(YaTeX-reindent (or (car (cdr (YaTeX-get-item-info t inenv)))
   1.805  			    (+ (save-excursion
   1.806  				 (beginning-of-line)
   1.807  				 (YaTeX-current-indentation))
   1.808 @@ -2695,6 +2881,20 @@
   1.809        )
   1.810       ((YaTeX-literal-p)			;verbatims
   1.811        (tab-to-tab-stop))
   1.812 +     ((string-match "\\(tabular\\|array\\)" inenv) ;1.73
   1.813 +      (let ((n 1))
   1.814 +	(condition-case err
   1.815 +	    (save-excursion
   1.816 +	      (beginning-of-line)
   1.817 +	      (skip-chars-forward "[ \t]")
   1.818 +	      ;;(if (looking-at "&") (forward-char 1))
   1.819 +	      (require 'yatexenv)
   1.820 +	      (setq n (car (YaTeX-array-what-column-internal))))
   1.821 +	  (error nil))
   1.822 +	(YaTeX-reindent
   1.823 +	 (+ (YaTeX-current-indentation)
   1.824 +	    YaTeX-environment-indent
   1.825 +	    (* (1- n) YaTeX-tabular-indentation)))))
   1.826       ((and inenv (not (equal "document" inenv)))
   1.827        (funcall indent-relative))
   1.828       ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
   1.829 @@ -2720,7 +2920,9 @@
   1.830  				      (point)))
   1.831  		(insert fill-prefix))
   1.832  	    (skip-chars-forward " \t")
   1.833 -	    (indent-relative-maybe)))
   1.834 +	    (if (bobp)
   1.835 +		nil
   1.836 +	      (indent-relative-maybe))))
   1.837  	(skip-chars-forward " \t")))
   1.838      ;;if current line is \begin, re-indent \end too
   1.839      (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
   1.840 @@ -2736,10 +2938,12 @@
   1.841  	      (save-excursion (beginning-of-line) (looking-at "[ \t]")))
   1.842  	 (save-excursion
   1.843  	   (beginning-of-line)
   1.844 -	   (backward-char 1)
   1.845  	   (and
   1.846 -	    (re-search-backward
   1.847 -	     "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t)
   1.848 +	    (not (bobp))
   1.849 +	    (progn
   1.850 +	      (backward-char 1)
   1.851 +	      (re-search-backward
   1.852 +	       "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t))
   1.853  	    (goto-char (1- (match-end 0)))
   1.854  	    (> (save-excursion
   1.855  		 (condition-case ()
   1.856 @@ -2790,8 +2994,7 @@
   1.857  
   1.858  ;; `History' was moved to ChangeLog
   1.859  ;----------------------------- End of yatex.el -----------------------------
   1.860 -
   1.861  
   1.862 -;;; Local variables: 
   1.863 -;;; buffer-file-coding-system: sjis
   1.864 -;;; End: 
   1.865 +; Local variables:
   1.866 +; coding: sjis
   1.867 +; End: