yatex

diff yatexprc.el @ 14:b7b023a74293

Region-based section-type completion. Kill section-type command and parens (sometimes with font) with [prefix] k. Rewrite error-jump functions. Fix the bug of recursive section-type completion.
author yuuji
date Fri, 22 Apr 1994 17:35:25 +0000
parents eafae54794a0
children cd762e854337
line diff
     1.1 --- a/yatexprc.el	Sat Jan 29 07:59:59 1994 +0000
     1.2 +++ b/yatexprc.el	Fri Apr 22 17:35:25 1994 +0000
     1.3 @@ -1,8 +1,8 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; YaTeX process handler.
     1.6  ;;; yatexprc.el
     1.7 -;;; (c )1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     1.8 -;;; Last modified Sat Jan 29 16:54:54 1994 on gloria
     1.9 +;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    1.10 +;;; Last modified Sat Apr 23 02:34:07 1994 on pajero
    1.11  ;;; $Id$
    1.12  
    1.13  (require 'yatex)
    1.14 @@ -16,6 +16,9 @@
    1.15  (defvar YaTeX-typeset-buffer-syntax nil
    1.16    "*Syntax table for typesetting buffer")
    1.17  
    1.18 +(defvar YaTeX-current-TeX-buffer nil
    1.19 +  "Keeps the buffer on which recently typeset run.")
    1.20 +
    1.21  (if YaTeX-typeset-buffer-syntax nil
    1.22    (setq YaTeX-typeset-buffer-syntax
    1.23  	(make-syntax-table (standard-syntax-table)))
    1.24 @@ -34,7 +37,7 @@
    1.25  	;; if tex command is halting.
    1.26  	(YaTeX-kill-typeset-process YaTeX-typeset-process))
    1.27      (YaTeX-visit-main t);;execution directory
    1.28 -    ;;Select under-most window if there are more than 2 windows and
    1.29 +    ;;Select lower-most window if there are more than 2 windows and
    1.30      ;;typeset buffer not seen.
    1.31      (YaTeX-showup-buffer
    1.32       buffer (function (lambda (x) (nth 3 (window-edges x)))))
    1.33 @@ -50,7 +53,7 @@
    1.34  	      (start-process "LaTeX" buffer shell-file-name "-c"
    1.35  			     command))
    1.36  	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    1.37 -    (setq current-TeX-buffer (buffer-name))
    1.38 +    (setq YaTeX-current-TeX-buffer (buffer-name))
    1.39      (select-window (get-buffer-window buffer))
    1.40      (use-local-map YaTeX-typesetting-mode-map)
    1.41      (set-syntax-table YaTeX-typeset-buffer-syntax)
    1.42 @@ -264,7 +267,6 @@
    1.43    (interactive
    1.44     (list (read-string "Preview command: " dvi2-command)
    1.45  	 (read-string "Preview file[.dvi]: "
    1.46 -		      ;;(substring (buffer-name) 0 -4)
    1.47  		      (if (get 'dvi2-command 'region)
    1.48  			  (substring YaTeX-texput-file
    1.49  				     0 (rindex YaTeX-texput-file ?.))
    1.50 @@ -287,85 +289,74 @@
    1.51  )
    1.52  
    1.53  (defun YaTeX-prev-error ()
    1.54 -  "Visit previous error.  The reason why not NEXT-error is to
    1.55 -avoid making confliction of line numbers by editing."
    1.56 +  "Visit previous typeset error.
    1.57 +  To avoid making confliction of line numbers by editing, jump to
    1.58 +error or warning lines in reverse order."
    1.59    (interactive)
    1.60    (let ((cur-buf (buffer-name)) (cur-win (selected-window))
    1.61 -	YaTeX-error-line typeset-win error-buffer error-win)
    1.62 +	error-line typeset-win error-buffer error-win)
    1.63      (if (null (get-buffer YaTeX-typeset-buffer))
    1.64 -	(message "There is no output buffer of typesetting.")
    1.65 -      (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
    1.66 -      (setq typeset-win (selected-window))
    1.67 -      (if YaTeX-dos
    1.68 -	  (if (search-backward latex-dos-emergency-message nil t)
    1.69 -	      (progn (goto-char (point-max))
    1.70 -		     (setq error-regexp latex-error-regexp))
    1.71 -	    (beginning-of-line)
    1.72 -	    (forward-char -1)
    1.73 -	    (setq error-regexp latex-warning-regexp))
    1.74 -	(if YaTeX-typeset-process      ; if jlatex on UNIX
    1.75 -	    (if (eq (process-status YaTeX-typeset-process) 'run)
    1.76 -		(progn
    1.77 -		  (goto-char (point-max))
    1.78 -		  (setq error-regexp latex-error-regexp))
    1.79 -	      (beginning-of-line)
    1.80 -	      (setq error-regexp latex-warning-regexp))))
    1.81 -      (if (re-search-backward error-regexp nil t)
    1.82 -	  (setq YaTeX-error-line
    1.83 -		(string-to-int
    1.84 -		 (buffer-substring
    1.85 -		  (progn (goto-char (match-beginning 0))
    1.86 -			 (skip-chars-forward "^0-9")
    1.87 -			 (point))
    1.88 -		  (progn (skip-chars-forward "0-9") (point)))))
    1.89 -	(message "No more errors on %s" cur-buf)
    1.90 -	(ding))
    1.91 -      (setq error-buffer (YaTeX-get-error-file cur-buf)); arg. is default buf.
    1.92 -      (setq error-win (get-buffer-window error-buffer))
    1.93 +	(error "There is no typesetting buffer."))
    1.94 +    (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
    1.95 +    (setq typeset-win (selected-window))
    1.96 +    (if (re-search-backward
    1.97 +	 (concat "\\(" latex-error-regexp "\\)\\|\\("
    1.98 +		 latex-warning-regexp "\\)")
    1.99 +	 nil t)
   1.100 +	nil
   1.101        (select-window cur-win)
   1.102 -      (if (or (null YaTeX-error-line) (equal 0 YaTeX-error-line))
   1.103 -	  nil
   1.104 -	;; if warning or error found
   1.105 -	(if error-win (select-window error-win)
   1.106 -	  (select-window (get-lru-window))
   1.107 -	  (YaTeX-switch-to-buffer error-buffer)
   1.108 -	  (setq error-win (selected-window)))
   1.109 -	(goto-line YaTeX-error-line)
   1.110 -	(message "latex error or warning in '%s' at line: %d"
   1.111 -		 error-buffer YaTeX-error-line)
   1.112 -	(select-window typeset-win)
   1.113 -	(skip-chars-backward "[0-9]")
   1.114 -	(recenter (/ (window-height) 2))
   1.115 -	(sit-for 3)
   1.116 -	(forward-char -1)
   1.117 -	(select-window error-win)
   1.118 -	)))
   1.119 +      (error "No more erros on %s" cur-buf))
   1.120 +    (goto-char (match-beginning 0))
   1.121 +    (skip-chars-forward "^0-9" (match-end 0))
   1.122 +    (setq error-line
   1.123 +	  (string-to-int
   1.124 +	   (buffer-substring
   1.125 +	    (point)
   1.126 +	    (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
   1.127 +	  error-buffer (YaTeX-get-error-file cur-buf)
   1.128 +	  error-win (get-buffer-window error-buffer))
   1.129 +    (if (or (null error-line) (equal 0 error-line))
   1.130 +	(error "Can't detect error position."))
   1.131 +    (select-window cur-win)
   1.132 +    (cond
   1.133 +     (error-win (select-window error-win))
   1.134 +     ((eq (get-lru-window) typeset-win)
   1.135 +      (YaTeX-switch-to-buffer error-buffer))
   1.136 +     (t (select-window (get-lru-window))
   1.137 +	(YaTeX-switch-to-buffer error-buffer)))
   1.138 +    (setq error-win (selected-window))
   1.139 +    (goto-line error-line)
   1.140 +    (message "LaTeX %s in `%s' on line: %d."
   1.141 +	     (if (match-beginning 1) "error" "warning")
   1.142 +	     error-buffer error-line)
   1.143 +    (select-window typeset-win)
   1.144 +    (skip-chars-backward "0-9")
   1.145 +    (recenter (/ (window-height) 2))
   1.146 +    (sit-for 3)
   1.147 +    (goto-char (match-beginning 0))
   1.148 +    (select-window error-win))
   1.149  )
   1.150  
   1.151  (defun YaTeX-jump-error-line ()
   1.152    "Jump to corresponding line on latex command's error message."
   1.153    (interactive)
   1.154 -  (let ((p (point))
   1.155 -	(end (progn (end-of-line) (point)))
   1.156 -	(begin (progn (beginning-of-line)(point))))
   1.157 -    (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
   1.158 -	(if (save-excursion (end-of-line) (eobp))
   1.159 -	    (progn (goto-char p) (insert (this-command-keys)))
   1.160 -	  (message "No line number expression"))
   1.161 +  (let (error-line error-file error-buf)
   1.162 +    (save-excursion
   1.163 +      (beginning-of-line)
   1.164 +      (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
   1.165 +					  (point-end-of-line) t)))
   1.166 +    (if (null error-line)
   1.167 +	(if (eobp) (insert (this-command-keys))
   1.168 +	  (error "No line number expression."))
   1.169        (goto-char (match-beginning 0))
   1.170 -      (re-search-forward "[1-9][0-9]*" end t)
   1.171 -      (save-restriction
   1.172 -	(let ((error-line
   1.173 -	       (string-to-int (buffer-substring (match-beginning 0)
   1.174 -						(match-end 0))))
   1.175 -	      (error-file (YaTeX-get-error-file current-TeX-buffer)))
   1.176 -	  ;;(goto-char (match-beginning 0))
   1.177 -	  (other-window -1)
   1.178 -	  (message "errors in %s" error-file)
   1.179 -	  ;(switch-to-buffer current-TeX-buffer)
   1.180 -	  (if (not (YaTeX-switch-to-buffer error-file))
   1.181 -	      (error "%s is not found in this directory."))
   1.182 -	  (goto-line error-line)))))
   1.183 +      (setq error-line (string-to-int
   1.184 +			(buffer-substring (match-beginning 1) (match-end 1)))
   1.185 +	    error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
   1.186 +	    error-buf (YaTeX-switch-to-buffer error-file t))
   1.187 +      (if (null error-buf)
   1.188 +	  (error "`%s' is not found in this directory." error-file))
   1.189 +      (YaTeX-showup-buffer error-buf nil t)
   1.190 +      (goto-line error-line)))
   1.191  )
   1.192  
   1.193  (defun YaTeX-send-string ()
   1.194 @@ -425,7 +416,7 @@
   1.195        
   1.196  (defun YaTeX-put-nonstopmode ()
   1.197    (if YaTeX-need-nonstop
   1.198 -      (if (re-search-backward "\\nonstopmode{}" (point-min) t)
   1.199 +      (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
   1.200  	  nil                    ;if already written in text then do nothing
   1.201  	(save-excursion
   1.202  	  (YaTeX-visit-main t)
   1.203 @@ -453,7 +444,9 @@
   1.204  	 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
   1.205  	 (period))
   1.206      (if (string= fname "")
   1.207 -	(setq fname (substring (buffer-name) 0 -4))
   1.208 +	(setq fname (substring (file-name-nondirectory
   1.209 +				(buffer-file-name))
   1.210 +			       0 -4))
   1.211        (setq period (rindex fname ?.))
   1.212        (setq fname (substring fname 0 (if (eq -1 period) nil period)))
   1.213        ))
   1.214 @@ -461,21 +454,24 @@
   1.215  
   1.216  (defun YaTeX-get-latex-command (&optional switch)
   1.217    "Specify the latex-command name and its argument.
   1.218 -If there is a line which begins by string: \"%#!\", the following
   1.219 +If there is a line which begins with string: \"%#!\", the following
   1.220  strings are assumed to be the latex-command and arguments.  The
   1.221  default value of latex-command is:
   1.222 -	tex-command (buffer-name)
   1.223 +	tex-command FileName
   1.224  and if you write \"%#!jlatex\" in the beginning of certain line.
   1.225 -	\"jlatex \" (buffer-name)
   1.226 +	\"jlatex \" FileName
   1.227  will be the latex-command,
   1.228  and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
   1.229 -is t, then
   1.230 +is non-nil, then
   1.231  	\"jlatex main.tex\"
   1.232  will be given to the shell."
   1.233 -  (let*
   1.234 -      ((default-command
   1.235 -	 (concat tex-command " "
   1.236 -		 (if switch (buffer-name) ""))));default value
   1.237 +  (let*((target (file-name-nondirectory
   1.238 +		 (or YaTeX-parent-file
   1.239 +		     (save-excursion
   1.240 +		       (YaTeX-visit-main t)
   1.241 +		       (buffer-file-name)))))
   1.242 +	(default-command
   1.243 +	  (concat tex-command " " (if switch target ""))));default value
   1.244      (save-excursion
   1.245        (goto-char (point-min))
   1.246        (if (null (re-search-forward "^%#!" (point-max) t))
   1.247 @@ -486,16 +482,16 @@
   1.248  	  (let ((s (point)))
   1.249  	    (skip-chars-forward "^ 	" (point-end-of-line)) ;Skip command
   1.250  	    (skip-chars-forward " 	" (point-end-of-line))
   1.251 -	    ;(setq YaTeX-latex-command (buffer-substring s (point)))
   1.252  	    (cond
   1.253  	     ((null switch)
   1.254  	      (buffer-substring s (point)))
   1.255  	     ((eolp)			 ;Only return command name
   1.256 -	      (concat (buffer-substring s (point)) " " (buffer-name)))
   1.257 +	      (concat (buffer-substring s (point)) " "
   1.258 +		      (file-name-nondirectory
   1.259 +		       (or YaTeX-parent-file (buffer-file-name)))))
   1.260  	     (t(end-of-line)		   ;Change entire command name
   1.261  	       (buffer-substring s (point))) ;including arguments.
   1.262 -	    ))
   1.263 -	))))
   1.264 +	    ))))))
   1.265  )
   1.266  
   1.267  (defun YaTeX-lpr (arg)
   1.268 @@ -542,26 +538,42 @@
   1.269  
   1.270  (defun YaTeX-main-file-p ()
   1.271    "Return if current buffer is main LaTeX source."
   1.272 -  (string-match (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name))
   1.273 +  (cond
   1.274 +   ((YaTeX-get-builtin "!")
   1.275 +    (string-match
   1.276 +     (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name)))
   1.277 +   (t
   1.278 +    (save-excursion
   1.279 +      (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
   1.280 +	(or (re-search-backward latex-main-id nil t)
   1.281 +	    (re-search-forward latex-main-id nil t))))))
   1.282  )
   1.283  
   1.284  (defun YaTeX-visit-main (&optional setbuf)
   1.285    "Switch to buffer main LaTeX source.  Use set-buffer instead of
   1.286 -switch-to-buffer if optional second argument SETBUF is t(Use it only
   1.287 +switch-to-buffer if the optional second argument SETBUF is t(Use it only
   1.288  in Emacs-Lisp program)."
   1.289    (interactive)
   1.290 -  (let ((main-file (YaTeX-get-preview-file-name)))
   1.291 -    (if (string-match (concat "^" main-file ".tex") (buffer-name))
   1.292 +  (let (main-file)
   1.293 +    (if (YaTeX-get-builtin "!")
   1.294 +	(setq main-file (concat (YaTeX-get-preview-file-name) ".tex")))
   1.295 +    (if YaTeX-parent-file
   1.296 +	(setq main-file YaTeX-parent-file))
   1.297 +    (if (YaTeX-main-file-p)
   1.298  	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
   1.299        (cond
   1.300 -       ((YaTeX-switch-to-buffer (setq main-file (concat main-file ".tex"))
   1.301 -				setbuf))
   1.302 -       ((and (file-exists-p (setq main-file (concat "../" main-file)))
   1.303 +       ((and (interactive-p) main-file (get-buffer-window main-file))
   1.304 +	(select-window (get-buffer-window main-file)))
   1.305 +       ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
   1.306 +       ((and main-file
   1.307 +	     (file-exists-p (setq main-file (concat "../" main-file)))
   1.308  	     (y-or-n-p (concat (expand-file-name main-file)
   1.309  			       " is main file?:")))
   1.310  	(YaTeX-switch-to-buffer main-file setbuf))
   1.311 -       (t (find-file (read-file-name "Enter your main text: " nil nil 1)))
   1.312 -	)))
   1.313 +       (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
   1.314 +	  (setq YaTeX-parent-file main-file)
   1.315 +	  (find-file main-file))
   1.316 +       )))
   1.317    nil
   1.318  )
   1.319  
   1.320 @@ -605,22 +617,32 @@
   1.321      (pop-to-buffer buffer))
   1.322  )
   1.323  
   1.324 -(defun YaTeX-showup-buffer (buffer &optional func)
   1.325 +(defun YaTeX-showup-buffer (buffer &optional func select)
   1.326    "Make BUFFER show up in certain window (but current window)
   1.327  that gives the maximum value by the FUNC.  FUNC should take an argument
   1.328 -of its window object"
   1.329 -  (or (get-buffer-window buffer)
   1.330 -      (< (length (YaTeX-window-list)) 3)
   1.331 -      (let ((window (selected-window)) (list (YaTeX-window-list)) win w (x 0))
   1.332 -	(while list
   1.333 -	  (setq w (car list))
   1.334 -	    (if (and (not (eq window w))
   1.335 -		     (> (funcall func w) x))
   1.336 -		(setq win w x (funcall func w)))
   1.337 -	    (setq list (cdr list)))
   1.338 -	(select-window win)
   1.339 -	(switch-to-buffer buffer)
   1.340 -	(select-window window)))
   1.341 +of its window object.  Non-nil for optional third argument SELECT selects
   1.342 +that window."
   1.343 +  (or (and (get-buffer-window buffer)
   1.344 +	   (progn (if select (select-window (get-buffer-window buffer))) t))
   1.345 +      (cond
   1.346 +       ((> (length (YaTeX-window-list)) 2)
   1.347 +	(let ((window (selected-window))
   1.348 +	      (list (YaTeX-window-list)) win w (x 0))
   1.349 +	  (if func
   1.350 +	      (while list
   1.351 +		(setq w (car list))
   1.352 +		(if (and (not (eq window w))
   1.353 +			 (> (funcall func w) x))
   1.354 +		    (setq win w x (funcall func w)))
   1.355 +		(setq list (cdr list)))
   1.356 +	    (setq win (get-lru-window)))
   1.357 +	  (select-window win)
   1.358 +	  (switch-to-buffer buffer)
   1.359 +	  (or select (select-window window))))
   1.360 +       ((= (length (YaTeX-window-list)) 2)
   1.361 +	(other-window 1)
   1.362 +	(switch-to-buffer buffer))
   1.363 +       (t nil)))
   1.364  )
   1.365  
   1.366  (defun YaTeX-window-list ()