bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#11640: 24.1.50; texinfo-format-printindex fails on Windows with Wind


From: Juanma Barranquero
Subject: bug#11640: 24.1.50; texinfo-format-printindex fails on Windows with Windows's sort
Date: Thu, 7 Jun 2012 13:04:48 +0200

On Wed, Jun 6, 2012 at 6:56 PM, Kazuhiro Ito <address@hidden> wrote:

> To avoid this problem, Emacs22 does not call sort program on Windows.
> But this workaround seems to have been dropped when VMS support
> have been removed (*1).
>
> (*1) http://bzr.savannah.gnu.org/lh/emacs/trunk/revision/89810

Does the following patch work for you?

    Juanma


=== modified file 'lisp/textmodes/texinfmt.el'
--- lisp/textmodes/texinfmt.el  2012-04-09 13:05:48 +0000
+++ lisp/textmodes/texinfmt.el  2012-06-07 11:02:59 +0000
@@ -2958,6 +2958,29 @@
     ("ky" . texinfo-format-kindex)))

 
+;;; Sort and index (for MS-DOS and Windows)
+
+;; Sort an index which is in the current buffer between START and END.
+;; Used on Microsoft OSes, which have a non-POSIX `sort'.
+(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)
@@ -2974,7 +2997,9 @@
     (insert "\n* Menu:\n\n")
     (setq opoint (point))
     (texinfo-print-index nil indexelts)
-    (shell-command-on-region opoint (point) "sort -fd" 1)))
+    (if (memq system-type '(windows-nt ms-dos))
+        (texinfo-sort-region opoint (point))
+      (shell-command-on-region opoint (point) "sort -fd" 1))))

 (defun texinfo-print-index (file indexelts)
   (while indexelts





reply via email to

[Prev in Thread] Current Thread [Next in Thread]