Function: tex-region-header
tex-region-header is a byte-compiled function defined in
tex-mode.el.gz.
Signature
(tex-region-header FILE &optional BEG)
Documentation
If there is a TeX header in the current buffer, write it to FILE.
Return point at the end of the region so written, or zero. If the optional buffer position BEG is specified, then the region written out starts at BEG, if this lies before the start of the header.
If the first line matches tex-first-line-header-regexp, it is
also written out. The variables tex-start-of-header and
tex-end-of-header are used to locate the header. Note that the
start of the header is required to be within the first 100 lines.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/tex-mode.el.gz
(defun tex-region-header (file &optional beg)
"If there is a TeX header in the current buffer, write it to FILE.
Return point at the end of the region so written, or zero. If
the optional buffer position BEG is specified, then the region
written out starts at BEG, if this lies before the start of the header.
If the first line matches `tex-first-line-header-regexp', it is
also written out. The variables `tex-start-of-header' and
`tex-end-of-header' are used to locate the header. Note that the
start of the header is required to be within the first 100 lines."
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(let ((search-end (save-excursion
(forward-line 100)
(point)))
(already-output 0)
hbeg hend)
;; 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)
(setq already-output (point)))
file))
;; 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.
(and tex-start-of-header
(re-search-forward tex-start-of-header search-end t)
(progn
(beginning-of-line)
(setq hbeg (point)) ; mark beginning of header
(when (re-search-forward tex-end-of-header nil t)
(forward-line 1)
(setq hend (point)) ; mark end of header
(write-region
(max (if beg
(min hbeg beg)
hbeg)
already-output)
hend file (not (zerop already-output)))
(setq already-output hend))))
already-output))))