]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/texinfmt.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / textmodes / texinfmt.el
index 812fcca06d649d288d862939c47a7006428310c2..19a21237d2b308a7699eac6b4fcbb5313aa7cfdb 100644 (file)
@@ -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-2016 Free Software
+;; Foundation, Inc.
 
 ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org>
 ;; 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 3, 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 <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; 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)
 If optional argument HERE is non-nil, insert info at point."
   (interactive "P")
   (let ((version-string
-         (format "Version of \`texinfmt.el\': %s" texinfmt-version)))
+         (format-message "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))))
 
@@ -103,7 +93,7 @@ If optional argument HERE is non-nil, insert info at point."
     (@unnumberedsubsubsec . @unnumberedsubsec)
     (@subsubheading . @subheading)
     (@appendixsubsubsec . @appendixsubsec))
-  "*An alist of next higher levels for chapters, sections, etc...
+  "An alist of next higher levels for chapters, sections, etc...
 For example, section to chapter, subsection to section.
 Used by `texinfo-raise-lower-sections'.
 The keys specify types of section; the values correspond to the next
@@ -131,7 +121,7 @@ higher types.")
     (@unnumberedsubsubsec . @unnumberedsubsubsec)
     (@subsubheading . @subsubheading)
     (@appendixsubsubsec . @appendixsubsubsec))
-  "*An alist of next lower levels for chapters, sections, etc...
+  "An alist of next lower levels for chapters, sections, etc...
 For example, chapter to section, section to subsection.
 Used by `texinfo-raise-lower-sections'.
 The keys specify types of section; the values correspond to the next
@@ -175,15 +165,16 @@ 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].")
+  "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.
@@ -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)
@@ -340,25 +330,24 @@ converted to Info is stored in a temporary buffer."
           (let ((arg (texinfo-parse-arg-discard)))
             (insert " "
               texinfo-region-buffer-name
-              " buffer for:  `")
+              (format-message " buffer for:  `"))
             (insert (file-name-nondirectory (expand-file-name arg)))
-            (insert "',        -*-Text-*-\n")))
+            (insert (format-message "',        -*-Text-*-\n"))))
       ;; Else no `@setfilename' line
       (insert " "
               texinfo-region-buffer-name
               " buffer                       -*-Text-*-\n"))
-    (insert "produced by `texinfo-format-region'\n"
+    (insert (format-message "produced by `texinfo-format-region'\n")
             "from a region in: "
             (if (buffer-file-name input-buffer)
-                  (concat "`"
-                          (file-name-sans-versions
-                           (file-name-nondirectory
-                            (buffer-file-name input-buffer)))
-                          "'")
-                (concat "buffer `" (buffer-name input-buffer) "'"))
-              "\nusing `texinfmt.el' version "
-              texinfmt-version
-              ".\n\n")
+               (format-message "`%s'"
+                       (file-name-sans-versions
+                        (file-name-nondirectory
+                         (buffer-file-name input-buffer))))
+             (format-message "buffer `%s'" (buffer-name input-buffer)))
+            (format-message "\nusing `texinfmt.el' version ")
+            texinfmt-version
+            ".\n\n")
 
     ;; Now convert for real.
     (goto-char (point-min))
@@ -489,19 +478,18 @@ if large.  You can use `Info-split' to do this manually."
     ;; Insert info about how this file was made.
     (insert "Info file: "
             texinfo-format-filename ",    -*-Text-*-\n"
-            "produced by `texinfo-format-buffer'\n"
+            (format-message "produced by `texinfo-format-buffer'\n")
             ;; Date string removed so that regression testing is easier.
             ;; "on "
             ;; (insert (format-time-string "%e %b %Y")) " "
             "from file"
             (if (buffer-file-name input-buffer)
-                (concat " `"
+                (format-message " `%s'"
                         (file-name-sans-versions
                          (file-name-nondirectory
-                          (buffer-file-name input-buffer)))
-                        "'")
-              (concat "buffer `" (buffer-name input-buffer) "'"))
-            "\nusing `texinfmt.el' version "
+                          (buffer-file-name input-buffer))))
+              (format-message "buffer `%s'" (buffer-name input-buffer)))
+            (format-message "\nusing `texinfmt.el' version ")
             texinfmt-version
             ".\n\n")
     ;; Return data for indices.
@@ -528,7 +516,7 @@ if large.  You can use `Info-split' to do this manually."
 \f
 ;;; Handle paragraph filling
 
-;; Keep as concatinated lists for ease of maintenance
+;; Keep as concatenated lists for ease of maintenance
 
 (defvar texinfo-no-refill-regexp
   (concat
@@ -630,7 +618,7 @@ if large.  You can use `Info-split' to do this manually."
    "var{\\|"
    "w{\\|"
    "xref{\\|"
-   "@-\\|"    ; @- is a descretionary hyphen (not an accent) (a noop).
+   "@-\\|"    ; @- is a discretionary hyphen (not an accent) (a noop).
    texinfo-accent-commands
    "\\)"
    )
@@ -672,11 +660,12 @@ Do not append @refill to paragraphs containing @w{TEXT} or @*."
         ;; 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)
