X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/a64bfdfa5a90731b804c057f2bcc74a8ba02937c..c79978fcad84052edbdb78b33f2eaa913acb7cb0:/lisp/textmodes/texinfmt.el diff --git a/lisp/textmodes/texinfmt.el b/lisp/textmodes/texinfmt.el index d33cbb97dd..19a21237d2 100644 --- a/lisp/textmodes/texinfmt.el +++ b/lisp/textmodes/texinfmt.el @@ -1,7 +1,7 @@ ;;; texinfmt.el --- format Texinfo files into Info files -;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2011 -;; Free Software Foundation, Inc. +;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2016 Free Software +;; Foundation, Inc. ;; Maintainer: Robert J. Chassell ;; Keywords: maint, tex, docs @@ -34,7 +34,7 @@ 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 (called-interactively-p 'interactive) @@ -93,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 @@ -121,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 @@ -174,7 +174,7 @@ and don't split the file if large. You can use `Info-tagify' and "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. @@ -330,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)) @@ -479,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. @@ -518,7 +516,7 @@ if large. You can use `Info-split' to do this manually." ;;; 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 @@ -620,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 "\\)" ) @@ -1045,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 () @@ -1287,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) @@ -1918,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-") @@ -2088,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 @@ -2194,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) @@ -2338,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 @@ -2447,7 +2445,7 @@ 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 "" ; searched-for character is a control-H (line-beginning-position) @@ -2493,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)))) @@ -2957,6 +2955,28 @@ Default is to leave paragraph indentation as is." ("pg" . texinfo-format-pindex) ("ky" . texinfo-format-kindex))) + +;;; Sort and index + +;; Sort an index which is in the current buffer between START and END. +(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 @@ -2974,7 +2994,7 @@ Default is to leave paragraph indentation as is." (insert "\n* Menu:\n\n") (setq opoint (point)) (texinfo-print-index nil indexelts) - (shell-command-on-region opoint (point) "sort -fd" 1))) + (texinfo-sort-region opoint (point)))) (defun texinfo-print-index (file indexelts) (while indexelts @@ -3105,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) @@ -3909,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. @@ -4238,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)