X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/4382021fc15f8a52c9dd12bacb7c75dbeb562302..233ba4d924933cb56129bd7511e6137b7c0b8e3e:/lisp/textmodes/texinfmt.el diff --git a/lisp/textmodes/texinfmt.el b/lisp/textmodes/texinfmt.el index 9f576b09db..d33cbb97dd 100644 --- a/lisp/textmodes/texinfmt.el +++ b/lisp/textmodes/texinfmt.el @@ -1,18 +1,17 @@ ;;; texinfmt.el --- format Texinfo files into Info files -;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, -;; 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, -;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2011 +;; Free Software Foundation, Inc. ;; Maintainer: Robert J. Chassell ;; Keywords: maint, tex, docs ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,9 +19,7 @@ ;; GNU General Public License for more details. ;; 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., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -30,13 +27,6 @@ ;;; Emacs lisp functions to convert Texinfo files to Info files. -(or (fboundp 'defgroup) - (defmacro defgroup (&rest ignore) nil)) - -(or (fboundp 'defcustom) - (defmacro defcustom (var value doc &rest ignore) - `(defvar ,var ,value ,doc))) - (defvar texinfmt-version "2.42 of 7 Jul 2006") (defun texinfmt-version (&optional here) @@ -47,7 +37,7 @@ If optional argument HERE is non-nil, insert info at point." (format "Version of \`texinfmt.el\': %s" texinfmt-version))) (if here (insert version-string) - (if (interactive-p) + (if (called-interactively-p 'interactive) (message "%s" version-string) version-string)))) @@ -175,12 +165,13 @@ and don't split the file if large. You can use `Info-tagify' and (Info-tagify) (if nosplit nil - (if (> (buffer-size) 100000) + (if (> (buffer-size) (+ 50000 Info-split-threshold)) (progn (message (setq lastmessage "Splitting Info file...")) (Info-split)))) (message (concat lastmessage - (if (interactive-p) "done. Now save it." "done."))))) + (if (called-interactively-p 'interactive) + "done. Now save it." "done."))))) (defvar texinfo-region-buffer-name "*Info Region*" "*Name of the temporary buffer used by \\[texinfo-format-region].") @@ -232,7 +223,7 @@ converted to Info is stored in a temporary buffer." (save-restriction (widen) (goto-char (point-min)) - (let ((search-end (save-excursion (forward-line 100) (point)))) + (let ((search-end (line-beginning-position 101))) (if (or ;; Either copy header text. (and @@ -293,7 +284,7 @@ converted to Info is stored in a temporary buffer." (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 @@ -331,8 +322,7 @@ converted to Info is stored in a temporary buffer." ;; Insert Info region title text. (goto-char (point-min)) - (if (search-forward - "@setfilename" (save-excursion (forward-line 100) (point)) t) + (if (search-forward "@setfilename" (line-beginning-position 101) t) (progn (setq texinfo-command-end (point)) (beginning-of-line) @@ -672,11 +662,12 @@ Do not append @refill to paragraphs containing @w{TEXT} or @*." ;; 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) + (line-beginning-position 2)) + t)) ;; Go to end of paragraph and do nothing. (forward-paragraph) ;; 4. Else go to end of paragraph and insert @refill @@ -780,13 +771,13 @@ commands." ((eq type '@raisesections) (setq level (1+ level)) (delete-region - (point) (save-excursion (forward-line 1) (point)))) + (point) (line-beginning-position 2))) ;; 2. Decrement level ((eq type '@lowersections) (setq level (1- level)) (delete-region - (point) (save-excursion (forward-line 1) (point)))) + (point) (line-beginning-position 2))) ;; Now handle structuring commands ((cond @@ -953,8 +944,8 @@ insert the text with the @insertcopying command." (end (progn (re-search-forward "^@end copying[ \t]*\n") (point)))) (setq texinfo-copying-text (buffer-substring-no-properties - (save-excursion (goto-char beg) (forward-line 1) (point)) - (save-excursion (goto-char end) (forward-line -1) (point)))) + (save-excursion (goto-char beg) (line-beginning-position 2)) + (save-excursion (goto-char end) (line-beginning-position 0)))) (delete-region beg end))) (defun texinfo-insertcopying () @@ -1513,9 +1504,7 @@ The node is constructed automatically." (progn (goto-char node-name-beginning) ; skip over node command (skip-chars-forward " \t") ; and over spaces (point)) - (if (search-forward - "," - (save-excursion (end-of-line) (point)) t) ; bound search + (if (search-forward "," (line-end-position) t) ; bound search (1- (point)) (end-of-line) (point)))))) (texinfo-discard-command) ; remove or insert whitespace, as needed @@ -1700,7 +1689,7 @@ Used by @refill indenting command to avoid indenting within lists, etc.") (put 'itemize 'texinfo-item 'texinfo-itemize-item) (defun texinfo-itemize-item () ;; (texinfo-discard-line) ; Did not handle text on same line as @item. - (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point))) + (delete-region (1+ (point)) (line-beginning-position)) (if (looking-at "[ \t]*[^ \t\n]+") ;; Text on same line as @item command. (insert "\b " (nth 1 (car texinfo-stack)) " \n") @@ -2061,9 +2050,8 @@ commands that are defined in texinfo.tex for printed output. (apply '+ texinfo-multitable-width-list)))) (if (> desired-columns fill-column) (error - (format - "Multi-column table width, %d chars, is greater than page width, %d chars." - desired-columns fill-column)))) + "Multi-column table width, %d chars, is greater than page width, %d chars." + desired-columns fill-column))) texinfo-multitable-width-list)) ;; @item A1 @tab A2 @tab A3 @@ -2141,10 +2129,10 @@ This command is executed when texinfmt sees @item inside @multitable." (narrow-to-region start end) ;; Remove whitespace before and after entry. (skip-chars-forward " ") - (delete-region (point) (save-excursion (beginning-of-line) (point))) + (delete-region (point) (line-beginning-position)) (goto-char (point-max)) (skip-chars-backward " ") - (delete-region (point) (save-excursion (end-of-line) (point))) + (delete-region (point) (line-end-position)) ;; Temporarily set texinfo-stack to nil so texinfo-format-scan ;; does not see an unterminated @multitable. (let (texinfo-stack) ; nil @@ -2418,16 +2406,14 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." (let ((start (1- (point))) args) (skip-chars-forward " ") - (save-excursion (end-of-line) (setq texinfo-command-end (point))) + (setq texinfo-command-end (line-end-position)) (if (not (looking-at "\\([^=]+\\)=\\(.*\\)")) (error "Invalid alias command") (push (cons (match-string-no-properties 1) (match-string-no-properties 2)) texinfo-alias-list) - (texinfo-discard-command)) - ) - ) + (texinfo-discard-command)))) ;;; @var, @code and the like @@ -2464,7 +2450,7 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image." "Insert ` ... ' around arg unless inside a table; in that case, no quotes." ;; `looking-at-backward' not available in v. 18.57, 20.2 (if (not (search-backward "" ; searched-for character is a control-H - (save-excursion (beginning-of-line) (point)) + (line-beginning-position) t)) (insert "`" (texinfo-parse-arg-discard) "'") (insert (texinfo-parse-arg-discard))) @@ -2516,7 +2502,7 @@ For example, @verb\{|@|\} results in @ and (error "Not found: @verb start brace")) (delete-region texinfo-command-start (+ 2 texinfo-command-end)) (search-forward delimiter)) - (delete-backward-char 1) + (delete-char -1) (unless (looking-at "}") (error "Not found: @verb end brace")) (delete-char 1)) @@ -2849,8 +2835,7 @@ Default is to leave paragraph indentation as is." (defun texinfo-noindent () (save-excursion (forward-paragraph 1) - (if (search-backward "@refill" - (save-excursion (forward-line -1) (point)) t) + (if (search-backward "@refill" (line-beginning-position 0) t) () ; leave @noindent command so @refill command knows not to indent ;; else (texinfo-discard-line)))) @@ -2972,46 +2957,24 @@ Default is to leave paragraph indentation as is." ("pg" . texinfo-format-pindex) ("ky" . texinfo-format-kindex))) - -;;; Sort and index (for VMS) - -;; Sort an index which is in the current buffer between START and END. -;; Used on VMS, where the `sort' utility is not available. -(defun texinfo-sort-region (start end) - (require 'sort) - (save-restriction - (narrow-to-region start end) - (goto-char (point-min)) - (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun))) - -;; 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) (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))))) - line)) - ;;; @printindex (put 'printindex 'texinfo-format 'texinfo-format-printindex) (defun texinfo-format-printindex () - (let ((indexelts (symbol-value - (cdr (assoc (texinfo-parse-arg-discard) - texinfo-indexvar-alist)))) - opoint) + (let* ((arg (texinfo-parse-arg-discard)) + (fmt (cdr (assoc arg texinfo-short-index-format-cmds-alist))) + (index-list (delq nil (mapcar (lambda (e) + (and (eq fmt (get (cdr e) 'texinfo-format)) + (cdr (assoc (car e) texinfo-indexvar-alist)))) + texinfo-short-index-cmds-alist))) + (indexelts (apply #'append nil (mapcar #'symbol-value index-list))) + opoint) (insert "\n* Menu:\n\n") (setq opoint (point)) (texinfo-print-index nil indexelts) - - (if (memq system-type '(vax-vms windows-nt ms-dos)) - (texinfo-sort-region opoint (point)) - (shell-command-on-region opoint (point) "sort -fd" 1)))) + (shell-command-on-region opoint (point) "sort -fd" 1))) (defun texinfo-print-index (file indexelts) (while indexelts @@ -3250,7 +3213,7 @@ Default is to leave paragraph indentation as is." ;; Take arguments ;; @,{c} ==> c, cedilla accent -(put ', 'texinfo-format 'texinfo-format-cedilla-accent) +(put '\, 'texinfo-format 'texinfo-format-cedilla-accent) (defun texinfo-format-cedilla-accent () (insert (texinfo-parse-arg-discard) ",") (goto-char texinfo-command-start)) @@ -4334,5 +4297,4 @@ For example, invoke ;;; Place `provide' at end of file. (provide 'texinfmt) -;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725 ;;; texinfmt.el ends here