0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-07-16 21:16:28 +00:00

Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2012-02-02 10:03:42 +01:00
commit 36cc7b4983

View file

@ -242,40 +242,46 @@ positions, and the definition, when inlined."
(match-end 0) (1- end))))))))) (match-end 0) (1- end)))))))))
(defun org-footnote-at-definition-p () (defun org-footnote-at-definition-p ()
"Is the cursor at a footnote definition? "Is point within a footnote definition?
This matches only pure definitions like [1] or [fn:name] at the beginning This matches only pure definitions like [1] or [fn:name] at the
of a line. It does not match references like [fn:name:definition], where the beginning of a line. It does not match references like
footnote text is included and defined locally. \[fn:name:definition], where the footnote text is included and
defined locally.
The return value will be nil if not at a footnote definition, and a list with The return value will be nil if not at a footnote definition, and
label, start, end and definition of the footnote otherwise." a list with label, start, end and definition of the footnote
otherwise."
(when (save-excursion (beginning-of-line) (org-footnote-in-valid-context-p)) (when (save-excursion (beginning-of-line) (org-footnote-in-valid-context-p))
(save-excursion (save-excursion
(end-of-line) (end-of-line)
;; Footnotes definitions are separated by new headlines or blank
;; lines.
(let ((lim (save-excursion (re-search-backward (let ((lim (save-excursion (re-search-backward
(concat org-outline-regexp-bol (concat org-outline-regexp-bol
"\\|^[ \t]*$") nil t)))) "\\|^[ \t]*$") nil t))))
(when (re-search-backward org-footnote-definition-re lim t) (when (re-search-backward org-footnote-definition-re lim t)
(end-of-line) (let ((label (org-match-string-no-properties 1))
(list (org-match-string-no-properties 1) (beg (match-beginning 0))
(match-beginning 0) (beg-def (match-end 0))
(save-match-data ;; In message-mode, do not search after signature.
;; In a message, limit search to signature. (end (let ((bound (and (derived-mode-p 'message-mode)
(let ((bound (and (derived-mode-p 'message-mode) (save-excursion
(save-excursion (goto-char (point-max))
(goto-char (point-max)) (re-search-backward
(re-search-backward message-signature-separator nil t)))))
message-signature-separator nil t))))) (if (progn
(or (and (re-search-forward (end-of-line)
(re-search-forward
(concat org-outline-regexp-bol "\\|" (concat org-outline-regexp-bol "\\|"
org-footnote-definition-re "\\|" org-footnote-definition-re "\\|"
"^[ \t]*$") "^[ \t]*$") bound 'move))
bound 'move) (progn (goto-char (match-beginning 0))
(progn (skip-chars-forward " \t\n") (point-at-bol))) (org-skip-whitespace)
(point)))) (point-at-bol))
(org-trim (buffer-substring-no-properties (point)))))
(match-end 0) (point))))))))) (list label beg end
(org-trim (buffer-substring-no-properties beg-def end)))))))))
(defun org-footnote-get-next-reference (&optional label backward limit) (defun org-footnote-get-next-reference (&optional label backward limit)
"Return complete reference of the next footnote. "Return complete reference of the next footnote.
@ -651,6 +657,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
(goto-char (point-min)) (goto-char (point-min))
(while (setq ref (org-footnote-get-next-reference)) (while (setq ref (org-footnote-get-next-reference))
(let* ((lbl (car ref)) (let* ((lbl (car ref))
(pos (nth 1 ref))
;; When footnote isn't anonymous, check if it's label ;; When footnote isn't anonymous, check if it's label
;; (REF) is already stored in REF-TABLE. In that case, ;; (REF) is already stored in REF-TABLE. In that case,
;; extract number used to identify it (MARKER). If ;; extract number used to identify it (MARKER). If
@ -678,7 +685,8 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
org-footnote-fill-after-inline-note-extraction org-footnote-fill-after-inline-note-extraction
(org-fill-paragraph))) (org-fill-paragraph)))
;; Add label (REF), identifier (MARKER), definition (DEF) ;; Add label (REF), identifier (MARKER), definition (DEF)
;; and type (INLINEP) to REF-TABLE if data was unknown. ;; type (INLINEP) and position (POS) to REF-TABLE if data
;; was unknown.
(unless a (unless a
(let ((def (or (nth 3 ref) ; inline (let ((def (or (nth 3 ref) ; inline
(and export-props (and export-props
@ -696,27 +704,31 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
'(:todo-keywords t :tags t :priority t)))) '(:todo-keywords t :tags t :priority t))))
(org-export-preprocess-string def parameters)) (org-export-preprocess-string def parameters))
def) def)
inlinep) ref-table))))) inlinep pos) ref-table)))))
;; 2. Find and remove the footnote section, if any. Also ;; 2. Find and remove the footnote section, if any. Also
;; determine where footnotes shall be inserted (INS-POINT). ;; determine where footnotes shall be inserted (INS-POINT).
(goto-char (point-min))
(cond (cond
((and org-footnote-section ((and org-footnote-section (eq major-mode 'org-mode))
(eq major-mode 'org-mode) (goto-char (point-min))
(re-search-forward (if (re-search-forward
(concat "^\\*[ \t]+" (regexp-quote org-footnote-section) (concat "^\\*[ \t]+" (regexp-quote org-footnote-section)
"[ \t]*$") "[ \t]*$") nil t)
nil t)) (delete-region (match-beginning 0) (org-end-of-subtree t)))
(delete-region (match-beginning 0) (org-end-of-subtree t))) ;; A new footnote section is inserted by default at the end of
((eq major-mode 'org-mode) ;; the buffer.
(goto-char (point-max)) (goto-char (point-max))
(unless (bolp) (newline))) (unless (bolp) (newline)))
;; No footnote section set: Footnotes will be added before next
;; headline.
((eq major-mode 'org-mode)
(org-with-limited-levels (outline-next-heading)))
(t (t
;; Remove any left-over tag in the buffer, if one is set up. ;; Remove any left-over tag in the buffer, if one is set up.
(when org-footnote-tag-for-non-org-mode-files (when org-footnote-tag-for-non-org-mode-files
(let ((tag (concat "^" (regexp-quote (let ((tag (concat "^" (regexp-quote
org-footnote-tag-for-non-org-mode-files) org-footnote-tag-for-non-org-mode-files)
"[ \t]*$"))) "[ \t]*$")))
(goto-char (point-min))
(while (re-search-forward tag nil t) (while (re-search-forward tag nil t)
(replace-match "") (replace-match "")
(delete-region (point) (progn (forward-line) (point)))))) (delete-region (point) (progn (forward-line) (point))))))
@ -763,8 +775,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
((not ref-table)) ((not ref-table))
;; Cases when footnotes should be inserted in one place. ;; Cases when footnotes should be inserted in one place.
((or (not (eq major-mode 'org-mode)) ((or (not (eq major-mode 'org-mode))
org-footnote-section org-footnote-section)
(not sort-only))
;; Insert again the section title, if any. Ensure that title, ;; Insert again the section title, if any. Ensure that title,
;; or the subsequent footnotes, will be separated by a blank ;; or the subsequent footnotes, will be separated by a blank
;; lines from the rest of the document. In an Org buffer, ;; lines from the rest of the document. In an Org buffer,
@ -789,14 +800,24 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
(insert "* " org-footnote-section "\n"))) (insert "* " org-footnote-section "\n")))
(set-marker ins-point nil) (set-marker ins-point nil)
;; Insert the footnotes, separated by a blank line. ;; Insert the footnotes, separated by a blank line.
(insert (mapconcat (lambda (x) (format "\n[%s] %s" (insert
(nth (if sort-only 0 1) x) (nth 2 x))) (mapconcat
ref-table "\n")) (lambda (x)
(format "\n[%s] %s" (nth (if sort-only 0 1) x) (nth 2 x)))
ref-table "\n"))
(unless (eobp) (insert "\n")) (unless (eobp) (insert "\n"))
;; When exporting, add newly inserted markers along with their ;; When exporting, add newly inserted markers along with their
;; associated definition to `org-export-footnotes-seen'. ;; associated definition to `org-export-footnotes-seen'.
(when export-props (when export-props (setq org-export-footnotes-seen ref-table)))
(setq org-export-footnotes-seen ref-table))) ;; Each footnote definition has to be inserted at the end of
;; the section where its first reference belongs.
((not sort-only)
(mapc
(lambda (x)
(goto-char (nth 4 x))
(org-footnote-goto-local-insertion-point)
(insert (format "\n[%s] %s\n" (nth 1 x) (nth 2 x))))
ref-table))
;; Else, insert each definition at the end of the section ;; Else, insert each definition at the end of the section
;; containing their first reference. Happens only in Org files ;; containing their first reference. Happens only in Org files
;; with no special footnote section, and only when doing ;; with no special footnote section, and only when doing