;;; texinfmt.el --- format Texinfo files into Info files
;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
-;; 1994, 1995, 1996, 1997, 1998, 2000, 2001
-;; Free Software Foundation, Inc.
+;; 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
+;; 2004, 2005 Free Software Foundation, Inc.
;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org>
;; Keywords: maint, tex, docs
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(defmacro defcustom (var value doc &rest ignore)
`(defvar ,var ,value ,doc)))
-(defvar texinfmt-version "2.40 of 6 Dec 2002")
+(defvar texinfmt-version "2.41 of 1 Mar 2005")
(defun texinfmt-version (&optional here)
"Show the version of texinfmt.el in the minibuffer.
(defvar texinfo-region-buffer-name "*Info Region*"
"*Name of the temporary buffer used by \\[texinfo-format-region].")
+(defvar texinfo-pre-format-hook nil
+ "Hook called before the conversion of the Texinfo file to Info format.
+The functions on this hook are called with argument BUFFER, the buffer
+containing the Texinfo file.")
+
;; These come from tex-mode.el.
(defvar tex-start-of-header)
(defvar tex-end-of-header)
input-buffer
(max region-beginning header-end)
region-end)
+ (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
;; Make sure region ends in a newline.
(or (= (preceding-char) ?\n)
(insert "\n"))
(goto-char (point-min))
;; Remove `@setfilename' line from included file, if any,
;; so @setfilename command not duplicated.
- (if (re-search-forward
- "^@setfilename" (save-excursion (forward-line 100) (point)) t)
- (progn
- (beginning-of-line)
- (delete-region
- (point) (save-excursion (forward-line 1) (point)))))))))
+ (if (re-search-forward "^@setfilename" (line-end-position 100) t)
+ (delete-region (line-beginning-position 1)
+ (line-beginning-position 2)))))))
;; Raise or lower level of each section, if necessary.
(goto-char (point-min))
(goto-char (point-min))
(if (looking-at "\\\\input[ \t]+texinfo")
- (delete-region (point) (save-excursion (forward-line 1) (point))))
+ (delete-region (point) (line-beginning-position 2)))
;; Insert Info region title text.
(goto-char (point-min))
(find-file outfile)
(texinfo-mode)
(erase-buffer)
+ (buffer-disable-undo)
(message "Formatting Info file: %s" outfile)
(setq texinfo-format-filename
(set-syntax-table texinfo-format-syntax-table)
(insert-buffer-substring input-buffer)
+ (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
(message "Converting %s to Info format..." (buffer-name input-buffer))
;; Insert @include files so `texinfo-raise-lower-sections' can
(let ((filename (concat input-directory
(texinfo-parse-line-arg))))
(re-search-backward "^@include")
- (delete-region (point) (save-excursion (forward-line 1) (point)))
+ (delete-region (point) (line-beginning-position 2))
(message "Reading included file: %s" filename)
(save-excursion
(save-restriction
(goto-char (point-min))
;; Remove `@setfilename' line from included file, if any,
;; so @setfilename command not duplicated.
- (if (re-search-forward
- "^@setfilename"
- (save-excursion (forward-line 100) (point)) t)
- (progn
- (beginning-of-line)
- (delete-region
- (point) (save-excursion (forward-line 1) (point)))))))))
+ (if (re-search-forward "^@setfilename" (line-end-position 100) t)
+ (delete-region (line-beginning-position 1)
+ (line-beginning-position 2)))))))
;; Raise or lower level of each section, if necessary.
(goto-char (point-min))
(texinfo-raise-lower-sections)
;; Convert three hyphens in a row to two.
(goto-char min)
(while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
- (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
- 2)))))
+ (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning 2)))))
\f
;;; Handle paragraph filling
;; I don't know if this causes other problems.
;; I suspect itemized lists don't get filled properly and a
;; more precise fix is required. Bob
- "itemize\\|"
+ ;; commented out on 2005 Feb 28 by Bob
+ ;; "itemize\\|"
"direntry\\|"
"lisp\\|"
"smalllisp\\|"
(forward-line 1))
;; 2. Skip over @example and similar no-refill environments.
(if (looking-at texinfo-no-refill-regexp)
- (let ((environment
- (buffer-substring-no-properties (match-beginning 1) (match-end 1))))
+ (let ((environment (match-string-no-properties 1)))
(progn (re-search-forward (concat "^@end " environment) nil t)
(forward-line 1)))
;; Else
;; 3. Do not refill a paragraph containing @w or @*, or ending
;; with @<newline> followed by a newline.
- (if (or
- (>= (point) (point-max))
- (re-search-forward
- "@w{\\|@\\*\\|@\n\n"
- (save-excursion
- (forward-paragraph)
- (forward-line 1)
- (point)) t))
+ (if (or (>= (point) (point-max))
+ (re-search-forward
+ "@w{\\|@\\*\\|@\n\n"
+ (save-excursion (forward-paragraph) (forward-line 1) (point))
+ t))
;; Go to end of paragraph and do nothing.
(forward-paragraph)
;; 4. Else go to end of paragraph and insert @refill
(forward-char 1)
(unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t)
(forward-char -1))
- (unless (re-search-backward "@refill\\|@bye" line-beg t)
+ (unless (re-search-backward "@refill\\|^[ \t]*@" line-beg t)
(insert "@refill")))
(forward-line 1))))))
(error "Unterminated @%s" (car (car texinfo-stack)))))
;; Remove excess whitespace
- (whitespace-cleanup))
+ (let ((whitespace-silent t))
+ (whitespace-cleanup)))
(defvar texinfo-copying-text ""
"Text of the copyright notice and copying permissions.")
(put 'iftex 'texinfo-format 'texinfo-format-iftex)
(defun texinfo-format-iftex ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end iftex[ \t]*\n")
- (point))))
+ (re-search-forward "@end iftex[ \t]*\n")))
(put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
(defun texinfo-format-ifhtml ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end ifhtml[ \t]*\n")
- (point))))
+ (re-search-forward "@end ifhtml[ \t]*\n")))
(put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
(defun texinfo-format-ifplaintext ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end ifplaintext[ \t]*\n")
- (point))))
+ (re-search-forward "@end ifplaintext[ \t]*\n")))
(put 'ifxml 'texinfo-format 'texinfo-format-ifxml)
(defun texinfo-format-ifxml ()
(put 'tex 'texinfo-format 'texinfo-format-tex)
(defun texinfo-format-tex ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end tex[ \t]*\n")
- (point))))
+ (re-search-forward "@end tex[ \t]*\n")))
(put 'html 'texinfo-format 'texinfo-format-html)
(defun texinfo-format-html ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end html[ \t]*\n")
- (point))))
+ (re-search-forward "@end html[ \t]*\n")))
(put 'xml 'texinfo-format 'texinfo-format-xml)
(defun texinfo-format-xml ()
(put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
(defun texinfo-format-ifnotinfo ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
- (point))))
+ (re-search-forward "@end ifnotinfo[ \t]*\n")))
(put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
(put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
(put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
(defun texinfo-format-titlepage ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end titlepage[ \t]*\n")
- (point))))
+ (re-search-forward "@end titlepage[ \t]*\n")))
(put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
(put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
(defun texinfo-format-titlespec ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end titlespec[ \t]*\n")
- (point))))
+ (re-search-forward "@end titlespec[ \t]*\n")))
(put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
(put 'ignore 'texinfo-format 'texinfo-format-ignore)
(defun texinfo-format-ignore ()
(delete-region texinfo-command-start
- (progn (re-search-forward "@end ignore[ \t]*\n")
- (point))))
+ (re-search-forward "@end ignore[ \t]*\n")))
(put 'endignore 'texinfo-format 'texinfo-discard-line)
(setq texinfo-alias-list
(cons
(cons
- (buffer-substring-no-properties (match-beginning 1) (match-end 1))
- (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
+ (match-string-no-properties 1)
+ (match-string-no-properties 2))
texinfo-alias-list))
(texinfo-discard-command))
)
(let ((arg (texinfo-parse-arg-discard)))
(if (string= "asis" arg)
(setq texinfo-paragraph-indent "asis")
- (setq texinfo-paragraph-indent (string-to-int arg)))))
+ (setq texinfo-paragraph-indent (string-to-number arg)))))
(put 'refill 'texinfo-format 'texinfo-format-refill)
(defun texinfo-format-refill ()
1))
(symbol-value indexvar)))))
-(defconst texinfo-indexvar-alist
+(defvar texinfo-indexvar-alist
'(("cp" . texinfo-cindex)
("fn" . texinfo-findex)
("vr" . texinfo-vindex)
;; Subroutine for sorting an index.
;; At start of a line, return a string to sort the line under.
(defun texinfo-sort-startkeyfun ()
- (let ((line
- (buffer-substring-no-properties (point) (save-excursion (end-of-line) (point)))))
+ (let ((line (buffer-substring-no-properties (point) (line-end-position))))
;; Canonicalize whitespace and eliminate funny chars.
(while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
(setq line (concat (substring line 0 (match-beginning 0))
" "
- (substring line (match-end 0) (length line)))))
+ (substring line (match-end 0)))))
line))
\f
(indent-to 54)
(insert
(if (nth 2 (car indexelts))
- (format " %d." (nth 2 (car indexelts)))
+ (format " (line %3d)" (1+ (nth 2 (car indexelts))))
"")
"\n"))
;; index entries from @include'd file
'flag-cleared)
;; Clear region (i.e., cause the text to be ignored).
(delete-region texinfo-command-start
- (progn (re-search-forward "@end ifset[ \t]*\n")
- (point))))
+ (re-search-forward "@end ifset[ \t]*\n")))
((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
nil)
;; In this case flag is neither set nor cleared.
'flag-set)
;; Clear region (i.e., cause the text to be ignored).
(delete-region texinfo-command-start
- (progn (re-search-forward "@end ifclear[ \t]*\n")
- (point))))
+ (re-search-forward "@end ifclear[ \t]*\n")))
((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
'flag-cleared)
;; Format the text (i.e., do not remove it); do nothing here.
(message ">> Error: %s" (prin1-to-string err))
(message ">> point at")
(let ((s (buffer-substring-no-properties (point)
- (min (+ (point) 100)
- (point-max))))
+ (min (+ (point) 100)
+ (point-max))))
(tem 0))
(while (setq tem (string-match "\n+" s tem))
(setq s (concat (substring s 0 (match-beginning 0))
;;; Place `provide' at end of file.
(provide 'texinfmt)
+;;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725
;;; texinfmt.el ends here