summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2011-06-29 15:26:22 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2011-06-29 15:26:22 +0200
commit560804b4d85ceb80d947e6f8f148215438e637bd (patch)
tree6bfb86f19dbdf837cf8cc2e67071ddd3d4f8172b
parent66537c520ce7810c1707bd0c0b95924ed3ff4645 (diff)
downloadorg-mode-560804b4d85ceb80d947e6f8f148215438e637bd.tar.gz
org-footnote: better action on footnotes with no definition associated
* lisp/org-footnote.el (org-footnote-action): offer to create definition when none is found.
-rw-r--r--lisp/org-footnote.el39
1 files changed, 24 insertions, 15 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 6de9bab..3bd5559 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -444,9 +444,15 @@ or new, let the user edit the definition of the footnote."
;;;###autoload
(defun org-footnote-action (&optional special)
"Do the right thing for footnotes.
-When at a footnote reference, jump to the definition. When at a definition,
-jump to the references. When neither at definition or reference,
-create a new footnote, interactively.
+
+When at a footnote reference, jump to the definition.
+
+When at a definition, jump to the references if they exist, offer
+to create them otherwise.
+
+When neither at definition or reference, create a new footnote,
+interactively.
+
With prefix arg SPECIAL, offer additional commands in a menu."
(interactive "P")
(let (tmp c)
@@ -455,23 +461,26 @@ With prefix arg SPECIAL, offer additional commands in a menu."
(message "Footnotes: [s]ort | [r]enumber fn:N | [S]=r+s |->[n]umeric | [d]elete")
(setq c (read-char-exclusive))
(cond
- ((equal c ?s)
- (org-footnote-normalize 'sort))
- ((equal c ?r)
- (org-footnote-renumber-fn:N))
- ((equal c ?S)
+ ((eq c ?s) (org-footnote-normalize 'sort))
+ ((eq c ?r) (org-footnote-renumber-fn:N))
+ ((eq c ?S)
(org-footnote-renumber-fn:N)
(org-footnote-normalize 'sort))
- ((equal c ?n)
- (org-footnote-normalize))
- ((equal c ?d)
- (org-footnote-delete))
+ ((eq c ?n) (org-footnote-normalize))
+ ((eq c ?d) (org-footnote-delete))
(t (error "No such footnote command %c" c))))
((setq tmp (org-footnote-at-reference-p))
- (if (car tmp)
- (org-footnote-goto-definition (car tmp))
+ (cond
+ ;; Anonymous footnote: move point at the beginning of its
+ ;; definition.
+ ((not (car tmp))
(goto-char (nth 1 tmp))
- (forward-char 5)))
+ (forward-char 5))
+ ;; A definition exists: move to it.
+ ((ignore-errors (org-footnote-goto-definition (car tmp))))
+ ;; No definition exists: offer to create it.
+ ((yes-or-no-p (format "No definition for %s. Create one? " (car tmp)))
+ (org-footnote-create-definition (car tmp)))))
((setq tmp (org-footnote-at-definition-p))
(org-footnote-goto-previous-reference (car tmp)))
(t (org-footnote-new)))))