aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes/tex-mode.el
diff options
context:
space:
mode:
authorGlenn Morris <[email protected]>2007-09-16 02:05:26 +0000
committerGlenn Morris <[email protected]>2007-09-16 02:05:26 +0000
commit80c2ab0f7dc26912f1701fb751813752710bc874 (patch)
treecf2a838d6f61b66f6f69fa057144e0686083dc74 /lisp/textmodes/tex-mode.el
parent86e80023f4df1f8abbff5295d17aab68d8e0e19c (diff)
(tex-region): Handle the case where the region is not in
`tex-main-file'. Move the old code that applies to both cases... (tex-region-1): ...to this new function.
Diffstat (limited to 'lisp/textmodes/tex-mode.el')
-rw-r--r--lisp/textmodes/tex-mode.el56
1 files changed, 45 insertions, 11 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index 44bc31d36d..0b32d6622c 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -2124,18 +2124,59 @@ The value of `tex-command' specifies the command to use to run TeX."
(let* ((zap-directory
(file-name-as-directory (expand-file-name tex-directory)))
(tex-out-file (expand-file-name (concat tex-zap-file ".tex")
- zap-directory)))
+ zap-directory))
+ (main-file (expand-file-name (tex-main-file)))
+ (texbuf (current-buffer))
+ ;; Variables local to texbuf that are needed by t-r-1.
+ (hstart tex-start-of-header)
+ (hend tex-end-of-header)
+ (first tex-first-line-header-regexp)
+ (trailer tex-trailer)
+ size)
;; 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))
- ;; Write the new temp file.
+ (if (string-equal main-file (buffer-file-name))
+ (tex-region-1 zap-directory tex-out-file beg end)
+ ; If this is not the main file, we need to first make a merged
+ ; buffer with the contents of the main file and this file.
+ (with-temp-buffer
+ ;; This is so we get prompted about any changes on disk.
+ (insert (with-current-buffer (find-file-noselect main-file)
+ (save-restriction
+ (widen)
+ (buffer-string))))
+ ;; Get the size of the text inserted before the specified region.
+ (setq size (- (point-max) (point-min))
+ beg (+ beg size)
+ end (+ end size))
+ (insert (with-current-buffer texbuf
+ (save-restriction
+ (widen)
+ (buffer-string))))
+ (set (make-local-variable 'tex-start-of-header) hstart)
+ (set (make-local-variable 'tex-end-of-header) hend)
+ (set (make-local-variable 'tex-first-line-header-regexp) first)
+ (set (make-local-variable 'tex-trailer) trailer)
+ (tex-region-1 zap-directory tex-out-file beg end)))
+ ;; Record the file name to be deleted afterward.
+ (setq tex-last-temp-file tex-out-file)
+ ;; Use a relative file name here because (1) the proper dir
+ ;; is already current, and (2) the abs file name is sometimes
+ ;; too long and can make tex crash.
+ (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory)
+ (setq tex-print-file tex-out-file)))
+
+(defun tex-region-1 (zap-directory tex-out-file beg end)
+ "Write the region BEG END of the current buffer to TEX-OUT-FILE.
+The region is surrounded by a header and trailer, if they are found."
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(forward-line 100)
(let ((search-end (point))
- (default-directory zap-directory)
+ (default-directory zap-directory) ; why?
(already-output 0))
(goto-char (point-min))
@@ -2174,14 +2215,7 @@ The value of `tex-command' specifies the command to use to run TeX."
;; 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)
- ;; Use a relative file name here because (1) the proper dir
- ;; is already current, and (2) the abs file name is sometimes
- ;; too long and can make tex crash.
- (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory)
- (setq tex-print-file tex-out-file)))
+ tex-out-file t nil)))))
(defun tex-buffer ()
"Run TeX on current buffer. See \\[tex-region] for more information.