emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Re: Bug: org-footnote-renumber-fn:N breaks if a footnote is the firs


From: Tassilo Horn
Subject: [O] 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
User-agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux)

Tassilo Horn <address@hidden> 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
>From ce5a7f085ddaa67b3712884e6d86500ed075c399 Mon Sep 17 00:00:00 2001
From: Tassilo Horn <address@hidden>
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 via email to

[Prev in Thread] Current Thread [Next in Thread]