org-element: Fix interpretation of affiliated keywords

* contrib/lisp/org-element.el (org-element-interpret--affiliated-keywords):
  Fix interpretation of affiliated keywords.
(org-element-interpret-data): If no `:post-blank' property is
specified, assumed there is no blank line or whitespace after the
element or object.
* testing/lisp/test-org-element.el: Add a test.
This commit is contained in:
Nicolas Goaziou 2012-04-10 23:15:32 +02:00
parent f42e40d978
commit 97d2db4867
2 changed files with 51 additions and 15 deletions

View File

@ -3415,17 +3415,17 @@ Return Org syntax as a string."
(results (funcall interpreter blob contents)))
;; Update PREVIOUS.
(setq previous type)
;; Build white spaces.
(cond
((eq type 'org-data) results)
((memq type org-element-all-elements)
(concat
(org-element-interpret--affiliated-keywords blob)
(org-element-normalize-string results)
(make-string (org-element-property :post-blank blob) 10)))
(t (concat
results
(make-string (org-element-property :post-blank blob) 32))))))))
;; Build white spaces. If no `:post-blank' property is
;; specified, assume its value is 0.
(let ((post-blank (or (org-element-property :post-blank blob) 0)))
(cond
((eq type 'org-data) results)
((memq type org-element-all-elements)
(concat
(org-element-interpret--affiliated-keywords blob)
(org-element-normalize-string results)
(make-string post-blank 10)))
(t (concat results (make-string post-blank 32)))))))))
(org-element-contents data) ""))
(defun org-element-interpret-secondary (secondary)
@ -3450,14 +3450,19 @@ If there is no affiliated keyword, return the empty string."
(let (dual)
(when (member key org-element-dual-keywords)
(setq dual (cdr value) value (car value)))
(concat "#+" key (and dual (format "[%s]" dual)) ": "
(concat "#+" key
(and dual
(format "[%s]"
(org-element-interpret-secondary dual)))
": "
(if (member key org-element-parsed-keywords)
(org-element-interpret-secondary value)
value)
"\n"))))))
(mapconcat
(lambda (key)
(let ((value (org-element-property (intern (concat ":" key)) element)))
(let ((value (org-element-property (intern (concat ":" (downcase key)))
element)))
(when value
(if (member key org-element-multiple-keywords)
(mapconcat (lambda (line)

View File

@ -261,7 +261,7 @@
;;; Granularity
;;;; Granularity
(ert-deftest test-org-element/granularity ()
"Test granularity impact on buffer parsing."
@ -346,7 +346,38 @@ Paragraph \\alpha."
;;; Navigation tools.
;;;; Interpretation.
(ert-deftest test-org-element/interpret-affiliated-keywords ()
"Test if affiliated keywords are correctly interpreted."
;; Interpret simple keywords.
(should
(equal
(org-element-interpret-data
'(org-data nil (paragraph (:name "para") "Paragraph")))
"#+NAME: para\nParagraph\n"))
;; Interpret multiple keywords.
(should
(equal
(org-element-interpret-data
'(org-data nil (paragraph (:attr_ascii ("line1" "line2")) "Paragraph")))
"#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph\n"))
;; Interpret parsed keywords.
(should
(equal
(org-element-interpret-data
'(org-data nil (paragraph (:caption ("caption")) "Paragraph")))
"#+CAPTION: caption\nParagraph\n"))
;; Interpret dual keywords.
(should
(equal
(org-element-interpret-data
'(org-data nil (paragraph (:caption (("long") "short")) "Paragraph")))
"#+CAPTION[short]: long\nParagraph\n")))
;;;; Navigation tools.
(ert-deftest test-org-element/forward-element ()
"Test `org-element-forward' specifications."