org-export: New function `org-export-get-parent'

* contrib/lisp/org-export.el (org-export-get-parent): New function.
(org-export-data, org-export-get-previous-element,
org-export-get-next-element): Use new function.
* EXPERIMENTAL/org-e-ascii.el (org-e-ascii-item): Use new function.
  Refactor code.
(org-e-ascii-paragraph): Use new function.
* EXPERIMENTAL/org-e-latex.el (org-e-latex-item): Use new function.
* EXPERIMENTAL/org-e-html.el (org-e-html-item): Use new function.
* EXPERIMENTAL/org-e-odt.el (org-e-odt-item): Use new function.
This commit is contained in:
Nicolas Goaziou 2012-02-22 17:46:59 +01:00
parent 620f1d5181
commit 40e42b9dca
5 changed files with 45 additions and 45 deletions

View File

@ -1279,34 +1279,32 @@ contextual information."
;; First parent of ITEM is always the plain-list. Get ;; First parent of ITEM is always the plain-list. Get
;; `:type' property from it. ;; `:type' property from it.
(org-list-bullet-string (org-list-bullet-string
(let ((type (org-element-property (case (org-element-property :type (org-export-get-parent item info))
:type (car (org-export-get-genealogy item info))))) (descriptive
(cond (concat
((eq type 'descriptive) (org-export-secondary-string
(concat (org-element-property :tag item) 'e-ascii info) ": "))
(org-export-secondary-string (ordered
(org-element-property :tag item) 'e-ascii info) ": ")) ;; Return correct number for ITEM, paying attention to
((eq type 'ordered) ;; counters.
;; Return correct number for ITEM, paying attention to (let* ((struct (org-element-property :structure item))
;; counters. (bul (org-element-property :bullet item))
(let* ((struct (org-element-property :structure item)) (num
(bul (org-element-property :bullet item)) (number-to-string
(num (car (last (org-list-get-item-number
(number-to-string (org-element-property :begin item)
(car (last (org-list-get-item-number struct
(org-element-property :begin item) (org-list-prevs-alist struct)
struct (org-list-parents-alist struct)))))))
(org-list-prevs-alist struct) (replace-regexp-in-string "[0-9]+" num bul)))
(org-list-parents-alist struct))))))) (t (let ((bul (org-element-property :bullet item)))
(replace-regexp-in-string "[0-9]+" num bul))) ;; Change bullets into more visible form if UTF-8 is active.
(t (let ((bul (org-element-property :bullet item))) (if (not (eq (plist-get info :ascii-charset) 'utf-8)) bul
;; Change bullets into more visible form if UTF-8 is active. (replace-regexp-in-string
(if (not (eq (plist-get info :ascii-charset) 'utf-8)) bul "-" ""
(replace-regexp-in-string (replace-regexp-in-string
"-" "" "+" ""
(replace-regexp-in-string (replace-regexp-in-string "*" "" bul))))))))))
"+" ""
(replace-regexp-in-string "*" "" bul)))))))))))
(concat (concat
bullet bullet
;; Contents: Pay attention to indentation. Note: check-boxes are ;; Contents: Pay attention to indentation. Note: check-boxes are
@ -1432,7 +1430,7 @@ information."
CONTENTS is the contents of the paragraph, as a string. INFO is CONTENTS is the contents of the paragraph, as a string. INFO is
the plist used as a communication channel." the plist used as a communication channel."
(org-e-ascii--fill-string (org-e-ascii--fill-string
(let ((parent (car (org-export-get-genealogy paragraph info)))) (let ((parent (org-export-get-parent paragraph info)))
;; If PARAGRAPH is the first one in a list element, be sure to ;; If PARAGRAPH is the first one in a list element, be sure to
;; add the check-box in front of it, before any filling. Later, ;; add the check-box in front of it, before any filling. Later,
;; it would interfere with line width. ;; it would interfere with line width.

View File

@ -2506,10 +2506,9 @@ CONTENTS holds the contents of the item. INFO is a plist holding
contextual information." contextual information."
;; Grab `:level' from plain-list properties, which is always the ;; Grab `:level' from plain-list properties, which is always the
;; first element above current item. ;; first element above current item.
(let* ((plain-list (car (org-export-get-genealogy item info))) (let* ((plain-list (org-export-get-parent item info))
(type (org-element-property :type plain-list)) (type (org-element-property :type plain-list))
(level (org-element-property (level (org-element-property :level plain-list))
:level (car (plist-get info :genealogy))))
(counter (org-element-property :counter item)) (counter (org-element-property :counter item))
(checkbox (org-element-property :checkbox item)) (checkbox (org-element-property :checkbox item))
(tag (let ((tag (org-element-property :tag item))) (tag (let ((tag (org-element-property :tag item)))

View File

@ -1233,8 +1233,7 @@ CONTENTS holds the contents of the item. INFO is a plist holding
contextual information." contextual information."
;; Grab `:level' from plain-list properties, which is always the ;; Grab `:level' from plain-list properties, which is always the
;; first element above current item. ;; first element above current item.
(let* ((level (org-element-property (let* ((level (org-element-property :level (org-export-get-parent item info)))
:level (car (org-export-get-genealogy item info))))
(counter (let ((count (org-element-property :counter item))) (counter (let ((count (org-element-property :counter item)))
(and count (and count
(< level 4) (< level 4)

View File

@ -4225,10 +4225,9 @@ CONTENTS holds the contents of the item. INFO is a plist holding
contextual information." contextual information."
;; Grab `:level' from plain-list properties, which is always the ;; Grab `:level' from plain-list properties, which is always the
;; first element above current item. ;; first element above current item.
(let* ((plain-list (car (org-export-get-genealogy item info))) (let* ((plain-list (org-export-get-parent item info))
(type (org-element-property :type plain-list)) (type (org-element-property :type plain-list))
(level (org-element-property (level (org-element-property :level plain-list))
:level (car (plist-get info :genealogy))))
(counter (org-element-property :counter item)) (counter (org-element-property :counter item))
(checkbox (org-element-property :checkbox item)) (checkbox (org-element-property :checkbox item))
(tag (let ((tag (org-element-property :tag item))) (tag (let ((tag (org-element-property :tag item)))

View File

@ -1519,9 +1519,7 @@ Return transcoded string."
;; indentation: there is none and it might be ;; indentation: there is none and it might be
;; misleading. ;; misleading.
(and (not (org-export-get-previous-element blob info)) (and (not (org-export-get-previous-element blob info))
(let ((parent (let ((parent (org-export-get-parent blob info)))
(car
(org-export-get-genealogy blob info))))
(memq (org-element-type parent) (memq (org-element-type parent)
'(footnote-definition item))))))) '(footnote-definition item)))))))
(org-export-data paragraph backend info))))) (org-export-data paragraph backend info)))))
@ -3138,10 +3136,11 @@ affiliated keyword."
;; Here are various functions to retrieve information about the ;; Here are various functions to retrieve information about the
;; neighbourhood of a given element or object. Neighbours of interest ;; neighbourhood of a given element or object. Neighbours of interest
;; are parent headline (`org-export-get-parent-headline'), parent ;; are direct parent (`org-export-get-parent'), parent headline
;; paragraph (`org-export-get-parent-paragraph'), previous element or ;; (`org-export-get-parent-headline'), parent paragraph
;; object (`org-export-get-previous-element') and next element or ;; (`org-export-get-parent-paragraph'), previous element or object
;; object (`org-export-get-next-element'). ;; (`org-export-get-previous-element') and next element or object
;; (`org-export-get-next-element').
;; All of these functions are just a specific use of the more generic ;; All of these functions are just a specific use of the more generic
;; `org-export-get-genealogy', which returns the genealogy relative to ;; `org-export-get-genealogy', which returns the genealogy relative to
@ -3164,6 +3163,12 @@ used as a communication channel."
(org-element-contents data))))) (org-element-contents data)))))
(catch 'exit (funcall walk-data (plist-get info :parse-tree) nil) nil))) (catch 'exit (funcall walk-data (plist-get info :parse-tree) nil) nil)))
(defun org-export-get-parent (blob info)
"Return BLOB parent or nil.
BLOB is the element or object considered. INFO is a plist used
as a communication channel."
(car (org-export-get-genealogy blob info)))
(defun org-export-get-parent-headline (blob info) (defun org-export-get-parent-headline (blob info)
"Return closest parent headline or nil. "Return closest parent headline or nil.
@ -3198,7 +3203,7 @@ BLOB is an element or object. INFO is a plist used as
a communication channel. a communication channel.
Return previous element or object, a string, or nil." Return previous element or object, a string, or nil."
(let ((parent (car (org-export-get-genealogy blob info)))) (let ((parent (org-export-get-parent blob info)))
(cadr (member blob (reverse (org-element-contents parent)))))) (cadr (member blob (reverse (org-element-contents parent))))))
(defun org-export-get-next-element (blob info) (defun org-export-get-next-element (blob info)
@ -3208,7 +3213,7 @@ BLOB is an element or object. INFO is a plist used as
a communication channel. a communication channel.
Return next element or object, a string, or nil." Return next element or object, a string, or nil."
(let ((parent (car (org-export-get-genealogy blob info)))) (let ((parent (org-export-get-parent blob info)))
(cadr (member blob (org-element-contents parent))))) (cadr (member blob (org-element-contents parent)))))