Merge branch 'master' of orgmode.org:org-mode

This commit is contained in:
Bastien Guerry 2012-12-19 00:23:46 +01:00
commit 77a6acff0b
4 changed files with 90 additions and 67 deletions

View File

@ -153,7 +153,7 @@ KEYWORD is a string representing a buffer keyword, or nil. Each
property). property).
OPTION is a string that could be found in an #+OPTIONS: line. OPTION is a string that could be found in an #+OPTIONS: line.
DEFAULT is the default value for the property. DEFAULT is the default value for the property.
BEHAVIOUR determine how Org should handle multiple keywords for BEHAVIOUR determines how Org should handle multiple keywords for
the same property. It is a symbol among: the same property. It is a symbol among:
nil Keep old value and discard the new one. nil Keep old value and discard the new one.
t Replace old value with the new one. t Replace old value with the new one.
@ -163,7 +163,8 @@ BEHAVIOUR determine how Org should handle multiple keywords for
`split' Split values at white spaces, and cons them to the `split' Split values at white spaces, and cons them to the
previous list. previous list.
KEYWORD and OPTION have precedence over DEFAULT. Values set through KEYWORD and OPTION have precedence over
DEFAULT.
All these properties should be back-end agnostic. Back-end All these properties should be back-end agnostic. Back-end
specific properties are set through `org-export-define-backend'. specific properties are set through `org-export-define-backend'.
@ -2591,7 +2592,7 @@ Return the updated communication channel."
;; associated to the file, that is before parsing. ;; associated to the file, that is before parsing.
(defun org-export-as (defun org-export-as
(backend &optional subtreep visible-only body-only ext-plist noexpand) (backend &optional subtreep visible-only body-only ext-plist)
"Transcode current Org buffer into BACKEND code. "Transcode current Org buffer into BACKEND code.
If narrowing is active in the current buffer, only transcode its If narrowing is active in the current buffer, only transcode its
@ -2613,9 +2614,6 @@ Optional argument EXT-PLIST, when provided, is a property list
with external parameters overriding Org default settings, but with external parameters overriding Org default settings, but
still inferior to file-local settings. still inferior to file-local settings.
Optional argument NOEXPAND, when non-nil, prevents included files
to be expanded and Babel code to be executed.
Return code as a string." Return code as a string."
;; Barf if BACKEND isn't registered. ;; Barf if BACKEND isn't registered.
(org-export-barf-if-invalid-backend backend) (org-export-barf-if-invalid-backend backend)
@ -2634,20 +2632,19 @@ Return code as a string."
;; Initialize communication channel with original buffer ;; Initialize communication channel with original buffer
;; attributes, unavailable in its copy. ;; attributes, unavailable in its copy.
(let ((info (org-export--get-buffer-attributes)) tree) (let ((info (org-export--get-buffer-attributes)) tree)
(org-export-with-buffer-copy
;; Run first hook with current back-end as argument.
(run-hook-with-args 'org-export-before-processing-hook backend)
;; Update communication channel and get parse tree. Buffer ;; Update communication channel and get parse tree. Buffer
;; isn't parsed directly. Instead, a temporary copy is ;; isn't parsed directly. Instead, a temporary copy is
;; created, where include keywords, macros are expanded and ;; created, where include keywords, macros are expanded and
;; code blocks are evaluated. ;; code blocks are evaluated.
(unless noexpand (org-export-with-buffer-copy
;; Run first hook with current back-end as argument.
(run-hook-with-args 'org-export-before-processing-hook backend)
(org-export-expand-include-keyword) (org-export-expand-include-keyword)
;; Update macro templates since #+INCLUDE keywords might ;; Update macro templates since #+INCLUDE keywords might have
;; have added some new ones. ;; added some new ones.
(org-macro-initialize-templates) (org-macro-initialize-templates)
(org-macro-replace-all org-macro-templates) (org-macro-replace-all org-macro-templates)
(org-export-execute-babel-code)) (org-export-execute-babel-code)
;; Update radio targets since keyword inclusion might have ;; Update radio targets since keyword inclusion might have
;; added some more. ;; added some more.
(org-update-radio-target-regexp) (org-update-radio-target-regexp)
@ -2664,7 +2661,6 @@ Return code as a string."
;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done ;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
;; once regular macros have been expanded, since document ;; once regular macros have been expanded, since document
;; keywords may contain one of them. ;; keywords may contain one of them.
(unless noexpand
(org-macro-replace-all (org-macro-replace-all
(list (cons "author" (list (cons "author"
(org-element-interpret-data (plist-get info :author))) (org-element-interpret-data (plist-get info :author)))
@ -2673,7 +2669,7 @@ Return code as a string."
;; EMAIL is not a parsed keyword: store it as-is. ;; EMAIL is not a parsed keyword: store it as-is.
(cons "email" (or (plist-get info :email) "")) (cons "email" (or (plist-get info :email) ""))
(cons "title" (cons "title"
(org-element-interpret-data (plist-get info :title)))))) (org-element-interpret-data (plist-get info :title)))))
;; Eventually parse buffer. Call parse-tree filters to get ;; Eventually parse buffer. Call parse-tree filters to get
;; the final tree. ;; the final tree.
(setq tree (setq tree
@ -2705,7 +2701,7 @@ Return code as a string."
output))))) output)))))
(defun org-export-to-buffer (defun org-export-to-buffer
(backend buffer &optional subtreep visible-only body-only ext-plist noexpand) (backend buffer &optional subtreep visible-only body-only ext-plist)
"Call `org-export-as' with output to a specified buffer. "Call `org-export-as' with output to a specified buffer.
BACKEND is the back-end used for transcoding, as a symbol. BACKEND is the back-end used for transcoding, as a symbol.
@ -2713,13 +2709,12 @@ BACKEND is the back-end used for transcoding, as a symbol.
BUFFER is the output buffer. If it already exists, it will be BUFFER is the output buffer. If it already exists, it will be
erased first, otherwise, it will be created. erased first, otherwise, it will be created.
Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY, EXT-PLIST Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
and NOEXPAND are similar to those used in `org-export-as', which EXT-PLIST are similar to those used in `org-export-as', which
see. see.
Return buffer." Return buffer."
(let ((out (org-export-as (let ((out (org-export-as backend subtreep visible-only body-only ext-plist))
backend subtreep visible-only body-only ext-plist noexpand))
(buffer (get-buffer-create buffer))) (buffer (get-buffer-create buffer)))
(with-current-buffer buffer (with-current-buffer buffer
(erase-buffer) (erase-buffer)
@ -2728,14 +2723,14 @@ Return buffer."
buffer)) buffer))
(defun org-export-to-file (defun org-export-to-file
(backend file &optional subtreep visible-only body-only ext-plist noexpand) (backend file &optional subtreep visible-only body-only ext-plist)
"Call `org-export-as' with output to a specified file. "Call `org-export-as' with output to a specified file.
BACKEND is the back-end used for transcoding, as a symbol. FILE BACKEND is the back-end used for transcoding, as a symbol. FILE
is the name of the output file, as a string. is the name of the output file, as a string.
Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY, EXT-PLIST Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
and NOEXPAND are similar to those used in `org-export-as', which EXT-PLIST are similar to those used in `org-export-as', which
see. see.
Return output file's name." Return output file's name."
@ -2743,8 +2738,7 @@ Return output file's name."
;; we'd rather avoid needless transcoding of parse tree. ;; we'd rather avoid needless transcoding of parse tree.
(unless (file-writable-p file) (error "Output file not writable")) (unless (file-writable-p file) (error "Output file not writable"))
;; Insert contents to a temporary buffer and write it to FILE. ;; Insert contents to a temporary buffer and write it to FILE.
(let ((out (org-export-as (let ((out (org-export-as backend subtreep visible-only body-only ext-plist)))
backend subtreep visible-only body-only ext-plist noexpand)))
(with-temp-buffer (with-temp-buffer
(insert out) (insert out)
(let ((coding-system-for-write org-export-coding-system)) (let ((coding-system-for-write org-export-coding-system))

View File

@ -358,6 +358,11 @@ still has an entry since one of its properties (`:title') does.")
(footnote-reference . :inline-definition)) (footnote-reference . :inline-definition))
"Alist between element types and location of secondary value.") "Alist between element types and location of secondary value.")
(defconst org-element-object-variables '(org-link-abbrev-alist-local)
"List of buffer-local variables used when parsing objects.
These variables are copied to the temporary buffer created by
`org-export-secondary-string'.")
;;; Accessors and Setters ;;; Accessors and Setters
@ -2998,10 +3003,10 @@ Assume point is at the beginning of the link."
contents-end (match-end 3) contents-end (match-end 3)
link-end (match-end 0) link-end (match-end 0)
;; RAW-LINK is the original link. ;; RAW-LINK is the original link.
raw-link (org-match-string-no-properties 1) raw-link (org-translate-link
link (org-translate-link
(org-link-expand-abbrev (org-link-expand-abbrev
(org-link-unescape raw-link)))) (org-match-string-no-properties 1)))
link (org-link-unescape raw-link))
;; Determine TYPE of link and set PATH accordingly. ;; Determine TYPE of link and set PATH accordingly.
(cond (cond
;; File type. ;; File type.
@ -3930,14 +3935,22 @@ looked after.
Optional argument PARENT, when non-nil, is the element or object Optional argument PARENT, when non-nil, is the element or object
containing the secondary string. It is used to set correctly containing the secondary string. It is used to set correctly
`:parent' property within the string." `:parent' property within the string."
;; Copy buffer-local variables listed in
;; `org-element-object-variables' into temporary buffer. This is
;; required since object parsing is dependent on these variables.
(let ((pairs (delq nil (mapcar (lambda (var)
(when (boundp var)
(cons var (symbol-value var))))
org-element-object-variables))))
(with-temp-buffer (with-temp-buffer
(mapc (lambda (pair) (org-set-local (car pair) (cdr pair))) pairs)
(insert string) (insert string)
(let ((secondary (org-element--parse-objects (let ((secondary (org-element--parse-objects
(point-min) (point-max) nil restriction))) (point-min) (point-max) nil restriction)))
(when parent (when parent
(mapc (lambda (obj) (org-element-put-property obj :parent parent)) (mapc (lambda (obj) (org-element-put-property obj :parent parent))
secondary)) secondary))
secondary))) secondary))))
(defun org-element-map (defun org-element-map
(data types fun &optional info first-match no-recursion with-affiliated) (data types fun &optional info first-match no-recursion with-affiliated)

View File

@ -21485,22 +21485,18 @@ width for filling.
For convenience, when point is at a plain list, an item or For convenience, when point is at a plain list, an item or
a footnote definition, try to fill the first paragraph within." a footnote definition, try to fill the first paragraph within."
(interactive) (interactive)
(cond ;; First ensure filling in correct in message-mode (if (and (derived-mode-p 'message-mode)
((and (derived-mode-p 'message-mode)
(or (not (message-in-body-p)) (or (not (message-in-body-p))
(save-excursion (move-beginning-of-line 1) (save-excursion (move-beginning-of-line 1)
(looking-at message-cite-prefix-regexp)))) (looking-at message-cite-prefix-regexp))))
;; First ensure filling is correct in message-mode.
(let ((fill-paragraph-function (let ((fill-paragraph-function
(cadadr (assoc 'fill-paragraph-function org-fb-vars))) (cadadr (assoc 'fill-paragraph-function org-fb-vars)))
(fill-prefix (cadadr (assoc 'fill-prefix org-fb-vars))) (fill-prefix (cadadr (assoc 'fill-prefix org-fb-vars)))
(paragraph-start (cadadr (assoc 'paragraph-start org-fb-vars))) (paragraph-start (cadadr (assoc 'paragraph-start org-fb-vars)))
(paragraph-separate (paragraph-separate
(cadadr (assoc 'paragraph-separate org-fb-vars)))) (cadadr (assoc 'paragraph-separate org-fb-vars))))
(fill-paragraph nil))) (fill-paragraph nil))
;; Correct filling in source block
((org-in-src-block-p)
(org-babel-do-key-sequence-in-edit-buffer (kbd "M-q")))
(t
(save-excursion (save-excursion
;; Move to end of line in order to get the first paragraph ;; Move to end of line in order to get the first paragraph
;; within a plain list or a footnote definition. ;; within a plain list or a footnote definition.
@ -21510,6 +21506,8 @@ a footnote definition, try to fill the first paragraph within."
;; the buffer. In that case, ignore filling. ;; the buffer. In that case, ignore filling.
(if (< (point) (org-element-property :begin element)) t (if (< (point) (org-element-property :begin element)) t
(case (org-element-type element) (case (org-element-type element)
;; Use major mode filling function is src blocks.
(src-block (org-babel-do-key-sequence-in-edit-buffer (kbd "M-q")))
;; Align Org tables, leave table.el tables as-is. ;; Align Org tables, leave table.el tables as-is.
(table-row (org-table-align) t) (table-row (org-table-align) t)
(table (table
@ -21586,7 +21584,7 @@ a footnote definition, try to fill the first paragraph within."
;; Fill comments. ;; Fill comments.
(comment (fill-comment-paragraph justify)) (comment (fill-comment-paragraph justify))
;; Ignore every other element. ;; Ignore every other element.
(otherwise t)))))))) (otherwise t)))))))
(defun org-auto-fill-function () (defun org-auto-fill-function ()
"Auto-fill function." "Auto-fill function."

View File

@ -1260,7 +1260,25 @@ e^{i\\pi}+1=0
;; 4. Angular link. ;; 4. Angular link.
(should (should
(org-test-with-temp-text "A link: <http://orgmode.org>" (org-test-with-temp-text "A link: <http://orgmode.org>"
(org-element-map (org-element-parse-buffer) 'link 'identity nil t)))) (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))
;; Link abbreviation.
(should
(equal "http"
(org-test-with-temp-text
"#+LINK: orgmode http://www.orgmode.org/\n[[orgmode:#docs]]"
(progn (org-mode-restart)
(goto-char (point-max))
(org-element-property :type (org-element-context))))))
;; Link abbreviation in a secondary string.
(should
(equal "http"
(org-test-with-temp-text
"#+LINK: orgmode http://www.orgmode.org/\n* H [[orgmode:#docs]]"
(progn (org-mode-restart)
(org-element-map
(org-element-parse-buffer) 'link
(lambda (link) (org-element-property :type link))
nil t nil t))))))
;;;; Macro ;;;; Macro