emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bastien <bzg@altern.org>
To: Alan L Tyree <alantyree@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Footnote disable & sorting
Date: Tue, 25 Dec 2012 04:16:21 +0100	[thread overview]
Message-ID: <871ueezure.fsf@bzg.ath.cx> (raw)
In-Reply-To: <87wqw79ryx.fsf@breezy.my.home> (Alan L. Tyree's message of "Tue, 25 Dec 2012 06:21:10 +1100")

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

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!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-footnote.el.patch --]
[-- Type: text/x-patch, Size: 3928 bytes --]

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)))
 

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

  reply	other threads:[~2012-12-25  3:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-04 22:24 Footnote disable & sorting Alan L Tyree
2012-12-24  1:29 ` Bastien
2012-12-24  2:26   ` Alan L Tyree
2012-12-24  9:05     ` Bastien
2012-12-24 19:21       ` Alan L Tyree
2012-12-25  3:16         ` Bastien [this message]
2012-12-25  5:08           ` Alan L Tyree
2012-12-25 10:30             ` Bastien
2012-12-25 18:45               ` Alan L Tyree

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=871ueezure.fsf@bzg.ath.cx \
    --to=bzg@altern.org \
    --cc=alantyree@gmail.com \
    --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).