diff options
| author | Glenn Morris | 2007-09-17 00:24:12 +0000 |
|---|---|---|
| committer | Glenn Morris | 2007-09-17 00:24:12 +0000 |
| commit | 595a68b4737ccade0463d6254fd38ec0dfde0759 (patch) | |
| tree | 455c6d3a3b9d71c48b9a7bd8faaa4ef89ec3f150 | |
| parent | f73dcb6f5421db7c2f72fb9dae63800715303ba0 (diff) | |
| download | emacs-595a68b4737ccade0463d6254fd38ec0dfde0759.tar.gz emacs-595a68b4737ccade0463d6254fd38ec0dfde0759.zip | |
(tex-region): Simplify previous change,
handling the case where the region is not in `tex-main-file'.
(tex-region-1): Delete.
(tex-region-header): New function, doing the header part of the
old tex-region-1.
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 144 |
1 files changed, 65 insertions, 79 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 0b32d6622c3..986c4fca20b 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -2126,39 +2126,29 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 2126 | (tex-out-file (expand-file-name (concat tex-zap-file ".tex") | 2126 | (tex-out-file (expand-file-name (concat tex-zap-file ".tex") |
| 2127 | zap-directory)) | 2127 | zap-directory)) |
| 2128 | (main-file (expand-file-name (tex-main-file))) | 2128 | (main-file (expand-file-name (tex-main-file))) |
| 2129 | (texbuf (current-buffer)) | 2129 | (ismain (string-equal main-file (buffer-file-name))) |
| 2130 | ;; Variables local to texbuf that are needed by t-r-1. | 2130 | already-output) |
| 2131 | (hstart tex-start-of-header) | ||
| 2132 | (hend tex-end-of-header) | ||
| 2133 | (first tex-first-line-header-regexp) | ||
| 2134 | (trailer tex-trailer) | ||
| 2135 | size) | ||
| 2136 | ;; Don't delete temp files if we do the same buffer twice in a row. | 2131 | ;; Don't delete temp files if we do the same buffer twice in a row. |
| 2137 | (or (eq (current-buffer) tex-last-buffer-texed) | 2132 | (or (eq (current-buffer) tex-last-buffer-texed) |
| 2138 | (tex-delete-last-temp-files t)) | 2133 | (tex-delete-last-temp-files t)) |
| 2139 | (if (string-equal main-file (buffer-file-name)) | 2134 | (let ((default-directory zap-directory)) ; why? |
| 2140 | (tex-region-1 zap-directory tex-out-file beg end) | 2135 | ;; We assume the header is fully contained in tex-main-file. |
| 2141 | ; If this is not the main file, we need to first make a merged | 2136 | ;; We use f-f-ns so we get prompted about any changes on disk. |
| 2142 | ; buffer with the contents of the main file and this file. | 2137 | (with-current-buffer (find-file-noselect main-file) |
| 2143 | (with-temp-buffer | 2138 | (setq already-output (tex-region-header tex-out-file |
| 2144 | ;; This is so we get prompted about any changes on disk. | 2139 | (and ismain beg)))) |
| 2145 | (insert (with-current-buffer (find-file-noselect main-file) | 2140 | ;; Write out the specified region (but don't repeat anything |
| 2146 | (save-restriction | 2141 | ;; already written in the header). |
| 2147 | (widen) | 2142 | (write-region (if ismain |
| 2148 | (buffer-string)))) | 2143 | (max beg already-output) |
| 2149 | ;; Get the size of the text inserted before the specified region. | 2144 | beg) |
| 2150 | (setq size (- (point-max) (point-min)) | 2145 | end tex-out-file (not (zerop already-output))) |
| 2151 | beg (+ beg size) | 2146 | ;; Write the trailer, if any. |
| 2152 | end (+ end size)) | 2147 | ;; Precede it with a newline to make sure it |
| 2153 | (insert (with-current-buffer texbuf | 2148 | ;; is not hidden in a comment. |
| 2154 | (save-restriction | 2149 | (if tex-trailer |
| 2155 | (widen) | 2150 | (write-region (concat "\n" tex-trailer) nil |
| 2156 | (buffer-string)))) | 2151 | tex-out-file t))) |
| 2157 | (set (make-local-variable 'tex-start-of-header) hstart) | ||
| 2158 | (set (make-local-variable 'tex-end-of-header) hend) | ||
| 2159 | (set (make-local-variable 'tex-first-line-header-regexp) first) | ||
| 2160 | (set (make-local-variable 'tex-trailer) trailer) | ||
| 2161 | (tex-region-1 zap-directory tex-out-file beg end))) | ||
| 2162 | ;; Record the file name to be deleted afterward. | 2152 | ;; Record the file name to be deleted afterward. |
| 2163 | (setq tex-last-temp-file tex-out-file) | 2153 | (setq tex-last-temp-file tex-out-file) |
| 2164 | ;; Use a relative file name here because (1) the proper dir | 2154 | ;; Use a relative file name here because (1) the proper dir |
| @@ -2167,55 +2157,51 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 2167 | (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory) | 2157 | (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory) |
| 2168 | (setq tex-print-file tex-out-file))) | 2158 | (setq tex-print-file tex-out-file))) |
| 2169 | 2159 | ||
| 2170 | (defun tex-region-1 (zap-directory tex-out-file beg end) | 2160 | (defun tex-region-header (file &optional beg) |
| 2171 | "Write the region BEG END of the current buffer to TEX-OUT-FILE. | 2161 | "If there is a TeX header in the current buffer, write it to FILE. |
| 2172 | The region is surrounded by a header and trailer, if they are found." | 2162 | Return point at the end of the region so written, or zero. If |
| 2173 | (save-excursion | 2163 | the optional buffer position BEG is specified, then the region |
| 2174 | (save-restriction | 2164 | written out starts at BEG, if this lies before the start of the header. |
| 2175 | (widen) | 2165 | |
| 2176 | (goto-char (point-min)) | 2166 | If the first line matches `tex-first-line-header-regexp', it is |
| 2177 | (forward-line 100) | 2167 | also written out. The variables `tex-start-of-header' and |
| 2178 | (let ((search-end (point)) | 2168 | `tex-end-of-header' are used to locate the header. Note that the |
| 2179 | (default-directory zap-directory) ; why? | 2169 | start of the header is required to be within the first 100 lines." |
| 2180 | (already-output 0)) | 2170 | (save-excursion |
| 2181 | (goto-char (point-min)) | 2171 | (save-restriction |
| 2182 | 2172 | (widen) | |
| 2183 | ;; Maybe copy first line, such as `\input texinfo', to temp file. | 2173 | (goto-char (point-min)) |
| 2184 | (and tex-first-line-header-regexp | 2174 | (let ((search-end (save-excursion |
| 2185 | (looking-at tex-first-line-header-regexp) | 2175 | (forward-line 100) |
| 2186 | (write-region (point) | 2176 | (point))) |
| 2187 | (progn (forward-line 1) | 2177 | (already-output 0) |
| 2188 | (setq already-output (point))) | 2178 | hbeg hend) |
| 2189 | tex-out-file nil nil)) | 2179 | ;; Maybe copy first line, such as `\input texinfo', to temp file. |
| 2190 | 2180 | (and tex-first-line-header-regexp | |
| 2191 | ;; Write out the header, if there is one, | 2181 | (looking-at tex-first-line-header-regexp) |
| 2192 | ;; and any of the specified region which extends before it. | 2182 | (write-region (point) |
| 2193 | ;; But don't repeat anything already written. | 2183 | (progn (forward-line 1) |
| 2194 | (if (re-search-forward tex-start-of-header search-end t) | 2184 | (setq already-output (point))) |
| 2195 | (let (hbeg) | 2185 | file)) |
| 2196 | (beginning-of-line) | 2186 | ;; Write out the header, if there is one, and any of the |
| 2197 | (setq hbeg (point)) ;mark beginning of header | 2187 | ;; specified region which extends before it. But don't repeat |
| 2198 | (if (re-search-forward tex-end-of-header nil t) | 2188 | ;; anything already written. |
| 2199 | (let (hend) | 2189 | (and tex-start-of-header |
| 2200 | (forward-line 1) | 2190 | (re-search-forward tex-start-of-header search-end t) |
| 2201 | (setq hend (point)) ;mark end of header | 2191 | (progn |
| 2202 | (write-region (max (min hbeg beg) already-output) | 2192 | (beginning-of-line) |
| 2203 | hend | 2193 | (setq hbeg (point)) ; mark beginning of header |
| 2204 | tex-out-file | 2194 | (when (re-search-forward tex-end-of-header nil t) |
| 2205 | (not (zerop already-output)) nil) | 2195 | (forward-line 1) |
| 2206 | (setq already-output hend))))) | 2196 | (setq hend (point)) ; mark end of header |
| 2207 | 2197 | (write-region | |
| 2208 | ;; Write out the specified region | 2198 | (max (if beg |
| 2209 | ;; (but don't repeat anything already written). | 2199 | (min hbeg beg) |
| 2210 | (write-region (max beg already-output) end | 2200 | hbeg) |
| 2211 | tex-out-file | 2201 | already-output) |
| 2212 | (not (zerop already-output)) nil)) | 2202 | hend file (not (zerop already-output))) |
| 2213 | ;; Write the trailer, if any. | 2203 | (setq already-output hend)))) |
| 2214 | ;; Precede it with a newline to make sure it | 2204 | already-output)))) |
| 2215 | ;; is not hidden in a comment. | ||
| 2216 | (if tex-trailer | ||
| 2217 | (write-region (concat "\n" tex-trailer) nil | ||
| 2218 | tex-out-file t nil))))) | ||
| 2219 | 2205 | ||
| 2220 | (defun tex-buffer () | 2206 | (defun tex-buffer () |
| 2221 | "Run TeX on current buffer. See \\[tex-region] for more information. | 2207 | "Run TeX on current buffer. See \\[tex-region] for more information. |