From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tassilo Horn Subject: Re: Bug: org-footnote-renumber-fn:N breaks if a footnote is the first thing on a line [7.5 (release_7.5.77.g74268)] Date: Sun, 20 Mar 2011 20:06:33 +0100 Message-ID: <87wrjtharq.fsf@member.fsf.org> References: <87fwqk4b73.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=37748 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q1NyC-0000FQ-9L for emacs-orgmode@gnu.org; Sun, 20 Mar 2011 15:08:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1NxT-00064z-NV for emacs-orgmode@gnu.org; Sun, 20 Mar 2011 15:06:37 -0400 Received: from out3.smtp.messagingengine.com ([66.111.4.27]:54945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1NxT-00064g-Jf for emacs-orgmode@gnu.org; Sun, 20 Mar 2011 15:06:35 -0400 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id BCA4C20296 for ; Sun, 20 Mar 2011 15:06:34 -0400 (EDT) Received: from thinkpad (88-134-173-46-dynip.superkabel.de [88.134.173.46]) by mail.messagingengine.com (Postfix) with ESMTPA id 2F053441195 for ; Sun, 20 Mar 2011 15:06:33 -0400 (EDT) In-Reply-To: <87fwqk4b73.fsf@fastmail.fm> (Tassilo Horn's message of "Fri, 18 Mar 2011 17:58:56 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Tassilo Horn writes: > Remember to cover the basics, that is, what you expected to happen and > what in fact did happen. You don't know how to make a good report? See > > http://orgmode.org/manual/Feedback.html#Feedback > > Your bug report will be posted to the Org-mode mailing list. > ------------------------------------------------------------------------ > > If a footnote is the first thing in a line, then > org-footnote-renumber-fn:N will break. It does not error, but the > footnote turns into [fn:]. Here's a recipe. Let's say, you have this minimal org file: --8<---------------cut here---------------start------------->8--- this is a test file with a footnote [fn:1] * Footnotes [fn:1] test. --8<---------------cut here---------------end--------------->8--- As you can see, the footnote is the first thing in a line. Now calling org-footnote-renumber-fn:N produces: --8<---------------cut here---------------start------------->8--- this is a test file with a footnote [fn:] * Footnotes [fn:] test. --8<---------------cut here---------------end--------------->8--- This is a major bug, because in larger org documents chances are high that you don't notice the breakage at first. The problem is that: --8<---------------cut here---------------start------------->8--- (defun org-footnote-renumber-fn:N () "Renumber the simple footnotes like fn:17 into a sequence in the document." (interactive) (let (map i (n 0)) (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) (setq i (string-to-number (match-string 1))) (when (and (string-match "\\S-" (buffer-substring (point-at-bol) (match-beginning 0))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (not (assq i map))) (push (cons i (number-to-string (incf n))) map))) (goto-char (point-min)) (while (re-search-forward "\\(\\[fn:\\)\\([0-9]+\\)\\([]:]\\)" nil t) (replace-match (concat "\\1" (cdr (assq (string-to-number (match-string 2)) map)) "\\3"))))))) --8<---------------cut here---------------end--------------->8--- I don't understand `string-match' test underlined above. In my case, the buffer-substring that is tested is the empty string "". That makes the test fail. Basically, the test ensures that the footnote is not the first thing in the line, but why? The assq check already ensures that the footnote definition lists produce no duplicates. Attached is a patch that simply deletes the check. It works fine for me. I also added an assertion that checks that you never replace a footnote with [fn:]. If the number after renumbering is nil, then an error is produced. > Emacs : GNU Emacs 24.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.22.1) > of 2011-03-12 on thinkpad > Package: Org-mode version 7.5 (release_7.5.77.g74268) Bye, Tassilo --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-renumbering-for-footnotes-at-BOL.patch >From ce5a7f085ddaa67b3712884e6d86500ed075c399 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sun, 20 Mar 2011 19:58:44 +0100 Subject: [PATCH] Fix renumbering for footnotes at BOL. --- lisp/org-footnote.el | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 9dbd6be..3985469 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -570,13 +570,13 @@ and all references of a footnote label." (goto-char (point-min)) (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) (setq i (string-to-number (match-string 1))) - (when (and (string-match "\\S-" (buffer-substring - (point-at-bol) (match-beginning 0))) - (not (assq i map))) + (when (not (assq i map)) (push (cons i (number-to-string (incf n))) map))) (goto-char (point-min)) (while (re-search-forward "\\(\\[fn:\\)\\([0-9]+\\)\\([]:]\\)" nil t) - (replace-match (concat "\\1" (cdr (assq (string-to-number (match-string 2)) map)) "\\3"))))))) + (setq i (cdr (assq (string-to-number (match-string 2)) map))) + (assert (progn i) t "Footnote has no number. Better undo renumbering!") + (replace-match (concat "\\1" i "\\3"))))))) (defun org-footnote-auto-adjust-maybe () "Renumber and/or sort footnotes according to user settings." -- 1.7.4.1 --=-=-=--