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

This commit is contained in:
Bastien Guerry 2013-04-05 08:38:07 +02:00
commit c0589aa63a
12 changed files with 224 additions and 178 deletions

View file

@ -1293,12 +1293,9 @@ INFO is a plist holding contextual information. See
(or desc
(org-export-data
(org-element-property :raw-link link) info))))
;; Fuzzy link points to an invisible target.
(keyword nil)
;; LINK points to a headline. If headlines are numbered
;; and the link has no description, display headline's
;; number. Otherwise, display description or headline's
;; title.
;; LINK points to a headline. If headlines are numbered and
;; the link has no description, display headline's number.
;; Otherwise, display description or headline's title.
(headline
(let ((label ""))
(if (and (plist-get info :section-numbers) (not desc))

View file

@ -520,6 +520,7 @@ depends on, if any."
(const :tag " man Export buffer to MAN format" man)
(const :tag " md Export buffer to Markdown format" md)
(const :tag " odt Export buffer to ODT format" odt)
(const :tag " org Export buffer to Org format" org)
(const :tag " texinfo Export buffer to Texinfo format" texinfo)
(const :tag "C confluence Export buffer to Confluence Wiki format" confluence)
(const :tag "C deck Export buffer to deck.js presentations" deck)
@ -9492,7 +9493,7 @@ active region."
(et (org-element-type ee))
(ev (plist-get (cadr ee) :value))
(ek (plist-get (cadr ee) :key))
(eok (and (stringp ek) (string-match "name\\|target" ek))))
(eok (and (stringp ek) (string-match "name" ek))))
(setq txt (cond
((org-at-heading-p) nil)
((and (eq et 'keyword) eok) ev)
@ -10666,14 +10667,6 @@ visibility around point, thus ignoring
pos (match-beginning 0))))
;; There is an exact target for this
(goto-char pos))
((save-excursion
(goto-char (point-min))
(and
(re-search-forward
(format "^[ \t]*#\\+TARGET: %s" (regexp-quote s0)) nil t)
(setq type 'dedicated pos (match-beginning 0))))
;; Found an invisible target.
(goto-char pos))
((save-excursion
(goto-char (point-min))
(and
@ -11907,7 +11900,7 @@ keywords relative to each registered export back-end."
"DESCRIPTION:" "DRAWERS:" "EMAIL:" "EXCLUDE_TAGS:" "FILETAGS:" "INCLUDE:"
"INDEX:" "KEYWORDS:" "LANGUAGE:" "MACRO:" "OPTIONS:" "PROPERTY:"
"PRIORITIES:" "SELECT_TAGS:" "SEQ_TODO:" "SETUPFILE:" "STARTUP:" "TAGS:"
"TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:" "TARGET:"))
"TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:"))
(defcustom org-structure-template-alist
'(("s" "#+BEGIN_SRC ?\n\n#+END_SRC"

View file

@ -1424,16 +1424,14 @@ INFO is a plist holding contextual information."
;; targets.
((string= type "fuzzy")
(let ((destination (org-export-resolve-fuzzy-link link info)))
;; Ignore invisible "#+TARGET: path".
(unless (eq (org-element-type destination) 'keyword)
(if (org-string-nw-p desc) desc
(when destination
(let ((number
(org-export-get-ordinal
destination info nil 'org-ascii--has-caption-p)))
(when number
(if (atom number) (number-to-string number)
(mapconcat 'number-to-string number ".")))))))))
(if (org-string-nw-p desc) desc
(when destination
(let ((number
(org-export-get-ordinal
destination info nil 'org-ascii--has-caption-p)))
(when number
(if (atom number) (number-to-string number)
(mapconcat 'number-to-string number "."))))))))
(t
(if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
(concat

View file

@ -2328,8 +2328,6 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(value (org-element-property :value keyword)))
(cond
((string= key "HTML") value)
;; Invisible targets.
((string= key "TARGET") nil)
((string= key "TOC")
(let ((value (downcase value)))
(cond

View file

@ -1722,8 +1722,6 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(cond
((string= key "LATEX") value)
((string= key "INDEX") (format "\\index{%s}" value))
;; Invisible targets.
((string= key "TARGET") nil)
((string= key "TOC")
(let ((value (downcase value)))
(cond
@ -1924,8 +1922,6 @@ INFO is a plist holding contextual information. See
(or desc
(org-export-data
(org-element-property :raw-link link) info))))
;; Fuzzy link points to an invisible target.
(keyword nil)
;; LINK points to a headline. If headlines are numbered
;; and the link has no description, display headline's
;; number. Otherwise, display description or headline's

View file

@ -618,8 +618,6 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(cond
((string= key "MAN") value)
((string= key "INDEX") nil)
;; Invisible targets.
((string= key "TARGET") nil)
((string= key "TOC" ) nil))))

View file

@ -310,14 +310,12 @@ a communication channel."
(org-export-data (org-element-contents destination) info)))
((equal type "fuzzy")
(let ((destination (org-export-resolve-fuzzy-link link info)))
;; Ignore invisible "#+TARGET: path".
(unless (eq (org-element-type destination) 'keyword)
(if (org-string-nw-p contents) contents
(when destination
(let ((number (org-export-get-ordinal destination info)))
(when number
(if (atom number) (number-to-string number)
(mapconcat 'number-to-string number ".")))))))))
(if (org-string-nw-p contents) contents
(when destination
(let ((number (org-export-get-ordinal destination info)))
(when number
(if (atom number) (number-to-string number)
(mapconcat 'number-to-string number "."))))))))
(t (let* ((raw-path (org-element-property :path link))
(path (cond
((member type '("http" "https" "ftp"))

View file

@ -2022,7 +2022,6 @@ CONTENTS is nil. INFO is a plist holding contextual information."
((string= key "INDEX")
;; FIXME
(ignore))
((string= key "TARGET") nil)
((string= key "TOC")
(let ((value (downcase value)))
(cond
@ -2836,10 +2835,10 @@ INFO is a plist holding contextual information. See
(let ((label (org-element-property :value destination)))
(format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
(org-export-solidify-link-text label) desc))))
;; LINK has no description. It points to either a HEADLINE, a
;; TARGET or an ELEMENT with a #+NAME: LABEL attached to it.
;; LINK to DESTINATION, but make a best effort to provide a
;; *meaningful* description.
;; LINK has no description. It points to either a HEADLINE or
;; an ELEMENT with a #+NAME: LABEL attached to it. LINK to
;; DESTINATION, but make a best effort to provide
;; a *meaningful* description.
(org-odt-link--infer-description destination info))))
;; Coderef: replace link with the reference name or the
;; equivalent line number.

View file

@ -20,9 +20,13 @@
;;; Commentary:
;; This library implements an Org back-end for Org exporter. Since
;; its usage is mainly internal, it doesn't provide any interactive
;; function.
;; This library implements an Org back-end for Org exporter.
;;
;; It introduces two interactive functions, `org-org-export-as-org'
;; and `org-org-export-to-org', which export, respectively, to
;; a temporary buffer and to a file.
;;
;; A publishing function is also provided: `org-org-publish-to-org'.
;;; Code:
(require 'ox)
@ -102,7 +106,15 @@ setting of `org-html-htmlize-output-type' is 'css."
(timestamp . org-org-identity)
(underline . org-org-identity)
(verbatim . org-org-identity)
(verse-block . org-org-identity)))
(verse-block . org-org-identity))
:menu-entry
'(?O "Export to Org"
((?O "As Org buffer" org-org-export-as-org)
(?o "As Org file" org-org-export-to-org)
(?v "As Org file and open"
(lambda (a s v b)
(if a (org-org-export-to-org t s v b)
(org-open-file (org-org-export-to-org nil s v b))))))))
(defun org-org-identity (blob contents info)
"Transcode BLOB element or object back into Org syntax."
@ -131,6 +143,86 @@ Ignore keywords targeted at other export back-ends."
org-element-block-name-alist))
(org-element-keyword-interpreter keyword nil)))
;;;###autoload
(defun org-org-export-as-org (&optional async subtreep visible-only ext-plist)
"Export current buffer to an Org buffer.
If narrowing is active in the current buffer, only export its
narrowed part.
If a region is active, export that region.
A non-nil optional argument ASYNC means the process should happen
asynchronously. The resulting buffer should be accessible
through the `org-export-stack' interface.
When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.
When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.
EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-local settings.
Export is done in a buffer named \"*Org ORG Export*\", which will
be displayed when `org-export-show-temporary-export-buffer' is
non-nil."
(interactive)
(if async
(org-export-async-start
(lambda (output)
(with-current-buffer (get-buffer-create "*Org ORG Export*")
(erase-buffer)
(insert output)
(goto-char (point-min))
(org-mode)
(org-export-add-to-stack (current-buffer) 'org)))
`(org-export-as 'org ,subtreep ,visible-only nil ',ext-plist))
(let ((outbuf
(org-export-to-buffer
'org "*Org ORG Export*" subtreep visible-only nil ext-plist)))
(with-current-buffer outbuf (org-mode))
(when org-export-show-temporary-export-buffer
(switch-to-buffer-other-window outbuf)))))
;;;###autoload
(defun org-org-export-to-org (&optional async subtreep visible-only ext-plist)
"Export current buffer to an org file.
If narrowing is active in the current buffer, only export its
narrowed part.
If a region is active, export that region.
A non-nil optional argument ASYNC means the process should happen
asynchronously. The resulting file should be accessible through
the `org-export-stack' interface.
When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.
When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.
EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-local settings.
Return output file name."
(interactive)
(let ((outfile (org-export-output-file-name ".org" subtreep)))
(if async
(org-export-async-start
(lambda (f) (org-export-add-to-stack f 'org))
`(expand-file-name
(org-export-to-file
'org ,outfile ,subtreep ,visible-only nil ',ext-plist)))
(org-export-to-file 'org outfile subtreep visible-only nil ext-plist))))
;;;###autoload
(defun org-org-publish-to-org (plist filename pub-dir)
"Publish an org file to org.
@ -167,6 +259,7 @@ Return output file name."
(unless visitingp (kill-buffer work-buffer)))
(set-buffer-modified-p nil)))
(provide 'ox-org)
;; Local variables:

View file

@ -3808,8 +3808,7 @@ INFO is a plist holding contextual information.
Return value can be an object, an element, or nil:
- If LINK path matches a target object (i.e. <<path>>) or
element (i.e. \"#+TARGET: path\"), return it.
- If LINK path matches a target object (i.e. <<path>>) return it.
- If LINK path exactly matches the name affiliated keyword
\(i.e. #+NAME: path) of an element, return that element.
@ -3831,14 +3830,12 @@ significant."
(if match-title-p (substring raw-path 1) raw-path))))
(cond
;; First try to find a matching "<<path>>" unless user specified
;; he was looking for a headline (path starts with a *
;; he was looking for a headline (path starts with a "*"
;; character).
((and (not match-title-p)
(org-element-map (plist-get info :parse-tree) '(keyword target)
(org-element-map (plist-get info :parse-tree) 'target
(lambda (blob)
(and (or (eq (org-element-type blob) 'target)
(equal (org-element-property :key blob) "TARGET"))
(equal (org-split-string (org-element-property :value blob))
(and (equal (org-split-string (org-element-property :value blob))
path)
blob))
info t)))
@ -3851,10 +3848,10 @@ significant."
(let ((name (org-element-property :name el)))
(when (and name (equal (org-split-string name) path)) el)))
info 'first-match)))
;; Last case: link either points to a headline or to
;; nothingness. Try to find the source, with priority given to
;; headlines with the closest common ancestor. If such candidate
;; is found, return it, otherwise return nil.
;; Last case: link either points to a headline or to nothingness.
;; Try to find the source, with priority given to headlines with
;; the closest common ancestor. If such candidate is found,
;; return it, otherwise return nil.
(t
(let ((find-headline
(function
@ -3946,43 +3943,40 @@ a target, return the same value as if ELEMENT was the closest
table, item or headline containing the target. In any other
case, return the sequence number of ELEMENT among elements or
objects of the same type."
;; A target keyword, representing an invisible target, never has
;; a sequence number.
(unless (eq (org-element-type element) 'keyword)
;; Ordinal of a target object refer to the ordinal of the closest
;; table, item, or headline containing the object.
(when (eq (org-element-type element) 'target)
(setq element
(loop for parent in (org-export-get-genealogy element)
when
(memq
(org-element-type parent)
'(footnote-definition footnote-reference headline item
table))
return parent)))
(case (org-element-type element)
;; Special case 1: A headline returns its number as a list.
(headline (org-export-get-headline-number element info))
;; Special case 2: An item returns its number as a list.
(item (let ((struct (org-element-property :structure element)))
(org-list-get-item-number
(org-element-property :begin element)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct))))
((footnote-definition footnote-reference)
(org-export-get-footnote-number element info))
(otherwise
(let ((counter 0))
;; Increment counter until ELEMENT is found again.
(org-element-map (plist-get info :parse-tree)
(or types (org-element-type element))
(lambda (el)
(cond
((eq element el) (1+ counter))
((not predicate) (incf counter) nil)
((funcall predicate el info) (incf counter) nil)))
info 'first-match))))))
;; Ordinal of a target object refer to the ordinal of the closest
;; table, item, or headline containing the object.
(when (eq (org-element-type element) 'target)
(setq element
(loop for parent in (org-export-get-genealogy element)
when
(memq
(org-element-type parent)
'(footnote-definition footnote-reference headline item
table))
return parent)))
(case (org-element-type element)
;; Special case 1: A headline returns its number as a list.
(headline (org-export-get-headline-number element info))
;; Special case 2: An item returns its number as a list.
(item (let ((struct (org-element-property :structure element)))
(org-list-get-item-number
(org-element-property :begin element)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct))))
((footnote-definition footnote-reference)
(org-export-get-footnote-number element info))
(otherwise
(let ((counter 0))
;; Increment counter until ELEMENT is found again.
(org-element-map (plist-get info :parse-tree)
(or types (org-element-type element))
(lambda (el)
(cond
((eq element el) (1+ counter))
((not predicate) (incf counter) nil)
((funcall predicate el info) (incf counter) nil)))
info 'first-match)))))
;;;; For Src-Blocks

View file

@ -295,38 +295,34 @@
;;;; Fuzzy Links
;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
;; a target keyword (aka an invisible target: #+TARGET: text), to
;; a named element (#+name: text) and to headlines (* Text).
(ert-deftest test-org/fuzzy-links ()
"Test fuzzy links specifications."
;; 1. Fuzzy link goes in priority to a matching target.
(org-test-with-temp-text
"#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
(goto-line 6)
(org-open-at-point)
(should (looking-at "<<Test>>")))
;; 2. Fuzzy link should then go to a matching target keyword.
(org-test-with-temp-text
"#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(should (looking-at "#\\+TARGET: Test")))
;; 3. Then fuzzy link points to an element with a given name.
(org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(should (looking-at "#\\+NAME: Test")))
;; 4. A target still lead to a matching headline otherwise.
(org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
(goto-line 4)
(org-open-at-point)
(should (looking-at "\\* Head2")))
;; 5. With a leading star in link, enforce heading match.
(org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
(goto-line 4)
(org-open-at-point)
(should (looking-at "\\* Test"))))
(should
(org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(looking-at "<<Test>>")))
;; 2. Then fuzzy link points to an element with a given name.
(should
(org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(looking-at "#\\+NAME: Test")))
;; 3. A target still lead to a matching headline otherwise.
(should
(org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
(goto-line 4)
(org-open-at-point)
(looking-at "\\* Head2")))
;; 4. With a leading star in link, enforce heading match.
(should
(org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
(goto-line 3)
(org-open-at-point)
(looking-at "\\* Test"))))
;;;; Link Escaping

View file

@ -1348,15 +1348,7 @@ Paragraph[fn:1]"
(ert-deftest test-org-export/fuzzy-link ()
"Test fuzzy links specifications."
;; 1. Links to invisible (keyword) targets should be ignored.
(org-test-with-parsed-data
"Paragraph.\n#+TARGET: Test\n[[Test]]"
(should-not
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info)))
;; 2. Link to an headline should return headline's number.
;; Link to an headline should return headline's number.
(org-test-with-parsed-data
"Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
(should
@ -1366,7 +1358,7 @@ Paragraph[fn:1]"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 3. Link to a target in an item should return item's number.
;; Link to a target in an item should return item's number.
(org-test-with-parsed-data
"- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
(should
@ -1376,8 +1368,7 @@ Paragraph[fn:1]"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 4. Link to a target in a footnote should return footnote's
;; number.
;; Link to a target in a footnote should return footnote's number.
(org-test-with-parsed-data "
Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(should
@ -1386,8 +1377,8 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info))))
;; 5. Link to a named element should return sequence number of that
;; element.
;; Link to a named element should return sequence number of that
;; element.
(org-test-with-parsed-data
"#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
(should
@ -1396,8 +1387,8 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 6. Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
;; Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
(org-test-with-parsed-data
"* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
(should
@ -1406,13 +1397,13 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 7. Space are not significant when matching a fuzzy link.
;; Space are not significant when matching a fuzzy link.
(should
(org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
(org-element-map tree 'link
(lambda (link) (org-export-resolve-fuzzy-link link info))
info t)))
;; 8. Statistics cookies are ignored for headline match.
;; Statistics cookies are ignored for headline match.
(should
(org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
(org-element-map tree 'link
@ -1491,55 +1482,50 @@ Another text. (ref:text)
(ert-deftest test-org-export/resolve-fuzzy-link ()
"Test `org-export-resolve-fuzzy-link' specifications."
;; 1. Match target objects.
(org-test-with-parsed-data "<<target>> [[target]]"
(should
;; Match target objects.
(should
(org-test-with-parsed-data "<<target>> [[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 2. Match target elements.
(org-test-with-parsed-data "#+TARGET: target\n[[target]]"
(should
;; Match named elements.
(should
(org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 3. Match named elements.
(org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
(should
;; Match exact headline's name.
(should
(org-test-with-parsed-data "* My headline\n[[My headline]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 4. Match exact headline's name.
(org-test-with-parsed-data "* My headline\n[[My headline]]"
(should
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 5. Targets objects have priority over named elements and headline
;; titles.
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[target]]"
(should
(eq 'target
;; Targets objects have priority over named elements and headline
;; titles.
(should
(eq 'target
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; 6. Named elements have priority over headline titles.
(org-test-with-parsed-data
"* target\n#+NAME: target\nParagraph\n\n[[target]]"
(should
(eq 'paragraph
;; Named elements have priority over headline titles.
(should
(eq 'paragraph
(org-test-with-parsed-data
"* target\n#+NAME: target\nParagraph\n\n[[target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; 7. If link's path starts with a "*", only match headline titles,
;; though.
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
(should
(eq 'headline
;; If link's path starts with a "*", only match headline titles,
;; though.
(should
(eq 'headline
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; 8. Return nil if no match.
(org-test-with-parsed-data "[[target]]"
(should-not
;; Return nil if no match.
(should-not
(org-test-with-parsed-data "[[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info))))