Mercurial > emacs
annotate lisp/org/org-footnote.el @ 110918:236342431786
nnimap.el (gnutls-negotiate): Silence the byte compiler.
*.el: Fix comment for declare-function.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Mon, 11 Oct 2010 23:29:33 +0000 |
parents | a150e8a14679 |
children | 5cb272c831e8 |
rev | line source |
---|---|
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
1 ;;; org-footnote.el --- Footnote support in Org and elsewhere |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
2 ;; |
106815 | 3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
4 ;; |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
5 ;; Author: Carsten Dominik <carsten at orgmode dot org> |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
6 ;; Keywords: outlines, hypermedia, calendar, wp |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
7 ;; Homepage: http://orgmode.org |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
8 ;; Version: 7.01 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
9 ;; |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
11 ;; |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
15 ;; (at your option) any later version. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
16 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
21 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
25 ;; |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
26 ;;; Commentary: |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
27 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
28 ;; This file contains the code dealing with footnotes in Org-mode. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
29 ;; The code can also be used in arbitrary text modes to provide |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
30 ;; footnotes. Compared to Steven L Baur's footnote.el it provides |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
31 ;; better support for resuming editing. It is less configurable than |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
32 ;; Steve's code, though. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
33 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
34 ;;; Code: |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
35 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
36 (eval-when-compile |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
37 (require 'cl)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
38 (require 'org-macs) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
39 (require 'org-compat) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
40 |
104810
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
41 (declare-function org-in-commented-line "org" ()) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
42 (declare-function org-in-regexp "org" (re &optional nlines visually)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
43 (declare-function org-mark-ring-push "org" (&optional pos buffer)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
44 (declare-function outline-next-heading "outline") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
45 (declare-function org-trim "org" (s)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
46 (declare-function org-show-context "org" (&optional key)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
47 (declare-function org-back-to-heading "org" (&optional invisible-ok)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
48 (declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading)) |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
49 (declare-function org-in-verbatim-emphasis "org" ()) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
50 (declare-function org-inside-latex-macro-p "org" ()) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
51 (defvar org-odd-levels-only) ;; defined in org.el |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
52 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
53 (defconst org-footnote-re |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
54 (concat "[^][\n]" ; to make sure it is not at the beginning of a line |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
55 "\\[" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
56 "\\(?:" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
57 "\\([0-9]+\\)" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
58 "\\|" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
59 (org-re "\\(fn:\\([-_[:word:]]+?\\)?\\)\\(?::\\([^\]]*?\\)\\)?") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
60 "\\)" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
61 "\\]") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
62 "Regular expression for matching footnotes.") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
63 |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
64 (defconst org-footnote-definition-re |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
65 (org-re "^\\(\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]\\)") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
66 "Regular expression matching the definition of a footnote.") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
67 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
68 (defgroup org-footnote nil |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
69 "Footnotes in Org-mode." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
70 :tag "Org Footnote" |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
71 :group 'org) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
72 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
73 (defcustom org-footnote-section "Footnotes" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
74 "Outline heading containing footnote definitions before export. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
75 This can be nil, to place footnotes locally at the end of the current |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
76 outline node. If can also be the name of a special outline heading |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
77 under which footnotes should be put. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
78 This variable defines the place where Org puts the definition |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
79 automatically, i.e. when creating the footnote, and when sorting the notes. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
80 However, by hand you may place definitions *anywhere*. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
81 If this is a string, during export, all subtrees starting with this |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
82 heading will be removed after extracting footnote definitions." |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
83 :group 'org-footnote |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
84 :type '(choice |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
85 (string :tag "Collect footnotes under heading") |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
86 (const :tag "Define footnotes locally" nil))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
87 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
88 (defcustom org-footnote-tag-for-non-org-mode-files "Footnotes:" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
89 "Tag marking the beginning of footnote section. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
90 The Org-mode footnote engine can be used in arbitrary text files as well |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
91 as in Org-mode. Outside Org-mode, new footnotes are always placed at |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
92 the end of the file. When you normalize the notes, any line containing |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
93 only this tag will be removed, a new one will be inserted at the end |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
94 of the file, followed by the collected and normalized footnotes." |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
95 :group 'org-footnote |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
96 :type 'string) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
97 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
98 (defcustom org-footnote-define-inline nil |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
99 "Non-nil means define footnotes inline, at reference location. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
100 When nil, footnotes will be defined in a special section near |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
101 the end of the document. When t, the [fn:label:definition] notation |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
102 will be used to define the footnote at the reference position." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
103 :group 'org-footnote |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
104 :type 'boolean) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
105 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
106 (defcustom org-footnote-auto-label t |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
107 "Non-nil means define automatically new labels for footnotes. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
108 Possible values are: |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
109 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
110 nil prompt the user for each label |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
111 t create unique labels of the form [fn:1], [fn:2], ... |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
112 confirm like t, but let the user edit the created value. In particular, |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
113 the label can be removed from the minibuffer, to create |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
114 an anonymous footnote. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
115 plain Automatically create plain number labels like [1]" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
116 :group 'org-footnote |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
117 :type '(choice |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
118 (const :tag "Prompt for label" nil) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
119 (const :tag "Create automatic [fn:N]" t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
120 (const :tag "Offer automatic [fn:N] for editing" confirm) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
121 (const :tag "Create automatic [N]" plain))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
122 |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
123 (defcustom org-footnote-auto-adjust nil |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
124 "Non-nil means automatically adjust footnotes after insert/delete. |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
125 When this is t, after each insertion or deletion of a footnote, |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
126 simple fn:N footnotes will be renumbered, and all footnotes will be sorted. |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
127 If you want to have just sorting or just renumbering, set this variable |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
128 to `sort' or `renumber'. |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
129 |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
130 The main values of this variable can be set with in-buffer options: |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
131 |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
132 #+STARTUP: fnadjust |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
133 #+STARTUP: nofnadjust" |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
134 :group 'org-footnote |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
135 :type '(choice |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
136 (const :tag "Renumber" renumber) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
137 (const :tag "Sort" sort) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
138 (const :tag "Renumber and Sort" t))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
139 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
140 (defcustom org-footnote-fill-after-inline-note-extraction nil |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
141 "Non-nil means fill paragraphs after extracting footnotes. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
142 When extracting inline footnotes, the lengths of lines can change a lot. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
143 When this option is set, paragraphs from which an inline footnote has been |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
144 extracted will be filled again." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
145 :group 'org-footnote |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
146 :type 'boolean) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
147 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
148 (defun org-footnote-at-reference-p () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
149 "Is the cursor at a footnote reference? |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
150 If yes, return the beginning position, the label, and the definition, if local." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
151 (when (org-in-regexp org-footnote-re 15) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
152 (list (match-beginning 0) |
101948
2591b7541793
(org-footnote-at-definition-p): Fix doc typo.
Glenn Morris <rgm@gnu.org>
parents:
101947
diff
changeset
|
153 (or (match-string 1) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
154 (if (equal (match-string 2) "fn:") nil (match-string 2))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
155 (match-string 4)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
156 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
157 (defun org-footnote-at-definition-p () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
158 "Is the cursor at a footnote definition. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
159 This matches only pure definitions like [1] or [fn:name] at the beginning |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
160 of a line. It does not a references like [fn:name:definition], where the |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
161 footnote text is included and defined locally. |
101948
2591b7541793
(org-footnote-at-definition-p): Fix doc typo.
Glenn Morris <rgm@gnu.org>
parents:
101947
diff
changeset
|
162 The return value will be nil if not at a footnote definition, and a list |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
163 with start and label of the footnote if there is a definition at point." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
164 (save-excursion |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
165 (end-of-line 1) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
166 (let ((lim (save-excursion (re-search-backward "^\\*+ \\|^[ \t]*$" nil t)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
167 (when (re-search-backward org-footnote-definition-re lim t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
168 (list (match-beginning 0) (match-string 2)))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
169 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
170 (defun org-footnote-goto-definition (label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
171 "Find the definition of the footnote with label LABEL." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
172 (interactive "sLabel: ") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
173 (org-mark-ring-push) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
174 (setq label (org-footnote-normalize-label label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
175 (let ((re (format "^\\[%s\\]\\|.\\[%s:" label label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
176 pos) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
177 (save-excursion |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
178 (setq pos (or (re-search-forward re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
179 (and (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
180 (re-search-forward re nil t)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
181 (and (progn (widen) t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
182 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
183 (re-search-forward re nil t))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
184 (if (not pos) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
185 (error "Cannot find definition of footnote %s" label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
186 (goto-char pos) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
187 (org-show-context 'link-search) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
188 (message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'.")))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
189 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
190 (defun org-footnote-goto-previous-reference (label) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
191 "Find the next previous of the footnote with label LABEL." |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
192 (interactive "sLabel: ") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
193 (org-mark-ring-push) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
194 (setq label (org-footnote-normalize-label label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
195 (let ((re (format ".\\[%s[]:]" label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
196 (p0 (point)) pos) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
197 (save-excursion |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
198 (setq pos (or (re-search-backward re nil t) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
199 (and (goto-char (point-max)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
200 (re-search-backward re nil t)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
201 (and (progn (widen) t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
202 (goto-char p0) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
203 (re-search-backward re nil t)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
204 (and (goto-char (point-max)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
205 (re-search-forward re nil t))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
206 (if pos |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
207 (progn |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
208 (goto-char (match-end 0)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
209 (org-show-context 'link-search)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
210 (error "Cannot find reference of footnote %s" label)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
211 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
212 (defun org-footnote-normalize-label (label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
213 (if (numberp label) (setq label (number-to-string label))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
214 (if (not (string-match "^[0-9]+$\\|^$\\|^fn:" label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
215 (setq label (concat "fn:" label))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
216 label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
217 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
218 (defun org-footnote-all-labels () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
219 "Return list with all defined foot labels used in the buffer." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
220 (let (rtn l) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
221 (save-excursion |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
222 (save-restriction |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
223 (widen) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
224 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
225 (while (re-search-forward org-footnote-definition-re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
226 (setq l (org-match-string-no-properties 2)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
227 (and l (add-to-list 'rtn l))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
228 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
229 (while (re-search-forward org-footnote-re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
230 (setq l (or (org-match-string-no-properties 1) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
231 (org-match-string-no-properties 2))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
232 (and l (not (equal l "fn:")) (add-to-list 'rtn l))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
233 rtn)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
234 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
235 (defun org-footnote-unique-label (&optional current) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
236 "Return a new unique footnote label. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
237 The returns the firsts fn:N labels that is currently not used." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
238 (unless current (setq current (org-footnote-all-labels))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
239 (let ((fmt (if (eq org-footnote-auto-label 'plain) "%d" "fn:%d")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
240 (cnt 1)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
241 (while (member (format fmt cnt) current) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
242 (incf cnt)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
243 (format fmt cnt))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
244 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
245 (defvar org-footnote-label-history nil |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
246 "History of footnote labels entered in current buffer.") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
247 (make-variable-buffer-local 'org-footnote-label-history) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
248 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
249 (defun org-footnote-new () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
250 "Insert a new footnote. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
251 This command prompts for a label. If this is a label referencing an |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
252 existing label, only insert the label. If the footnote label is empty |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
253 or new, let the user edit the definition of the footnote." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
254 (interactive) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
255 (let* ((labels (org-footnote-all-labels)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
256 (propose (org-footnote-unique-label labels)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
257 (label |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
258 (if (member org-footnote-auto-label '(t plain)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
259 propose |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
260 (completing-read |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
261 "Label (leave empty for anonymous): " |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
262 (mapcar 'list labels) nil nil |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
263 (if (eq org-footnote-auto-label 'confirm) propose nil) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
264 'org-footnote-label-history)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
265 (setq label (org-footnote-normalize-label label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
266 (cond |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
267 ((equal label "") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
268 (insert "[fn:: ]") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
269 (backward-char 1)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
270 ((member label labels) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
271 (insert "[" label "]") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
272 (message "New reference to existing note")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
273 (org-footnote-define-inline |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
274 (insert "[" label ": ]") |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
275 (backward-char 1) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
276 (org-footnote-auto-adjust-maybe)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
277 (t |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
278 (insert "[" label "]") |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
279 (org-footnote-create-definition label) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
280 (org-footnote-auto-adjust-maybe))))) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
281 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
282 (defun org-footnote-create-definition (label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
283 "Start the definition of a footnote with label LABEL." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
284 (interactive "sLabel: ") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
285 (setq label (org-footnote-normalize-label label)) |
101568
f5aedb5cbd80
2009-01-27 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101458
diff
changeset
|
286 (let (re) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
287 (cond |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
288 ((org-mode-p) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
289 (if (not org-footnote-section) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
290 ;; No section, put footnote into the current outline node |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
291 nil |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
292 ;; Try to find or make the special node |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
293 (setq re (concat "^\\*+[ \t]+" org-footnote-section "[ \t]*$")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
294 (unless (or (re-search-forward re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
295 (and (progn (widen) t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
296 (re-search-forward re nil t))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
297 (goto-char (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
298 (insert "\n\n* " org-footnote-section "\n"))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
299 ;; Now go to the end of this entry and insert there. |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104810
diff
changeset
|
300 (org-footnote-goto-local-insertion-point) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104810
diff
changeset
|
301 (org-show-context 'link-search)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
302 (t |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
303 (setq re (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
304 (unless (re-search-forward re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
305 (goto-char (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
306 (skip-chars-backward " \t\r\n") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
307 (insert "\n\n") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
308 (delete-region (point) (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
309 (insert org-footnote-tag-for-non-org-mode-files "\n")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
310 (goto-char (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
311 (skip-chars-backward " \t\r\n"))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
312 (insert "\n\n") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
313 (insert "[" label "] ") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
314 (message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'."))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
315 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
316 ;;;###autoload |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
317 (defun org-footnote-action (&optional special) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
318 "Do the right thing for footnotes. |
101947
5eee9e7321f6
Joachim Reiter <Reiter.Joachim at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
101757
diff
changeset
|
319 When at a footnote reference, jump to the definition. When at a definition, |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
320 jump to the references. When neither at definition or reference, |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
321 create a new footnote, interactively. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
322 With prefix arg SPECIAL, offer additional commands in a menu." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
323 (interactive "P") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
324 (let (tmp c) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
325 (cond |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
326 (special |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
327 (message "Footnotes: [s]ort | [r]enumber fn:N | [S]=r+s |->[n]umeric | [d]elete") |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
328 (setq c (read-char-exclusive)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
329 (cond |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
330 ((equal c ?s) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
331 (org-footnote-normalize 'sort)) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
332 ((equal c ?r) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
333 (org-footnote-renumber-fn:N)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
334 ((equal c ?S) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
335 (org-footnote-renumber-fn:N) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
336 (org-footnote-normalize 'sort)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
337 ((equal c ?n) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
338 (org-footnote-normalize)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
339 ((equal c ?d) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
340 (org-footnote-delete)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
341 (t (error "No such footnote command %c" c)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
342 ((setq tmp (org-footnote-at-reference-p)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
343 (if (nth 1 tmp) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
344 (org-footnote-goto-definition (nth 1 tmp)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
345 (goto-char (match-beginning 4)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
346 ((setq tmp (org-footnote-at-definition-p)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
347 (org-footnote-goto-previous-reference (nth 1 tmp))) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
348 (t (org-footnote-new))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
349 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
350 ;;;###autoload |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
351 (defun org-footnote-normalize (&optional sort-only for-preprocessor) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
352 "Collect the footnotes in various formats and normalize them. |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
353 This finds the different sorts of footnotes allowed in Org, and |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
354 normalizes them to the usual [N] format that is understood by the |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
355 Org-mode exporters. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
356 When SORT-ONLY is set, only sort the footnote definitions into the |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
357 referenced sequence." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
358 ;; This is based on Paul's function, but rewritten. |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
359 (let* ((limit-level |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
360 (and (boundp 'org-inlinetask-min-level) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
361 org-inlinetask-min-level |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
362 (1- org-inlinetask-min-level))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
363 (nstars (and limit-level |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
364 (if org-odd-levels-only |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
365 (and limit-level (1- (* limit-level 2))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
366 limit-level))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
367 (outline-regexp |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
368 (concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ "))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
369 (count 0) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
370 ref def idef ref-table beg beg1 marker a before ins-point) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
371 (save-excursion |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
372 ;; Now find footnote references, and extract the definitions |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
373 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
374 (while (re-search-forward org-footnote-re nil t) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
375 (unless (or (org-in-commented-line) (org-in-verbatim-emphasis) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
376 (org-inside-latex-macro-p)) |
104810
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
377 (org-if-unprotected |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
378 (setq def (match-string 4) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
379 idef def |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
380 ref (or (match-string 1) (match-string 2)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
381 before (char-to-string (char-after (match-beginning 0)))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
382 (if (equal ref "fn:") (setq ref nil)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
383 (if (and ref (setq a (assoc ref ref-table))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
384 (progn |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
385 (setq marker (nth 1 a)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
386 (unless (nth 2 a) (setf (caddr a) def))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
387 (setq marker (number-to-string (incf count)))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
388 (save-match-data |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
389 (if def |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
390 (setq def (org-trim def)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
391 (save-excursion |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
392 (goto-char (point-min)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
393 (if (not (re-search-forward (concat "^\\[" (regexp-quote ref) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
394 "\\]") nil t)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
395 (setq def nil) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
396 (setq beg (match-beginning 0)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
397 (setq beg1 (match-end 0)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
398 (re-search-forward |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
399 (org-re "^[ \t]*$\\|^\\*+ \\|^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]") |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
400 nil 'move) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
401 (setq def (buffer-substring beg1 (or (match-beginning 0) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
402 (point-max)))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
403 (goto-char beg) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
404 (skip-chars-backward " \t\n\t") |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
405 (delete-region (1+ (point)) (match-beginning 0)))))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
406 (unless sort-only |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
407 (replace-match (concat before "[" marker "]") t t) |
104810
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
408 (and idef |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
409 org-footnote-fill-after-inline-note-extraction |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
410 (fill-paragraph))) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
411 (if (not a) (push (list ref marker def (if idef t nil)) |
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
412 ref-table))))) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
413 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
414 ;; First find and remove the footnote section |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
415 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
416 (cond |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
417 ((org-mode-p) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
418 (if (and org-footnote-section |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
419 (re-search-forward |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
420 (concat "^\\*[ \t]+" (regexp-quote org-footnote-section) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
421 "[ \t]*$") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
422 nil t)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
423 (if (or for-preprocessor (not org-footnote-section)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
424 (replace-match "") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
425 (org-back-to-heading t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
426 (forward-line 1) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
427 (setq ins-point (point)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
428 (delete-region (point) (org-end-of-subtree t))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
429 (goto-char (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
430 (unless for-preprocessor |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
431 (when org-footnote-section |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
432 (or (bolp) (insert "\n")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
433 (insert "* " org-footnote-section "\n") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
434 (setq ins-point (point)))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
435 (t |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
436 (if (re-search-forward |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
437 (concat "^" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
438 (regexp-quote org-footnote-tag-for-non-org-mode-files) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
439 "[ \t]*$") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
440 nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
441 (replace-match "")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
442 (goto-char (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
443 (skip-chars-backward " \t\n\r") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
444 (delete-region (point) (point-max)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
445 (insert "\n\n" org-footnote-tag-for-non-org-mode-files "\n") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
446 (setq ins-point (point)))) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
447 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
448 ;; Insert the footnotes again |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
449 (goto-char (or ins-point (point-max))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
450 (setq ref-table (reverse ref-table)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
451 (when sort-only |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
452 ;; remove anonymous and inline footnotes from the list |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
453 (setq ref-table |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
454 (delq nil (mapcar |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
455 (lambda (x) (and (car x) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
456 (not (equal (car x) "fn:")) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
457 (not (nth 3 x)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
458 x)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
459 ref-table)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
460 ;; Make sure each footnote has a description, or an error message. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
461 (setq ref-table |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
462 (mapcar |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
463 (lambda (x) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
464 (if (not (nth 2 x)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
465 (setcar (cddr x) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
466 (format "FOOTNOTE DEFINITION NOT FOUND: %s" (car x))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
467 (setcar (cddr x) (org-trim (nth 2 x)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
468 x) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
469 ref-table)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
470 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
471 (if (or (not (org-mode-p)) ; not an Org file |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
472 org-footnote-section ; we do not use a footnote section |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
473 (not sort-only) ; this is normalization |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
474 for-preprocessor) ; the is the preprocessor |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
475 ;; Insert the footnotes together in one place |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
476 (progn |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
477 (setq def |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
478 (mapconcat |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
479 (lambda (x) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
480 (format "[%s] %s" (nth (if sort-only 0 1) x) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
481 (org-trim (nth 2 x)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
482 ref-table "\n\n")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
483 (if ref-table (insert "\n" def "\n\n"))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
484 ;; Insert each footnote near the first reference |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
485 ;; Happens only in Org files with no special footnote section, |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
486 ;; and only when doing sorting |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
487 (mapc 'org-insert-footnote-reference-near-definition |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
488 ref-table))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
489 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
490 (defun org-insert-footnote-reference-near-definition (entry) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
491 "Find first reference of footnote ENTRY and insert the definition there. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
492 ENTRY is (fn-label num-mark definition)." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
493 (when (car entry) |
101568
f5aedb5cbd80
2009-01-27 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101458
diff
changeset
|
494 (goto-char (point-min)) |
f5aedb5cbd80
2009-01-27 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101458
diff
changeset
|
495 (when (re-search-forward (format ".\\[%s[]:]" (regexp-quote (car entry))) |
f5aedb5cbd80
2009-01-27 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101458
diff
changeset
|
496 nil t) |
f5aedb5cbd80
2009-01-27 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101458
diff
changeset
|
497 (org-footnote-goto-local-insertion-point) |
f5aedb5cbd80
2009-01-27 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101458
diff
changeset
|
498 (insert (format "\n\n[%s] %s" (car entry) (nth 2 entry)))))) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
499 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
500 (defun org-footnote-goto-local-insertion-point () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
501 "Find insertion point for footnote, just before next outline heading." |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
502 (org-with-limited-levels (outline-next-heading)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
503 (or (bolp) (newline)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
504 (beginning-of-line 0) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
505 (while (and (not (bobp)) (= (char-after) ?#)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
506 (beginning-of-line 0)) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
507 (if (looking-at "[ \t]*#\\+TBLFM:") (beginning-of-line 2)) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
508 (end-of-line 1) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
509 (skip-chars-backward "\n\r\t ")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
510 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
511 (defun org-footnote-delete (&optional label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
512 "Delete the footnote at point. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
513 This will remove the definition (even multiple definitions if they exist) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
514 and all references of a footnote label." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
515 (catch 'done |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
516 (let (x label l beg def-re (nref 0) (ndef 0)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
517 (unless label |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
518 (when (setq x (org-footnote-at-reference-p)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
519 (setq label (nth 1 x)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
520 (when (or (not label) (equal "fn:" label)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
521 (delete-region (1+ (match-beginning 0)) (match-end 0)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
522 (message "Anonymous footnote removed") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
523 (throw 'done t))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
524 (when (and (not label) (setq x (org-footnote-at-definition-p))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
525 (setq label (nth 1 x))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
526 (unless label (error "Don't know which footnote to remove"))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
527 (save-excursion |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
528 (save-restriction |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
529 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
530 (while (re-search-forward org-footnote-re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
531 (setq l (or (match-string 1) (match-string 2))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
532 (when (equal l label) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
533 (delete-region (1+ (match-beginning 0)) (match-end 0)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
534 (incf nref))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
535 (goto-char (point-min)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
536 (setq def-re (concat "^\\[" (regexp-quote label) "\\]")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
537 (while (re-search-forward def-re nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
538 (setq beg (match-beginning 0)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
539 (if (re-search-forward "^\\[\\|^[ \t]*$\\|^\\*+ " nil t) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
540 (goto-char (match-beginning 0)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
541 (goto-char (point-max))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
542 (delete-region beg (point)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
543 (incf ndef)))) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
544 (org-footnote-auto-adjust-maybe) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
545 (message "%d definition(s) of and %d reference(s) of footnote %s removed" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
546 ndef nref label)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
547 |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
548 (defun org-footnote-renumber-fn:N () |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
549 "Renumber the simple footnotes like fn:17 into a sequence in the document." |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
550 (interactive) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
551 (let (map i (n 0)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
552 (save-excursion |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
553 (save-restriction |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
554 (widen) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
555 (goto-char (point-min)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
556 (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
557 (setq i (string-to-number (match-string 1))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
558 (when (and (string-match "\\S-" (buffer-substring |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
559 (point-at-bol) (match-beginning 0))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
560 (not (assq i map))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
561 (push (cons i (number-to-string (incf n))) map))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
562 (goto-char (point-min)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
563 (while (re-search-forward "\\(\\[fn:\\)\\([0-9]+\\)\\([]:]\\)" nil t) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
564 (replace-match (concat "\\1" (cdr (assq (string-to-number (match-string 2)) map)) "\\3"))))))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
565 |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
566 (defun org-footnote-auto-adjust-maybe () |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
567 "Renumber and/or sort footnotes according to user settings." |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
568 (when (memq org-footnote-auto-adjust '(t renumber)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
569 (org-footnote-renumber-fn:N)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
570 (when (memq org-footnote-auto-adjust '(t sort)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
571 (let ((label (nth 1 (org-footnote-at-definition-p)))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
572 (org-footnote-normalize 'sort) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
573 (when label |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
574 (goto-char (point-min)) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
575 (and (re-search-forward (concat "^\\[" (regexp-quote label) "\\]") |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
576 nil t) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
577 (progn (insert " ") |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
578 (just-one-space))))))) |
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101948
diff
changeset
|
579 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
580 (provide 'org-footnote) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
581 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
582 ;; arch-tag: 1b5954df-fb5d-4da5-8709-78d944dbfc37 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
583 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
584 ;;; org-footnote.el ends here |