]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/texinfmt.el
Update copyright year to 2014 by running admin/update-copyright.
[gnu-emacs] / lisp / textmodes / texinfmt.el
index 3ec59ebcd3e79a35392522326242cc3a66e5c566..218b6dbc7098bbe3eabf9c90b86192b85e7fd363 100644 (file)
@@ -1,7 +1,7 @@
 ;;; texinfmt.el --- format Texinfo files into Info files
 
-;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2012
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2014 Free Software
+;; Foundation, Inc.
 
 ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org>
 ;; Keywords: maint, tex, docs
@@ -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.
@@ -1918,7 +1918,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-")
@@ -2957,6 +2957,28 @@ Default is to leave paragraph indentation as is."
     ("pg" . texinfo-format-pindex)
     ("ky" . texinfo-format-kindex)))
 
+\f
+;;; 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))
+
 \f
 ;;; @printindex
 
@@ -2974,7 +2996,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