Subject: bug#20704: info.el bug fix; Interprets Info format wrongly

From: Teddy Hogeborn <[email-masked]>
Date: Sun, 31 May 2015 16:54:05 +0200

The Info file format (see (texinfo)Info Format Tag Table.)  is
documented as having the reference position in bytes.  However, the
info.el functions "Info-find-in-tag-table-1", "Info-read-subfile", and
"Info-search" reads the byte value and adds it to (point-min), which is
a character position, not a byte position.  This causes the Emacs Info
reader to jump to the wrong position in Info files with a lot of
non-ascii characters.  Solution: Convert the read value to position
using byte-to-position:

diff --git a/lisp/info.el b/lisp/info.el
index 80428e7..b179510 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -1020,7 +1020,8 @@ which the match was found."
       (beginning-of-line)
       (when (re-search-forward regexp nil t)
 	(list (string-equal "Ref:" (match-string 1))
-	      (+ (point-min) (read (current-buffer)))
+	      (+ (point-min) (byte-to-position
+                              (read (current-buffer))))
 	      major-mode)))))
 
 (defun Info-find-in-tag-table (marker regexp &optional strict-case)
@@ -1523,7 +1524,9 @@ is non-nil)."
 			thisfilepos thisfilename)
 		    (search-forward ": ")
 		    (setq thisfilename  (buffer-substring beg (- (point) 2)))
-		    (setq thisfilepos (+ (point-min) (read (current-buffer))))
+		    (setq thisfilepos (+ (point-min)
+                                         (byte-to-position
+                                          (read (current-buffer)))))
 		    ;; read in version 19 stops at the end of number.
 		    ;; Advance to the next line.
 		    (forward-line 1)
@@ -2013,9 +2016,11 @@ If DIRECTION is `backward', search in the reverse direction."
 		        (re-search-backward "\\(^.*\\): [0-9]+$")
 		      (re-search-forward "\\(^.*\\): [0-9]+$"))
 		    (goto-char (+ (match-end 1) 2))
-		    (setq list (cons (cons (+ (point-min)
-					      (read (current-buffer)))
-					   (match-string-no-properties 1))
+		    (setq list (cons (cons
+                                      (+ (point-min)
+                                         (byte-to-position
+                                          (read (current-buffer))))
+                                      (match-string-no-properties 1))
 				     list))
 		    (goto-char (if backward
                                    (1- (match-beginning 0))

Suggested ChangeLog:

----
Convert reference byte positions from Info file to character position.

* lisp/info.el (Info-find-in-tag-table-1, Info-read-subfile)
(Info-search): Convert position read from Info file from bytes to
character position.  Patch by Teddy Hogeborn <[email-masked]>.
----

/Teddy Hogeborn