org-footnote: Fix references collection

* lisp/org-footnote.el (org-footnote--collect-references): Include
  inline references at the beginning of the line, which are allowed,
  unlike regular references.
This commit is contained in:
Nicolas Goaziou 2015-12-17 14:33:33 +01:00
parent 8eb318f2d0
commit f229ee8e34

View file

@ -389,31 +389,35 @@ references. In such cases, LABEL is nil.
References are sorted according to a deep-reading order." References are sorted according to a deep-reading order."
(org-with-wide-buffer (org-with-wide-buffer
(goto-char (point-min)) (goto-char (point-min))
(let ((regexp (format ".\\[fn:[-_[:word:]]%s[]:]" (if anonymous "*" "+"))) (let ((regexp (if anonymous org-footnote-re "\\[fn:[-_[:word:]]+[]:]"))
references nested) references nested)
(save-excursion (save-excursion
(while (re-search-forward regexp nil t) (while (re-search-forward regexp nil t)
(backward-char) ;; Ignore definitions.
(let ((context (org-element-context))) (unless (and (eq (char-before) ?\])
(when (eq (org-element-type context) 'footnote-reference) (= (line-beginning-position) (match-beginning 0)))
(let* ((label (org-element-property :label context)) ;; Ensure point is within the reference before parsing it.
(begin (org-element-property :begin context)) (backward-char)
(size (let ((object (org-element-context)))
(and (eq (org-element-property :type context) 'inline) (when (eq (org-element-type object) 'footnote-reference)
(- (org-element-property :contents-end context) (let* ((label (org-element-property :label object))
(org-element-property :contents-begin context))))) (begin (org-element-property :begin object))
(let ((d (org-element-lineage context '(footnote-definition)))) (size
(push (list label (copy-marker begin) (not d) size) (and (eq (org-element-property :type object) 'inline)
references) (- (org-element-property :contents-end object)
(when d (org-element-property :contents-begin object)))))
;; Nested references are stored in alist NESTED. (let ((d (org-element-lineage object '(footnote-definition))))
;; Associations there follow the pattern (push (list label (copy-marker begin) (not d) size)
;; references)
;; (DEFINITION-LABEL . REFERENCES) (when d
(let* ((def-label (org-element-property :label d)) ;; Nested references are stored in alist NESTED.
(labels (assoc def-label nested))) ;; Associations there follow the pattern
(if labels (push label (cdr labels)) ;;
(push (list def-label label) nested)))))))))) ;; (DEFINITION-LABEL . REFERENCES)
(let* ((def-label (org-element-property :label d))
(labels (assoc def-label nested)))
(if labels (push label (cdr labels))
(push (list def-label label) nested)))))))))))
;; Sort the list of references. Nested footnotes have priority ;; Sort the list of references. Nested footnotes have priority
;; over top-level ones. ;; over top-level ones.
(letrec ((ordered nil) (letrec ((ordered nil)