summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1997-01-02 01:30:36 +0000
committerRichard M. Stallman <rms@gnu.org>1997-01-02 01:30:36 +0000
commit9041182340d1beae7ebefc66821639d705b652cf (patch)
tree2520a566c49e7465e10a408671d5f1df34ad8612
parentfe15f95e952270524252faa6a3042a1d02c08754 (diff)
downloademacs-9041182340d1beae7ebefc66821639d705b652cf.tar.gz
(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.el65
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."
(tex-start-shell))
(or tex-zap-file
(setq tex-zap-file (tex-generate-zap-file-name)))
- (let* ((temp-buffer (get-buffer-create " TeX-Output-Buffer"))
- ; Temp file will be written and TeX will be run in zap-directory.
- ; If the TEXINPUTS file has relative directories or if the region has
- ; \input of files, this must be the same directory as the file for
- ; TeX to access the correct inputs. That's why it's safest if
- ; tex-directory is ".".
- (zap-directory
+ ;; Temp file will be written and TeX will be run in zap-directory.
+ ;; If the TEXINPUTS file has relative directories or if the region has
+ ;; \input of files, this must be the same directory as the file for
+ ;; TeX to access the correct inputs. That's why it's safest if
+ ;; tex-directory is ".".
+ (let* ((zap-directory
(file-name-as-directory (expand-file-name tex-directory)))
- (tex-out-file (concat zap-directory tex-zap-file)))
+ (tex-out-file (concat zap-directory tex-zap-file ".tex")))
;; Don't delete temp files if we do the same buffer twice in a row.
(or (eq (current-buffer) tex-last-buffer-texed)
(tex-delete-last-temp-files t))
@@ -1014,38 +1013,46 @@ The value of `tex-command' specifies the command to use to run TeX."
(goto-char (point-min))
(forward-line 100)
(let ((search-end (point))
- (hbeg (point-min)) (hend (point-min))
- (default-directory zap-directory))
+ (default-directory zap-directory)
+ (already-output 0))
(goto-char (point-min))
-
+
;; Maybe copy first line, such as `\input texinfo', to temp file.
(and tex-first-line-header-regexp
(looking-at tex-first-line-header-regexp)
(write-region (point)
- (progn (forward-line 1) (point))
+ (progn (forward-line 1)
+ (setq already-output (point)))
tex-out-file nil nil))
- ;; Initialize the temp file with either the header or nothing
+ ;; Write out the header, if there is one,
+ ;; and any of the specified region which extends before it.
+ ;; But don't repeat anything already written.
(if (re-search-forward tex-start-of-header search-end t)
- (progn
+ (let (hbeg)
(beginning-of-line)
(setq hbeg (point)) ;mark beginning of header
(if (re-search-forward tex-end-of-header nil t)
- (progn (forward-line 1)
- (setq hend (point))) ;mark end of header
- (setq hbeg (point-min))))) ;no header
- (write-region (min hbeg beg) hend
- (concat tex-out-file ".tex") nil nil)
- (write-region (max beg hend) end (concat tex-out-file ".tex") t nil))
- (let ((local-tex-trailer tex-trailer))
- (set-buffer temp-buffer)
- (erase-buffer)
- ;; make sure trailer isn't hidden by a comment
- (insert-string "\n")
- (if local-tex-trailer (insert-string local-tex-trailer))
- (tex-set-buffer-directory temp-buffer zap-directory)
- (write-region (point-min) (point-max)
- (concat tex-out-file ".tex") t nil))))
+ (let (hend)
+ (forward-line 1)
+ (setq hend (point)) ;mark end of header
+ (write-region (max (min hbeg beg) already-output)
+ hend
+ tex-out-file
+ (not (zerop already-output)) nil)
+ (setq already-output hend)))))
+
+ ;; Write out the specified region
+ ;; (but don't repeat anything already written).
+ (write-region (max beg already-output) end
+ tex-out-file
+ (not (zerop already-output)) nil))
+ ;; Write the trailer, if any.
+ ;; Precede it with a newline to make sure it
+ ;; is not hidden in a comment.
+ (if tex-trailer
+ (write-region (concat "\n" tex-trailer) nil
+ tex-out-file t nil))))
;; Record the file name to be deleted afterward.
(setq tex-last-temp-file tex-out-file)
(tex-send-command tex-shell-cd-command zap-directory)