+                                 (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 +769,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 +942,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 ()
@@ -1054,7 +1043,7 @@ Leave point after argument."
            (setq texinfo-command-end (point)))
           (t
            (error
-            "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
+            "Invalid `texinfo-optional-braces-discard' format (need braces?)")))
     (delete-region texinfo-command-start texinfo-command-end)))
 
 (defun texinfo-format-parse-line-args ()
@@ -1296,7 +1285,7 @@ Leave point after argument."
 (put 'uref 'texinfo-format 'texinfo-format-uref)
 (defun texinfo-format-uref ()
   "Format URL and optional URL-TITLE.
-Insert ` ... ' around URL if no URL-TITLE argument;
+Insert \\=` ... \\=' around URL if no URL-TITLE argument;
 otherwise, insert URL-TITLE followed by URL in parentheses."
   (let ((args (texinfo-format-parse-args)))
     (texinfo-discard-command)
@@ -1513,9 +1502,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 +1687,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")
@@ -1929,7 +1916,7 @@ Used by @refill indenting command to avoid indenting within lists, etc.")
 ;; Texinfo commands.
 
 (defvar texinfo-extra-inter-column-width 0
-  "*Number of extra spaces between entries (columns) in @multitable.")
+  "Number of extra spaces between entries (columns) in @multitable.")
 
 (defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
 (defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
@@ -2099,11 +2086,11 @@ This command is executed when texinfmt sees @item inside @multitable."
         (table-entry-height 0)
         ;; unformatted row looks like:  A1  @tab  A2  @tab  A3
         ;; extract-row command deletes the source line in the table.
-        (unformated-row (texinfo-multitable-extract-row)))
+        (unformatted-row (texinfo-multitable-extract-row)))
     ;; Use a temporary buffer
     (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
     (delete-region (point-min) (point-max))
-    (insert unformated-row)
+    (insert unformatted-row)
     (goto-char (point-min))
 ;; 1. Check for correct number of @tab in line.
     (let ((tab-number 1))               ; one @tab between two columns
@@ -2140,10 +2127,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
@@ -2205,7 +2192,7 @@ This command is executed when texinfmt sees @item inside @multitable."
 
 (put 'image 'texinfo-format 'texinfo-format-image)
 (defun texinfo-format-image ()
-  "Insert an image from an an file ending in .txt.
+  "Insert an image from a file ending in .txt.
 Use only the FILENAME arg; for Info, ignore the other arguments to @image."
   (let ((args (texinfo-format-parse-args))
        filename)
@@ -2349,7 +2336,7 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image."
 ;; Write a `@definfoenclose' command on a line and follow it with three
 ;; arguments separated by commas (commas are used as separators in an
 ;; `@node' line in the same way).  The first argument to
-;; `@definfoenclose' is the @-command name \(without the `@'\); the
+;; `@definfoenclose' is the @-command name (without the `@'); the
 ;; second argument is the Info start delimiter string; and the third
 ;; argument is the Info end delimiter string.  The latter two arguments
 ;; enclose the highlighted text in the Info file.  A delimiter string
@@ -2417,16 +2404,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))))
 
 \f
 ;;; @var, @code and the like
@@ -2460,10 +2445,10 @@ Use only the FILENAME arg; for Info, ignore the other arguments to @image."
 ;; not lead to inserted ` ... ' in a table, but does elsewhere.
 (put 'option 'texinfo-format 'texinfo-format-option)
 (defun texinfo-format-option ()
-  "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
+  "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 "\b"    ; 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)))
@@ -2506,8 +2491,8 @@ surrounded by in angle brackets."
 Enclose the verbatim text, including the delimiters, in braces.  Print
 text exactly as written (but not the delimiters) in a fixed-width.
 
-For example, @verb\{|@|\} results in @ and
-@verb\{+@'e?`!`+} results in @'e?`!`."
+For example, @verb{|@|} results in @ and
+@verb{+@\\='e?\\=`!\\=`+} results in @\\='e?\\=`!\\=`."
 
   (let ((delimiter (buffer-substring-no-properties
                    (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
@@ -2515,7 +2500,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))
@@ -2848,8 +2833,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,10 +2956,9 @@ Default is to leave paragraph indentation as is."
     ("ky" . texinfo-format-kindex)))
 
 \f
-;;; Sort and index (for VMS)
+;;; Sort and index
 
 ;; 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
@@ -3011,9 +2994,7 @@ Default is to leave paragraph indentation as is."
     (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))))
+    (texinfo-sort-region opoint (point))))
 
 (defun texinfo-print-index (file indexelts)
   (while indexelts
@@ -3144,7 +3125,7 @@ Default is to leave paragraph indentation as is."
 ;; (put '\` 'texinfo-format 'texinfo-format-grave-accent)
 ;; (defun texinfo-format-grave-accent ()
 ;;   (texinfo-discard-command)
-;;   (insert "\`"))
+;;   (insert "`"))
 ;;
 ;; @'              ==>    '         acute accent
 ;; (put '\' 'texinfo-format 'texinfo-format-acute-accent)
@@ -3948,11 +3929,11 @@ Default is to leave paragraph indentation as is."
 ;;; @set, @clear, @ifset, @ifclear
 
 ;; If a flag is set with @set FLAG, then text between @ifset and @end
-;; ifset is formatted normally, but if the flag is is cleared with
+;; ifset is formatted normally, but if the flag is cleared with
 ;; @clear FLAG, then the text is not formatted; it is ignored.
 
 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
-;; and @end ifclear is formatted normally, but if the flag is is set with
+;; and @end ifclear is formatted normally, but if the flag is set with
 ;; @set FLAG, then the text is not formatted; it is ignored.  @ifclear
 ;; is the opposite of @ifset.
 
@@ -4277,7 +4258,7 @@ the @ifeq command."
 Must be used only with -batch, and kills Emacs on completion.
 Each file will be processed even if an error occurred previously.
 For example, invoke
-  \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
+  \"emacs -batch -l texinfmt -f batch-texinfo-format $docs/ ~/*.texinfo\"."
   (if (not noninteractive)
       (error "batch-texinfo-format may only be used -batch"))
   (let ((version-control t)
@@ -4336,5 +4317,4 @@ For example, invoke
 ;;; Place `provide' at end of file.
 (provide 'texinfmt)
 
-;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725
 ;;; texinfmt.el ends here