diff options
| author | Stefan Monnier | 2000-09-29 01:45:46 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-09-29 01:45:46 +0000 |
| commit | d6709b80940bb4ed50fe98c6882f4f8d2d6ca299 (patch) | |
| tree | 24f164800de8c57584594dec093ed8586452a799 | |
| parent | 4f837d3b58c504d033e65670e3a76004fb2f57c2 (diff) | |
| download | emacs-d6709b80940bb4ed50fe98c6882f4f8d2d6ca299.tar.gz emacs-d6709b80940bb4ed50fe98c6882f4f8d2d6ca299.zip | |
(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.
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 286 |
1 files changed, 134 insertions, 152 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 315b61a8ab2..beb468c0ca1 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -269,12 +269,18 @@ Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].") | |||
| 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 | 277 | ||
| 278 | (defvar latex-section-alist | ||
| 279 | '(("part" . 0) ("chapter" . 1) | ||
| 280 | ("section" . 2) ("subsection" . 3) | ||
| 281 | ("subsubsection" . 4) | ||
| 282 | ("paragraph" . 5) ("subparagraph" . 6))) | ||
| 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) |
| @@ -291,33 +297,29 @@ An alternative value is \" . \", if you use a font with a narrow period." | |||
| 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. |
| @@ -408,7 +410,11 @@ subsubsection\\|paragraph\\|subparagraph\\)\\*?[ \t]*{" nil t) | |||
| 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 | ||
| @@ -436,7 +442,7 @@ this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', | |||
| 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)) |
| @@ -451,8 +457,7 @@ says which mode to use." | |||
| 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) |
| @@ -462,7 +467,7 @@ says which mode to use." | |||
| 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, |
| @@ -502,19 +507,15 @@ tex-show-queue-command | |||
| 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, |
| @@ -554,10 +555,7 @@ tex-show-queue-command | |||
| 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}") |
| @@ -565,34 +563,39 @@ subshell is initiated, `tex-shell-hook' is run." | |||
| 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) |
| 591 | (set (make-local-variable 'fill-nobreak-predicate) | ||
| 592 | 'latex-fill-nobreak-predicate) | ||
| 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)) | ||
| 593 | 596 | ||
| 594 | ;;;###autoload | 597 | ;;;###autoload |
| 595 | (defun slitex-mode () | 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, |
| @@ -633,46 +636,10 @@ 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) |
| @@ -697,39 +664,36 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook | |||
| 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) |
| @@ -991,18 +955,15 @@ Mark is left at original location." | |||
| 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) |
| @@ -1105,7 +1066,18 @@ If NOT-ALL is non-nil, save the `.dvi' file." | |||
| 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 |
| @@ -1118,13 +1090,18 @@ If NOT-ALL is non-nil, save the `.dvi' file." | |||
| 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. |
| @@ -1249,7 +1226,8 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 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)) |
| @@ -1302,15 +1280,11 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 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. |
| @@ -1324,22 +1298,14 @@ See \\[tex-file] for an alternative." | |||
| 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 () |
| @@ -1495,6 +1461,22 @@ Runs the shell command defined by `tex-show-queue-command'." | |||
| 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) |