forked from mirrors/org-mode
org-element: White space fixing and trivial refactoring
This commit is contained in:
parent
6951f9af15
commit
096ffd571c
|
@ -134,6 +134,7 @@
|
|||
|
||||
|
||||
;;;; Center Block
|
||||
|
||||
(defun org-element-center-block-parser ()
|
||||
"Parse a center block.
|
||||
|
||||
|
@ -158,8 +159,8 @@ Assume point is at beginning or end of the block."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'center-block
|
||||
`(:begin ,begin
|
||||
`(center-block
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:hiddenp ,hidden
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -172,7 +173,9 @@ Assume point is at beginning or end of the block."
|
|||
CONTENTS is the contents of the element."
|
||||
(format "#+begin_center\n%s#+end_center" contents))
|
||||
|
||||
|
||||
;;;; Drawer
|
||||
|
||||
(defun org-element-drawer-parser ()
|
||||
"Parse a drawer.
|
||||
|
||||
|
@ -194,8 +197,8 @@ Assume point is at beginning of drawer."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'drawer
|
||||
`(:begin ,begin
|
||||
`(drawer
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:drawer-name ,name
|
||||
:hiddenp ,hidden
|
||||
|
@ -211,7 +214,9 @@ CONTENTS is the contents of the element."
|
|||
(org-element-get-property :drawer-name drawer)
|
||||
contents))
|
||||
|
||||
|
||||
;;;; Dynamic Block
|
||||
|
||||
(defun org-element-dynamic-block-parser ()
|
||||
"Parse a dynamic block.
|
||||
|
||||
|
@ -255,6 +260,7 @@ CONTENTS is the contents of the element."
|
|||
(and arg (concat " " args)))
|
||||
contents))
|
||||
|
||||
|
||||
;;;; Footnote Definition
|
||||
|
||||
(defun org-element-footnote-definition-parser ()
|
||||
|
@ -277,8 +283,8 @@ a plist containing `:label', `:begin' `:end', `:contents-begin',
|
|||
(contents-end (progn (skip-chars-backward " \r\t\n")
|
||||
(forward-line)
|
||||
(point))))
|
||||
(list 'footnote-definition
|
||||
`(:label ,label
|
||||
`(footnote-definition
|
||||
(:label ,label
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -295,6 +301,7 @@ CONTENTS is the contents of the footnote-definition."
|
|||
|
||||
|
||||
;;;; Headline
|
||||
|
||||
(defun org-element-headline-parser ()
|
||||
"Parse an headline.
|
||||
|
||||
|
@ -372,8 +379,8 @@ Assume point is at beginning of the headline."
|
|||
(setq title (org-element-parse-secondary-string
|
||||
raw-value
|
||||
(cdr (assq 'headline org-element-string-restrictions))))
|
||||
(list 'headline
|
||||
`(:raw-value ,raw-value
|
||||
`(headline
|
||||
(:raw-value ,raw-value
|
||||
:title ,title
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
|
@ -440,7 +447,9 @@ CONTENTS is the contents of the element."
|
|||
(make-string (1+ pre-blank) 10)
|
||||
contents)))
|
||||
|
||||
|
||||
;;;; Inlinetask
|
||||
|
||||
(defun org-element-inlinetask-parser ()
|
||||
"Parse an inline task.
|
||||
|
||||
|
@ -493,8 +502,8 @@ Assume point is at beginning of the inline task."
|
|||
(save-excursion (forward-line -1) (point))))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'inlinetask
|
||||
`(:raw-value ,raw-value
|
||||
`(inlinetask
|
||||
(:raw-value ,raw-value
|
||||
:title ,title
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
|
@ -540,7 +549,9 @@ CONTENTS is the contents of inlinetask."
|
|||
1)))))))
|
||||
(concat inlinetask (and tags (format tags-fmt tags) "\n" contents))))
|
||||
|
||||
|
||||
;;;; Item
|
||||
|
||||
(defun org-element-item-parser (struct)
|
||||
"Parse an item.
|
||||
|
||||
|
@ -587,8 +598,8 @@ Assume point is at the beginning of the item."
|
|||
(skip-chars-backward " \r\t\n")
|
||||
(forward-line)
|
||||
(point))))
|
||||
(list 'item
|
||||
`(:bullet ,bullet
|
||||
`(item
|
||||
(:bullet ,bullet
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
;; CONTENTS-BEGIN and CONTENTS-END may be mixed
|
||||
|
@ -630,7 +641,9 @@ CONTENTS is the contents of the element."
|
|||
(replace-regexp-in-string
|
||||
"\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))))
|
||||
|
||||
|
||||
;;;; Plain List
|
||||
|
||||
(defun org-element-plain-list-parser (&optional structure)
|
||||
"Parse a plain list.
|
||||
|
||||
|
@ -667,8 +680,8 @@ Assume point is at one of the list items."
|
|||
(progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol))))))
|
||||
;; Return value.
|
||||
(list 'plain-list
|
||||
`(:type ,type
|
||||
`(plain-list
|
||||
(:type ,type
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -683,7 +696,9 @@ Assume point is at one of the list items."
|
|||
CONTENTS is the contents of the element."
|
||||
contents)
|
||||
|
||||
|
||||
;;;; Quote Block
|
||||
|
||||
(defun org-element-quote-block-parser ()
|
||||
"Parse a quote block.
|
||||
|
||||
|
@ -708,8 +723,8 @@ Assume point is at beginning or end of the block."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'quote-block
|
||||
`(:begin ,begin
|
||||
`(quote-block
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:hiddenp ,hidden
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -743,8 +758,8 @@ and `:post-blank' keywords."
|
|||
(pos-before-blank (progn (skip-chars-backward " \r\t\n")
|
||||
(forward-line)
|
||||
(point))))
|
||||
(list 'section
|
||||
`(:begin ,begin
|
||||
`(section
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,begin
|
||||
:contents-end ,pos-before-blank
|
||||
|
@ -757,6 +772,7 @@ CONTENTS is the contents of the element."
|
|||
|
||||
|
||||
;;;; Special Block
|
||||
|
||||
(defun org-element-special-block-parser ()
|
||||
"Parse a special block.
|
||||
|
||||
|
@ -784,8 +800,8 @@ Assume point is at beginning or end of the block."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'special-block
|
||||
`(:type ,type
|
||||
`(special-block
|
||||
(:type ,type
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:hiddenp ,hidden
|
||||
|
@ -818,6 +834,7 @@ CONTENTS is the contents of the element."
|
|||
|
||||
|
||||
;;;; Babel Call
|
||||
|
||||
(defun org-element-babel-call-parser ()
|
||||
"Parse a babel call.
|
||||
|
||||
|
@ -831,8 +848,8 @@ keywords."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'babel-call
|
||||
`(:beg ,beg
|
||||
`(babel-call
|
||||
(:beg ,beg
|
||||
:end ,end
|
||||
:info ,info
|
||||
:post-blank ,(count-lines pos-before-blank end))))))
|
||||
|
@ -851,7 +868,9 @@ CONTENTS is nil."
|
|||
main-source)
|
||||
(and post-options (format "[%s]" post-options)))))
|
||||
|
||||
|
||||
;;;; Comment
|
||||
|
||||
(defun org-element-comment-parser ()
|
||||
"Parse a comment.
|
||||
|
||||
|
@ -886,8 +905,8 @@ keywords."
|
|||
(setq end (if (eobp) (point) (point-at-bol)))
|
||||
;; Extract value.
|
||||
(setq value (buffer-substring-no-properties beg-coms pos-before-blank)))
|
||||
(list 'comment
|
||||
`(:begin ,begin
|
||||
`(comment
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:post-blank ,(count-lines pos-before-blank end)
|
||||
|
@ -898,7 +917,9 @@ keywords."
|
|||
CONTENTS is nil."
|
||||
(org-element-get-property :value comment))
|
||||
|
||||
|
||||
;;;; Comment Block
|
||||
|
||||
(defun org-element-comment-block-parser ()
|
||||
"Parse an export block.
|
||||
|
||||
|
@ -921,8 +942,8 @@ containing `:begin', `:end', `:hiddenp', `:value' and
|
|||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol))))
|
||||
(value (buffer-substring-no-properties contents-begin contents-end)))
|
||||
(list 'comment-block
|
||||
`(:begin ,begin
|
||||
`(comment-block
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:hiddenp ,hidden
|
||||
|
@ -937,7 +958,9 @@ CONTENTS is nil."
|
|||
(org-element-get-property :value comment-block))
|
||||
"#+begin_comment"))
|
||||
|
||||
|
||||
;;;; Example Block
|
||||
|
||||
(defun org-element-example-block-parser ()
|
||||
"Parse an example block.
|
||||
|
||||
|
@ -962,8 +985,8 @@ containing `:begin', `:end', `:options', `:hiddenp', `:value' and
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'example-block
|
||||
`(:begin ,begin
|
||||
`(example-block
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:options ,options
|
||||
|
@ -980,7 +1003,9 @@ CONTENTS is nil."
|
|||
(org-element-get-property :value example-block))
|
||||
"#+end_example")))
|
||||
|
||||
|
||||
;;;; Export Block
|
||||
|
||||
(defun org-element-export-block-parser ()
|
||||
"Parse an export block.
|
||||
|
||||
|
@ -1006,8 +1031,8 @@ containing `:begin', `:end', `:type', `:hiddenp', `:value' and
|
|||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol))))
|
||||
(value (buffer-substring-no-properties contents-begin contents-end)))
|
||||
(list 'export-block
|
||||
`(:begin ,begin
|
||||
`(export-block
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:type ,type
|
||||
:value ,value
|
||||
|
@ -1023,7 +1048,9 @@ CONTENTS is nil."
|
|||
(org-element-get-property :value export-block)
|
||||
(format "#+end_%s" type))))
|
||||
|
||||
|
||||
;;;; Fixed-width
|
||||
|
||||
(defun org-element-fixed-width-parser ()
|
||||
"Parse a fixed-width section.
|
||||
|
||||
|
@ -1058,8 +1085,8 @@ keywords."
|
|||
(setq end (if (eobp) (point) (point-at-bol)))
|
||||
;; Extract value.
|
||||
(setq value (buffer-substring-no-properties beg-area pos-before-blank)))
|
||||
(list 'fixed-width
|
||||
`(:begin ,begin
|
||||
`(fixed-width
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:post-blank ,(count-lines pos-before-blank end)
|
||||
|
@ -1070,7 +1097,9 @@ keywords."
|
|||
CONTENTS is nil."
|
||||
(org-remove-indentation (org-element-get-property :value fixed-width)))
|
||||
|
||||
|
||||
;;;; Horizontal Rule
|
||||
|
||||
(defun org-element-horizontal-rule-parser ()
|
||||
"Parse an horizontal rule.
|
||||
|
||||
|
@ -1083,8 +1112,8 @@ CONTENTS is nil."
|
|||
(post-hr (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'horizontal-rule
|
||||
`(:begin ,begin
|
||||
`(horizontal-rule
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:post-blank ,(count-lines post-hr end)
|
||||
,@(cadr keywords))))))
|
||||
|
@ -1094,7 +1123,9 @@ CONTENTS is nil."
|
|||
CONTENTS is nil."
|
||||
"-----")
|
||||
|
||||
|
||||
;;;; Keyword
|
||||
|
||||
(defun org-element-keyword-parser ()
|
||||
"Parse a keyword at point.
|
||||
|
||||
|
@ -1111,8 +1142,8 @@ keywords."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'keyword
|
||||
`(:key ,key
|
||||
`(keyword
|
||||
(:key ,key
|
||||
:value ,value
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
|
@ -1125,7 +1156,9 @@ CONTENTS is nil."
|
|||
(org-element-get-property :key keyword)
|
||||
(org-element-get-property :value keyword)))
|
||||
|
||||
|
||||
;;;; Latex Environment
|
||||
|
||||
(defun org-element-latex-environment-parser ()
|
||||
"Parse a LaTeX environment.
|
||||
|
||||
|
@ -1143,8 +1176,8 @@ containing `:begin', `:end', `:value' and `:post-blank' keywords."
|
|||
(value (buffer-substring-no-properties contents-begin contents-end))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'latex-environment
|
||||
`(:begin ,begin
|
||||
`(latex-environment
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:post-blank ,(count-lines contents-end end)
|
||||
|
@ -1155,7 +1188,9 @@ containing `:begin', `:end', `:value' and `:post-blank' keywords."
|
|||
CONTENTS is nil."
|
||||
(org-element-get-property :value latex-environment))
|
||||
|
||||
|
||||
;;;; Paragraph
|
||||
|
||||
(defun org-element-paragraph-parser ()
|
||||
"Parse a paragraph.
|
||||
|
||||
|
@ -1177,8 +1212,8 @@ Assume point is at the beginning of the paragraph."
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'paragraph
|
||||
`(:begin ,begin
|
||||
`(paragraph
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,contents-begin
|
||||
:contents-end ,contents-end
|
||||
|
@ -1190,7 +1225,9 @@ Assume point is at the beginning of the paragraph."
|
|||
CONTENTS is the contents of the element."
|
||||
contents)
|
||||
|
||||
|
||||
;;;; Property Drawer
|
||||
|
||||
(defun org-element-property-drawer-parser ()
|
||||
"Parse a property drawer.
|
||||
|
||||
|
@ -1221,8 +1258,8 @@ containing `:begin', `:end', `:hiddenp', `:contents-begin',
|
|||
(pos-before-blank (progn (forward-line) (point)))
|
||||
(end (progn (org-skip-whitespace)
|
||||
(if (eobp) (point) (point-at-bol)))))
|
||||
(list 'property-drawer
|
||||
`(:begin ,begin
|
||||
`(property-drawer
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:hiddenp ,hidden
|
||||
:properties ,properties
|
||||
|
@ -1239,7 +1276,9 @@ CONTENTS is nil."
|
|||
(nreverse props) "\n")
|
||||
"\n:END:")))
|
||||
|
||||
|
||||
;;;; Quote Section
|
||||
|
||||
(defun org-element-quote-section-parser ()
|
||||
"Parse a quote section.
|
||||
|
||||
|
@ -1258,8 +1297,8 @@ keywords."
|
|||
(point)))
|
||||
(value (unless (= begin end)
|
||||
(buffer-substring-no-properties begin pos-before-blank))))
|
||||
(list 'quote-section
|
||||
`(:begin ,begin
|
||||
`(quote-section
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:post-blank ,(if value
|
||||
|
@ -1271,7 +1310,9 @@ keywords."
|
|||
CONTENTS is nil."
|
||||
(org-element-get-property :value quote-section))
|
||||
|
||||
|
||||
;;;; Src Block
|
||||
|
||||
(defun org-element-src-block-parser ()
|
||||
"Parse a src block.
|
||||
|
||||
|
@ -1317,8 +1358,8 @@ and `:post-blank' keywords."
|
|||
(hidden (progn (goto-char contents-begin)
|
||||
(forward-line)
|
||||
(org-truely-invisible-p))))
|
||||
(list 'src-block
|
||||
`(:language ,language
|
||||
`(src-block
|
||||
(:language ,language
|
||||
:switches ,switches
|
||||
:parameters ,parameters
|
||||
:begin ,begin
|
||||
|
@ -1352,7 +1393,9 @@ CONTENTS is nil."
|
|||
value
|
||||
"#+end_src")))
|
||||
|
||||
|
||||
;;;; Table
|
||||
|
||||
(defun org-element-table-parser ()
|
||||
"Parse a table at point.
|
||||
|
||||
|
@ -1373,8 +1416,8 @@ Return a list whose car is `table' and cdr is a plist containing
|
|||
(if (eobp) (point) (point-at-bol))))
|
||||
(raw-table (org-remove-indentation
|
||||
(buffer-substring-no-properties table-begin table-end))))
|
||||
(list 'table
|
||||
`(:begin ,begin
|
||||
`(table
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:type ,type
|
||||
:raw-table ,raw-table
|
||||
|
@ -1387,7 +1430,9 @@ Return a list whose car is `table' and cdr is a plist containing
|
|||
CONTENTS is nil."
|
||||
(org-element-get-property :raw-table table))
|
||||
|
||||
|
||||
;;;; Verse Block
|
||||
|
||||
(defun org-element-verse-block-parser ()
|
||||
"Parse a verse block.
|
||||
|
||||
|
@ -1416,8 +1461,8 @@ Assume point is at beginning or end of the block."
|
|||
(value (org-element-parse-secondary-string
|
||||
(org-remove-indentation raw-val)
|
||||
(cdr (assq 'verse org-element-string-restrictions)))))
|
||||
(list 'verse-block
|
||||
`(:begin ,begin
|
||||
`(verse-block
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:hiddenp ,hidden
|
||||
:raw-value ,raw-val
|
||||
|
@ -1425,7 +1470,6 @@ Assume point is at beginning or end of the block."
|
|||
:post-blank ,(count-lines pos-before-blank end)
|
||||
,@(cadr keywords))))))
|
||||
|
||||
|
||||
(defun org-element-verse-block-interpreter (verse-block contents)
|
||||
"Interpret VERSE-BLOCK element as Org syntax.
|
||||
CONTENTS is nil."
|
||||
|
@ -1460,6 +1504,7 @@ CONTENTS is nil."
|
|||
;; maybe tweak restrictions about it, and that's it.
|
||||
|
||||
;;;; Emphasis
|
||||
|
||||
(defun org-element-emphasis-parser ()
|
||||
"Parse text markup object at point.
|
||||
|
||||
|
@ -1478,8 +1523,8 @@ Assume point is at the first emphasis marker."
|
|||
(post-blank (progn (goto-char (match-end 2))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'emphasis
|
||||
`(:marker ,marker
|
||||
`(emphasis
|
||||
(:marker ,marker
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -1508,6 +1553,7 @@ Return value is a cons cell whose car is `emphasis' or
|
|||
(match-beginning 2)))))
|
||||
|
||||
;;;; Entity
|
||||
|
||||
(defun org-element-entity-parser ()
|
||||
"Parse entity at point.
|
||||
|
||||
|
@ -1526,8 +1572,8 @@ Assume point is at the beginning of the entity."
|
|||
(when bracketsp (forward-char 2))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'entity
|
||||
`(:name ,(car value)
|
||||
`(entity
|
||||
(:name ,(car value)
|
||||
:latex ,(nth 1 value)
|
||||
:latex-math-p ,(nth 2 value)
|
||||
:html ,(nth 3 value)
|
||||
|
@ -1580,7 +1626,9 @@ Return value is a cons cell whose car is `entity' or
|
|||
matchers)
|
||||
(point))))))))
|
||||
|
||||
|
||||
;;;; Export Snippet
|
||||
|
||||
(defun org-element-export-snippet-parser ()
|
||||
"Parse export snippet at point.
|
||||
|
||||
|
@ -1598,8 +1646,8 @@ Assume point is at the beginning of the snippet."
|
|||
(match-end 0) (1- before-blank)))
|
||||
(post-blank (skip-chars-forward " \t"))
|
||||
(end (point)))
|
||||
(list 'export-snippet
|
||||
`(:back-end ,back-end
|
||||
`(export-snippet
|
||||
(:back-end ,back-end
|
||||
:value ,value
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
|
@ -1626,6 +1674,7 @@ its beginning position."
|
|||
(and end (eq (char-before end) ?})))
|
||||
(throw 'exit (cons 'export-snippet (match-beginning 0))))))))
|
||||
|
||||
|
||||
;;;; Footnote Reference
|
||||
|
||||
(defun org-element-footnote-reference-parser ()
|
||||
|
@ -1645,8 +1694,8 @@ with `:label', `:type', `:definition', `:begin', `:end' and
|
|||
(post-blank (progn (goto-char (nth 2 ref))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'footnote-reference
|
||||
`(:label ,label
|
||||
`(footnote-reference
|
||||
(:label ,label
|
||||
:type ,type
|
||||
:inline-definition ,inline-def
|
||||
:begin ,begin
|
||||
|
@ -1678,6 +1727,7 @@ cdr is beginning position."
|
|||
|
||||
|
||||
;;;; Inline Babel Call
|
||||
|
||||
(defun org-element-inline-babel-call-parser ()
|
||||
"Parse inline babel call at point.
|
||||
|
||||
|
@ -1693,8 +1743,8 @@ Assume point is at the beginning of the babel call."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'inline-babel-call
|
||||
`(:begin ,begin
|
||||
`(inline-babel-call
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:info ,info
|
||||
:post-blank ,post-blank)))))
|
||||
|
@ -1729,7 +1779,9 @@ cdr is beginning position."
|
|||
limit t)
|
||||
(cons 'inline-babel-call (match-beginning 0)))))
|
||||
|
||||
|
||||
;;;; Inline Src Block
|
||||
|
||||
(defun org-element-inline-src-block-parser ()
|
||||
"Parse inline source block at point.
|
||||
|
||||
|
@ -1748,16 +1800,14 @@ Assume point is at the beginning of the inline src block."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'inline-src-block
|
||||
`(:language ,language
|
||||
`(inline-src-block
|
||||
(:language ,language
|
||||
:value ,value
|
||||
:parameters ,parameters
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:post-blank ,post-blank)))))
|
||||
|
||||
|
||||
|
||||
(defun org-element-inline-src-block-successor (limit)
|
||||
"Search for the next inline-babel-call and return beginning position.
|
||||
|
||||
|
@ -1769,7 +1819,9 @@ cdr is beginning position."
|
|||
(when (re-search-forward org-babel-inline-src-block-regexp limit t)
|
||||
(cons 'inline-src-block (match-beginning 1)))))
|
||||
|
||||
|
||||
;;;; Latex Fragment
|
||||
|
||||
(defun org-element-latex-fragment-parser ()
|
||||
"Parse latex fragment at point.
|
||||
|
||||
|
@ -1797,8 +1849,8 @@ Assume point is at the beginning of the latex fragment."
|
|||
(post-blank (progn (goto-char (match-end substring-match))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'latex-fragment
|
||||
`(:value ,value
|
||||
`(latex-fragment
|
||||
(:value ,value
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:post-blank ,post-blank)))))
|
||||
|
@ -1809,6 +1861,7 @@ CONTENTS is nil."
|
|||
(org-element-get-property :value latex-fragment))
|
||||
|
||||
;;;; Line Break
|
||||
|
||||
(defun org-element-line-break-parser ()
|
||||
"Parse line break at point.
|
||||
|
||||
|
@ -1821,8 +1874,8 @@ Assume point is at the beginning of the line break."
|
|||
(end (progn (end-of-line) (point)))
|
||||
(post-blank (- (skip-chars-backward " \t")))
|
||||
(end (point)))
|
||||
(list 'line-break
|
||||
`(:begin ,begin
|
||||
`(line-break
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:post-blank ,post-blank)))))
|
||||
|
||||
|
@ -1845,7 +1898,9 @@ beginning position."
|
|||
(when (and beg (re-search-backward "\\S-" (point-at-bol) t))
|
||||
(cons 'line-break beg)))))
|
||||
|
||||
|
||||
;;;; Link
|
||||
|
||||
(defun org-element-link-parser ()
|
||||
"Parse link at point.
|
||||
|
||||
|
@ -1914,8 +1969,8 @@ Assume point is at the beginning of the link."
|
|||
;; LINK-END variable.
|
||||
(setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t"))
|
||||
end (point))
|
||||
(list 'link
|
||||
`(:type ,type
|
||||
`(link
|
||||
(:type ,type
|
||||
:path ,path
|
||||
:raw-link ,(or raw-link path)
|
||||
:begin ,begin
|
||||
|
@ -1950,7 +2005,9 @@ beginning position."
|
|||
(when (re-search-forward link-regexp limit t)
|
||||
(cons 'link (match-beginning 0))))))
|
||||
|
||||
|
||||
;;;; Macro
|
||||
|
||||
(defun org-element-macro-parser ()
|
||||
"Parse macro at point.
|
||||
|
||||
|
@ -1978,8 +2035,8 @@ Assume point is at the macro."
|
|||
(pop args))
|
||||
(push (pop args) args2))
|
||||
(mapcar 'org-trim (nreverse args2))))))
|
||||
(list 'macro
|
||||
`(:key ,key
|
||||
`(macro
|
||||
(:key ,key
|
||||
:value ,value
|
||||
:args ,args
|
||||
:begin ,begin
|
||||
|
@ -2004,7 +2061,9 @@ beginning position."
|
|||
limit t)
|
||||
(cons 'macro (match-beginning 0)))))
|
||||
|
||||
|
||||
;;;; Radio-target
|
||||
|
||||
(defun org-element-radio-target-parser ()
|
||||
"Parse radio target at point.
|
||||
|
||||
|
@ -2022,8 +2081,8 @@ Assume point is at the radio target."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'radio-target
|
||||
`(:begin ,begin
|
||||
`(radio-target
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,contents-begin
|
||||
:contents-end ,contents-end
|
||||
|
@ -2046,7 +2105,9 @@ is beginning position."
|
|||
(when (re-search-forward org-radio-target-regexp limit t)
|
||||
(cons 'radio-target (match-beginning 0)))))
|
||||
|
||||
|
||||
;;;; Statistics Cookie
|
||||
|
||||
(defun org-element-statistics-cookie-parser ()
|
||||
"Parse statistics cookie at point.
|
||||
|
||||
|
@ -2062,8 +2123,8 @@ Assume point is at the beginning of the statistics-cookie."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'statistics-cookie
|
||||
`(:begin ,begin
|
||||
`(statistics-cookie
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
:post-blank ,post-blank)))))
|
||||
|
@ -2084,7 +2145,9 @@ cdr is beginning position."
|
|||
(when (re-search-forward "\\[[0-9]*\\(%\\|/[0-9]*\\)\\]" limit t)
|
||||
(cons 'statistics-cookie (match-beginning 0)))))
|
||||
|
||||
|
||||
;;;; Subscript
|
||||
|
||||
(defun org-element-subscript-parser ()
|
||||
"Parse subscript at point.
|
||||
|
||||
|
@ -2105,8 +2168,8 @@ Assume point is at the underscore."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'subscript
|
||||
`(:begin ,begin
|
||||
`(subscript
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:use-brackets-p ,bracketsp
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -2133,7 +2196,9 @@ Return value is a cons cell whose car is either `subscript' or
|
|||
(cons (if (string= (match-string 2) "_") 'subscript 'superscript)
|
||||
(match-beginning 2)))))
|
||||
|
||||
|
||||
;;;; Superscript
|
||||
|
||||
(defun org-element-superscript-parser ()
|
||||
"Parse superscript at point.
|
||||
|
||||
|
@ -2154,8 +2219,8 @@ Assume point is at the caret."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'superscript
|
||||
`(:begin ,begin
|
||||
`(superscript
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:use-brackets-p ,bracketsp
|
||||
:contents-begin ,contents-begin
|
||||
|
@ -2169,7 +2234,9 @@ CONTENTS is the contents of the object."
|
|||
(if (org-element-get-property :use-brackets-p superscript) "^{%s}" "^%s")
|
||||
contents))
|
||||
|
||||
|
||||
;;;; Target
|
||||
|
||||
(defun org-element-target-parser ()
|
||||
"Parse target at point.
|
||||
|
||||
|
@ -2187,8 +2254,8 @@ Assume point is at the target."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'target
|
||||
`(:begin ,begin
|
||||
`(target
|
||||
(:begin ,begin
|
||||
:end ,end
|
||||
:contents-begin ,contents-begin
|
||||
:contents-end ,contents-end
|
||||
|
@ -2211,7 +2278,9 @@ beginning position."
|
|||
(when (re-search-forward org-target-regexp limit t)
|
||||
(cons 'target (match-beginning 0)))))
|
||||
|
||||
|
||||
;;;; Time-stamp
|
||||
|
||||
(defun org-element-time-stamp-parser ()
|
||||
"Parse time stamp at point.
|
||||
|
||||
|
@ -2248,8 +2317,8 @@ Assume point is at the beginning of the time-stamp."
|
|||
(post-blank (progn (goto-char (match-end 0))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'time-stamp
|
||||
`(:appt-type ,appt-type
|
||||
`(time-stamp
|
||||
(:appt-type ,appt-type
|
||||
:type ,type
|
||||
:value ,value
|
||||
:begin ,begin
|
||||
|
@ -2285,7 +2354,9 @@ beginning position."
|
|||
limit t)
|
||||
(cons 'time-stamp (match-beginning 0)))))
|
||||
|
||||
|
||||
;;;; Verbatim
|
||||
|
||||
(defun org-element-verbatim-parser ()
|
||||
"Parse verbatim object at point.
|
||||
|
||||
|
@ -2302,8 +2373,8 @@ Assume point is at the first verbatim marker."
|
|||
(post-blank (progn (goto-char (match-end 2))
|
||||
(skip-chars-forward " \t")))
|
||||
(end (point)))
|
||||
(list 'verbatim
|
||||
`(:marker ,marker
|
||||
`(verbatim
|
||||
(:marker ,marker
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
:value ,value
|
||||
|
@ -2483,6 +2554,7 @@ matching `org-element-parsed-keywords'.")
|
|||
;;
|
||||
;; Provide two accessors: `org-element-get-property' and
|
||||
;; `org-element-get-contents'.
|
||||
|
||||
(defun org-element-get-property (property element)
|
||||
"Extract the value from the PROPERTY of an ELEMENT."
|
||||
(plist-get (nth 1 element) property))
|
||||
|
@ -2505,6 +2577,7 @@ matching `org-element-parsed-keywords'.")
|
|||
;; corresponding `item' element. By default, `org-element-at-point'
|
||||
;; works at the `plain-list' level. But, by providing an optional
|
||||
;; argument, one can make it switch to the `item' level.
|
||||
|
||||
(defconst org-element--affiliated-re
|
||||
(format "[ \t]*#\\+\\(%s\\):"
|
||||
(mapconcat
|
||||
|
@ -2609,6 +2682,7 @@ be computed."
|
|||
;; looking for a specific regexp in the current line, or by using
|
||||
;; already implemented functions. This is the goal of
|
||||
;; `org-element-guess-type'.
|
||||
|
||||
(defconst org-element--element-block-types
|
||||
(mapcar 'car org-element-non-recursive-block-alist)
|
||||
"List of non-recursive block types, as strings.
|
||||
|
@ -2667,8 +2741,7 @@ point is in a section in priority."
|
|||
((or (looking-at org-drawer-regexp) (looking-at "[ \t]*:END:[ \t]*$"))
|
||||
(let ((completep (org-between-regexps-p
|
||||
org-drawer-regexp "^[ \t]*:END:[ \t]*$")))
|
||||
(if (not completep)
|
||||
'paragraph
|
||||
(if (not completep) 'paragraph
|
||||
(goto-char (car completep)) 'drawer)))
|
||||
((looking-at "[ \t]*:\\( \\|$\\)") 'fixed-width)
|
||||
;; Babel calls must be tested before general keywords as they are
|
||||
|
@ -2685,8 +2758,7 @@ point is in a section in priority."
|
|||
(let ((completep (org-between-regexps-p
|
||||
"^[ \t]*#\\+begin:\\(?:\\s-\\|$\\)"
|
||||
"^[ \t]*#\\+end:\\(?:\\s-\\|$\\)")))
|
||||
(if (not completep)
|
||||
'paragraph
|
||||
(if (not completep) 'paragraph
|
||||
(goto-char (car completep)) 'dynamic-block)))
|
||||
((looking-at "\\(#\\|[ \t]*#\\+\\( \\|$\\)\\)") 'comment)
|
||||
((looking-at "[ \t]*-\\{5,\\}[ \t]*$") 'horizontal-rule)
|
||||
|
@ -2694,8 +2766,7 @@ point is in a section in priority."
|
|||
((looking-at "[ \t]*#\\+tblfm:")
|
||||
(forward-line -1)
|
||||
;; A TBLFM line separated from any table is just plain text.
|
||||
(if (org-at-table-p)
|
||||
'table
|
||||
(if (org-at-table-p) 'table
|
||||
(forward-line) 'paragraph))
|
||||
((looking-at (org-item-re)) 'plain-list))))
|
||||
|
||||
|
@ -2726,6 +2797,7 @@ point is in a section in priority."
|
|||
;; optional square brackets as the secondary one.
|
||||
|
||||
;; A keyword may belong to more than one category.
|
||||
|
||||
(defun org-element-collect-affiliated-keywords (&optional key-re trans-list
|
||||
consed parsed duals)
|
||||
"Collect affiliated keywords before point.
|
||||
|
@ -2809,6 +2881,7 @@ cdr a plist of keywords and values."
|
|||
;; parts of the parse tree, transparently walks into included files,
|
||||
;; and maintain a list of local properties (i.e. those inherited from
|
||||
;; parent headlines) for function's consumption.
|
||||
|
||||
(defun org-element-parse-buffer (&optional granularity visible-only)
|
||||
"Recursively parse the buffer and return structure.
|
||||
If narrowing is in effect, only parse the visible part of the
|
||||
|
@ -2991,6 +3064,7 @@ Nil values returned from FUN are ignored in the result."
|
|||
;; calls. Thus, searching for a given type fails only once, and every
|
||||
;; object is searched only once at top level (but sometimes more for
|
||||
;; nested types).
|
||||
|
||||
(defun org-element-parse-elements
|
||||
(beg end special structure granularity visible-only acc)
|
||||
"Parse ELEMENT with point at its beginning.
|
||||
|
@ -3140,11 +3214,9 @@ allowed in the current object."
|
|||
(let ((new-restr
|
||||
(cdr (assq (car next-object)
|
||||
org-element-object-restrictions))))
|
||||
(if (not restriction)
|
||||
new-restr
|
||||
(delq nil
|
||||
(mapcar (lambda (e)
|
||||
(and (memq e restriction) e))
|
||||
(if (not restriction) new-restr
|
||||
(delq nil (mapcar
|
||||
(lambda (e) (and (memq e restriction) e))
|
||||
new-restr))))))
|
||||
;; ... not recursive.
|
||||
next-object)
|
||||
|
@ -3173,13 +3245,11 @@ OBJECTS is the previous candidates alist."
|
|||
;; If no previous result, search every object type in RESTRICTION.
|
||||
;; Otherwise, keep potential candidates (old objects located after
|
||||
;; point) and ask to search again those which had matched before.
|
||||
(if objects
|
||||
(if (not objects) (setq types-to-search restriction)
|
||||
(mapc (lambda (obj)
|
||||
(if (< (cdr obj) (point))
|
||||
(push (car obj) types-to-search)
|
||||
(if (< (cdr obj) (point)) (push (car obj) types-to-search)
|
||||
(push obj next-candidates)))
|
||||
objects)
|
||||
(setq types-to-search restriction))
|
||||
objects))
|
||||
;; Call the appropriate "get-next" function for each type to
|
||||
;; search and accumulate matches.
|
||||
(mapc
|
||||
|
@ -3210,6 +3280,7 @@ OBJECTS is the previous candidates alist."
|
|||
;;
|
||||
;; Both functions rely internally on
|
||||
;; `org-element-interpret--affiliated-keywords'.
|
||||
|
||||
(defun org-element-interpret-data (data &optional genealogy previous)
|
||||
"Interpret a parse tree representing Org data.
|
||||
|
||||
|
@ -3232,8 +3303,7 @@ Return Org syntax as a string."
|
|||
(t
|
||||
(let* ((type (car blob))
|
||||
(interpreter
|
||||
(if (eq type 'org-data)
|
||||
'identity
|
||||
(if (eq type 'org-data) 'identity
|
||||
(intern (format "org-element-%s-interpreter" type))))
|
||||
(contents
|
||||
(cond
|
||||
|
@ -3333,6 +3403,7 @@ If there is no affiliated keyword, return the empty string."
|
|||
;;
|
||||
;; The second function, `org-element-normalize-contents', removes
|
||||
;; global indentation from the contents of the current element.
|
||||
|
||||
(defun org-element-normalize-string (s)
|
||||
"Ensure string S ends with a single newline character.
|
||||
|
||||
|
@ -3361,28 +3432,24 @@ Return the normalized element."
|
|||
(nconc
|
||||
(list (car element) (nth 1 element))
|
||||
(let ((contents (org-element-get-contents element)))
|
||||
(cond
|
||||
((and (not ignore-first) (not (stringp (car contents)))) contents)
|
||||
(t
|
||||
(if (not (or ignore-first (stringp (car contents)))) contents
|
||||
(catch 'exit
|
||||
;; 1. Remove tabs from each string in CONTENTS. Get maximal
|
||||
;; common indentation (MCI) along the way.
|
||||
(let* ((ind-list (unless ignore-first
|
||||
(list (org-get-string-indentation (car contents)))))
|
||||
(contents
|
||||
(mapcar (lambda (object)
|
||||
(if (not (stringp object))
|
||||
object
|
||||
(mapcar
|
||||
(lambda (object)
|
||||
(if (not (stringp object)) object
|
||||
(let ((start 0)
|
||||
(object (org-remove-tabs object)))
|
||||
(while (string-match "\n\\( *\\)" object start)
|
||||
(setq start (match-end 0))
|
||||
(push (length (match-string 1 object))
|
||||
ind-list))
|
||||
(push (length (match-string 1 object)) ind-list))
|
||||
object)))
|
||||
contents))
|
||||
(mci (if ind-list
|
||||
(apply 'min ind-list)
|
||||
(mci (if ind-list (apply 'min ind-list)
|
||||
(throw 'exit contents))))
|
||||
;; 2. Remove that indentation from CONTENTS. First string
|
||||
;; must be treated differently because it's the only one
|
||||
|
@ -3395,11 +3462,10 @@ Return the normalized element."
|
|||
(format "\\` \\{%d\\}" mci) "" first-obj)
|
||||
(cdr contents)))))
|
||||
(mapcar (lambda (object)
|
||||
(if (not (stringp object))
|
||||
object
|
||||
(if (not (stringp object)) object
|
||||
(replace-regexp-in-string
|
||||
(format "\n \\{%d\\}" mci) "\n" object)))
|
||||
contents))))))))
|
||||
contents)))))))
|
||||
|
||||
|
||||
|
||||
|
@ -3422,6 +3488,7 @@ Return the normalized element."
|
|||
|
||||
;; `org-element-nested-p' and `org-element-swap-A-B' are used
|
||||
;; internally by some of the previously cited tools.
|
||||
|
||||
(defsubst org-element-nested-p (elem-A elem-B)
|
||||
"Non-nil when elements ELEM-A and ELEM-B are nested."
|
||||
(let ((beg-A (org-element-get-property :begin elem-A))
|
||||
|
|
|
@ -1346,18 +1346,14 @@ Return transcoded string."
|
|||
;; the original buffer, and call appropriate filters.
|
||||
(when results
|
||||
;; No filter for a full document.
|
||||
(if (eq type 'org-data)
|
||||
results
|
||||
(if (eq type 'org-data) results
|
||||
(org-export-filter-apply-functions
|
||||
(eval (intern (format "org-export-filter-%s-functions" type)))
|
||||
(let ((post-blank (org-element-get-property :post-blank blob)))
|
||||
(if (memq type org-element-all-elements)
|
||||
(concat
|
||||
(org-element-normalize-string results)
|
||||
(make-string (org-element-get-property :post-blank blob) 10))
|
||||
(concat
|
||||
results
|
||||
(make-string
|
||||
(org-element-get-property :post-blank blob) 32)))
|
||||
(concat (org-element-normalize-string results)
|
||||
(make-string post-blank ?\n))
|
||||
(concat results (make-string post-blank ? ))))
|
||||
backend)))))))
|
||||
(org-element-get-contents data) ""))
|
||||
|
||||
|
|
Loading…
Reference in New Issue