org-element: Fix bug with `greater-element' granularity
* contrib/lisp/org-element.el (org-element-parse-elements): Enter section type elements even if granularity is set to `greater-element'. (org-element-parse-buffer): Update doc-string. * testing/lisp/test-org-element.el: Add test.
This commit is contained in:
parent
bb671936b5
commit
82281bcc94
|
@ -2995,8 +2995,9 @@ Optional argument GRANULARITY determines the depth of the
|
|||
recursion. It can be set to the following symbols:
|
||||
|
||||
`headline' Only parse headlines.
|
||||
`greater-element' Don't recurse into greater elements. Thus,
|
||||
elements parsed are the top-level ones.
|
||||
`greater-element' Don't recurse into greater elements excepted
|
||||
headlines and sections. Thus, elements
|
||||
parsed are the top-level ones.
|
||||
`element' Parse everything but objects and plain text.
|
||||
`object' Parse the complete buffer (default).
|
||||
|
||||
|
@ -3195,6 +3196,7 @@ Elements are accumulated into ACC."
|
|||
((and (memq type org-element-greater-elements)
|
||||
(or (not granularity)
|
||||
(memq granularity '(element object))
|
||||
(and (eq granularity 'greater-element) (eq type 'section))
|
||||
(eq type 'headline))
|
||||
(not (and visible-only
|
||||
(org-element-property :hiddenp element))))
|
||||
|
|
|
@ -204,10 +204,39 @@
|
|||
|
||||
|
||||
|
||||
;;; Secondary strings
|
||||
;;; Granularity
|
||||
|
||||
(ert-deftest test-org-element/granularity ()
|
||||
"Test granularity impact on buffer parsing."
|
||||
(org-test-with-temp-text "
|
||||
* Head 1
|
||||
** Head 2
|
||||
#+BEGIN_CENTER
|
||||
Centered paragraph.
|
||||
#+END_CENTER
|
||||
Paragraph \\alpha."
|
||||
;; 1.1. Granularity set to `headline' should parse every headline
|
||||
;; in buffer, and only them.
|
||||
(let ((tree (org-element-parse-buffer 'headline)))
|
||||
(should (= 2 (length (org-element-map tree 'headline 'identity))))
|
||||
(should-not (org-element-map tree 'paragraph 'identity)))
|
||||
;; 1.2. Granularity set to `greater-element' should not enter
|
||||
;; greater elements excepted headlines and sections.
|
||||
(let ((tree (org-element-parse-buffer 'greater-element)))
|
||||
(should (= 1 (length (org-element-map tree 'center-block 'identity))))
|
||||
(should (= 1 (length (org-element-map tree 'paragraph 'identity))))
|
||||
(should-not (org-element-map tree 'entity 'identity)))
|
||||
;; 1.3. Granularity set to `element' should enter every
|
||||
;; greater-element.
|
||||
(let ((tree (org-element-parse-buffer 'element)))
|
||||
(should (= 2 (length (org-element-map tree 'paragraph 'identity))))
|
||||
(should-not (org-element-map tree 'entity 'identity)))
|
||||
;; 1.4. Granularity set to `object' can see everything.
|
||||
(let ((tree (org-element-parse-buffer 'object)))
|
||||
(should (= 1 (length (org-element-map tree 'entity 'identity)))))))
|
||||
|
||||
(ert-deftest test-org-element/secondary-string-parsing ()
|
||||
"Test granularity correctly toggles secondary strings parsing."
|
||||
"Test if granularity correctly toggles secondary strings parsing."
|
||||
;; 1. With a granularity bigger than `object', no secondary string
|
||||
;; should be parsed.
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue