yatex

diff yatexadd.el @ 48:a0640ff3f72f

Inter-file ref/label, cite/bibitem jump.
author yuuji
date Mon, 31 Oct 1994 17:49:43 +0000
parents cd1b63102eed
children eb0512bfcb7f
line diff
     1.1 --- a/yatexadd.el	Mon Sep 19 16:54:19 1994 +0000
     1.2 +++ b/yatexadd.el	Mon Oct 31 17:49:43 1994 +0000
     1.3 @@ -2,7 +2,7 @@
     1.4  ;;; YaTeX add-in functions.
     1.5  ;;; yatexadd.el rev.9
     1.6  ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     1.7 -;;; Last modified Mon Aug 22 14:19:39 1994 on figaro
     1.8 +;;; Last modified Mon Oct 31 12:55:54 1994 on pajero
     1.9  ;;; $Id$
    1.10  
    1.11  ;;;
    1.12 @@ -246,6 +246,18 @@
    1.13    nil
    1.14  )
    1.15  
    1.16 +(defun YaTeX:cite ()
    1.17 +  (let ((comment (read-string "Comment for citation: ")))
    1.18 +    (if (string= comment "") ""
    1.19 +      (concat "[" comment "]")))
    1.20 +)
    1.21 +
    1.22 +(defun YaTeX:bibitem ()
    1.23 +  (let ((label (read-string "Citation label: ")))
    1.24 +    (if (string= label "") ""
    1.25 +      (concat "[" label "]")))
    1.26 +)
    1.27 +
    1.28  ;;;
    1.29  ;;Subroutine
    1.30  ;;;
    1.31 @@ -327,11 +339,12 @@
    1.32        (goto-char (match-beginning 0))))
    1.33      (message YaTeX-label-guide-msg))
    1.34  )
    1.35 -(defun YaTeX::ref (argp)
    1.36 +(defun YaTeX::ref (argp &optional labelcmd refcmd)
    1.37    (cond
    1.38     ((= argp 1)
    1.39      (save-excursion
    1.40 -      (let ((lnum 0) e0 m1 e1 label label-list (buf (current-buffer))
    1.41 +      (let ((lnum 0) e0 label label-list (buf (current-buffer))
    1.42 +	    (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
    1.43  	    (p (point)) initl line)
    1.44  	(goto-char (point-min))
    1.45  	(message "Collecting labels...")
    1.46 @@ -339,27 +352,31 @@
    1.47  	  (YaTeX-showup-buffer
    1.48  	   YaTeX-label-buffer (function (lambda (x) (window-width x))))
    1.49  	  (with-output-to-temp-buffer YaTeX-label-buffer
    1.50 -	    (while (re-search-forward "\\label{\\([^}]+\\)}" nil t)
    1.51 -	      (setq e0 (match-end 0) m1 (match-beginning 1) e1 (match-end 1))
    1.52 -	      (if (search-backward
    1.53 -		   YaTeX-comment-prefix (point-beginning-of-line) t) nil
    1.54 -		(setq label (buffer-substring m1 e1)
    1.55 -		      label-list (cons label label-list))
    1.56 -		(or initl
    1.57 -		    (if (< p (point)) (setq initl lnum)))
    1.58 -		(beginning-of-line)
    1.59 -		(skip-chars-forward " \t\n" nil)
    1.60 -		(princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
    1.61 -			       (buffer-substring (point) (point-end-of-line))))
    1.62 -		(setq lnum (1+ lnum))
    1.63 -		(message "Collecting \\label{}... %d" lnum))
    1.64 +	    (while (YaTeX-re-search-active-forward
    1.65 +		    (concat "\\\\" labelcmd)
    1.66 +		    (regexp-quote YaTeX-comment-prefix) nil t)
    1.67 +	      (goto-char (match-beginning 0))
    1.68 +	      (skip-chars-forward "^{")
    1.69 +	      (setq label
    1.70 +		    (buffer-substring
    1.71 +		     (1+ (point))
    1.72 +		     (prog2 (forward-list 1) (setq e0 (1- (point)))))
    1.73 +		    label-list (cons label label-list))
    1.74 +	      (or initl
    1.75 +		  (if (< p (point)) (setq initl lnum)))
    1.76 +	      (beginning-of-line)
    1.77 +	      (skip-chars-forward " \t\n" nil)
    1.78 +	      (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
    1.79 +			     (buffer-substring (point) (point-end-of-line))))
    1.80 +	      (setq lnum (1+ lnum))
    1.81 +	      (message "Collecting \\%s{}... %d" labelcmd lnum)
    1.82  	      (goto-char e0))
    1.83  	    (princ YaTeX-label-menu-other)
    1.84  	    (princ YaTeX-label-menu-repeat)
    1.85  	    (princ YaTeX-label-menu-any)
    1.86  	    );with
    1.87  	  (goto-char p)
    1.88 -	  (message "Collecting labels...Done")
    1.89 +	  (message "Collecting %s...Done" labelcmd)
    1.90  	  (pop-to-buffer YaTeX-label-buffer)
    1.91  	  (YaTeX::label-setup-key-map)
    1.92  	  (setq truncate-lines t)
    1.93 @@ -379,12 +396,12 @@
    1.94  		  (save-excursion
    1.95  		    (switch-to-buffer buf)
    1.96  		    (goto-char p)
    1.97 -		    (if (re-search-backward "\\\\ref{\\([^}]+\\)}" nil t)
    1.98 -			(setq label (buffer-substring
    1.99 -				     (match-beginning 1) (match-end 1)))
   1.100 +		    (if (re-search-backward
   1.101 +			 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
   1.102 +			(setq label (YaTeX-match-string 1))
   1.103  		      (setq label ""))))
   1.104  		 ((>= line (+ lnum 2))
   1.105 -		  (setq label (read-string "\\ref{???}: ")))
   1.106 +		  (setq label (read-string (format "\\%s{???}: " refcmd))))
   1.107  		 (t (setq label (nth (- lnum line 1) label-list)))))
   1.108  	    (bury-buffer YaTeX-label-buffer)))
   1.109  	label
   1.110 @@ -392,19 +409,33 @@
   1.111      ))
   1.112  )
   1.113  (fset 'YaTeX::pageref 'YaTeX::ref)
   1.114 +(defun YaTeX::cite (argp)
   1.115 +  (cond
   1.116 +   ((eq argp 1)
   1.117 +    (YaTeX::ref argp "bibitem\\(\\[.*\\]\\)?" "cite"))
   1.118 +   (t nil)))
   1.119  
   1.120 -(defun YaTeX-label-other ()
   1.121 -  (let ((lbuf "*YaTeX mode buffers*") (blist (buffer-list)) (lnum -1) buf rv
   1.122 +(defun YaTeX-yatex-buffer-list ()
   1.123 +  (save-excursion
   1.124 +    (delq nil (mapcar (function (lambda (buf)
   1.125 +				  (set-buffer buf)
   1.126 +				  (if (eq major-mode 'yatex-mode) buf)))
   1.127 +		      (buffer-list))))
   1.128 +)
   1.129 +
   1.130 +(defun YaTeX-select-other-yatex-buffer ()
   1.131 +  "Select buffer from all yatex-mode's buffers interactivelly."
   1.132 +  (interactive)
   1.133 +  (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
   1.134 +	(lnum -1) buf rv
   1.135  	(ff "**find-file**"))
   1.136      (YaTeX-showup-buffer
   1.137       lbuf (function (lambda (x) 1)))	;;Select next window surely.
   1.138      (with-output-to-temp-buffer lbuf
   1.139        (while blist
   1.140 -	(if (and (buffer-file-name (setq buf (car blist)))
   1.141 -		 (progn (set-buffer buf) (eq major-mode 'yatex-mode)))
   1.142 -	    (princ
   1.143 -	     (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
   1.144 -		     (buffer-name buf))))
   1.145 +	(princ
   1.146 +	 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
   1.147 +		 (buffer-name (car blist))))
   1.148  	(setq blist (cdr blist)))
   1.149        (princ (format "':{%s}" ff)))
   1.150      (pop-to-buffer lbuf)
   1.151 @@ -421,14 +452,20 @@
   1.152  		(if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
   1.153  		    (buffer-substring (match-beginning 1) (match-end 1)) nil)))
   1.154        (kill-buffer lbuf))
   1.155 +    (if (string= rv ff)
   1.156 +	(progn
   1.157 +	  (call-interactively 'find-file)
   1.158 +	  (current-buffer))
   1.159 +      rv))
   1.160 +)
   1.161 +
   1.162 +(defun YaTeX-label-other ()
   1.163 +  (let ((rv (YaTeX-select-other-yatex-buffer)))
   1.164      (cond
   1.165       ((null rv) "")
   1.166 -     ((string= rv ff)
   1.167 -      (call-interactively 'find-file)
   1.168 -      (YaTeX::ref argp))
   1.169       (t
   1.170        (set-buffer rv)
   1.171 -      (YaTeX::ref argp)))
   1.172 +      (YaTeX::ref argp labelcmd refcmd)))
   1.173      )
   1.174  )
   1.175