Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug#11640: 24.1.50; texinfo-format-printindex fails on Windows with Windows's sort

2 views
Skip to first unread message

Kazuhiro Ito

unread,
Jun 6, 2012, 12:56:25 PM6/6/12
to 11...@debbugs.gnu.org
When I format .texi files on Windows, Emacs fails to make indices.
Emacs calls external sort program to make indices, but Windows's sort
program does not behave as Emacs expected.

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

--
Kazuhiro Ito



Juanma Barranquero

unread,
Jun 7, 2012, 7:04:48 AM6/7/12
to Kazuhiro Ito, 11...@debbugs.gnu.org
On Wed, Jun 6, 2012 at 6:56 PM, Kazuhiro Ito <kz...@d1.dion.ne.jp> 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



Andreas Schwab

unread,
Jun 7, 2012, 7:43:33 AM6/7/12
to Juanma Barranquero, Kazuhiro Ito, 11...@debbugs.gnu.org
Juanma Barranquero <lek...@gmail.com> writes:

> +;; Sort an index which is in the current buffer between START and END.
> +;; Used on Microsoft OSes, which have a non-POSIX `sort'.

Wouldn't it make sense to use it everywhere?

Andreas.

--
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Juanma Barranquero

unread,
Jun 7, 2012, 7:49:58 AM6/7/12
to Andreas Schwab, Kazuhiro Ito, 11...@debbugs.gnu.org
On Thu, Jun 7, 2012 at 1:43 PM, Andreas Schwab <sch...@linux-m68k.org> wrote:

> Wouldn't it make sense to use it everywhere?

I don't know. That code was removed in revno:89810, and was only used
for MS-DOS, Windows and VMS. I don't know the rationale for using the
system sort on other OSes. Performance, perhaps?

    Juanma



Eli Zaretskii

unread,
Jun 7, 2012, 12:23:46 PM6/7/12
to Juanma Barranquero, Stefan Monnier, Chong Yidong, kz...@d1.dion.ne.jp, 11...@debbugs.gnu.org, sch...@linux-m68k.org
> From: Juanma Barranquero <lek...@gmail.com>
> Date: Thu, 7 Jun 2012 13:49:58 +0200
> Cc: Kazuhiro Ito <kz...@d1.dion.ne.jp>, 11...@debbugs.gnu.org
>
> On Thu, Jun 7, 2012 at 1:43 PM, Andreas Schwab <sch...@linux-m68k.org> wrote:
>
> > Wouldn't it make sense to use it everywhere?
>
> I don't know. That code was removed in revno:89810, and was only used
> for MS-DOS, Windows and VMS.

I agree with Andreas: if we have a built-in functionality, using it is
better than relying on an external program.

> I don't know the rationale for using the system sort on other
> OSes. Performance, perhaps?

How about tradition? ;-)

Seriously, I find it hard to believe that performance matters in this
case, especially since texinfmt.el is no longer the main recommended
way of producing Info from Texinfo, which is why it doesn't get
updated with the latest features of the Texinfo language.

Stefan, Chong, any objections to sorting the indices in Lisp in this
case?



Eli Zaretskii

unread,
Jun 7, 2012, 12:24:50 PM6/7/12
to Juanma Barranquero, kz...@d1.dion.ne.jp, 11...@debbugs.gnu.org
> From: Juanma Barranquero <lek...@gmail.com>
> Date: Thu, 7 Jun 2012 13:04:48 +0200
> Cc: 11...@debbugs.gnu.org
>
> On Wed, Jun 6, 2012 at 6:56 PM, Kazuhiro Ito <kz...@d1.dion.ne.jp> 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?

If you eventually install something like this, please mention in the
log that it was inadvertently removed in revision 89810.



Juanma Barranquero

unread,
Jun 7, 2012, 2:47:57 PM6/7/12
to Eli Zaretskii, 11...@debbugs.gnu.org, kz...@d1.dion.ne.jp, sch...@linux-m68k.org, Chong Yidong
On Thu, Jun 7, 2012 at 6:23 PM, Eli Zaretskii <el...@gnu.org> wrote:

> Seriously, I find it hard to believe that performance matters in this
> case, especially since texinfmt.el is no longer the main recommended
> way of producing Info from Texinfo, which is why it doesn't get
> updated with the latest features of the Texinfo language.

I'm perfectly willing to believe you. As I said, I don't know why was
it done otherwise.

> Stefan, Chong, any objections to sorting the indices in Lisp in this
> case?

The patch is even simpler.


2012-06-07 Juanma Barranquero <lek...@gmail.com>

* textmodes/texinfmt.el: Use internal sort (partial revert of revno:89810).
(texinfo-sort-region, texinfo-sort-startkeyfun): Restore functions.
(texinfo-format-printindex): Use `texinfo-sort-region' instead of
calling external sort utility.


=== modified file 'lisp/textmodes/texinfmt.el'
--- lisp/textmodes/texinfmt.el 2012-04-09 13:05:48 +0000
+++ lisp/textmodes/texinfmt.el 2012-06-07 18:38:56 +0000
@@ -2958,6 +2958,28 @@
("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

(put 'printindex 'texinfo-format 'texinfo-format-printindex)
@@ -2974,7 +2996,7 @@
(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))))

Stefan Monnier

unread,
Jun 8, 2012, 1:45:21 AM6/8/12
to Eli Zaretskii, Juanma Barranquero, kz...@d1.dion.ne.jp, 11...@debbugs.gnu.org, sch...@linux-m68k.org, Chong Yidong
> Stefan, Chong, any objections to sorting the indices in Lisp in this
> case?

Nope,


Stefan



Juanma Barranquero

unread,
Jun 8, 2012, 8:25:49 AM6/8/12
to Stefan Monnier, 11640...@debbugs.gnu.org
On Fri, Jun 8, 2012 at 7:45 AM, Stefan Monnier <mon...@iro.umontreal.ca> wrote:

> Nope,

Committed in revno:108524.



0 new messages