Hi Alan,

if you can, please test this patch against current maint branch.
All tests don't pass fine, so I'll have to work on this a bit more
but I think it's an improvement, as it doesn't treat [1] as a 
footnote when `org-footnote-auto-label' is t (the default.)

Let me know, thanks!

diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index c598965..57ee678 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -67,25 +67,6 @@
 (defvar message-cite-prefix-regexp)	; defined in message.el
 (defvar message-signature-separator)	; defined in message.el
 
-(defconst org-footnote-re
-  ;; Only [1]-like footnotes are closed in this regexp, as footnotes
-  ;; from other types might contain square brackets (i.e. links) in
-  ;; their definition.
-  ;;
-  ;; `org-re' is used for regexp compatibility with XEmacs.
-  (concat "\\[\\(?:"
-	  ;; Match inline footnotes.
-	  (org-re "fn:\\([-_[:word:]]+\\)?:\\|")
-	  ;; Match other footnotes.
-	  "\\(?:\\([0-9]+\\)\\]\\)\\|"
-	  (org-re "\\(fn:[-_[:word:]]+\\)")
-	  "\\)")
-  "Regular expression for matching footnotes.")
-
-(defconst org-footnote-definition-re
-  (org-re "^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]")
-  "Regular expression matching the definition of a footnote.")
-
 (defconst org-footnote-forbidden-blocks
   '("ascii" "beamer" "comment" "docbook" "example" "html" "latex" "odt" "src")
   "Names of blocks where footnotes are not allowed.")
@@ -136,13 +117,13 @@ will be used to define the footnote at the reference position."
   "Non-nil means define automatically new labels for footnotes.
 Possible values are:
 
-nil        prompt the user for each label
-t          create unique labels of the form [fn:1], [fn:2], ...
-confirm    like t, but let the user edit the created value.  In particular,
-           the label can be removed from the minibuffer, to create
-           an anonymous footnote.
+nil        Prompt the user for each label.
+t          Create unique labels of the form [fn:1], [fn:2], etc.
+confirm    Like t, but let the user edit the created value.
+           In particular, the label can be removed from the
+           minibuffer, to create an anonymous footnote.
 random	   Automatically generate a unique, random label.
-plain      Automatically create plain number labels like [1]"
+plain      Automatically create plain number labels like [1]."
   :group 'org-footnote
   :type '(choice
 	  (const :tag "Prompt for label" nil)
@@ -151,6 +132,36 @@ plain      Automatically create plain number labels like [1]"
 	  (const :tag "Create a random label" random)
 	  (const :tag "Create automatic [N]" plain)))
 
+(defvar org-footnote-re nil
+  "Regular expression for matching footnotes.")
+(defvar org-footnote-definition-re nil
+  "Regular expression matching the definition of a footnote.")
+
+(defun org-footnote-set-re ()
+  "Set the regular expression `org-footnote-re'."
+  ;; Only [1]-like footnotes are closed in this regexp, as footnotes
+  ;; from other types might contain square brackets (i.e. links) in
+  ;; their definition.
+  ;;
+  ;; `org-re' is used for regexp compatibility with XEmacs.
+  (setq org-footnote-re
+	(concat "\\[\\(?:"
+		;; Match inline footnotes.
+		(org-re "fn:\\([-_[:word:]]+\\)?:\\|")
+		;; Match other footnotes.
+		(when (eq org-footnote-auto-label 'plain)
+		  "\\(?:\\([0-9]+\\)\\]\\)\\|")
+		(org-re "\\(fn:[-_[:word:]]+\\)")
+		"\\)")))
+(org-footnote-set-re)
+
+(defun org-footnote-definition-set-re ()
+  (setq org-footnote-definition-re
+	(if (eq org-footnote-auto-label 'plain)
+	    (org-re "^\\[\\([0-9]+\\)\\]")
+	  (org-re "^\\[\\(fn:[-_[:word:]]+\\)\\]"))))
+(org-footnote-definition-set-re)
+
 (defcustom org-footnote-auto-adjust nil
   "Non-nil means automatically adjust footnotes after insert/delete.
 When this is t, after each insertion or deletion of a footnote,
@@ -388,7 +399,9 @@ Return a non-nil value when a definition has been found."
   (cond
    ((numberp label) (number-to-string label))
    ((equal "" label) nil)
-   ((not (string-match "^[0-9]+$\\|^fn:" label))
+   ((not (if (eq org-footnote-auto-label 'plain)
+	     (string-match "^[0-9]+$" label)
+	   (string-match "^fn:" label)))
     (concat "fn:" label))
    (t label)))
 
-- 
 Bastien

Reply via email to