Mercurial > emacs
comparison lisp/textmodes/tex-mode.el @ 31968:dc896c1b6a26
(latex-imenu-indent-string): Add a space.
(latex-outline-regexp): New var.
(latex-outline-level): New fun.
(latex-section-alist): New var.
(latex-imenu-create-index): Use it. Use `push' as well.
(tex-shell-map): Initialize it properly.
(tex-mode): Minor stylistic change.
(plain-tex-mode): Use define-derived-mode.
(latex-mode): Use define-derived-mode.
Construct the paragraph regexps in a more readable way.
Set the buffer-local outline-{level,regexp} vars.
(slitex-mode): Derive from latex-mode.
(tex-common-initialization): Don't kill-all-vars anymore.
Add setting for comment-add and font-lock-defaults.
(tex-start-shell): Use with-current-buffer and don't re-init keymap.
(tex-main-file): New fun. Obey TeX-master as well and remove `.tex'.
(tex-start-tex): New arg DIR (and send a chdir command for it).
Also display the shell buffer and save it in tex-last-buffer-texed.
(tex-region): Use expand-file-name rather than concat.
Remove code made useless by changes in tex-start-tex.
(tex-file): Use tex-main-file and adapt to new tex-start-tex.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 29 Sep 2000 01:45:46 +0000 |
parents | e559f0aa6b2d |
children | 170342999dcc |
comparison
equal
deleted
inserted
replaced
31967:54b09b09e4bd | 31968:dc896c1b6a26 |
---|---|
267 Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].") | 267 Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].") |
268 | 268 |
269 (defvar tex-mode-syntax-table nil | 269 (defvar tex-mode-syntax-table nil |
270 "Syntax table used while in TeX mode.") | 270 "Syntax table used while in TeX mode.") |
271 | 271 |
272 (defcustom latex-imenu-indent-string "." | 272 (defcustom latex-imenu-indent-string ". " |
273 "*String to add repeated in front of nested sectional units for Imenu. | 273 "*String to add repeated in front of nested sectional units for Imenu. |
274 An alternative value is \" . \", if you use a font with a narrow period." | 274 An alternative value is \" . \", if you use a font with a narrow period." |
275 :type 'string | 275 :type 'string |
276 :group 'tex) | 276 :group 'tex) |
277 | |
278 (defvar latex-section-alist | |
279 '(("part" . 0) ("chapter" . 1) | |
280 ("section" . 2) ("subsection" . 3) | |
281 ("subsubsection" . 4) | |
282 ("paragraph" . 5) ("subparagraph" . 6))) | |
277 | 283 |
278 (defun latex-imenu-create-index () | 284 (defun latex-imenu-create-index () |
279 "Generates an alist for imenu from a LaTeX buffer." | 285 "Generates an alist for imenu from a LaTeX buffer." |
280 (let (i0 menu case-fold-search) | 286 (let (i0 menu case-fold-search) |
281 (save-excursion | 287 (save-excursion |
289 (setq i0 2))) | 295 (setq i0 2))) |
290 | 296 |
291 ;; Look for chapters and sections. | 297 ;; Look for chapters and sections. |
292 (goto-char (point-min)) | 298 (goto-char (point-min)) |
293 (while (search-forward-regexp | 299 (while (search-forward-regexp |
294 "\\\\\\(part\\|chapter\\|section\\|subsection\\|\ | 300 (eval-when-compile |
295 subsubsection\\|paragraph\\|subparagraph\\)\\*?[ \t]*{" nil t) | 301 (concat "\\\\" (regexp-opt (mapcar 'car latex-section-alist) t) |
302 "\\*?[ \t]*{")) nil t) | |
296 (let ((start (match-beginning 0)) | 303 (let ((start (match-beginning 0)) |
297 (here (point)) | 304 (here (point)) |
298 (i (cdr (assoc (buffer-substring-no-properties | 305 (i (cdr (assoc (buffer-substring-no-properties |
299 (match-beginning 1) | 306 (match-beginning 1) |
300 (match-end 1)) | 307 (match-end 1)) |
301 '(("part" . 0) ("chapter" . 1) | 308 latex-section-alist)))) |
302 ("section" . 2) ("subsection" . 3) | |
303 ("subsubsection" . 4) | |
304 ("paragraph" . 5) ("subparagraph" . 6)))))) | |
305 (backward-char 1) | 309 (backward-char 1) |
306 (condition-case err | 310 (condition-case err |
307 (progn | 311 (progn |
308 ;; Using sexps allows some use of matching {...} inside | 312 ;; Using sexps allows some use of matching {...} inside |
309 ;; titles. | 313 ;; titles. |
310 (forward-sexp 1) | 314 (forward-sexp 1) |
311 (setq menu | 315 (push (cons (concat (apply 'concat |
312 (cons (cons (concat (apply 'concat | 316 (make-list |
313 (make-list | 317 (max 0 (- i i0)) |
314 (max 0 (- i i0)) | 318 latex-imenu-indent-string)) |
315 latex-imenu-indent-string)) | 319 (buffer-substring-no-properties |
316 (buffer-substring-no-properties | 320 here (1- (point)))) |
317 here (1- (point)))) | 321 start) |
318 start) | 322 menu)) |
319 menu)) | |
320 ) | |
321 (error nil)))) | 323 (error nil)))) |
322 | 324 |
323 ;; Look for included material. | 325 ;; Look for included material. |
324 (goto-char (point-min)) | 326 (goto-char (point-min)) |
325 (while (search-forward-regexp | 327 (while (search-forward-regexp |
406 (put 'tex-alt-print 'menu-enable '(stringp tex-print-file)) | 408 (put 'tex-alt-print 'menu-enable '(stringp tex-print-file)) |
407 (put 'tex-view 'menu-enable '(stringp tex-print-file)) | 409 (put 'tex-view 'menu-enable '(stringp tex-print-file)) |
408 (put 'tex-recenter-output-buffer 'menu-enable '(get-buffer "*tex-shell*")) | 410 (put 'tex-recenter-output-buffer 'menu-enable '(get-buffer "*tex-shell*")) |
409 (put 'tex-kill-job 'menu-enable '(tex-shell-running)) | 411 (put 'tex-kill-job 'menu-enable '(tex-shell-running)) |
410 | 412 |
411 (defvar tex-shell-map nil | 413 (defvar tex-shell-map |
414 (let ((m (make-sparse-keymap))) | |
415 (set-keymap-parent m shell-mode-map) | |
416 (tex-define-common-keys m) | |
417 m) | |
412 "Keymap for the TeX shell. | 418 "Keymap for the TeX shell. |
413 Inherits `shell-mode-map' with a few additions.") | 419 Inherits `shell-mode-map' with a few additions.") |
414 | 420 |
415 (defvar tex-face-alist | 421 (defvar tex-face-alist |
416 '((bold . "{\\bf ") | 422 '((bold . "{\\bf ") |
434 this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', | 440 this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', |
435 `latex-mode', or `slitex-mode', respectively. If it cannot be determined, | 441 `latex-mode', or `slitex-mode', respectively. If it cannot be determined, |
436 such as if there are no commands in the file, the value of `tex-default-mode' | 442 such as if there are no commands in the file, the value of `tex-default-mode' |
437 says which mode to use." | 443 says which mode to use." |
438 (interactive) | 444 (interactive) |
439 (let (mode slash comment) | 445 (let ((mode tex-default-mode) slash comment) |
440 (save-excursion | 446 (save-excursion |
441 (goto-char (point-min)) | 447 (goto-char (point-min)) |
442 (while (and (setq slash (search-forward "\\" nil t)) | 448 (while (and (setq slash (search-forward "\\" nil t)) |
443 (setq comment (let ((search-end (point))) | 449 (setq comment (let ((search-end (point))) |
444 (save-excursion | 450 (save-excursion |
449 (if (looking-at | 455 (if (looking-at |
450 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}") | 456 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}") |
451 'slitex-mode | 457 'slitex-mode |
452 'latex-mode) | 458 'latex-mode) |
453 'plain-tex-mode)))) | 459 'plain-tex-mode)))) |
454 (if mode (funcall mode) | 460 (funcall mode))) |
455 (funcall tex-default-mode)))) | |
456 | 461 |
457 ;;;###autoload | 462 ;;;###autoload |
458 (defalias 'TeX-mode 'tex-mode) | 463 (defalias 'TeX-mode 'tex-mode) |
459 ;;;###autoload | 464 ;;;###autoload |
460 (defalias 'plain-TeX-mode 'plain-tex-mode) | 465 (defalias 'plain-TeX-mode 'plain-tex-mode) |
461 ;;;###autoload | 466 ;;;###autoload |
462 (defalias 'LaTeX-mode 'latex-mode) | 467 (defalias 'LaTeX-mode 'latex-mode) |
463 | 468 |
464 ;;;###autoload | 469 ;;;###autoload |
465 (defun plain-tex-mode () | 470 (define-derived-mode plain-tex-mode text-mode "TeX" |
466 "Major mode for editing files of input for plain TeX. | 471 "Major mode for editing files of input for plain TeX. |
467 Makes $ and } display the characters they match. | 472 Makes $ and } display the characters they match. |
468 Makes \" insert `` when it seems to be the beginning of a quotation, | 473 Makes \" insert `` when it seems to be the beginning of a quotation, |
469 and '' when it appears to be the end; it inserts \" only after a \\. | 474 and '' when it appears to be the end; it inserts \" only after a \\. |
470 | 475 |
500 queue that \\[tex-print] put your job on. | 505 queue that \\[tex-print] put your job on. |
501 | 506 |
502 Entering Plain-tex mode runs the hook `text-mode-hook', then the hook | 507 Entering Plain-tex mode runs the hook `text-mode-hook', then the hook |
503 `tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the | 508 `tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the |
504 special subshell is initiated, the hook `tex-shell-hook' is run." | 509 special subshell is initiated, the hook `tex-shell-hook' is run." |
505 | |
506 (interactive) | |
507 (tex-common-initialization) | 510 (tex-common-initialization) |
508 (setq mode-name "TeX") | |
509 (setq major-mode 'plain-tex-mode) | |
510 (setq tex-command tex-run-command) | 511 (setq tex-command tex-run-command) |
511 (setq tex-start-of-header "%\\*\\*start of header") | 512 (setq tex-start-of-header "%\\*\\*start of header") |
512 (setq tex-end-of-header "%\\*\\*end of header") | 513 (setq tex-end-of-header "%\\*\\*end of header") |
513 (setq tex-trailer "\\bye\n") | 514 (setq tex-trailer "\\bye\n") |
514 (run-hooks 'text-mode-hook 'tex-mode-hook 'plain-tex-mode-hook)) | 515 (run-hooks 'tex-mode-hook)) |
515 | 516 |
516 ;;;###autoload | 517 ;;;###autoload |
517 (defun latex-mode () | 518 (define-derived-mode latex-mode text-mode "LaTeX" |
518 "Major mode for editing files of input for LaTeX. | 519 "Major mode for editing files of input for LaTeX. |
519 Makes $ and } display the characters they match. | 520 Makes $ and } display the characters they match. |
520 Makes \" insert `` when it seems to be the beginning of a quotation, | 521 Makes \" insert `` when it seems to be the beginning of a quotation, |
521 and '' when it appears to be the end; it inserts \" only after a \\. | 522 and '' when it appears to be the end; it inserts \" only after a \\. |
522 | 523 |
552 queue that \\[tex-print] put your job on. | 553 queue that \\[tex-print] put your job on. |
553 | 554 |
554 Entering Latex mode runs the hook `text-mode-hook', then | 555 Entering Latex mode runs the hook `text-mode-hook', then |
555 `tex-mode-hook', and finally `latex-mode-hook'. When the special | 556 `tex-mode-hook', and finally `latex-mode-hook'. When the special |
556 subshell is initiated, `tex-shell-hook' is run." | 557 subshell is initiated, `tex-shell-hook' is run." |
557 (interactive) | |
558 (tex-common-initialization) | 558 (tex-common-initialization) |
559 (setq mode-name "LaTeX") | |
560 (setq major-mode 'latex-mode) | |
561 (setq tex-command latex-run-command) | 559 (setq tex-command latex-run-command) |
562 (setq tex-start-of-header "\\\\documentstyle\\|\\\\documentclass") | 560 (setq tex-start-of-header "\\\\documentstyle\\|\\\\documentclass") |
563 (setq tex-end-of-header "\\\\begin{document}") | 561 (setq tex-end-of-header "\\\\begin{document}") |
564 (setq tex-trailer "\\end{document}\n") | 562 (setq tex-trailer "\\end{document}\n") |
565 ;; A line containing just $$ is treated as a paragraph separator. | 563 ;; A line containing just $$ is treated as a paragraph separator. |
566 ;; A line starting with $$ starts a paragraph, | 564 ;; A line starting with $$ starts a paragraph, |
567 ;; but does not separate paragraphs if it has more stuff on it. | 565 ;; but does not separate paragraphs if it has more stuff on it. |
568 (setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\ | 566 (setq paragraph-start |
569 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\ | 567 (concat "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|" |
570 \\\\chapter\\>\\|\\\\section\\>\\|\ | 568 "\\\\[][]\\|" |
571 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\ | 569 "\\\\" (regexp-opt (append |
572 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\ | 570 (mapcar 'car latex-section-alist) |
573 \\\\item\\>\\|\\\\bibitem\\>\\|\\\\newline\\>\\|\\\\noindent\\>\\|\ | 571 '("begin" "label" "end" |
574 \\\\[a-z]*space\\>\\|\\\\[a-z]*skip\\>\\|\ | 572 "item" "bibitem" "newline" "noindent" |
575 \\\\newpage\\>\\|\\\\[a-z]*page\\|\\\\footnote\\>\\|\ | 573 "newpage" "footnote" "marginpar" |
576 \\\\marginpar\\>\\|\\\\parbox\\>\\|\\\\caption\\>") | 574 "parbox" "caption")) t) |
577 (setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\ | 575 "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t) |
578 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\ | 576 "\\>")) |
579 \\\\chapter\\>\\|\\\\section\\>\\|\ | 577 (setq paragraph-separate |
580 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\ | 578 (concat "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|" |
581 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\ | 579 "\\\\[][]\\|" |
582 \\(\\\\item\\|\\\\bibitem\\|\\\\newline\\|\\\\noindent\\|\ | 580 "\\\\" (regexp-opt (append |
583 \\\\[a-z]*space\\|\\\\[a-z]*skip\\|\ | 581 (mapcar 'car latex-section-alist) |
584 \\\\newpage\\|\\\\[a-z]*page[a-z]*\\|\\\\footnote\\|\ | 582 '("begin" "label" "end" )) t) |
585 \\\\marginpar\\|\\\\parbox\\|\\\\caption\\)[ \t]*\\($\\|%\\)") | 583 "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline" |
586 (make-local-variable 'imenu-create-index-function) | 584 "noindent" "newpage" "footnote" |
587 (setq imenu-create-index-function 'latex-imenu-create-index) | 585 "marginpar" "parbox" "caption")) |
588 (make-local-variable 'tex-face-alist) | 586 "\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)" |
589 (setq tex-face-alist tex-latex-face-alist) | 587 "\\)[ \t]*\\($\\|%\\)")) |
590 (make-local-variable 'fill-nobreak-predicate) | 588 (set (make-local-variable 'imenu-create-index-function) |
591 (setq fill-nobreak-predicate 'latex-fill-nobreak-predicate) | 589 'latex-imenu-create-index) |
592 (run-hooks 'text-mode-hook 'tex-mode-hook 'latex-mode-hook)) | 590 (set (make-local-variable 'tex-face-alist) tex-latex-face-alist) |
593 | 591 (set (make-local-variable 'fill-nobreak-predicate) |
594 ;;;###autoload | 592 'latex-fill-nobreak-predicate) |
595 (defun slitex-mode () | 593 (set (make-local-variable 'outline-regexp) latex-outline-regexp) |
594 (set (make-local-variable 'outline-level) 'latex-outline-level) | |
595 (run-hooks 'tex-mode-hook)) | |
596 | |
597 ;;;###autoload | |
598 (define-derived-mode slitex-mode latex-mode "SliTeX" | |
596 "Major mode for editing files of input for SliTeX. | 599 "Major mode for editing files of input for SliTeX. |
597 Makes $ and } display the characters they match. | 600 Makes $ and } display the characters they match. |
598 Makes \" insert `` when it seems to be the beginning of a quotation, | 601 Makes \" insert `` when it seems to be the beginning of a quotation, |
599 and '' when it appears to be the end; it inserts \" only after a \\. | 602 and '' when it appears to be the end; it inserts \" only after a \\. |
600 | 603 |
631 | 634 |
632 Entering SliTeX mode runs the hook `text-mode-hook', then the hook | 635 Entering SliTeX mode runs the hook `text-mode-hook', then the hook |
633 `tex-mode-hook', then the hook `latex-mode-hook', and finally the hook | 636 `tex-mode-hook', then the hook `latex-mode-hook', and finally the hook |
634 `slitex-mode-hook'. When the special subshell is initiated, the hook | 637 `slitex-mode-hook'. When the special subshell is initiated, the hook |
635 `tex-shell-hook' is run." | 638 `tex-shell-hook' is run." |
636 (interactive) | |
637 (tex-common-initialization) | |
638 (setq mode-name "SliTeX") | |
639 (setq major-mode 'slitex-mode) | |
640 (setq tex-command slitex-run-command) | 639 (setq tex-command slitex-run-command) |
641 (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}") | 640 (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")) |
642 (setq tex-end-of-header "\\\\begin{document}") | |
643 (setq tex-trailer "\\end{document}\n") | |
644 ;; A line containing just $$ is treated as a paragraph separator. | |
645 ;; A line starting with $$ starts a paragraph, | |
646 ;; but does not separate paragraphs if it has more stuff on it. | |
647 (setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\ | |
648 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\ | |
649 \\\\chapter\\>\\|\\\\section\\>\\|\ | |
650 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\ | |
651 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\ | |
652 \\\\item\\>\\|\\\\bibitem\\>\\|\\\\newline\\>\\|\\\\noindent\\>\\|\ | |
653 \\\\[a-z]*space\\>\\|\\\\[a-z]*skip\\>\\|\ | |
654 \\\\newpage\\>\\|\\\\[a-z]*page\\|\\\\footnote\\>\\|\ | |
655 \\\\marginpar\\>\\|\\\\parbox\\>\\|\\\\caption\\>") | |
656 (setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\ | |
657 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\ | |
658 \\\\chapter\\>\\|\\\\section\\>\\|\ | |
659 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\ | |
660 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\ | |
661 \\\\item[ \t]*$\\|\\\\bibitem[ \t]*$\\|\\\\newline[ \t]*$\\|\\\\noindent[ \t]*$\\|\ | |
662 \\\\[a-z]*space[ \t]*$\\|\\\\[a-z]*skip[ \t]*$\\|\ | |
663 \\\\newpage[ \t]*$\\|\\\\[a-z]*page[a-z]*[ \t]*$\\|\\\\footnote[ \t]*$\\|\ | |
664 \\\\marginpar[ \t]*$\\|\\\\parbox[ \t]*$\\|\\\\caption[ \t]*$") | |
665 (make-local-variable 'imenu-create-index-function) | |
666 (setq imenu-create-index-function 'latex-imenu-create-index) | |
667 (make-local-variable 'tex-face-alist) | |
668 (setq tex-face-alist tex-latex-face-alist) | |
669 (make-local-variable 'fill-nobreak-predicate) | |
670 (setq fill-nobreak-predicate 'latex-fill-nobreak-predicate) | |
671 (run-hooks | |
672 'text-mode-hook 'tex-mode-hook 'latex-mode-hook 'slitex-mode-hook)) | |
673 | 641 |
674 (defun tex-common-initialization () | 642 (defun tex-common-initialization () |
675 (kill-all-local-variables) | |
676 (use-local-map tex-mode-map) | 643 (use-local-map tex-mode-map) |
677 (setq local-abbrev-table text-mode-abbrev-table) | 644 (setq local-abbrev-table text-mode-abbrev-table) |
678 (if (null tex-mode-syntax-table) | 645 (if (null tex-mode-syntax-table) |
679 (let ((char 0)) | 646 (let ((char 0)) |
680 (setq tex-mode-syntax-table (make-syntax-table)) | 647 (setq tex-mode-syntax-table (make-syntax-table)) |
695 (modify-syntax-entry ?@ "_") | 662 (modify-syntax-entry ?@ "_") |
696 (modify-syntax-entry ?~ " ") | 663 (modify-syntax-entry ?~ " ") |
697 (modify-syntax-entry ?' "w")) | 664 (modify-syntax-entry ?' "w")) |
698 (set-syntax-table tex-mode-syntax-table)) | 665 (set-syntax-table tex-mode-syntax-table)) |
699 ;; Regexp isearch should accept newline and formfeed as whitespace. | 666 ;; Regexp isearch should accept newline and formfeed as whitespace. |
700 (make-local-variable 'search-whitespace-regexp) | 667 (set (make-local-variable 'search-whitespace-regexp) "[ \t\r\n\f]+") |
701 (setq search-whitespace-regexp "[ \t\r\n\f]+") | |
702 (make-local-variable 'paragraph-start) | |
703 ;; A line containing just $$ is treated as a paragraph separator. | 668 ;; A line containing just $$ is treated as a paragraph separator. |
704 (setq paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$") | 669 (set (make-local-variable 'paragraph-start) |
705 (make-local-variable 'paragraph-separate) | 670 "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$") |
706 ;; A line starting with $$ starts a paragraph, | 671 ;; A line starting with $$ starts a paragraph, |
707 ;; but does not separate paragraphs if it has more stuff on it. | 672 ;; but does not separate paragraphs if it has more stuff on it. |
708 (setq paragraph-separate "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$") | 673 (set (make-local-variable 'paragraph-separate) |
709 (make-local-variable 'comment-start) | 674 "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$") |
710 (setq comment-start "%") | 675 (set (make-local-variable 'comment-start) "%") |
711 (make-local-variable 'comment-start-skip) | 676 (set (make-local-variable 'comment-add) 1) |
712 (setq comment-start-skip "\\(\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\)\\(%+ *\\)") | 677 (set (make-local-variable 'comment-start-skip) |
713 (make-local-variable 'comment-indent-function) | 678 "\\(\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\)\\(%+ *\\)") |
714 (setq comment-indent-function 'tex-comment-indent) | 679 (set (make-local-variable 'comment-indent-function) 'tex-comment-indent) |
715 (make-local-variable 'parse-sexp-ignore-comments) | 680 (set (make-local-variable 'parse-sexp-ignore-comments) t) |
716 (setq parse-sexp-ignore-comments t) | 681 (set (make-local-variable 'compare-windows-whitespace) |
717 (make-local-variable 'compare-windows-whitespace) | 682 'tex-categorize-whitespace) |
718 (setq compare-windows-whitespace 'tex-categorize-whitespace) | 683 (set (make-local-variable 'facemenu-add-face-function) |
719 (make-local-variable 'skeleton-further-elements) | 684 (lambda (face end) |
720 (setq skeleton-further-elements | 685 (let ((face-text (cdr (assq face tex-face-alist)))) |
721 '((indent-line-function 'indent-relative-maybe))) | 686 (if face-text |
722 (make-local-variable 'facemenu-add-face-function) | 687 face-text |
723 (make-local-variable 'facemenu-end-add-face) | 688 (error "Face %s not configured for %s mode" face mode-name))))) |
724 (make-local-variable 'facemenu-remove-face-function) | 689 (set (make-local-variable 'facemenu-end-add-face) "}") |
725 (setq facemenu-add-face-function | 690 (set (make-local-variable 'facemenu-remove-face-function) t) |
726 (lambda (face end) | 691 (set (make-local-variable 'font-lock-defaults) |
727 (let ((face-text (cdr (assq face tex-face-alist)))) | 692 '((tex-font-lock-keywords |
728 (if face-text | 693 tex-font-lock-keywords-1 tex-font-lock-keywords-2) |
729 face-text | 694 nil nil ((?$ . "\"")) nil |
730 (error "Face %s not configured for %s mode" face mode-name)))) | 695 ;; Who ever uses that anyway ??? |
731 facemenu-end-add-face "}" | 696 (font-lock-mark-block-function . mark-paragraph))) |
732 facemenu-remove-face-function t) | |
733 (make-local-variable 'tex-command) | 697 (make-local-variable 'tex-command) |
734 (make-local-variable 'tex-start-of-header) | 698 (make-local-variable 'tex-start-of-header) |
735 (make-local-variable 'tex-end-of-header) | 699 (make-local-variable 'tex-end-of-header) |
736 (make-local-variable 'tex-trailer)) | 700 (make-local-variable 'tex-trailer)) |
737 | 701 |
989 | 953 |
990 ;;; The utility functions: | 954 ;;; The utility functions: |
991 | 955 |
992 ;;;###autoload | 956 ;;;###autoload |
993 (defun tex-start-shell () | 957 (defun tex-start-shell () |
994 (save-excursion | 958 (with-current-buffer |
995 (set-buffer | 959 (make-comint |
996 (make-comint | 960 "tex-shell" |
997 "tex-shell" | 961 (or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh") |
998 (or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh") | 962 nil) |
999 nil)) | |
1000 (let ((proc (get-process "tex-shell"))) | 963 (let ((proc (get-process "tex-shell"))) |
1001 (set-process-sentinel proc 'tex-shell-sentinel) | 964 (set-process-sentinel proc 'tex-shell-sentinel) |
1002 (process-kill-without-query proc) | 965 (process-kill-without-query proc) |
1003 (setq comint-prompt-regexp shell-prompt-pattern) | 966 (setq comint-prompt-regexp shell-prompt-pattern) |
1004 (setq tex-shell-map (nconc (make-sparse-keymap) shell-mode-map)) | |
1005 (tex-define-common-keys tex-shell-map) | |
1006 (use-local-map tex-shell-map) | 967 (use-local-map tex-shell-map) |
1007 (compilation-shell-minor-mode t) | 968 (compilation-shell-minor-mode t) |
1008 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t) | 969 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t) |
1009 (make-local-variable 'list-buffers-directory) | 970 (make-local-variable 'list-buffers-directory) |
1010 (make-local-variable 'shell-dirstack) | 971 (make-local-variable 'shell-dirstack) |
1103 (add-hook 'kill-emacs-hook 'tex-delete-last-temp-files) | 1064 (add-hook 'kill-emacs-hook 'tex-delete-last-temp-files) |
1104 | 1065 |
1105 (defvar tex-start-tex-marker nil | 1066 (defvar tex-start-tex-marker nil |
1106 "Marker pointing after last TeX-running command in the TeX shell buffer.") | 1067 "Marker pointing after last TeX-running command in the TeX shell buffer.") |
1107 | 1068 |
1108 (defun tex-start-tex (command file) | 1069 (defun tex-main-file () |
1070 (let ((file (or tex-main-file | |
1071 ;; Compatibility with AUCTeX | |
1072 (and (boundp 'TeX-master) (stringp TeX-master) TeX-master) | |
1073 (if (buffer-file-name) | |
1074 (file-relative-name (buffer-file-name)) | |
1075 (error "Buffer is not associated with any file"))))) | |
1076 (if (string-match "\\.tex\\'" file) | |
1077 (substring file 0 (match-beginning 0)) | |
1078 file))) | |
1079 | |
1080 (defun tex-start-tex (command file &optional dir) | |
1109 "Start a TeX run, using COMMAND on FILE." | 1081 "Start a TeX run, using COMMAND on FILE." |
1110 (let* ((star (string-match "\\*" command)) | 1082 (let* ((star (string-match "\\*" command)) |
1111 (compile-command | 1083 (compile-command |
1112 (if star | 1084 (if star |
1113 (concat (substring command 0 star) | 1085 (concat (substring command 0 star) |
1116 (concat command " " | 1088 (concat command " " |
1117 (if (< 0 (length tex-start-options-string)) | 1089 (if (< 0 (length tex-start-options-string)) |
1118 (concat | 1090 (concat |
1119 (shell-quote-argument tex-start-options-string) " ")) | 1091 (shell-quote-argument tex-start-options-string) " ")) |
1120 (comint-quote-filename file))))) | 1092 (comint-quote-filename file))))) |
1093 (when dir | |
1094 (let (shell-dirtrack-verbose) | |
1095 (tex-send-command tex-shell-cd-command dir))) | |
1121 (with-current-buffer (process-buffer (tex-send-command compile-command)) | 1096 (with-current-buffer (process-buffer (tex-send-command compile-command)) |
1122 (save-excursion | 1097 (save-excursion |
1123 (forward-line -1) | 1098 (forward-line -1) |
1124 (setq tex-start-tex-marker (point-marker))) | 1099 (setq tex-start-tex-marker (point-marker))) |
1125 (make-local-variable 'compilation-parse-errors-function) | 1100 (make-local-variable 'compilation-parse-errors-function) |
1126 (setq compilation-parse-errors-function 'tex-compilation-parse-errors) | 1101 (setq compilation-parse-errors-function 'tex-compilation-parse-errors) |
1127 (compilation-forget-errors)))) | 1102 (compilation-forget-errors)) |
1103 (tex-display-shell) | |
1104 (setq tex-last-buffer-texed (current-buffer)))) | |
1128 | 1105 |
1129 (defun tex-compilation-parse-errors (limit-search find-at-least) | 1106 (defun tex-compilation-parse-errors (limit-search find-at-least) |
1130 "Parse the current buffer as TeX error messages. | 1107 "Parse the current buffer as TeX error messages. |
1131 See the variable `compilation-parse-errors-function' for the interface it uses. | 1108 See the variable `compilation-parse-errors-function' for the interface it uses. |
1132 | 1109 |
1247 ;; \input of files, this must be the same directory as the file for | 1224 ;; \input of files, this must be the same directory as the file for |
1248 ;; TeX to access the correct inputs. That's why it's safest if | 1225 ;; TeX to access the correct inputs. That's why it's safest if |
1249 ;; tex-directory is ".". | 1226 ;; tex-directory is ".". |
1250 (let* ((zap-directory | 1227 (let* ((zap-directory |
1251 (file-name-as-directory (expand-file-name tex-directory))) | 1228 (file-name-as-directory (expand-file-name tex-directory))) |
1252 (tex-out-file (concat zap-directory tex-zap-file ".tex"))) | 1229 (tex-out-file (expand-file-name (concat tex-zap-file ".tex") |
1230 zap-directory))) | |
1253 ;; Don't delete temp files if we do the same buffer twice in a row. | 1231 ;; Don't delete temp files if we do the same buffer twice in a row. |
1254 (or (eq (current-buffer) tex-last-buffer-texed) | 1232 (or (eq (current-buffer) tex-last-buffer-texed) |
1255 (tex-delete-last-temp-files t)) | 1233 (tex-delete-last-temp-files t)) |
1256 ;; Write the new temp file. | 1234 ;; Write the new temp file. |
1257 (save-excursion | 1235 (save-excursion |
1300 (if tex-trailer | 1278 (if tex-trailer |
1301 (write-region (concat "\n" tex-trailer) nil | 1279 (write-region (concat "\n" tex-trailer) nil |
1302 tex-out-file t nil)))) | 1280 tex-out-file t nil)))) |
1303 ;; Record the file name to be deleted afterward. | 1281 ;; Record the file name to be deleted afterward. |
1304 (setq tex-last-temp-file tex-out-file) | 1282 (setq tex-last-temp-file tex-out-file) |
1305 (let (shell-dirtrack-verbose) | |
1306 (tex-send-command tex-shell-cd-command zap-directory)) | |
1307 ;; Use a relative file name here because (1) the proper dir | 1283 ;; Use a relative file name here because (1) the proper dir |
1308 ;; is already current, and (2) the abs file name is sometimes | 1284 ;; is already current, and (2) the abs file name is sometimes |
1309 ;; too long and can make tex crash. | 1285 ;; too long and can make tex crash. |
1310 (tex-start-tex tex-command (concat tex-zap-file ".tex")) | 1286 (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory) |
1311 (tex-display-shell) | 1287 (setq tex-print-file tex-out-file))) |
1312 (setq tex-print-file tex-out-file) | |
1313 (setq tex-last-buffer-texed (current-buffer)))) | |
1314 | 1288 |
1315 (defun tex-buffer () | 1289 (defun tex-buffer () |
1316 "Run TeX on current buffer. See \\[tex-region] for more information. | 1290 "Run TeX on current buffer. See \\[tex-region] for more information. |
1317 Does not save the buffer, so it's useful for trying experimental versions. | 1291 Does not save the buffer, so it's useful for trying experimental versions. |
1318 See \\[tex-file] for an alternative." | 1292 See \\[tex-file] for an alternative." |
1322 (defun tex-file () | 1296 (defun tex-file () |
1323 "Prompt to save all buffers and run TeX (or LaTeX) on current buffer's file. | 1297 "Prompt to save all buffers and run TeX (or LaTeX) on current buffer's file. |
1324 This function is more useful than \\[tex-buffer] when you need the | 1298 This function is more useful than \\[tex-buffer] when you need the |
1325 `.aux' file of LaTeX to have the correct name." | 1299 `.aux' file of LaTeX to have the correct name." |
1326 (interactive) | 1300 (interactive) |
1327 (let ((source-file | 1301 (let* ((source-file (tex-main-file)) |
1328 (or tex-main-file | 1302 (file-dir (expand-file-name (file-name-directory source-file)))) |
1329 (if (buffer-file-name) | |
1330 (file-name-nondirectory (buffer-file-name)) | |
1331 (error "Buffer does not seem to be associated with any file")))) | |
1332 (file-dir (file-name-directory (buffer-file-name)))) | |
1333 (if tex-offer-save | 1303 (if tex-offer-save |
1334 (save-some-buffers)) | 1304 (save-some-buffers)) |
1335 (if (tex-shell-running) | 1305 (if (tex-shell-running) |
1336 (tex-kill-job) | 1306 (tex-kill-job) |
1337 (tex-start-shell)) | 1307 (tex-start-shell)) |
1338 (let (shell-dirtrack-verbose) | 1308 (tex-start-tex tex-command source-file file-dir) |
1339 (tex-send-command tex-shell-cd-command file-dir)) | |
1340 (tex-start-tex tex-command source-file) | |
1341 (tex-display-shell) | |
1342 (setq tex-last-buffer-texed (current-buffer)) | |
1343 (setq tex-print-file (expand-file-name source-file)))) | 1309 (setq tex-print-file (expand-file-name source-file)))) |
1344 | 1310 |
1345 (defun tex-generate-zap-file-name () | 1311 (defun tex-generate-zap-file-name () |
1346 "Generate a unique name suitable for use as a file name." | 1312 "Generate a unique name suitable for use as a file name." |
1347 ;; Include the shell process number and host name | 1313 ;; Include the shell process number and host name |
1493 (file-dir (file-name-directory (buffer-file-name)))) | 1459 (file-dir (file-name-directory (buffer-file-name)))) |
1494 (tex-send-command tex-shell-cd-command file-dir) | 1460 (tex-send-command tex-shell-cd-command file-dir) |
1495 (tex-send-command tex-bibtex-command tex-out-file)) | 1461 (tex-send-command tex-bibtex-command tex-out-file)) |
1496 (tex-display-shell)) | 1462 (tex-display-shell)) |
1497 | 1463 |
1464 ;;;; | |
1465 ;;;; Outline support | |
1466 ;;;; | |
1467 | |
1468 (defvar latex-outline-regexp | |
1469 (concat "\\\\" | |
1470 (regexp-opt (list* "documentstyle" "documentclass" | |
1471 "begin{document}" "end{document}" "appendix" | |
1472 (mapcar 'car latex-section-alist)) t))) | |
1473 | |
1474 (defun latex-outline-level () | |
1475 (if (looking-at latex-outline-regexp) | |
1476 (1+ (or (cdr (assoc (match-string 1) latex-section-alist)) -1)) | |
1477 1000)) | |
1478 | |
1479 | |
1498 (run-hooks 'tex-mode-load-hook) | 1480 (run-hooks 'tex-mode-load-hook) |
1499 | 1481 |
1500 (provide 'tex-mode) | 1482 (provide 'tex-mode) |
1501 | 1483 |
1502 ;;; tex-mode.el ends here | 1484 ;;; tex-mode.el ends here |