From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#20704: info.el bug fix; Interprets Info format wrongly Date: Wed, 10 Jun 2015 13:50:29 -0400 Message-ID: References: <87d21gpzle.fsf@tower.recompile.se> <83382btqcc.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1433958684 16521 80.91.229.3 (10 Jun 2015 17:51:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Jun 2015 17:51:24 +0000 (UTC) Cc: teddy@recompile.se, 20704@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 10 19:51:12 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z2k9e-0006Uz-Gu for geb-bug-gnu-emacs@m.gmane.org; Wed, 10 Jun 2015 19:51:10 +0200 Original-Received: from localhost ([::1]:41631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2k9d-0000bB-Qh for geb-bug-gnu-emacs@m.gmane.org; Wed, 10 Jun 2015 13:51:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2k9a-0000b5-Gn for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2015 13:51:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z2k9X-0000in-3H for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2015 13:51:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37457) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2k9W-0000iN-Vy for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2015 13:51:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z2k9W-0002ag-BH for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2015 13:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Jun 2015 17:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20704 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 20704-submit@debbugs.gnu.org id=B20704.14339586399892 (code B ref 20704); Wed, 10 Jun 2015 17:51:02 +0000 Original-Received: (at 20704) by debbugs.gnu.org; 10 Jun 2015 17:50:39 +0000 Original-Received: from localhost ([127.0.0.1]:47432 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z2k97-0002ZS-I0 for submit@debbugs.gnu.org; Wed, 10 Jun 2015 13:50:38 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:50132) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z2k93-0002ZC-Tm for 20704@debbugs.gnu.org; Wed, 10 Jun 2015 13:50:35 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id t5AHoTrN000811; Wed, 10 Jun 2015 13:50:30 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id C51D466166; Wed, 10 Jun 2015 13:50:29 -0400 (EDT) In-Reply-To: <83382btqcc.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 01 Jun 2015 18:12:35 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV5333=0 X-NAI-Spam-Version: 2.3.0.9393 : core <5333> : inlines <3178> : streams <1453233> : uri <1955083> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:103796 Archived-At: > Using byte-to-position would make things worse for Latin-1 and the likes. There's also the problem of EOL encoding, but I'll just ignore it for now. Could someone test the patch below? Stefan diff --git a/lisp/info.el b/lisp/info.el index 9602337..0de7f1e 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -1020,7 +1020,7 @@ 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))) + (filepos-to-bufferpos (read (current-buffer)) 'approximate) major-mode))))) (defun Info-find-in-tag-table (marker regexp &optional strict-case) @@ -1187,7 +1187,8 @@ is non-nil)." (when found ;; FOUND is (ANCHOR POS MODE). - (setq guesspos (nth 1 found)) + (setq guesspos (filepos-to-bufferpos (nth 1 found) + 'approximate)) ;; If this is an indirect file, determine which ;; file really holds this node and read it in. @@ -1203,8 +1204,7 @@ is non-nil)." (throw 'foo t))))) ;; Else we may have a node, which we search for: - (goto-char (max (point-min) - (- (byte-to-position guesspos) 1000))) + (goto-char (max (point-min) (- guesspos 1000))) ;; Now search from our advised position (or from beg of ;; buffer) to find the actual node. First, check @@ -1523,7 +1523,9 @@ is non-nil)." thisfilepos thisfilename) (search-forward ": ") (setq thisfilename (buffer-substring beg (- (point) 2))) - (setq thisfilepos (+ (point-min) (read (current-buffer)))) + (setq thisfilepos + (filepos-to-bufferpos (read (current-buffer)) + 'approximate)) ;; read in version 19 stops at the end of number. ;; Advance to the next line. (forward-line 1) @@ -1554,7 +1556,7 @@ is non-nil)." ;; Don't add the length of the skipped summary segment to ;; the value returned to `Info-find-node-2'. (Bug#14125) (if (numberp nodepos) - (+ (- nodepos lastfilepos) (point-min))))) + (- nodepos lastfilepos)))) (defun Info-unescape-quotes (value) "Unescape double quotes and backslashes in VALUE." @@ -2013,8 +2015,9 @@ 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))) + (setq list (cons (cons (filepos-to-bufferpos + (read (current-buffer)) + 'approximate) (match-string-no-properties 1)) list)) (goto-char (if backward diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el index eae787b..1f7df0b 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el @@ -313,6 +313,35 @@ per-character basis, this may not be accurate." (throw 'tag3 charset))) charset-list) nil))))))))) + +;;;###autoload +(defun filepos-to-bufferpos (byte &optional quality coding-system) + "Try to return the buffer position corresponding to a particular file position. +The file position is given as a BYTE count. +The function presumes the file is encoded with CODING-SYSTEM, which defaults +to `buffer-file-coding-system'. +QUALITY can be: + `approximate', in which case we may cut some corners to avoid + excessive work. + nil, in which case we may return nil rather than an approximation." + ;; `exact', in which case we may end up re-(en|de)coding a large + ;; part of the file. + (unless coding-system (setq coding-system buffer-file-coding-system)) + (let ((eol (coding-system-eol-type coding-system)) + (type (coding-system-type coding-system)) + (pm (save-restriction (widen) (point-min)))) + (pcase (cons type eol) + (`(utf-8 . ,(or 0 2)) + (let ((bom-offset (coding-system-get coding-system :bom))) + (byte-to-position + (+ pm (max 0 (- byte (if bom-offset 3 0))))))) + ;; FIXME: What if it's a 2-byte charset? Are there such beasts? + (`(charset . ,(or 0 2)) (+ pm byte)) + (_ + (pcase quality + (`approximate (+ pm (byte-to-position byte))) + ;; (`exact ...) + ))))) (provide 'mule-util)