From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: Footnote disable & sorting Date: Tue, 25 Dec 2012 04:16:21 +0100 Message-ID: <871ueezure.fsf@bzg.ath.cx> References: <50BE7801.4020502@gmail.com> <87ip7stey2.fsf@bzg.ath.cx> <87y5go9ocw.fsf@breezy.my.home> <87pq1zrfau.fsf@bzg.ath.cx> <87wqw79ryx.fsf@breezy.my.home> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:36488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TnL0B-0003FK-VA for emacs-orgmode@gnu.org; Mon, 24 Dec 2012 22:16:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TnL0A-00068p-LD for emacs-orgmode@gnu.org; Mon, 24 Dec 2012 22:16:23 -0500 Received: from mail-we0-f173.google.com ([74.125.82.173]:36339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TnL0A-00068k-Aq for emacs-orgmode@gnu.org; Mon, 24 Dec 2012 22:16:22 -0500 Received: by mail-we0-f173.google.com with SMTP id z2so3492241wey.18 for ; Mon, 24 Dec 2012 19:16:21 -0800 (PST) In-Reply-To: <87wqw79ryx.fsf@breezy.my.home> (Alan L. Tyree's message of "Tue, 25 Dec 2012 06:21:10 +1100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Alan L Tyree Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=org-footnote.el.patch 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))) --=-=-= Content-Type: text/plain -- Bastien --=-=-=--