emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <87wrjtharq.fsf@member.fsf.org> (raw)
In-Reply-To: <87fwqk4b73.fsf@fastmail.fm> (Tassilo Horn's message of "Fri, 18 Mar 2011 17:58:56 +0100")

[-- Attachment #1: Type: text/plain, Size: 3031 bytes --]

Tassilo Horn <thorn@fastmail.fm> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-renumbering-for-footnotes-at-BOL.patch --]
[-- Type: text/x-patch, Size: 1362 bytes --]

From ce5a7f085ddaa67b3712884e6d86500ed075c399 Mon Sep 17 00:00:00 2001
From: Tassilo Horn <tassilo@member.fsf.org>
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


      reply	other threads:[~2011-03-20 19:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-18 16:58 Bug: org-footnote-renumber-fn:N breaks if a footnote is the first thing on a line [7.5 (release_7.5.77.g74268)] Tassilo Horn
2011-03-20 19:06 ` Tassilo Horn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wrjtharq.fsf@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).