X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/db95369be096960245dd38678f68464627698678..614b38a99518cb219f3b24016ca8aa638f0581be:/lisp/textmodes/texinfmt.el diff --git a/lisp/textmodes/texinfmt.el b/lisp/textmodes/texinfmt.el index 35d40a1efd..d46d2f81fd 100644 --- a/lisp/textmodes/texinfmt.el +++ b/lisp/textmodes/texinfmt.el @@ -1,8 +1,8 @@ ;;; 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 ;; Keywords: maint, tex, docs @@ -21,8 +21,8 @@ ;; 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: @@ -37,7 +37,7 @@ (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. @@ -134,6 +134,11 @@ Info-split to do these manually." (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) @@ -215,6 +220,7 @@ converted to Info is stored in a temporary buffer." 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")) @@ -244,12 +250,9 @@ converted to Info is stored in a temporary buffer." (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)) @@ -271,7 +274,7 @@ converted to Info is stored in a temporary buffer." (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)) @@ -375,6 +378,7 @@ if large. You can use Info-split to do this manually." (find-file outfile) (texinfo-mode) (erase-buffer) + (buffer-disable-undo) (message "Formatting Info file: %s" outfile) (setq texinfo-format-filename @@ -384,6 +388,7 @@ if large. You can use Info-split to do this manually." (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 @@ -395,7 +400,7 @@ if large. You can use Info-split to do this manually." (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 @@ -405,13 +410,9 @@ if large. You can use Info-split to do this manually." (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) @@ -469,8 +470,7 @@ if large. You can use Info-split to do this manually." ;; 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))))) ;;; Handle paragraph filling @@ -486,7 +486,8 @@ if large. You can use Info-split to do this manually." ;; 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\\|" @@ -612,21 +613,17 @@ Do not append @refill to paragraphs containing @w{TEXT} or @*." (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 @ 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 @@ -640,7 +637,7 @@ Do not append @refill to paragraphs containing @w{TEXT} or @*." (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)))))) @@ -947,7 +944,8 @@ lower types.") (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.") @@ -2234,20 +2232,17 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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 () @@ -2258,14 +2253,12 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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 () @@ -2276,8 +2269,7 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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) @@ -2297,8 +2289,7 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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) @@ -2307,8 +2298,7 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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) @@ -2343,8 +2333,7 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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) @@ -2439,8 +2428,8 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (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)) ) @@ -2818,7 +2807,7 @@ Default is to leave the number of spaces as is." (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 () @@ -2912,7 +2901,7 @@ Default is to leave paragraph indentation as is." 1)) (symbol-value indexvar))))) -(defconst texinfo-indexvar-alist +(defvar texinfo-indexvar-alist '(("cp" . texinfo-cindex) ("fn" . texinfo-findex) ("vr" . texinfo-vindex) @@ -3007,13 +2996,12 @@ Default is to leave paragraph indentation as is." ;; 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)) @@ -3046,7 +3034,7 @@ Default is to leave paragraph indentation as is." (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 @@ -4036,8 +4024,7 @@ The command `@value{foo}' expands to the value." '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. @@ -4054,8 +4041,7 @@ The command `@value{foo}' expands to the value." '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. @@ -4341,8 +4327,8 @@ For example, invoke (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)) @@ -4357,4 +4343,5 @@ For example, invoke ;;; Place `provide' at end of file. (provide 'texinfmt) +;;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725 ;;; texinfmt.el ends here