Mercurial > emacs
comparison lisp/textmodes/tex-mode.el @ 78813:776b9b17aed0
(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.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 17 Sep 2007 00:26:00 +0000 |
parents | c72d88d40ef8 |
children | b93f64a362b4 |
comparison
equal
deleted
inserted
replaced
78812:dfb375e20bcc | 78813:776b9b17aed0 |
---|---|
2103 (let* ((zap-directory | 2103 (let* ((zap-directory |
2104 (file-name-as-directory (expand-file-name tex-directory))) | 2104 (file-name-as-directory (expand-file-name tex-directory))) |
2105 (tex-out-file (expand-file-name (concat tex-zap-file ".tex") | 2105 (tex-out-file (expand-file-name (concat tex-zap-file ".tex") |
2106 zap-directory)) | 2106 zap-directory)) |
2107 (main-file (expand-file-name (tex-main-file))) | 2107 (main-file (expand-file-name (tex-main-file))) |
2108 (texbuf (current-buffer)) | 2108 (ismain (string-equal main-file (buffer-file-name))) |
2109 ;; Variables local to texbuf that are needed by t-r-1. | 2109 already-output) |
2110 (hstart tex-start-of-header) | |
2111 (hend tex-end-of-header) | |
2112 (first tex-first-line-header-regexp) | |
2113 (trailer tex-trailer) | |
2114 size) | |
2115 ;; Don't delete temp files if we do the same buffer twice in a row. | 2110 ;; Don't delete temp files if we do the same buffer twice in a row. |
2116 (or (eq (current-buffer) tex-last-buffer-texed) | 2111 (or (eq (current-buffer) tex-last-buffer-texed) |
2117 (tex-delete-last-temp-files t)) | 2112 (tex-delete-last-temp-files t)) |
2118 (if (string-equal main-file (buffer-file-name)) | 2113 (let ((default-directory zap-directory)) ; why? |
2119 (tex-region-1 zap-directory tex-out-file beg end) | 2114 ;; We assume the header is fully contained in tex-main-file. |
2120 ; If this is not the main file, we need to first make a merged | 2115 ;; We use f-f-ns so we get prompted about any changes on disk. |
2121 ; buffer with the contents of the main file and this file. | 2116 (with-current-buffer (find-file-noselect main-file) |
2122 (with-temp-buffer | 2117 (setq already-output (tex-region-header tex-out-file |
2123 ;; This is so we get prompted about any changes on disk. | 2118 (and ismain beg)))) |
2124 (insert (with-current-buffer (find-file-noselect main-file) | 2119 ;; Write out the specified region (but don't repeat anything |
2125 (save-restriction | 2120 ;; already written in the header). |
2126 (widen) | 2121 (write-region (if ismain |
2127 (buffer-string)))) | 2122 (max beg already-output) |
2128 ;; Get the size of the text inserted before the specified region. | 2123 beg) |
2129 (setq size (- (point-max) (point-min)) | 2124 end tex-out-file (not (zerop already-output))) |
2130 beg (+ beg size) | 2125 ;; Write the trailer, if any. |
2131 end (+ end size)) | 2126 ;; Precede it with a newline to make sure it |
2132 (insert (with-current-buffer texbuf | 2127 ;; is not hidden in a comment. |
2133 (save-restriction | 2128 (if tex-trailer |
2134 (widen) | 2129 (write-region (concat "\n" tex-trailer) nil |
2135 (buffer-string)))) | 2130 tex-out-file t))) |
2136 (set (make-local-variable 'tex-start-of-header) hstart) | |
2137 (set (make-local-variable 'tex-end-of-header) hend) | |
2138 (set (make-local-variable 'tex-first-line-header-regexp) first) | |
2139 (set (make-local-variable 'tex-trailer) trailer) | |
2140 (tex-region-1 zap-directory tex-out-file beg end))) | |
2141 ;; Record the file name to be deleted afterward. | 2131 ;; Record the file name to be deleted afterward. |
2142 (setq tex-last-temp-file tex-out-file) | 2132 (setq tex-last-temp-file tex-out-file) |
2143 ;; Use a relative file name here because (1) the proper dir | 2133 ;; Use a relative file name here because (1) the proper dir |
2144 ;; is already current, and (2) the abs file name is sometimes | 2134 ;; is already current, and (2) the abs file name is sometimes |
2145 ;; too long and can make tex crash. | 2135 ;; too long and can make tex crash. |
2146 (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory) | 2136 (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory) |
2147 (setq tex-print-file tex-out-file))) | 2137 (setq tex-print-file tex-out-file))) |
2148 | 2138 |
2149 (defun tex-region-1 (zap-directory tex-out-file beg end) | 2139 (defun tex-region-header (file &optional beg) |
2150 "Write the region BEG END of the current buffer to TEX-OUT-FILE. | 2140 "If there is a TeX header in the current buffer, write it to FILE. |
2151 The region is surrounded by a header and trailer, if they are found." | 2141 Return point at the end of the region so written, or zero. If |
2142 the optional buffer position BEG is specified, then the region | |
2143 written out starts at BEG, if this lies before the start of the header. | |
2144 | |
2145 If the first line matches `tex-first-line-header-regexp', it is | |
2146 also written out. The variables `tex-start-of-header' and | |
2147 `tex-end-of-header' are used to locate the header. Note that the | |
2148 start of the header is required to be within the first 100 lines." | |
2152 (save-excursion | 2149 (save-excursion |
2153 (save-restriction | 2150 (save-restriction |
2154 (widen) | 2151 (widen) |
2155 (goto-char (point-min)) | 2152 (goto-char (point-min)) |
2153 (let ((search-end (save-excursion | |
2156 (forward-line 100) | 2154 (forward-line 100) |
2157 (let ((search-end (point)) | 2155 (point))) |
2158 (default-directory zap-directory) ; why? | 2156 (already-output 0) |
2159 (already-output 0)) | 2157 hbeg hend) |
2160 (goto-char (point-min)) | |
2161 | |
2162 ;; Maybe copy first line, such as `\input texinfo', to temp file. | 2158 ;; Maybe copy first line, such as `\input texinfo', to temp file. |
2163 (and tex-first-line-header-regexp | 2159 (and tex-first-line-header-regexp |
2164 (looking-at tex-first-line-header-regexp) | 2160 (looking-at tex-first-line-header-regexp) |
2165 (write-region (point) | 2161 (write-region (point) |
2166 (progn (forward-line 1) | 2162 (progn (forward-line 1) |
2167 (setq already-output (point))) | 2163 (setq already-output (point))) |
2168 tex-out-file nil nil)) | 2164 file)) |
2169 | 2165 ;; Write out the header, if there is one, and any of the |
2170 ;; Write out the header, if there is one, | 2166 ;; specified region which extends before it. But don't repeat |
2171 ;; and any of the specified region which extends before it. | 2167 ;; anything already written. |
2172 ;; But don't repeat anything already written. | 2168 (and tex-start-of-header |
2173 (if (re-search-forward tex-start-of-header search-end t) | 2169 (re-search-forward tex-start-of-header search-end t) |
2174 (let (hbeg) | 2170 (progn |
2175 (beginning-of-line) | 2171 (beginning-of-line) |
2176 (setq hbeg (point)) ;mark beginning of header | 2172 (setq hbeg (point)) ;mark beginning of header |
2177 (if (re-search-forward tex-end-of-header nil t) | 2173 (when (re-search-forward tex-end-of-header nil t) |
2178 (let (hend) | |
2179 (forward-line 1) | 2174 (forward-line 1) |
2180 (setq hend (point)) ;mark end of header | 2175 (setq hend (point)) ;mark end of header |
2181 (write-region (max (min hbeg beg) already-output) | 2176 (write-region |
2182 hend | 2177 (max (if beg |
2183 tex-out-file | 2178 (min hbeg beg) |
2184 (not (zerop already-output)) nil) | 2179 hbeg) |
2185 (setq already-output hend))))) | 2180 already-output) |
2186 | 2181 hend file (not (zerop already-output))) |
2187 ;; Write out the specified region | 2182 (setq already-output hend)))) |
2188 ;; (but don't repeat anything already written). | 2183 already-output)))) |
2189 (write-region (max beg already-output) end | |
2190 tex-out-file | |
2191 (not (zerop already-output)) nil)) | |
2192 ;; Write the trailer, if any. | |
2193 ;; Precede it with a newline to make sure it | |
2194 ;; is not hidden in a comment. | |
2195 (if tex-trailer | |
2196 (write-region (concat "\n" tex-trailer) nil | |
2197 tex-out-file t nil))))) | |
2198 | 2184 |
2199 (defun tex-buffer () | 2185 (defun tex-buffer () |
2200 "Run TeX on current buffer. See \\[tex-region] for more information. | 2186 "Run TeX on current buffer. See \\[tex-region] for more information. |
2201 Does not save the buffer, so it's useful for trying experimental versions. | 2187 Does not save the buffer, so it's useful for trying experimental versions. |
2202 See \\[tex-file] for an alternative." | 2188 See \\[tex-file] for an alternative." |