diff options
| author | Richard M. Stallman | 1997-01-02 01:30:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-01-02 01:30:36 +0000 |
| commit | 6d34c59ffb4b6ebaef4a1489aac7d179038410ba (patch) | |
| tree | 4ac075c8c079bb378528c8d9145bf76e4c6f31e9 | |
| parent | c75cfabd5acf3c5564669c8b0d0035e32edff5ba (diff) | |
| download | emacs-6d34c59ffb4b6ebaef4a1489aac7d179038410ba.tar.gz emacs-6d34c59ffb4b6ebaef4a1489aac7d179038410ba.zip | |
(tex-region): Correctly handle possible
overlap between first line, header, and region.
New local var ALREADY-OUTPUT makes this general.
Write tex-trailer directly as a string; get rid of temp-buffer.
Make tex-out-file include the .tex suffix.
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index c20c6b9f18d..f12047153e4 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -995,15 +995,14 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 995 | (tex-start-shell)) | 995 | (tex-start-shell)) |
| 996 | (or tex-zap-file | 996 | (or tex-zap-file |
| 997 | (setq tex-zap-file (tex-generate-zap-file-name))) | 997 | (setq tex-zap-file (tex-generate-zap-file-name))) |
| 998 | (let* ((temp-buffer (get-buffer-create " TeX-Output-Buffer")) | 998 | ;; Temp file will be written and TeX will be run in zap-directory. |
| 999 | ; Temp file will be written and TeX will be run in zap-directory. | 999 | ;; If the TEXINPUTS file has relative directories or if the region has |
| 1000 | ; If the TEXINPUTS file has relative directories or if the region has | 1000 | ;; \input of files, this must be the same directory as the file for |
| 1001 | ; \input of files, this must be the same directory as the file for | 1001 | ;; TeX to access the correct inputs. That's why it's safest if |
| 1002 | ; TeX to access the correct inputs. That's why it's safest if | 1002 | ;; tex-directory is ".". |
| 1003 | ; tex-directory is ".". | 1003 | (let* ((zap-directory |
| 1004 | (zap-directory | ||
| 1005 | (file-name-as-directory (expand-file-name tex-directory))) | 1004 | (file-name-as-directory (expand-file-name tex-directory))) |
| 1006 | (tex-out-file (concat zap-directory tex-zap-file))) | 1005 | (tex-out-file (concat zap-directory tex-zap-file ".tex"))) |
| 1007 | ;; Don't delete temp files if we do the same buffer twice in a row. | 1006 | ;; Don't delete temp files if we do the same buffer twice in a row. |
| 1008 | (or (eq (current-buffer) tex-last-buffer-texed) | 1007 | (or (eq (current-buffer) tex-last-buffer-texed) |
| 1009 | (tex-delete-last-temp-files t)) | 1008 | (tex-delete-last-temp-files t)) |
| @@ -1014,38 +1013,46 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 1014 | (goto-char (point-min)) | 1013 | (goto-char (point-min)) |
| 1015 | (forward-line 100) | 1014 | (forward-line 100) |
| 1016 | (let ((search-end (point)) | 1015 | (let ((search-end (point)) |
| 1017 | (hbeg (point-min)) (hend (point-min)) | 1016 | (default-directory zap-directory) |
| 1018 | (default-directory zap-directory)) | 1017 | (already-output 0)) |
| 1019 | (goto-char (point-min)) | 1018 | (goto-char (point-min)) |
| 1020 | 1019 | ||
| 1021 | ;; Maybe copy first line, such as `\input texinfo', to temp file. | 1020 | ;; Maybe copy first line, such as `\input texinfo', to temp file. |
| 1022 | (and tex-first-line-header-regexp | 1021 | (and tex-first-line-header-regexp |
| 1023 | (looking-at tex-first-line-header-regexp) | 1022 | (looking-at tex-first-line-header-regexp) |
| 1024 | (write-region (point) | 1023 | (write-region (point) |
| 1025 | (progn (forward-line 1) (point)) | 1024 | (progn (forward-line 1) |
| 1025 | (setq already-output (point))) | ||
| 1026 | tex-out-file nil nil)) | 1026 | tex-out-file nil nil)) |
| 1027 | 1027 | ||
| 1028 | ;; Initialize the temp file with either the header or nothing | 1028 | ;; Write out the header, if there is one, |
| 1029 | ;; and any of the specified region which extends before it. | ||
| 1030 | ;; But don't repeat anything already written. | ||
| 1029 | (if (re-search-forward tex-start-of-header search-end t) | 1031 | (if (re-search-forward tex-start-of-header search-end t) |
| 1030 | (progn | 1032 | (let (hbeg) |
| 1031 | (beginning-of-line) | 1033 | (beginning-of-line) |
| 1032 | (setq hbeg (point)) ;mark beginning of header | 1034 | (setq hbeg (point)) ;mark beginning of header |
| 1033 | (if (re-search-forward tex-end-of-header nil t) | 1035 | (if (re-search-forward tex-end-of-header nil t) |
| 1034 | (progn (forward-line 1) | 1036 | (let (hend) |
| 1035 | (setq hend (point))) ;mark end of header | 1037 | (forward-line 1) |
| 1036 | (setq hbeg (point-min))))) ;no header | 1038 | (setq hend (point)) ;mark end of header |
| 1037 | (write-region (min hbeg beg) hend | 1039 | (write-region (max (min hbeg beg) already-output) |
| 1038 | (concat tex-out-file ".tex") nil nil) | 1040 | hend |
| 1039 | (write-region (max beg hend) end (concat tex-out-file ".tex") t nil)) | 1041 | tex-out-file |
| 1040 | (let ((local-tex-trailer tex-trailer)) | 1042 | (not (zerop already-output)) nil) |
| 1041 | (set-buffer temp-buffer) | 1043 | (setq already-output hend))))) |
| 1042 | (erase-buffer) | 1044 | |
| 1043 | ;; make sure trailer isn't hidden by a comment | 1045 | ;; Write out the specified region |
| 1044 | (insert-string "\n") | 1046 | ;; (but don't repeat anything already written). |
| 1045 | (if local-tex-trailer (insert-string local-tex-trailer)) | 1047 | (write-region (max beg already-output) end |
| 1046 | (tex-set-buffer-directory temp-buffer zap-directory) | 1048 | tex-out-file |
| 1047 | (write-region (point-min) (point-max) | 1049 | (not (zerop already-output)) nil)) |
| 1048 | (concat tex-out-file ".tex") t nil)))) | 1050 | ;; Write the trailer, if any. |
| 1051 | ;; Precede it with a newline to make sure it | ||
| 1052 | ;; is not hidden in a comment. | ||
| 1053 | (if tex-trailer | ||
| 1054 | (write-region (concat "\n" tex-trailer) nil | ||
| 1055 | tex-out-file t nil)))) | ||
| 1049 | ;; Record the file name to be deleted afterward. | 1056 | ;; Record the file name to be deleted afterward. |
| 1050 | (setq tex-last-temp-file tex-out-file) | 1057 | (setq tex-last-temp-file tex-out-file) |
| 1051 | (tex-send-command tex-shell-cd-command zap-directory) | 1058 | (tex-send-command tex-shell-cd-command zap-directory) |