comparison lisp/textmodes/tex-mode.el @ 33472:1de979dabe6f

(tex-font-lock-keywords-1): Use `keep' rather than `prepend' and add an interesting comment. (tex-math-face, tex-font-lock-syntactic-face-function): New face and function to use it. (tex-define-common-keys, tex-mode-map): Use menu-item rather than `menu-enable' symbol property. (tex-mode-map): Bind {, (, [ and $ to skeleton-pair-insert-maybe. (tex-mode): Add some latex-mode commands for auto-selection. Use tex-font-lock-syntactic-face-function. (tex-insert-quote): Simplify. (tex-shell): New mode. (tex-start-shell): Use it. (tex-shell-proc, tex-shell-buf): New functions. (tex-send-command): Use it. (tex-main-file): Fix the meaning of the new arg REALFILE. (tex-send-tex-command): New function split from `tex-start-tex'. Set compilation-last-buffer and compilation-parsing-end.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 14 Nov 2000 11:41:35 +0000
parents 1a5b4e0146bc
children 51a929f58d72
comparison
equal deleted inserted replaced
33471:777242c79937 33472:1de979dabe6f
444 (opt "\\(\\[[^]]*\\]\\)?") 444 (opt "\\(\\[[^]]*\\]\\)?")
445 (arg "{\\(\\(?:[^{}]+\\(?:{[^}]*}\\)?\\)+\\)")) 445 (arg "{\\(\\(?:[^{}]+\\(?:{[^}]*}\\)?\\)+\\)"))
446 (list 446 (list
447 ;; Heading args. 447 ;; Heading args.
448 (list (concat slash headings "\\*?" opt arg) 448 (list (concat slash headings "\\*?" opt arg)
449 3 'font-lock-function-name-face 'prepend) 449 ;; If ARG ends up matching too much (if the {} don't match, f.ex)
450 ;; jit-lock will do funny things: when updating the buffer
451 ;; the re-highlighting is only done locally so it will just
452 ;; match the local line, but defer-contextually will
453 ;; match more lines at a time, so ARG will end up matching
454 ;; a lot more, which might suddenly include a comment
455 ;; so you get things highlighted bold when you type them
456 ;; but they get turned back to normal a little while later
457 ;; because "there's already a face there".
458 ;; Using `keep' works around this un-intuitive behavior as well
459 ;; as improves the behavior in the very rare case where you do have
460 ;; a comment in ARG.
461 3 'font-lock-function-name-face 'keep)
450 ;; Variable args. 462 ;; Variable args.
451 (list (concat slash variables arg) 2 'font-lock-variable-name-face) 463 (list (concat slash variables arg) 2 'font-lock-variable-name-face)
452 ;; Include args. 464 ;; Include args.
453 (list (concat slash includes opt arg) 3 'font-lock-builtin-face) 465 (list (concat slash includes opt arg) 3 'font-lock-builtin-face)
454 ;; Definitions. I think. 466 ;; Definitions. I think.
455 '("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 467 '("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)"
456 1 font-lock-function-name-face) 468 1 font-lock-function-name-face))))
457 )))
458 "Subdued expressions to highlight in TeX modes.") 469 "Subdued expressions to highlight in TeX modes.")
459 470
460 (defconst tex-font-lock-keywords-2 471 (defconst tex-font-lock-keywords-2
461 (append tex-font-lock-keywords-1 472 (append tex-font-lock-keywords-1
462 (eval-when-compile 473 (eval-when-compile
503 (list (concat slash type arg) 2 '(quote bold-italic) 'append) 514 (list (concat slash type arg) 2 '(quote bold-italic) 'append)
504 ;; 515 ;;
505 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables. 516 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
506 (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>" 517 (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>"
507 "\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)") 518 "\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)")
508 3 '(if (match-beginning 2) 'bold 'italic) 'append) 519 3 '(if (match-beginning 2) 'bold 'italic) 'append)))))
509 ))))
510 "Gaudy expressions to highlight in TeX modes.") 520 "Gaudy expressions to highlight in TeX modes.")
511 521
512 (defvar tex-font-lock-keywords tex-font-lock-keywords-1 522 (defvar tex-font-lock-keywords tex-font-lock-keywords-1
513 "Default expressions to highlight in TeX modes.") 523 "Default expressions to highlight in TeX modes.")
524
525
526 (defface tex-math-face
527 '((t :inherit font-lock-string-face))
528 "Face used to highlight TeX math expressions.")
529 (defvar tex-math-face 'tex-math-face)
530
531 ;; Use string syntax but math face for $...$.
532 (defun tex-font-lock-syntactic-face-function (state)
533 (if (nth 3 state) tex-math-face font-lock-comment-face))
514 534
515 535
516 (defun tex-define-common-keys (keymap) 536 (defun tex-define-common-keys (keymap)
517 "Define the keys that we want defined both in TeX mode and in the TeX shell." 537 "Define the keys that we want defined both in TeX mode and in the TeX shell."
518 (define-key keymap "\C-c\C-k" 'tex-kill-job) 538 (define-key keymap "\C-c\C-k" 'tex-kill-job)
521 (define-key keymap "\C-c\C-p" 'tex-print) 541 (define-key keymap "\C-c\C-p" 'tex-print)
522 (define-key keymap "\C-c\C-v" 'tex-view) 542 (define-key keymap "\C-c\C-v" 'tex-view)
523 543
524 (define-key keymap [menu-bar tex] (cons "TeX" (make-sparse-keymap "TeX"))) 544 (define-key keymap [menu-bar tex] (cons "TeX" (make-sparse-keymap "TeX")))
525 545
526 (define-key keymap [menu-bar tex tex-kill-job] '("Tex Kill" . tex-kill-job)) 546 (define-key keymap [menu-bar tex tex-kill-job]
547 '(menu-item "Tex Kill" tex-kill-job :enable (tex-shell-running)))
527 (define-key keymap [menu-bar tex tex-recenter-output-buffer] 548 (define-key keymap [menu-bar tex tex-recenter-output-buffer]
528 '("Tex Recenter" . tex-recenter-output-buffer)) 549 '(menu-item "Tex Recenter" tex-recenter-output-buffer
550 :enable (get-buffer "*tex-shell*")))
529 (define-key keymap [menu-bar tex tex-show-print-queue] 551 (define-key keymap [menu-bar tex tex-show-print-queue]
530 '("Show Print Queue" . tex-show-print-queue)) 552 '("Show Print Queue" . tex-show-print-queue))
531 (define-key keymap [menu-bar tex tex-alt-print] 553 (define-key keymap [menu-bar tex tex-alt-print]
532 '("Tex Print (alt printer)" . tex-alt-print)) 554 '(menu-item "Tex Print (alt printer)" tex-alt-print
533 (define-key keymap [menu-bar tex tex-print] '("Tex Print" . tex-print)) 555 :enable (stringp tex-print-file)))
534 (define-key keymap [menu-bar tex tex-view] '("Tex View" . tex-view)) 556 (define-key keymap [menu-bar tex tex-print]
535 ) 557 '(menu-item "Tex Print" tex-print :enable (stringp tex-print-file)))
536 558 (define-key keymap [menu-bar tex tex-view]
537 (defvar tex-mode-map nil "Keymap for TeX mode.") 559 '(menu-item "Tex View" tex-view :enable (stringp tex-print-file))))
538 560
539 (if tex-mode-map 561 (defvar tex-mode-map
540 nil 562 (let ((map (make-sparse-keymap)))
541 (setq tex-mode-map (make-sparse-keymap)) 563 (tex-define-common-keys map)
542 (tex-define-common-keys tex-mode-map) 564 (define-key map "\"" 'tex-insert-quote)
543 (define-key tex-mode-map "\"" 'tex-insert-quote) 565 (define-key map "(" 'skeleton-pair-insert-maybe)
544 (define-key tex-mode-map "\n" 'tex-terminate-paragraph) 566 (define-key map "{" 'skeleton-pair-insert-maybe)
545 (define-key tex-mode-map "\M-\r" 'latex-insert-item) 567 (define-key map "[" 'skeleton-pair-insert-maybe)
546 (define-key tex-mode-map "\C-c}" 'up-list) 568 (define-key map "$" 'skeleton-pair-insert-maybe)
547 (define-key tex-mode-map "\C-c{" 'tex-insert-braces) 569 (define-key map "\n" 'tex-terminate-paragraph)
548 (define-key tex-mode-map "\C-c\C-r" 'tex-region) 570 (define-key map "\M-\r" 'latex-insert-item)
549 (define-key tex-mode-map "\C-c\C-b" 'tex-buffer) 571 (define-key map "\C-c}" 'up-list)
550 (define-key tex-mode-map "\C-c\C-f" 'tex-file) 572 (define-key map "\C-c{" 'tex-insert-braces)
551 (define-key tex-mode-map "\C-c\C-i" 'tex-bibtex-file) 573 (define-key map "\C-c\C-r" 'tex-region)
552 (define-key tex-mode-map "\C-c\C-o" 'tex-latex-block) 574 (define-key map "\C-c\C-b" 'tex-buffer)
553 (define-key tex-mode-map "\C-c\C-e" 'tex-close-latex-block) 575 (define-key map "\C-c\C-f" 'tex-file)
554 (define-key tex-mode-map "\C-c\C-u" 'tex-goto-last-unclosed-latex-block) 576 (define-key map "\C-c\C-c" 'tex-compile)
555 (define-key tex-mode-map "\C-c\C-m" 'tex-feed-input) 577 (define-key map "\C-c\C-i" 'tex-bibtex-file)
556 (define-key tex-mode-map [(control return)] 'tex-feed-input) 578 (define-key map "\C-c\C-o" 'tex-latex-block)
557 (define-key tex-mode-map [menu-bar tex tex-bibtex-file] 579 (define-key map "\C-c\C-e" 'tex-close-latex-block)
558 '("BibTeX File" . tex-bibtex-file)) 580 (define-key map "\C-c\C-u" 'tex-goto-last-unclosed-latex-block)
559 (define-key tex-mode-map [menu-bar tex tex-validate-region] 581 (define-key map "\C-c\C-m" 'tex-feed-input)
560 '("Validate Region" . tex-validate-region)) 582 (define-key map [(control return)] 'tex-feed-input)
561 (define-key tex-mode-map [menu-bar tex tex-validate-buffer] 583 (define-key map [menu-bar tex tex-bibtex-file]
562 '("Validate Buffer" . tex-validate-buffer)) 584 '("BibTeX File" . tex-bibtex-file))
563 (define-key tex-mode-map [menu-bar tex tex-region] 585 (define-key map [menu-bar tex tex-validate-region]
564 '("TeX Region" . tex-region)) 586 '(menu-item "Validate Region" tex-validate-region :enable mark-active))
565 (define-key tex-mode-map [menu-bar tex tex-buffer] 587 (define-key map [menu-bar tex tex-validate-buffer]
566 '("TeX Buffer" . tex-buffer)) 588 '("Validate Buffer" . tex-validate-buffer))
567 (define-key tex-mode-map [menu-bar tex tex-file] '("TeX File" . tex-file))) 589 (define-key map [menu-bar tex tex-region]
568 590 '(menu-item "TeX Region" tex-region :enable mark-active))
569 (put 'tex-region 'menu-enable 'mark-active) 591 (define-key map [menu-bar tex tex-buffer]
570 (put 'tex-validate-region 'menu-enable 'mark-active) 592 '("TeX Buffer" . tex-buffer))
571 (put 'tex-print 'menu-enable '(stringp tex-print-file)) 593 (define-key map [menu-bar tex tex-file] '("TeX File" . tex-file))
572 (put 'tex-alt-print 'menu-enable '(stringp tex-print-file)) 594 map)
573 (put 'tex-view 'menu-enable '(stringp tex-print-file)) 595 "Keymap for TeX modes.")
574 (put 'tex-recenter-output-buffer 'menu-enable '(get-buffer "*tex-shell*"))
575 (put 'tex-kill-job 'menu-enable '(tex-shell-running))
576 596
577 (defvar tex-shell-map 597 (defvar tex-shell-map
578 (let ((m (make-sparse-keymap))) 598 (let ((m (make-sparse-keymap)))
579 (set-keymap-parent m shell-mode-map) 599 (set-keymap-parent m shell-mode-map)
580 (tex-define-common-keys m) 600 (tex-define-common-keys m)
612 (while (and (setq slash (search-forward "\\" nil t)) 632 (while (and (setq slash (search-forward "\\" nil t))
613 (setq comment (let ((search-end (point))) 633 (setq comment (let ((search-end (point)))
614 (save-excursion 634 (save-excursion
615 (beginning-of-line) 635 (beginning-of-line)
616 (search-forward "%" search-end t)))))) 636 (search-forward "%" search-end t))))))
617 (if (and slash (not comment)) 637 (when (and slash (not comment))
618 (setq mode (if (looking-at "documentstyle\\|documentclass\\|begin\\b\\|NeedsTeXFormat{LaTeX") 638 (setq mode
619 (if (looking-at 639 (if (looking-at
620 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}") 640 (eval-when-compile
621 'slitex-mode 641 (concat
622 'latex-mode) 642 (regexp-opt '("documentstyle" "documentclass"
623 'plain-tex-mode)))) 643 "begin" "section" "part" "chapter") 'words)
644 "\\|NeedsTeXFormat{LaTeX")))
645 (if (looking-at
646 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
647 'slitex-mode
648 'latex-mode)
649 'plain-tex-mode))))
624 (funcall mode))) 650 (funcall mode)))
625 651
626 ;;;###autoload 652 ;;;###autoload
627 (defalias 'TeX-mode 'tex-mode) 653 (defalias 'TeX-mode 'tex-mode)
628 ;;;###autoload 654 ;;;###autoload
836 (set (make-local-variable 'font-lock-defaults) 862 (set (make-local-variable 'font-lock-defaults)
837 '((tex-font-lock-keywords 863 '((tex-font-lock-keywords
838 tex-font-lock-keywords-1 tex-font-lock-keywords-2) 864 tex-font-lock-keywords-1 tex-font-lock-keywords-2)
839 nil nil ((?$ . "\"")) nil 865 nil nil ((?$ . "\"")) nil
840 ;; Who ever uses that anyway ??? 866 ;; Who ever uses that anyway ???
841 (font-lock-mark-block-function . mark-paragraph))) 867 (font-lock-mark-block-function . mark-paragraph)
868 (font-lock-syntactic-face-function
869 . tex-font-lock-syntactic-face-function)))
842 (make-local-variable 'tex-command) 870 (make-local-variable 'tex-command)
843 (make-local-variable 'tex-start-of-header) 871 (make-local-variable 'tex-start-of-header)
844 (make-local-variable 'tex-end-of-header) 872 (make-local-variable 'tex-end-of-header)
845 (make-local-variable 'tex-trailer)) 873 (make-local-variable 'tex-trailer))
846 874
881 inserts \" characters." 909 inserts \" characters."
882 (interactive "*P") 910 (interactive "*P")
883 (if arg 911 (if arg
884 (self-insert-command (prefix-numeric-value arg)) 912 (self-insert-command (prefix-numeric-value arg))
885 (insert 913 (insert
886 (cond ((or (bobp) 914 (cond ((= (preceding-char) ?\\) ?\")
887 (save-excursion 915 ((memq (char-syntax (preceding-char)) '(?\( ?> ?\ )) tex-open-quote)
888 (forward-char -1) 916 (t tex-close-quote)))))
889 (looking-at "\\s(\\|\\s \\|\\s>")))
890 tex-open-quote)
891 ((= (preceding-char) ?\\)
892 ?\")
893 (t
894 tex-close-quote)))))
895 917
896 (defun tex-validate-buffer () 918 (defun tex-validate-buffer ()
897 "Check current buffer for paragraphs containing mismatched braces or $s. 919 "Check current buffer for paragraphs containing mismatched braces or $s.
898 Their positions are recorded in the buffer `*Occur*'. 920 Their positions are recorded in the buffer `*Occur*'.
899 To find a particular invalidity from `*Occur*', switch to that buffer 921 To find a particular invalidity from `*Occur*', switch to that buffer
954 'mouse-face 'highlight) 976 'mouse-face 'highlight)
955 (put-text-property (marker-position text-beg) 977 (put-text-property (marker-position text-beg)
956 (- (marker-position text-end) 1) 978 (- (marker-position text-end) 1)
957 'occur tem))))) 979 'occur tem)))))
958 (goto-char prev-end)))) 980 (goto-char prev-end))))
959 (save-excursion 981 (with-current-buffer standard-output
960 (set-buffer standard-output)
961 (if (eq num-matches 0) 982 (if (eq num-matches 0)
962 (insert "None!\n")) 983 (insert "None!\n"))
963 (if (interactive-p) 984 (if (interactive-p)
964 (message "%d mismatches found" num-matches)))))) 985 (message "%d mismatches found" num-matches))))))
965 986
988 (error "Mismatched parentheses")))) 1009 (error "Mismatched parentheses"))))
989 (forward-char 1))) 1010 (forward-char 1)))
990 (error 1011 (error
991 (skip-syntax-forward " .>") 1012 (skip-syntax-forward " .>")
992 (setq failure-point (point))))) 1013 (setq failure-point (point)))))
993 (if failure-point 1014 (if failure-point (goto-char failure-point))
994 (progn 1015 (not failure-point)))
995 (goto-char failure-point)
996 nil)
997 t)))
998 1016
999 (defun tex-terminate-paragraph (inhibit-validation) 1017 (defun tex-terminate-paragraph (inhibit-validation)
1000 "Insert two newlines, breaking a paragraph for TeX. 1018 "Insert two newlines, breaking a paragraph for TeX.
1001 Check for mismatched braces or $s in paragraph being terminated. 1019 Check for mismatched braces or $s in paragraph being terminated.
1002 A prefix arg inhibits the checking." 1020 A prefix arg inhibits the checking."
1187 ;;; Why use a shell instead of running TeX directly? Because if TeX 1205 ;;; Why use a shell instead of running TeX directly? Because if TeX
1188 ;;; gets stuck, the user can switch to the shell window and type at it. 1206 ;;; gets stuck, the user can switch to the shell window and type at it.
1189 1207
1190 ;;; The utility functions: 1208 ;;; The utility functions:
1191 1209
1210 (define-derived-mode tex-shell shell-mode "TeX-Shell"
1211 (compilation-shell-minor-mode t))
1212
1192 ;;;###autoload 1213 ;;;###autoload
1193 (defun tex-start-shell () 1214 (defun tex-start-shell ()
1194 (with-current-buffer 1215 (with-current-buffer
1195 (make-comint 1216 (make-comint
1196 "tex-shell" 1217 "tex-shell"
1197 (or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh") 1218 (or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh")
1198 nil) 1219 nil)
1199 (let ((proc (get-process "tex-shell"))) 1220 (let ((proc (get-process "tex-shell")))
1200 (set-process-sentinel proc 'tex-shell-sentinel) 1221 (set-process-sentinel proc 'tex-shell-sentinel)
1201 (process-kill-without-query proc) 1222 (process-kill-without-query proc)
1202 (setq comint-prompt-regexp shell-prompt-pattern) 1223 (tex-shell)
1203 (use-local-map tex-shell-map)
1204 (compilation-shell-minor-mode t)
1205 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t)
1206 (make-local-variable 'list-buffers-directory)
1207 (make-local-variable 'shell-dirstack)
1208 (make-local-variable 'shell-last-dir)
1209 (make-local-variable 'shell-dirtrackp)
1210 (run-hooks 'tex-shell-hook)
1211 (while (zerop (buffer-size)) 1224 (while (zerop (buffer-size))
1212 (sleep-for 1))))) 1225 (sleep-for 1)))))
1213 1226
1214 (defun tex-feed-input () 1227 (defun tex-feed-input ()
1215 "Send input to the tex shell process. 1228 "Send input to the tex shell process.
1243 (setq default-directory directory)))) 1256 (setq default-directory directory))))
1244 1257
1245 (defvar tex-send-command-modified-tick 0) 1258 (defvar tex-send-command-modified-tick 0)
1246 (make-variable-buffer-local 'tex-send-command-modified-tick) 1259 (make-variable-buffer-local 'tex-send-command-modified-tick)
1247 1260
1261 (defun tex-shell-proc ()
1262 (or (get-process "tex-shell") (error "No TeX subprocess")))
1263 (defun tex-shell-buf ()
1264 (process-buffer (tex-shell-proc)))
1265
1248 (defun tex-send-command (command &optional file background) 1266 (defun tex-send-command (command &optional file background)
1249 "Send COMMAND to TeX shell process, substituting optional FILE for *. 1267 "Send COMMAND to TeX shell process, substituting optional FILE for *.
1250 Do this in background if optional BACKGROUND is t. If COMMAND has no *, 1268 Do this in background if optional BACKGROUND is t. If COMMAND has no *,
1251 FILE will be appended, preceded by a blank, to COMMAND. If FILE is nil, no 1269 FILE will be appended, preceded by a blank, to COMMAND. If FILE is nil, no
1252 substitution will be made in COMMAND. COMMAND can be any expression that 1270 substitution will be made in COMMAND. COMMAND can be any expression that
1253 evaluates to a command string. 1271 evaluates to a command string.
1254 1272
1255 Return the process in which TeX is running." 1273 Return the process in which TeX is running."
1256 (save-excursion 1274 (save-excursion
1257 (let* ((cmd (eval command)) 1275 (let* ((cmd (eval command))
1258 (proc (or (get-process "tex-shell") (error "No TeX subprocess"))) 1276 (proc (tex-shell-proc))
1259 (buf (process-buffer proc)) 1277 (buf (process-buffer proc))
1260 (star (string-match "\\*" cmd)) 1278 (star (string-match "\\*" cmd))
1261 (string 1279 (string
1262 (concat 1280 (concat
1263 (if file 1281 (if file
1327 (re-search-forward header-re 10000 t))) 1345 (re-search-forward header-re 10000 t)))
1328 (throw 'found (expand-file-name buffer-file-name)))))))) 1346 (throw 'found (expand-file-name buffer-file-name))))))))
1329 1347
1330 (defun tex-main-file (&optional realfile) 1348 (defun tex-main-file (&optional realfile)
1331 "Return the name of the main file with the `.tex' extension stripped. 1349 "Return the name of the main file with the `.tex' extension stripped.
1332 If REALFILE is non-nil, don't strip the extension." 1350 If REALFILE is non-nil, return the pair (FILE . REALFILE) where FILE
1333 (let ((file (or tex-main-file 1351 is the filename without the extension while REALFILE is the filename
1334 ;; Compatibility with AUCTeX. 1352 with extension."
1335 (and (boundp 'TeX-master) (stringp TeX-master) 1353 (let* ((file (or tex-main-file
1336 (set (make-local-variable 'tex-main-file) TeX-master)) 1354 ;; Compatibility with AUCTeX.
1337 ;; Try to guess the main file. 1355 (and (boundp 'TeX-master) (stringp TeX-master)
1338 (if (not buffer-file-name) 1356 (set (make-local-variable 'tex-main-file) TeX-master))
1339 (error "Buffer is not associated with any file") 1357 ;; Try to guess the main file.
1340 (file-relative-name 1358 (if (not buffer-file-name)
1341 (if (save-excursion 1359 (error "Buffer is not associated with any file")
1342 (goto-char (point-min)) 1360 (file-relative-name
1343 (re-search-forward tex-start-of-header 10000 t)) 1361 (if (save-excursion
1344 ;; This is the main file. 1362 (goto-char (point-min))
1345 buffer-file-name 1363 (re-search-forward tex-start-of-header 10000 t))
1346 ;; This isn't the main file, let's try to find better, 1364 ;; This is the main file.
1347 (or (tex-guess-main-file) 1365 buffer-file-name
1348 ;; (tex-guess-main-file t) 1366 ;; This isn't the main file, let's try to find better,
1349 buffer-file-name))))))) 1367 (or (tex-guess-main-file)
1350 (cond 1368 ;; (tex-guess-main-file t)
1351 (realfile (if (file-exists-p file) file (concat file ".tex"))) 1369 buffer-file-name))))))
1352 ((string-match "\\.tex\\'" file) (substring file 0 (match-beginning 0))) 1370 (real (if (file-exists-p file) file (concat file ".tex"))))
1353 (t file)))) 1371 (when (string-match "\\.tex\\'" file)
1372 (setq file (substring file 0 (match-beginning 0))))
1373 (if realfile (cons file real) file)))
1354 1374
1355 1375
1356 (defun tex-start-tex (command file &optional dir) 1376 (defun tex-start-tex (command file &optional dir)
1357 "Start a TeX run, using COMMAND on FILE." 1377 "Start a TeX run, using COMMAND on FILE."
1358 (let* ((star (string-match "\\*" command)) 1378 (let* ((star (string-match "\\*" command))
1364 (concat command " " 1384 (concat command " "
1365 (if (< 0 (length tex-start-options-string)) 1385 (if (< 0 (length tex-start-options-string))
1366 (concat 1386 (concat
1367 (shell-quote-argument tex-start-options-string) " ")) 1387 (shell-quote-argument tex-start-options-string) " "))
1368 (comint-quote-filename file))))) 1388 (comint-quote-filename file)))))
1369 (when dir 1389 (tex-send-tex-command compile-command dir)))
1370 (let (shell-dirtrack-verbose) 1390
1371 (tex-send-command tex-shell-cd-command dir))) 1391 (defun tex-send-tex-command (cmd &optional dir)
1372 (with-current-buffer (process-buffer (tex-send-command compile-command)) 1392 (unless (or (equal dir (with-current-buffer (tex-shell-buf)
1373 (save-excursion 1393 default-directory))
1374 (forward-line -1) 1394 (not dir))
1375 (setq tex-start-tex-marker (point-marker))) 1395 (let (shell-dirtrack-verbose)
1376 (make-local-variable 'compilation-parse-errors-function) 1396 (tex-send-command tex-shell-cd-command dir)))
1377 (setq compilation-parse-errors-function 'tex-compilation-parse-errors) 1397 (with-current-buffer (process-buffer (tex-send-command cmd))
1378 (compilation-forget-errors)) 1398 (save-excursion
1379 (tex-display-shell) 1399 (forward-line -1)
1380 (setq tex-last-buffer-texed (current-buffer)))) 1400 (setq tex-start-tex-marker (point-marker)))
1401 (make-local-variable 'compilation-parse-errors-function)
1402 (setq compilation-parse-errors-function 'tex-compilation-parse-errors)
1403 (setq compilation-last-buffer (current-buffer))
1404 (compilation-forget-errors)
1405 (set-marker compilation-parsing-end (1- (point-max))))
1406 (tex-display-shell)
1407 (setq tex-last-buffer-texed (current-buffer)))
1381 1408
1382 (defun tex-compilation-parse-errors (limit-search find-at-least) 1409 (defun tex-compilation-parse-errors (limit-search find-at-least)
1383 "Parse the current buffer as TeX error messages. 1410 "Parse the current buffer as TeX error messages.
1384 See the variable `compilation-parse-errors-function' for the interface it uses. 1411 See the variable `compilation-parse-errors-function' for the interface it uses.
1385 1412