comparison 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
comparison
equal deleted inserted replaced
13:eafae54794a0 14:b7b023a74293
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX process handler. 2 ;;; YaTeX process handler.
3 ;;; yatexprc.el 3 ;;; yatexprc.el
4 ;;; (c )1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 4 ;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Sat Jan 29 16:54:54 1994 on gloria 5 ;;; Last modified Sat Apr 23 02:34:07 1994 on pajero
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 (require 'yatex) 8 (require 'yatex)
9 9
10 (defvar YaTeX-typeset-process nil 10 (defvar YaTeX-typeset-process nil
13 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*" 13 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
14 "Process buffer for jlatex") 14 "Process buffer for jlatex")
15 15
16 (defvar YaTeX-typeset-buffer-syntax nil 16 (defvar YaTeX-typeset-buffer-syntax nil
17 "*Syntax table for typesetting buffer") 17 "*Syntax table for typesetting buffer")
18
19 (defvar YaTeX-current-TeX-buffer nil
20 "Keeps the buffer on which recently typeset run.")
18 21
19 (if YaTeX-typeset-buffer-syntax nil 22 (if YaTeX-typeset-buffer-syntax nil
20 (setq YaTeX-typeset-buffer-syntax 23 (setq YaTeX-typeset-buffer-syntax
21 (make-syntax-table (standard-syntax-table))) 24 (make-syntax-table (standard-syntax-table)))
22 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax) 25 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax)
32 (if (and YaTeX-typeset-process 35 (if (and YaTeX-typeset-process
33 (eq (process-status YaTeX-typeset-process) 'run)) 36 (eq (process-status YaTeX-typeset-process) 'run))
34 ;; if tex command is halting. 37 ;; if tex command is halting.
35 (YaTeX-kill-typeset-process YaTeX-typeset-process)) 38 (YaTeX-kill-typeset-process YaTeX-typeset-process))
36 (YaTeX-visit-main t);;execution directory 39 (YaTeX-visit-main t);;execution directory
37 ;;Select under-most window if there are more than 2 windows and 40 ;;Select lower-most window if there are more than 2 windows and
38 ;;typeset buffer not seen. 41 ;;typeset buffer not seen.
39 (YaTeX-showup-buffer 42 (YaTeX-showup-buffer
40 buffer (function (lambda (x) (nth 3 (window-edges x))))) 43 buffer (function (lambda (x) (nth 3 (window-edges x)))))
41 (with-output-to-temp-buffer buffer 44 (with-output-to-temp-buffer buffer
42 (if YaTeX-dos ;if MS-DOS 45 (if YaTeX-dos ;if MS-DOS
48 (YaTeX-remove-nonstopmode)) 51 (YaTeX-remove-nonstopmode))
49 (setq YaTeX-typeset-process ;if UNIX 52 (setq YaTeX-typeset-process ;if UNIX
50 (start-process "LaTeX" buffer shell-file-name "-c" 53 (start-process "LaTeX" buffer shell-file-name "-c"
51 command)) 54 command))
52 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel))) 55 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
53 (setq current-TeX-buffer (buffer-name)) 56 (setq YaTeX-current-TeX-buffer (buffer-name))
54 (select-window (get-buffer-window buffer)) 57 (select-window (get-buffer-window buffer))
55 (use-local-map YaTeX-typesetting-mode-map) 58 (use-local-map YaTeX-typesetting-mode-map)
56 (set-syntax-table YaTeX-typeset-buffer-syntax) 59 (set-syntax-table YaTeX-typeset-buffer-syntax)
57 (setq mode-name "typeset") 60 (setq mode-name "typeset")
58 (if YaTeX-typeset-process ; if process is running (maybe on UNIX) 61 (if YaTeX-typeset-process ; if process is running (maybe on UNIX)
262 (defun YaTeX-preview (preview-command preview-file) 265 (defun YaTeX-preview (preview-command preview-file)
263 "Execute xdvi (or other) to tex-preview." 266 "Execute xdvi (or other) to tex-preview."
264 (interactive 267 (interactive
265 (list (read-string "Preview command: " dvi2-command) 268 (list (read-string "Preview command: " dvi2-command)
266 (read-string "Preview file[.dvi]: " 269 (read-string "Preview file[.dvi]: "
267 ;;(substring (buffer-name) 0 -4)
268 (if (get 'dvi2-command 'region) 270 (if (get 'dvi2-command 'region)
269 (substring YaTeX-texput-file 271 (substring YaTeX-texput-file
270 0 (rindex YaTeX-texput-file ?.)) 272 0 (rindex YaTeX-texput-file ?.))
271 (YaTeX-get-preview-file-name)) 273 (YaTeX-get-preview-file-name))
272 ))) 274 )))
285 (message 287 (message
286 (concat "Starting " dvi2-command " to preview " preview-file))))) 288 (concat "Starting " dvi2-command " to preview " preview-file)))))
287 ) 289 )
288 290
289 (defun YaTeX-prev-error () 291 (defun YaTeX-prev-error ()
290 "Visit previous error. The reason why not NEXT-error is to 292 "Visit previous typeset error.
291 avoid making confliction of line numbers by editing." 293 To avoid making confliction of line numbers by editing, jump to
294 error or warning lines in reverse order."
292 (interactive) 295 (interactive)
293 (let ((cur-buf (buffer-name)) (cur-win (selected-window)) 296 (let ((cur-buf (buffer-name)) (cur-win (selected-window))
294 YaTeX-error-line typeset-win error-buffer error-win) 297 error-line typeset-win error-buffer error-win)
295 (if (null (get-buffer YaTeX-typeset-buffer)) 298 (if (null (get-buffer YaTeX-typeset-buffer))
296 (message "There is no output buffer of typesetting.") 299 (error "There is no typesetting buffer."))
297 (YaTeX-pop-to-buffer YaTeX-typeset-buffer) 300 (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
298 (setq typeset-win (selected-window)) 301 (setq typeset-win (selected-window))
299 (if YaTeX-dos 302 (if (re-search-backward
300 (if (search-backward latex-dos-emergency-message nil t) 303 (concat "\\(" latex-error-regexp "\\)\\|\\("
301 (progn (goto-char (point-max)) 304 latex-warning-regexp "\\)")
302 (setq error-regexp latex-error-regexp)) 305 nil t)
303 (beginning-of-line) 306 nil
304 (forward-char -1)
305 (setq error-regexp latex-warning-regexp))
306 (if YaTeX-typeset-process ; if jlatex on UNIX
307 (if (eq (process-status YaTeX-typeset-process) 'run)
308 (progn
309 (goto-char (point-max))
310 (setq error-regexp latex-error-regexp))
311 (beginning-of-line)
312 (setq error-regexp latex-warning-regexp))))
313 (if (re-search-backward error-regexp nil t)
314 (setq YaTeX-error-line
315 (string-to-int
316 (buffer-substring
317 (progn (goto-char (match-beginning 0))
318 (skip-chars-forward "^0-9")
319 (point))
320 (progn (skip-chars-forward "0-9") (point)))))
321 (message "No more errors on %s" cur-buf)
322 (ding))
323 (setq error-buffer (YaTeX-get-error-file cur-buf)); arg. is default buf.
324 (setq error-win (get-buffer-window error-buffer))
325 (select-window cur-win) 307 (select-window cur-win)
326 (if (or (null YaTeX-error-line) (equal 0 YaTeX-error-line)) 308 (error "No more erros on %s" cur-buf))
327 nil 309 (goto-char (match-beginning 0))
328 ;; if warning or error found 310 (skip-chars-forward "^0-9" (match-end 0))
329 (if error-win (select-window error-win) 311 (setq error-line
330 (select-window (get-lru-window)) 312 (string-to-int
331 (YaTeX-switch-to-buffer error-buffer) 313 (buffer-substring
332 (setq error-win (selected-window))) 314 (point)
333 (goto-line YaTeX-error-line) 315 (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
334 (message "latex error or warning in '%s' at line: %d" 316 error-buffer (YaTeX-get-error-file cur-buf)
335 error-buffer YaTeX-error-line) 317 error-win (get-buffer-window error-buffer))
336 (select-window typeset-win) 318 (if (or (null error-line) (equal 0 error-line))
337 (skip-chars-backward "[0-9]") 319 (error "Can't detect error position."))
338 (recenter (/ (window-height) 2)) 320 (select-window cur-win)
339 (sit-for 3) 321 (cond
340 (forward-char -1) 322 (error-win (select-window error-win))
341 (select-window error-win) 323 ((eq (get-lru-window) typeset-win)
342 ))) 324 (YaTeX-switch-to-buffer error-buffer))
325 (t (select-window (get-lru-window))
326 (YaTeX-switch-to-buffer error-buffer)))
327 (setq error-win (selected-window))
328 (goto-line error-line)
329 (message "LaTeX %s in `%s' on line: %d."
330 (if (match-beginning 1) "error" "warning")
331 error-buffer error-line)
332 (select-window typeset-win)
333 (skip-chars-backward "0-9")
334 (recenter (/ (window-height) 2))
335 (sit-for 3)
336 (goto-char (match-beginning 0))
337 (select-window error-win))
343 ) 338 )
344 339
345 (defun YaTeX-jump-error-line () 340 (defun YaTeX-jump-error-line ()
346 "Jump to corresponding line on latex command's error message." 341 "Jump to corresponding line on latex command's error message."
347 (interactive) 342 (interactive)
348 (let ((p (point)) 343 (let (error-line error-file error-buf)
349 (end (progn (end-of-line) (point))) 344 (save-excursion
350 (begin (progn (beginning-of-line)(point)))) 345 (beginning-of-line)
351 (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t)) 346 (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
352 (if (save-excursion (end-of-line) (eobp)) 347 (point-end-of-line) t)))
353 (progn (goto-char p) (insert (this-command-keys))) 348 (if (null error-line)
354 (message "No line number expression")) 349 (if (eobp) (insert (this-command-keys))
350 (error "No line number expression."))
355 (goto-char (match-beginning 0)) 351 (goto-char (match-beginning 0))
356 (re-search-forward "[1-9][0-9]*" end t) 352 (setq error-line (string-to-int
357 (save-restriction 353 (buffer-substring (match-beginning 1) (match-end 1)))
358 (let ((error-line 354 error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
359 (string-to-int (buffer-substring (match-beginning 0) 355 error-buf (YaTeX-switch-to-buffer error-file t))
360 (match-end 0)))) 356 (if (null error-buf)
361 (error-file (YaTeX-get-error-file current-TeX-buffer))) 357 (error "`%s' is not found in this directory." error-file))
362 ;;(goto-char (match-beginning 0)) 358 (YaTeX-showup-buffer error-buf nil t)
363 (other-window -1) 359 (goto-line error-line)))
364 (message "errors in %s" error-file)
365 ;(switch-to-buffer current-TeX-buffer)
366 (if (not (YaTeX-switch-to-buffer error-file))
367 (error "%s is not found in this directory."))
368 (goto-line error-line)))))
369 ) 360 )
370 361
371 (defun YaTeX-send-string () 362 (defun YaTeX-send-string ()
372 "Send string to current typeset process." 363 "Send string to current typeset process."
373 (interactive) 364 (interactive)
423 (if (string= "" s) default s))) 414 (if (string= "" s) default s)))
424 ) 415 )
425 416
426 (defun YaTeX-put-nonstopmode () 417 (defun YaTeX-put-nonstopmode ()
427 (if YaTeX-need-nonstop 418 (if YaTeX-need-nonstop
428 (if (re-search-backward "\\nonstopmode{}" (point-min) t) 419 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
429 nil ;if already written in text then do nothing 420 nil ;if already written in text then do nothing
430 (save-excursion 421 (save-excursion
431 (YaTeX-visit-main t) 422 (YaTeX-visit-main t)
432 (goto-char (point-min)) 423 (goto-char (point-min))
433 (insert "\\nonstopmode{}%_YaTeX_%\n"))) 424 (insert "\\nonstopmode{}%_YaTeX_%\n")))
451 (let* ((latex-cmd (YaTeX-get-latex-command t)) 442 (let* ((latex-cmd (YaTeX-get-latex-command t))
452 (rin (rindex latex-cmd ? )) 443 (rin (rindex latex-cmd ? ))
453 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) "")) 444 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
454 (period)) 445 (period))
455 (if (string= fname "") 446 (if (string= fname "")
456 (setq fname (substring (buffer-name) 0 -4)) 447 (setq fname (substring (file-name-nondirectory
448 (buffer-file-name))
449 0 -4))
457 (setq period (rindex fname ?.)) 450 (setq period (rindex fname ?.))
458 (setq fname (substring fname 0 (if (eq -1 period) nil period))) 451 (setq fname (substring fname 0 (if (eq -1 period) nil period)))
459 )) 452 ))
460 ) 453 )
461 454
462 (defun YaTeX-get-latex-command (&optional switch) 455 (defun YaTeX-get-latex-command (&optional switch)
463 "Specify the latex-command name and its argument. 456 "Specify the latex-command name and its argument.
464 If there is a line which begins by string: \"%#!\", the following 457 If there is a line which begins with string: \"%#!\", the following
465 strings are assumed to be the latex-command and arguments. The 458 strings are assumed to be the latex-command and arguments. The
466 default value of latex-command is: 459 default value of latex-command is:
467 tex-command (buffer-name) 460 tex-command FileName
468 and if you write \"%#!jlatex\" in the beginning of certain line. 461 and if you write \"%#!jlatex\" in the beginning of certain line.
469 \"jlatex \" (buffer-name) 462 \"jlatex \" FileName
470 will be the latex-command, 463 will be the latex-command,
471 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH 464 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
472 is t, then 465 is non-nil, then
473 \"jlatex main.tex\" 466 \"jlatex main.tex\"
474 will be given to the shell." 467 will be given to the shell."
475 (let* 468 (let*((target (file-name-nondirectory
476 ((default-command 469 (or YaTeX-parent-file
477 (concat tex-command " " 470 (save-excursion
478 (if switch (buffer-name) ""))));default value 471 (YaTeX-visit-main t)
472 (buffer-file-name)))))
473 (default-command
474 (concat tex-command " " (if switch target ""))));default value
479 (save-excursion 475 (save-excursion
480 (goto-char (point-min)) 476 (goto-char (point-min))
481 (if (null (re-search-forward "^%#!" (point-max) t)) 477 (if (null (re-search-forward "^%#!" (point-max) t))
482 default-command 478 default-command
483 (skip-chars-forward "%#! ") 479 (skip-chars-forward "%#! ")
484 (if (eolp) 480 (if (eolp)
485 default-command 481 default-command
486 (let ((s (point))) 482 (let ((s (point)))
487 (skip-chars-forward "^ " (point-end-of-line)) ;Skip command 483 (skip-chars-forward "^ " (point-end-of-line)) ;Skip command
488 (skip-chars-forward " " (point-end-of-line)) 484 (skip-chars-forward " " (point-end-of-line))
489 ;(setq YaTeX-latex-command (buffer-substring s (point)))
490 (cond 485 (cond
491 ((null switch) 486 ((null switch)
492 (buffer-substring s (point))) 487 (buffer-substring s (point)))
493 ((eolp) ;Only return command name 488 ((eolp) ;Only return command name
494 (concat (buffer-substring s (point)) " " (buffer-name))) 489 (concat (buffer-substring s (point)) " "
490 (file-name-nondirectory
491 (or YaTeX-parent-file (buffer-file-name)))))
495 (t(end-of-line) ;Change entire command name 492 (t(end-of-line) ;Change entire command name
496 (buffer-substring s (point))) ;including arguments. 493 (buffer-substring s (point))) ;including arguments.
497 )) 494 ))))))
498 ))))
499 ) 495 )
500 496
501 (defun YaTeX-lpr (arg) 497 (defun YaTeX-lpr (arg)
502 "Print out. If prefix arg ARG is non nil, call print driver without 498 "Print out. If prefix arg ARG is non nil, call print driver without
503 page range description." 499 page range description."
540 ))) 536 )))
541 ) 537 )
542 538
543 (defun YaTeX-main-file-p () 539 (defun YaTeX-main-file-p ()
544 "Return if current buffer is main LaTeX source." 540 "Return if current buffer is main LaTeX source."
545 (string-match (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name)) 541 (cond
542 ((YaTeX-get-builtin "!")
543 (string-match
544 (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name)))
545 (t
546 (save-excursion
547 (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
548 (or (re-search-backward latex-main-id nil t)
549 (re-search-forward latex-main-id nil t))))))
546 ) 550 )
547 551
548 (defun YaTeX-visit-main (&optional setbuf) 552 (defun YaTeX-visit-main (&optional setbuf)
549 "Switch to buffer main LaTeX source. Use set-buffer instead of 553 "Switch to buffer main LaTeX source. Use set-buffer instead of
550 switch-to-buffer if optional second argument SETBUF is t(Use it only 554 switch-to-buffer if the optional second argument SETBUF is t(Use it only
551 in Emacs-Lisp program)." 555 in Emacs-Lisp program)."
552 (interactive) 556 (interactive)
553 (let ((main-file (YaTeX-get-preview-file-name))) 557 (let (main-file)
554 (if (string-match (concat "^" main-file ".tex") (buffer-name)) 558 (if (YaTeX-get-builtin "!")
559 (setq main-file (concat (YaTeX-get-preview-file-name) ".tex")))
560 (if YaTeX-parent-file
561 (setq main-file YaTeX-parent-file))
562 (if (YaTeX-main-file-p)
555 (if (interactive-p) (message "I think this is main LaTeX source.") nil) 563 (if (interactive-p) (message "I think this is main LaTeX source.") nil)
556 (cond 564 (cond
557 ((YaTeX-switch-to-buffer (setq main-file (concat main-file ".tex")) 565 ((and (interactive-p) main-file (get-buffer-window main-file))
558 setbuf)) 566 (select-window (get-buffer-window main-file)))
559 ((and (file-exists-p (setq main-file (concat "../" main-file))) 567 ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
568 ((and main-file
569 (file-exists-p (setq main-file (concat "../" main-file)))
560 (y-or-n-p (concat (expand-file-name main-file) 570 (y-or-n-p (concat (expand-file-name main-file)
561 " is main file?:"))) 571 " is main file?:")))
562 (YaTeX-switch-to-buffer main-file setbuf)) 572 (YaTeX-switch-to-buffer main-file setbuf))
563 (t (find-file (read-file-name "Enter your main text: " nil nil 1))) 573 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
564 ))) 574 (setq YaTeX-parent-file main-file)
575 (find-file main-file))
576 )))
565 nil 577 nil
566 ) 578 )
567 579
568 (defun YaTeX-visit-main-other-window () 580 (defun YaTeX-visit-main-other-window ()
569 "Switch to buffer main LaTeX source in other window." 581 "Switch to buffer main LaTeX source in other window."
603 (if (setq win (get-buffer-window buffer)) 615 (if (setq win (get-buffer-window buffer))
604 (select-window win) 616 (select-window win)
605 (pop-to-buffer buffer)) 617 (pop-to-buffer buffer))
606 ) 618 )
607 619
608 (defun YaTeX-showup-buffer (buffer &optional func) 620 (defun YaTeX-showup-buffer (buffer &optional func select)
609 "Make BUFFER show up in certain window (but current window) 621 "Make BUFFER show up in certain window (but current window)
610 that gives the maximum value by the FUNC. FUNC should take an argument 622 that gives the maximum value by the FUNC. FUNC should take an argument
611 of its window object" 623 of its window object. Non-nil for optional third argument SELECT selects
612 (or (get-buffer-window buffer) 624 that window."
613 (< (length (YaTeX-window-list)) 3) 625 (or (and (get-buffer-window buffer)
614 (let ((window (selected-window)) (list (YaTeX-window-list)) win w (x 0)) 626 (progn (if select (select-window (get-buffer-window buffer))) t))
615 (while list 627 (cond
616 (setq w (car list)) 628 ((> (length (YaTeX-window-list)) 2)
617 (if (and (not (eq window w)) 629 (let ((window (selected-window))
618 (> (funcall func w) x)) 630 (list (YaTeX-window-list)) win w (x 0))
619 (setq win w x (funcall func w))) 631 (if func
620 (setq list (cdr list))) 632 (while list
621 (select-window win) 633 (setq w (car list))
622 (switch-to-buffer buffer) 634 (if (and (not (eq window w))
623 (select-window window))) 635 (> (funcall func w) x))
636 (setq win w x (funcall func w)))
637 (setq list (cdr list)))
638 (setq win (get-lru-window)))
639 (select-window win)
640 (switch-to-buffer buffer)
641 (or select (select-window window))))
642 ((= (length (YaTeX-window-list)) 2)
643 (other-window 1)
644 (switch-to-buffer buffer))
645 (t nil)))
624 ) 646 )
625 647
626 (defun YaTeX-window-list () 648 (defun YaTeX-window-list ()
627 (let*((curw (selected-window)) (win curw) (wlist (list curw))) 649 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
628 (while (not (eq curw (setq win (next-window win)))) 650 (while (not (eq curw (setq win (next-window win))))

yatex.org