1 ;;; org-element.el --- Parser And Applications for Org syntax
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; This file is not part of GNU Emacs.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ;; Org syntax can be divided into three categories: "Greater
26 ;; elements", "Elements" and "Objects".
28 ;; Elements are related to the structure of the document. Indeed, all
29 ;; elements are a cover for the document: each position within belongs
30 ;; to at least one element.
32 ;; An element always starts and ends at the beginning of a line. With
33 ;; a few exceptions (namely `babel-call', `clock', `headline', `item',
34 ;; `keyword', `planning', `property-drawer' and `section' types), it
35 ;; can also accept a fixed set of keywords as attributes. Those are
36 ;; called "affiliated keywords" to distinguish them from other
37 ;; keywords, which are full-fledged elements. Almost all affiliated
38 ;; keywords are referenced in `org-element-affiliated-keywords'; the
39 ;; others are export attributes and start with "ATTR_" prefix.
41 ;; Element containing other elements (and only elements) are called
42 ;; greater elements. Concerned types are: `center-block', `drawer',
43 ;; `dynamic-block', `footnote-definition', `headline', `inlinetask',
44 ;; `item', `plain-list', `quote-block', `section' and `special-block'.
46 ;; Other element types are: `babel-call', `clock', `comment',
47 ;; `comment-block', `example-block', `export-block', `fixed-width',
48 ;; `horizontal-rule', `keyword', `latex-environment', `paragraph',
49 ;; `planning', `property-drawer', `quote-section', `src-block',
50 ;; `table', `table-row' and `verse-block'. Among them, `paragraph'
51 ;; and `verse-block' types can contain Org objects and plain text.
53 ;; Objects are related to document's contents. Some of them are
54 ;; recursive. Associated types are of the following: `bold', `code',
55 ;; `entity', `export-snippet', `footnote-reference',
56 ;; `inline-babel-call', `inline-src-block', `italic',
57 ;; `latex-fragment', `line-break', `link', `macro', `radio-target',
58 ;; `statistics-cookie', `strike-through', `subscript', `superscript',
59 ;; `table-cell', `target', `timestamp', `underline' and `verbatim'.
61 ;; Some elements also have special properties whose value can hold
62 ;; objects themselves (i.e. an item tag or an headline name). Such
63 ;; values are called "secondary strings". Any object belongs to
64 ;; either an element or a secondary string.
66 ;; Notwithstanding affiliated keywords, each greater element, element
67 ;; and object has a fixed set of properties attached to it. Among
68 ;; them, four are shared by all types: `:begin' and `:end', which
69 ;; refer to the beginning and ending buffer positions of the
70 ;; considered element or object, `:post-blank', which holds the number
71 ;; of blank lines, or white spaces, at its end and `:parent' which
72 ;; refers to the element or object containing it. Greater elements
73 ;; and elements containing objects will also have `:contents-begin'
74 ;; and `:contents-end' properties to delimit contents.
76 ;; Lisp-wise, an element or an object can be represented as a list.
77 ;; It follows the pattern (TYPE PROPERTIES CONTENTS), where:
78 ;; TYPE is a symbol describing the Org element or object.
79 ;; PROPERTIES is the property list attached to it. See docstring of
80 ;; appropriate parsing function to get an exhaustive
82 ;; CONTENTS is a list of elements, objects or raw strings contained
83 ;; in the current element or object, when applicable.
85 ;; An Org buffer is a nested list of such elements and objects, whose
86 ;; type is `org-data' and properties is nil.
88 ;; The first part of this file defines Org syntax, while the second
89 ;; one provide accessors and setters functions.
91 ;; The next part implements a parser and an interpreter for each
92 ;; element and object type in Org syntax.
94 ;; The following part creates a fully recursive buffer parser. It
95 ;; also provides a tool to map a function to elements or objects
96 ;; matching some criteria in the parse tree. Functions of interest
97 ;; are `org-element-parse-buffer', `org-element-map' and, to a lesser
98 ;; extent, `org-element-parse-secondary-string'.
100 ;; The penultimate part is the cradle of an interpreter for the
101 ;; obtained parse tree: `org-element-interpret-data'.
103 ;; The library ends by furnishing `org-element-at-point' function, and
104 ;; a way to give information about document structure around point
105 ;; with `org-element-context'.
116 ;;; Definitions And Rules
118 ;; Define elements, greater elements and specify recursive objects,
119 ;; along with the affiliated keywords recognized. Also set up
120 ;; restrictions on recursive objects combinations.
122 ;; These variables really act as a control center for the parsing
125 (defconst org-element-paragraph-separate
127 ;; Headlines, inlinetasks.
128 org-outline-regexp
"\\|"
129 ;; Footnote definitions.
130 "\\[\\(?:[0-9]+\\|fn:[-_[:word:]]+\\)\\]" "\\|"
134 ;; Tables (any type).
135 "\\(?:|\\|\\+-[-+]\\)" "\\|"
136 ;; Blocks (any type), Babel calls, drawers (any type),
137 ;; fixed-width areas and keywords. Note: this is only an
138 ;; indication and need some thorough check.
141 "-\\{5,\\}[ \t]*$" "\\|"
142 ;; LaTeX environments.
143 "\\\\begin{\\([A-Za-z0-9]+\\*?\\)}" "\\|"
144 ;; Planning and Clock lines.
145 (regexp-opt (list org-scheduled-string
151 (let ((term (case org-plain-list-ordered-item-terminator
152 (?\
) ")") (?.
"\\.") (otherwise "[.)]")))
153 (alpha (and org-alphabetical-lists
"\\|[A-Za-z]")))
154 (concat "\\(?:[-+*]\\|\\(?:[0-9]+" alpha
"\\)" term
"\\)"
155 "\\(?:[ \t]\\|$\\)"))
157 "Regexp to separate paragraphs in an Org buffer.
158 In the case of lines starting with \"#\" and \":\", this regexp
159 is not sufficient to know if point is at a paragraph ending. See
160 `org-element-paragraph-parser' for more information.")
162 (defconst org-element-all-elements
163 '(center-block clock comment comment-block drawer dynamic-block example-block
164 export-block fixed-width footnote-definition headline
165 horizontal-rule inlinetask item keyword latex-environment
166 babel-call paragraph plain-list planning property-drawer
167 quote-block quote-section section special-block src-block table
168 table-row verse-block
)
169 "Complete list of element types.")
171 (defconst org-element-greater-elements
172 '(center-block drawer dynamic-block footnote-definition headline inlinetask
173 item plain-list quote-block section special-block table
)
174 "List of recursive element types aka Greater Elements.")
176 (defconst org-element-all-successors
177 '(export-snippet footnote-reference inline-babel-call inline-src-block
178 latex-or-entity line-break link macro radio-target
179 statistics-cookie sub
/superscript table-cell target
180 text-markup timestamp
)
181 "Complete list of successors.")
183 (defconst org-element-object-successor-alist
184 '((subscript . sub
/superscript
) (superscript . sub
/superscript
)
185 (bold . text-markup
) (code . text-markup
) (italic . text-markup
)
186 (strike-through . text-markup
) (underline . text-markup
)
187 (verbatim . text-markup
) (entity . latex-or-entity
)
188 (latex-fragment . latex-or-entity
))
189 "Alist of translations between object type and successor name.
191 Sharing the same successor comes handy when, for example, the
192 regexp matching one object can also match the other object.")
194 (defconst org-element-all-objects
195 '(bold code entity export-snippet footnote-reference inline-babel-call
196 inline-src-block italic line-break latex-fragment link macro
197 radio-target statistics-cookie strike-through subscript superscript
198 table-cell target timestamp underline verbatim
)
199 "Complete list of object types.")
201 (defconst org-element-recursive-objects
202 '(bold italic link macro subscript radio-target strike-through superscript
203 table-cell underline
)
204 "List of recursive object types.")
206 (defconst org-element-block-name-alist
207 '(("CENTER" . org-element-center-block-parser
)
208 ("COMMENT" . org-element-comment-block-parser
)
209 ("EXAMPLE" . org-element-example-block-parser
)
210 ("QUOTE" . org-element-quote-block-parser
)
211 ("SRC" . org-element-src-block-parser
)
212 ("VERSE" . org-element-verse-block-parser
))
213 "Alist between block names and the associated parsing function.
214 Names must be uppercase. Any block whose name has no association
215 is parsed with `org-element-special-block-parser'.")
217 (defconst org-element-affiliated-keywords
218 '("CAPTION" "DATA" "HEADER" "HEADERS" "LABEL" "NAME" "PLOT" "RESNAME" "RESULT"
219 "RESULTS" "SOURCE" "SRCNAME" "TBLNAME")
220 "List of affiliated keywords as strings.
221 By default, all keywords setting attributes (i.e. \"ATTR_LATEX\")
222 are affiliated keywords and need not to be in this list.")
224 (defconst org-element--affiliated-re
225 (format "[ \t]*#\\+%s:"
226 ;; Regular affiliated keywords.
227 (format "\\(%s\\|ATTR_[-_A-Za-z0-9]+\\)\\(?:\\[\\(.*\\)\\]\\)?"
228 (regexp-opt org-element-affiliated-keywords
)))
229 "Regexp matching any affiliated keyword.
231 Keyword name is put in match group 1. Moreover, if keyword
232 belongs to `org-element-dual-keywords', put the dual value in
235 Don't modify it, set `org-element-affiliated-keywords' instead.")
237 (defconst org-element-keyword-translation-alist
238 '(("DATA" .
"NAME") ("LABEL" .
"NAME") ("RESNAME" .
"NAME")
239 ("SOURCE" .
"NAME") ("SRCNAME" .
"NAME") ("TBLNAME" .
"NAME")
240 ("RESULT" .
"RESULTS") ("HEADERS" .
"HEADER"))
241 "Alist of usual translations for keywords.
242 The key is the old name and the value the new one. The property
243 holding their value will be named after the translated name.")
245 (defconst org-element-multiple-keywords
'("HEADER")
246 "List of affiliated keywords that can occur more that once in an element.
248 Their value will be consed into a list of strings, which will be
249 returned as the value of the property.
251 This list is checked after translations have been applied. See
252 `org-element-keyword-translation-alist'.
254 By default, all keywords setting attributes (i.e. \"ATTR_LATEX\")
255 allow multiple occurrences and need not to be in this list.")
257 (defconst org-element-parsed-keywords
'("AUTHOR" "CAPTION" "DATE" "TITLE")
258 "List of keywords whose value can be parsed.
260 Their value will be stored as a secondary string: a list of
263 This list is checked after translations have been applied. See
264 `org-element-keyword-translation-alist'.")
266 (defconst org-element-dual-keywords
'("CAPTION" "RESULTS")
267 "List of keywords which can have a secondary value.
269 In Org syntax, they can be written with optional square brackets
270 before the colons. For example, results keyword can be
271 associated to a hash value with the following:
273 #+RESULTS[hash-string]: some-source
275 This list is checked after translations have been applied. See
276 `org-element-keyword-translation-alist'.")
278 (defconst org-element-object-restrictions
279 '((bold export-snippet inline-babel-call inline-src-block latex-or-entity link
280 radio-target sub
/superscript target text-markup timestamp
)
281 (footnote-reference export-snippet footnote-reference inline-babel-call
282 inline-src-block latex-or-entity line-break link macro
283 radio-target sub
/superscript target text-markup
285 (headline inline-babel-call inline-src-block latex-or-entity link macro
286 radio-target statistics-cookie sub
/superscript target text-markup
288 (inlinetask inline-babel-call inline-src-block latex-or-entity link macro
289 radio-target sub
/superscript target text-markup timestamp
)
290 (italic export-snippet inline-babel-call inline-src-block latex-or-entity
291 link radio-target sub
/superscript target text-markup timestamp
)
292 (item export-snippet footnote-reference inline-babel-call latex-or-entity
293 link macro radio-target sub
/superscript target text-markup
)
294 (keyword latex-or-entity macro sub
/superscript text-markup
)
295 (link export-snippet inline-babel-call inline-src-block latex-or-entity link
296 sub
/superscript text-markup
)
298 (paragraph export-snippet footnote-reference inline-babel-call
299 inline-src-block latex-or-entity line-break link macro
300 radio-target statistics-cookie sub
/superscript target text-markup
302 (radio-target export-snippet latex-or-entity sub
/superscript
)
303 (strike-through export-snippet inline-babel-call inline-src-block
304 latex-or-entity link radio-target sub
/superscript target
305 text-markup timestamp
)
306 (subscript export-snippet inline-babel-call inline-src-block latex-or-entity
307 sub
/superscript target text-markup
)
308 (superscript export-snippet inline-babel-call inline-src-block
309 latex-or-entity sub
/superscript target text-markup
)
310 (table-cell export-snippet latex-or-entity link macro radio-target
311 sub
/superscript target text-markup timestamp
)
312 (table-row table-cell
)
313 (underline export-snippet inline-babel-call inline-src-block latex-or-entity
314 link radio-target sub
/superscript target text-markup timestamp
)
315 (verse-block footnote-reference inline-babel-call inline-src-block
316 latex-or-entity line-break link macro radio-target
317 sub
/superscript target text-markup timestamp
))
318 "Alist of objects restrictions.
320 CAR is an element or object type containing objects and CDR is
321 a list of successors that will be called within an element or
324 For example, in a `radio-target' object, one can only find
325 entities, export snippets, latex-fragments, subscript and
328 This alist also applies to secondary string. For example, an
329 `headline' type element doesn't directly contain objects, but
330 still has an entry since one of its properties (`:title') does.")
332 (defconst org-element-secondary-value-alist
333 '((headline .
:title
)
334 (inlinetask .
:title
)
336 (footnote-reference .
:inline-definition
))
337 "Alist between element types and location of secondary value.")
341 ;;; Accessors and Setters
343 ;; Provide four accessors: `org-element-type', `org-element-property'
344 ;; `org-element-contents' and `org-element-restriction'.
346 ;; Setter functions allow to modify elements by side effect. There is
347 ;; `org-element-put-property', `org-element-set-contents',
348 ;; `org-element-set-element' and `org-element-adopt-element'. Note
349 ;; that `org-element-set-element' and `org-element-adopt-elements' are
350 ;; higher level functions since also update `:parent' property.
352 (defsubst org-element-type
(element)
353 "Return type of ELEMENT.
355 The function returns the type of the element or object provided.
356 It can also return the following special value:
357 `plain-text' for a string
358 `org-data' for a complete document
359 nil in any other case."
361 ((not (consp element
)) (and (stringp element
) 'plain-text
))
362 ((symbolp (car element
)) (car element
))))
364 (defsubst org-element-property
(property element
)
365 "Extract the value from the PROPERTY of an ELEMENT."
366 (plist-get (nth 1 element
) property
))
368 (defsubst org-element-contents
(element)
369 "Extract contents from an ELEMENT."
370 (and (consp element
) (nthcdr 2 element
)))
372 (defsubst org-element-restriction
(element)
373 "Return restriction associated to ELEMENT.
374 ELEMENT can be an element, an object or a symbol representing an
375 element or object type."
376 (cdr (assq (if (symbolp element
) element
(org-element-type element
))
377 org-element-object-restrictions
)))
379 (defsubst org-element-put-property
(element property value
)
380 "In ELEMENT set PROPERTY to VALUE.
381 Return modified element."
382 (when (consp element
)
383 (setcar (cdr element
) (plist-put (nth 1 element
) property value
)))
386 (defsubst org-element-set-contents
(element &rest contents
)
387 "Set ELEMENT contents to CONTENTS.
388 Return modified element."
389 (cond ((not element
) (list contents
))
390 ((cdr element
) (setcdr (cdr element
) contents
))
391 (t (nconc element contents
))))
393 (defsubst org-element-set-element
(old new
)
394 "Replace element or object OLD with element or object NEW.
395 The function takes care of setting `:parent' property for NEW."
396 ;; Since OLD is going to be changed into NEW by side-effect, first
397 ;; make sure that every element or object within NEW has OLD as
399 (mapc (lambda (blob) (org-element-put-property blob
:parent old
))
400 (org-element-contents new
))
401 ;; Transfer contents.
402 (apply 'org-element-set-contents old
(org-element-contents new
))
403 ;; Ensure NEW has same parent as OLD, then overwrite OLD properties
405 (org-element-put-property new
:parent
(org-element-property :parent old
))
406 (setcar (cdr old
) (nth 1 new
))
408 (setcar old
(car new
)))
410 (defsubst org-element-adopt-elements
(parent &rest children
)
411 "Append elements to the contents of another element.
413 PARENT is an element or object. CHILDREN can be elements,
414 objects, or a strings.
416 The function takes care of setting `:parent' property for CHILD.
417 Return parent element."
418 (if (not parent
) children
419 ;; Link every child to PARENT.
420 (mapc (lambda (child)
421 (unless (stringp child
)
422 (org-element-put-property child
:parent parent
)))
424 ;; Add CHILDREN at the end of PARENT contents.
425 (apply 'org-element-set-contents
427 (nconc (org-element-contents parent
) children
))
428 ;; Return modified PARENT element.
435 ;; For each greater element type, we define a parser and an
438 ;; A parser returns the element or object as the list described above.
439 ;; Most of them accepts no argument. Though, exceptions exist. Hence
440 ;; every element containing a secondary string (see
441 ;; `org-element-secondary-value-alist') will accept an optional
442 ;; argument to toggle parsing of that secondary string. Moreover,
443 ;; `item' parser requires current list's structure as its first
446 ;; An interpreter accepts two arguments: the list representation of
447 ;; the element or object, and its contents. The latter may be nil,
448 ;; depending on the element or object considered. It returns the
449 ;; appropriate Org syntax, as a string.
451 ;; Parsing functions must follow the naming convention:
452 ;; org-element-TYPE-parser, where TYPE is greater element's type, as
453 ;; defined in `org-element-greater-elements'.
455 ;; Similarly, interpreting functions must follow the naming
456 ;; convention: org-element-TYPE-interpreter.
458 ;; With the exception of `headline' and `item' types, greater elements
459 ;; cannot contain other greater elements of their own type.
461 ;; Beside implementing a parser and an interpreter, adding a new
462 ;; greater element requires to tweak `org-element--current-element'.
463 ;; Moreover, the newly defined type must be added to both
464 ;; `org-element-all-elements' and `org-element-greater-elements'.
469 (defun org-element-center-block-parser (limit)
470 "Parse a center block.
472 LIMIT bounds the search.
474 Return a list whose CAR is `center-block' and CDR is a plist
475 containing `:begin', `:end', `:hiddenp', `:contents-begin',
476 `:contents-end' and `:post-blank' keywords.
478 Assume point is at the beginning of the block."
479 (let ((case-fold-search t
))
480 (if (not (save-excursion
481 (re-search-forward "^[ \t]*#\\+END_CENTER" limit t
)))
482 ;; Incomplete block: parse it as a paragraph.
483 (org-element-paragraph-parser limit
)
484 (let ((block-end-line (match-beginning 0)))
485 (let* ((keywords (org-element--collect-affiliated-keywords))
486 (begin (car keywords
))
487 ;; Empty blocks have no contents.
488 (contents-begin (progn (forward-line)
489 (and (< (point) block-end-line
)
491 (contents-end (and contents-begin block-end-line
))
492 (hidden (org-invisible-p2))
493 (pos-before-blank (progn (goto-char block-end-line
)
496 (end (save-excursion (skip-chars-forward " \r\t\n" limit
)
497 (if (eobp) (point) (point-at-bol)))))
503 :contents-begin contents-begin
504 :contents-end contents-end
505 :post-blank
(count-lines pos-before-blank end
))
506 (cadr keywords
))))))))
508 (defun org-element-center-block-interpreter (center-block contents
)
509 "Interpret CENTER-BLOCK element as Org syntax.
510 CONTENTS is the contents of the element."
511 (format "#+BEGIN_CENTER\n%s#+END_CENTER" contents
))
516 (defun org-element-drawer-parser (limit)
519 LIMIT bounds the search.
521 Return a list whose CAR is `drawer' and CDR is a plist containing
522 `:drawer-name', `:begin', `:end', `:hiddenp', `:contents-begin',
523 `:contents-end' and `:post-blank' keywords.
525 Assume point is at beginning of drawer."
526 (let ((case-fold-search t
))
527 (if (not (save-excursion (re-search-forward "^[ \t]*:END:" limit t
)))
528 ;; Incomplete drawer: parse it as a paragraph.
529 (org-element-paragraph-parser limit
)
530 (let ((drawer-end-line (match-beginning 0)))
532 (let* ((case-fold-search t
)
533 (name (progn (looking-at org-drawer-regexp
)
534 (org-match-string-no-properties 1)))
535 (keywords (org-element--collect-affiliated-keywords))
536 (begin (car keywords
))
537 ;; Empty drawers have no contents.
538 (contents-begin (progn (forward-line)
539 (and (< (point) drawer-end-line
)
541 (contents-end (and contents-begin drawer-end-line
))
542 (hidden (org-invisible-p2))
543 (pos-before-blank (progn (goto-char drawer-end-line
)
546 (end (progn (skip-chars-forward " \r\t\n" limit
)
547 (if (eobp) (point) (point-at-bol)))))
554 :contents-begin contents-begin
555 :contents-end contents-end
556 :post-blank
(count-lines pos-before-blank end
))
557 (cadr keywords
)))))))))
559 (defun org-element-drawer-interpreter (drawer contents
)
560 "Interpret DRAWER element as Org syntax.
561 CONTENTS is the contents of the element."
562 (format ":%s:\n%s:END:"
563 (org-element-property :drawer-name drawer
)
569 (defun org-element-dynamic-block-parser (limit)
570 "Parse a dynamic block.
572 LIMIT bounds the search.
574 Return a list whose CAR is `dynamic-block' and CDR is a plist
575 containing `:block-name', `:begin', `:end', `:hiddenp',
576 `:contents-begin', `:contents-end', `:arguments' and
577 `:post-blank' keywords.
579 Assume point is at beginning of dynamic block."
580 (let ((case-fold-search t
))
581 (if (not (save-excursion (re-search-forward org-dblock-end-re limit t
)))
582 ;; Incomplete block: parse it as a paragraph.
583 (org-element-paragraph-parser limit
)
584 (let ((block-end-line (match-beginning 0)))
586 (let* ((name (progn (looking-at org-dblock-start-re
)
587 (org-match-string-no-properties 1)))
588 (arguments (org-match-string-no-properties 3))
589 (keywords (org-element--collect-affiliated-keywords))
590 (begin (car keywords
))
591 ;; Empty blocks have no contents.
592 (contents-begin (progn (forward-line)
593 (and (< (point) block-end-line
)
595 (contents-end (and contents-begin block-end-line
))
596 (hidden (org-invisible-p2))
597 (pos-before-blank (progn (goto-char block-end-line
)
600 (end (progn (skip-chars-forward " \r\t\n" limit
)
601 (if (eobp) (point) (point-at-bol)))))
609 :contents-begin contents-begin
610 :contents-end contents-end
611 :post-blank
(count-lines pos-before-blank end
))
612 (cadr keywords
)))))))))
614 (defun org-element-dynamic-block-interpreter (dynamic-block contents
)
615 "Interpret DYNAMIC-BLOCK element as Org syntax.
616 CONTENTS is the contents of the element."
617 (format "#+BEGIN: %s%s\n%s#+END:"
618 (org-element-property :block-name dynamic-block
)
619 (let ((args (org-element-property :arguments dynamic-block
)))
620 (and args
(concat " " args
)))
624 ;;;; Footnote Definition
626 (defun org-element-footnote-definition-parser (limit)
627 "Parse a footnote definition.
629 LIMIT bounds the search.
631 Return a list whose CAR is `footnote-definition' and CDR is
632 a plist containing `:label', `:begin' `:end', `:contents-begin',
633 `:contents-end' and `:post-blank' keywords.
635 Assume point is at the beginning of the footnote definition."
637 (let* ((label (progn (looking-at org-footnote-definition-re
)
638 (org-match-string-no-properties 1)))
639 (keywords (org-element--collect-affiliated-keywords))
640 (begin (car keywords
))
641 (ending (save-excursion
645 (concat org-outline-regexp-bol
"\\|"
646 org-footnote-definition-re
"\\|"
647 "^[ \t]*$") limit
'move
))
650 (contents-begin (progn (search-forward "]")
651 (skip-chars-forward " \r\t\n" ending
)
652 (and (/= (point) ending
) (point))))
653 (contents-end (and contents-begin ending
))
654 (end (progn (goto-char ending
)
655 (skip-chars-forward " \r\t\n" limit
)
656 (if (eobp) (point) (point-at-bol)))))
657 (list 'footnote-definition
662 :contents-begin contents-begin
663 :contents-end contents-end
664 :post-blank
(count-lines ending end
))
667 (defun org-element-footnote-definition-interpreter (footnote-definition contents
)
668 "Interpret FOOTNOTE-DEFINITION element as Org syntax.
669 CONTENTS is the contents of the footnote-definition."
670 (concat (format "[%s]" (org-element-property :label footnote-definition
))
677 (defun org-element-headline-parser (limit &optional raw-secondary-p
)
680 Return a list whose CAR is `headline' and CDR is a plist
681 containing `:raw-value', `:title', `:begin', `:end',
682 `:pre-blank', `:hiddenp', `:contents-begin' and `:contents-end',
683 `:level', `:priority', `:tags', `:todo-keyword',`:todo-type',
684 `:scheduled', `:deadline', `:timestamp', `:clock', `:category',
685 `:quotedp', `:archivedp', `:commentedp' and `:footnote-section-p'
688 The plist also contains any property set in the property drawer,
689 with its name in lowercase, the underscores replaced with hyphens
690 and colons at the beginning (i.e. `:custom-id').
692 When RAW-SECONDARY-P is non-nil, headline's title will not be
693 parsed as a secondary string, but as a plain string instead.
695 Assume point is at beginning of the headline."
697 (let* ((components (org-heading-components))
698 (level (nth 1 components
))
699 (todo (nth 2 components
))
701 (and todo
(if (member todo org-done-keywords
) 'done
'todo
)))
702 (tags (let ((raw-tags (nth 5 components
)))
703 (and raw-tags
(org-split-string raw-tags
":"))))
704 (raw-value (nth 4 components
))
706 (let ((case-fold-search nil
))
707 (string-match (format "^%s +" org-quote-string
) raw-value
)))
709 (let ((case-fold-search nil
))
710 (string-match (format "^%s +" org-comment-string
) raw-value
)))
711 (archivedp (member org-archive-tag tags
))
712 (footnote-section-p (and org-footnote-section
713 (string= org-footnote-section raw-value
)))
714 ;; Normalize property names: ":SOME_PROP:" becomes
716 (standard-props (let (plist)
719 (let ((p-name (downcase (car p
))))
720 (while (string-match "_" p-name
)
722 (replace-match "-" nil nil p-name
)))
723 (setq p-name
(intern (concat ":" p-name
)))
725 (plist-put plist p-name
(cdr p
)))))
726 (org-entry-properties nil
'standard
))
728 (time-props (org-entry-properties nil
'special
"CLOCK"))
729 (scheduled (cdr (assoc "SCHEDULED" time-props
)))
730 (deadline (cdr (assoc "DEADLINE" time-props
)))
731 (clock (cdr (assoc "CLOCK" time-props
)))
732 (timestamp (cdr (assoc "TIMESTAMP" time-props
)))
734 (end (save-excursion (goto-char (org-end-of-subtree t t
))))
735 (pos-after-head (progn (forward-line) (point)))
736 (contents-begin (save-excursion
737 (skip-chars-forward " \r\t\n" end
)
738 (and (/= (point) end
) (line-beginning-position))))
739 (hidden (org-invisible-p2))
740 (contents-end (and contents-begin
741 (progn (goto-char end
)
742 (skip-chars-backward " \r\t\n")
745 ;; Clean RAW-VALUE from any quote or comment string.
746 (when (or quotedp commentedp
)
748 (replace-regexp-in-string
749 (concat "\\(" org-quote-string
"\\|" org-comment-string
"\\) +")
752 ;; Clean TAGS from archive tag, if any.
753 (when archivedp
(setq tags
(delete org-archive-tag tags
)))
757 (list :raw-value raw-value
761 (if (not contents-begin
) 0
762 (count-lines pos-after-head contents-begin
))
764 :contents-begin contents-begin
765 :contents-end contents-end
767 :priority
(nth 3 components
)
775 :post-blank
(count-lines
776 (if (not contents-end
) pos-after-head
777 (goto-char contents-end
)
781 :footnote-section-p footnote-section-p
783 :commentedp commentedp
786 (org-element-put-property
788 (if raw-secondary-p raw-value
789 (org-element-parse-secondary-string
790 raw-value
(org-element-restriction 'headline
) headline
)))))))
792 (defun org-element-headline-interpreter (headline contents
)
793 "Interpret HEADLINE element as Org syntax.
794 CONTENTS is the contents of the element."
795 (let* ((level (org-element-property :level headline
))
796 (todo (org-element-property :todo-keyword headline
))
797 (priority (org-element-property :priority headline
))
798 (title (org-element-interpret-data
799 (org-element-property :title headline
)))
800 (tags (let ((tag-list (if (org-element-property :archivedp headline
)
801 (cons org-archive-tag
802 (org-element-property :tags headline
))
803 (org-element-property :tags headline
))))
805 (format ":%s:" (mapconcat 'identity tag-list
":")))))
806 (commentedp (org-element-property :commentedp headline
))
807 (quotedp (org-element-property :quotedp headline
))
808 (pre-blank (or (org-element-property :pre-blank headline
) 0))
809 (heading (concat (make-string level ?
*)
810 (and todo
(concat " " todo
))
811 (and quotedp
(concat " " org-quote-string
))
812 (and commentedp
(concat " " org-comment-string
))
814 (format " [#%s]" (char-to-string priority
)))
815 (cond ((and org-footnote-section
816 (org-element-property
817 :footnote-section-p headline
))
818 (concat " " org-footnote-section
))
819 (title (concat " " title
))))))
824 ((zerop org-tags-column
) (format " %s" tags
))
825 ((< org-tags-column
0)
828 (max (- (+ org-tags-column
(length heading
) (length tags
))) 1)
833 (make-string (max (- org-tags-column
(length heading
)) 1) ?
)
835 (make-string (1+ pre-blank
) 10)
841 (defun org-element-inlinetask-parser (limit &optional raw-secondary-p
)
842 "Parse an inline task.
844 Return a list whose CAR is `inlinetask' and CDR is a plist
845 containing `:title', `:begin', `:end', `:hiddenp',
846 `:contents-begin' and `:contents-end', `:level', `:priority',
847 `:tags', `:todo-keyword', `:todo-type', `:scheduled',
848 `:deadline', `:timestamp', `:clock' and `:post-blank' keywords.
850 The plist also contains any property set in the property drawer,
851 with its name in lowercase, the underscores replaced with hyphens
852 and colons at the beginning (i.e. `:custom-id').
854 When optional argument RAW-SECONDARY-P is non-nil, inline-task's
855 title will not be parsed as a secondary string, but as a plain
858 Assume point is at beginning of the inline task."
860 (let* ((keywords (org-element--collect-affiliated-keywords))
861 (begin (car keywords
))
862 (components (org-heading-components))
863 (todo (nth 2 components
))
865 (if (member todo org-done-keywords
) 'done
'todo
)))
866 (tags (let ((raw-tags (nth 5 components
)))
867 (and raw-tags
(org-split-string raw-tags
":"))))
868 ;; Normalize property names: ":SOME_PROP:" becomes
870 (standard-props (let (plist)
873 (let ((p-name (downcase (car p
))))
874 (while (string-match "_" p-name
)
876 (replace-match "-" nil nil p-name
)))
877 (setq p-name
(intern (concat ":" p-name
)))
879 (plist-put plist p-name
(cdr p
)))))
880 (org-entry-properties nil
'standard
))
882 (time-props (org-entry-properties nil
'special
"CLOCK"))
883 (scheduled (cdr (assoc "SCHEDULED" time-props
)))
884 (deadline (cdr (assoc "DEADLINE" time-props
)))
885 (clock (cdr (assoc "CLOCK" time-props
)))
886 (timestamp (cdr (assoc "TIMESTAMP" time-props
)))
887 (task-end (save-excursion
889 (and (re-search-forward "^\\*+ END" limit t
)
890 (match-beginning 0))))
891 (contents-begin (progn (forward-line)
892 (and task-end
(< (point) task-end
) (point))))
893 (hidden (and contents-begin
(org-invisible-p2)))
894 (contents-end (and contents-begin task-end
))
895 (before-blank (if (not task-end
) (point)
899 (end (progn (skip-chars-forward " \r\t\n" limit
)
900 (if (eobp) (point) (point-at-bol))))
907 :contents-begin contents-begin
908 :contents-end contents-end
909 :level
(nth 1 components
)
910 :priority
(nth 3 components
)
918 :post-blank
(count-lines before-blank end
))
921 (org-element-put-property
923 (if raw-secondary-p
(nth 4 components
)
924 (org-element-parse-secondary-string
926 (org-element-restriction 'inlinetask
)
929 (defun org-element-inlinetask-interpreter (inlinetask contents
)
930 "Interpret INLINETASK element as Org syntax.
931 CONTENTS is the contents of inlinetask."
932 (let* ((level (org-element-property :level inlinetask
))
933 (todo (org-element-property :todo-keyword inlinetask
))
934 (priority (org-element-property :priority inlinetask
))
935 (title (org-element-interpret-data
936 (org-element-property :title inlinetask
)))
937 (tags (let ((tag-list (org-element-property :tags inlinetask
)))
939 (format ":%s:" (mapconcat 'identity tag-list
":")))))
940 (task (concat (make-string level ?
*)
941 (and todo
(concat " " todo
))
943 (format " [#%s]" (char-to-string priority
)))
944 (and title
(concat " " title
)))))
949 ((zerop org-tags-column
) (format " %s" tags
))
950 ((< org-tags-column
0)
953 (max (- (+ org-tags-column
(length task
) (length tags
))) 1)
958 (make-string (max (- org-tags-column
(length task
)) 1) ?
)
960 ;; Prefer degenerate inlinetasks when there are no
965 (make-string level ?
*) " END")))))
970 (defun org-element-item-parser (limit struct
&optional raw-secondary-p
)
973 STRUCT is the structure of the plain list.
975 Return a list whose CAR is `item' and CDR is a plist containing
976 `:bullet', `:begin', `:end', `:contents-begin', `:contents-end',
977 `:checkbox', `:counter', `:tag', `:structure', `:hiddenp' and
978 `:post-blank' keywords.
980 When optional argument RAW-SECONDARY-P is non-nil, item's tag, if
981 any, will not be parsed as a secondary string, but as a plain
984 Assume point is at the beginning of the item."
987 (looking-at org-list-full-item-re
)
988 (let* ((begin (point))
989 (bullet (org-match-string-no-properties 1))
990 (checkbox (let ((box (org-match-string-no-properties 3)))
991 (cond ((equal "[ ]" box
) 'off
)
992 ((equal "[X]" box
) 'on
)
993 ((equal "[-]" box
) 'trans
))))
994 (counter (let ((c (org-match-string-no-properties 2)))
998 ((string-match "[A-Za-z]" c
)
999 (- (string-to-char (upcase (match-string 0 c
)))
1001 ((string-match "[0-9]+" c
)
1002 (string-to-number (match-string 0 c
)))))))
1003 (end (save-excursion (goto-char (org-list-get-item-end begin struct
))
1004 (unless (bolp) (forward-line))
1008 ;; Ignore tags in un-ordered lists: they are just
1009 ;; a part of item's body.
1010 (if (and (match-beginning 4)
1011 (save-match-data (string-match "[.)]" bullet
)))
1014 (skip-chars-forward " \r\t\n" limit
)
1015 ;; If first line isn't empty, contents really start
1016 ;; at the text after item's meta-data.
1017 (if (= (point-at-bol) begin
) (point) (point-at-bol))))
1018 (hidden (progn (forward-line)
1019 (and (not (= (point) end
)) (org-invisible-p2))))
1020 (contents-end (progn (goto-char end
)
1021 (skip-chars-backward " \r\t\n")
1026 (list :bullet bullet
1029 ;; CONTENTS-BEGIN and CONTENTS-END may be
1030 ;; mixed up in the case of an empty item
1031 ;; separated from the next by a blank line.
1032 ;; Thus ensure the former is always the
1034 :contents-begin
(min contents-begin contents-end
)
1035 :contents-end
(max contents-begin contents-end
)
1040 :post-blank
(count-lines contents-end end
)))))
1041 (org-element-put-property
1043 (let ((raw-tag (org-list-get-tag begin struct
)))
1045 (if raw-secondary-p raw-tag
1046 (org-element-parse-secondary-string
1047 raw-tag
(org-element-restriction 'item
) item
))))))))
1049 (defun org-element-item-interpreter (item contents
)
1050 "Interpret ITEM element as Org syntax.
1051 CONTENTS is the contents of the element."
1052 (let* ((bullet (org-list-bullet-string (org-element-property :bullet item
)))
1053 (checkbox (org-element-property :checkbox item
))
1054 (counter (org-element-property :counter item
))
1055 (tag (let ((tag (org-element-property :tag item
)))
1056 (and tag
(org-element-interpret-data tag
))))
1057 ;; Compute indentation.
1058 (ind (make-string (length bullet
) 32))
1059 (item-starts-with-par-p
1060 (eq (org-element-type (car (org-element-contents item
)))
1065 (and counter
(format "[@%d] " counter
))
1070 (and tag
(format "%s :: " tag
))
1071 (let ((contents (replace-regexp-in-string
1072 "\\(^\\)[ \t]*\\S-" ind contents nil nil
1)))
1073 (if item-starts-with-par-p
(org-trim contents
)
1074 (concat "\n" contents
))))))
1079 (defun org-element-plain-list-parser (limit &optional structure
)
1080 "Parse a plain list.
1082 Optional argument STRUCTURE, when non-nil, is the structure of
1083 the plain list being parsed.
1085 Return a list whose CAR is `plain-list' and CDR is a plist
1086 containing `:type', `:begin', `:end', `:contents-begin' and
1087 `:contents-end', `:structure' and `:post-blank' keywords.
1089 Assume point is at the beginning of the list."
1091 (let* ((struct (or structure
(org-list-struct)))
1092 (prevs (org-list-prevs-alist struct
))
1093 (parents (org-list-parents-alist struct
))
1094 (type (org-list-get-list-type (point) struct prevs
))
1095 (contents-begin (point))
1096 (keywords (org-element--collect-affiliated-keywords))
1097 (begin (car keywords
))
1099 (progn (goto-char (org-list-get-list-end (point) struct prevs
))
1100 (unless (bolp) (forward-line))
1102 (end (progn (skip-chars-forward " \r\t\n" limit
)
1103 (if (eobp) (point) (point-at-bol)))))
1110 :contents-begin contents-begin
1111 :contents-end contents-end
1113 :post-blank
(count-lines contents-end end
))
1114 (cadr keywords
))))))
1116 (defun org-element-plain-list-interpreter (plain-list contents
)
1117 "Interpret PLAIN-LIST element as Org syntax.
1118 CONTENTS is the contents of the element."
1121 (goto-char (point-min))
1128 (defun org-element-quote-block-parser (limit)
1129 "Parse a quote block.
1131 LIMIT bounds the search.
1133 Return a list whose CAR is `quote-block' and CDR is a plist
1134 containing `:begin', `:end', `:hiddenp', `:contents-begin',
1135 `:contents-end' and `:post-blank' keywords.
1137 Assume point is at the beginning of the block."
1138 (let ((case-fold-search t
))
1139 (if (not (save-excursion
1140 (re-search-forward "^[ \t]*#\\+END_QUOTE" limit t
)))
1141 ;; Incomplete block: parse it as a paragraph.
1142 (org-element-paragraph-parser limit
)
1143 (let ((block-end-line (match-beginning 0)))
1145 (let* ((keywords (org-element--collect-affiliated-keywords))
1146 (begin (car keywords
))
1147 ;; Empty blocks have no contents.
1148 (contents-begin (progn (forward-line)
1149 (and (< (point) block-end-line
)
1151 (contents-end (and contents-begin block-end-line
))
1152 (hidden (org-invisible-p2))
1153 (pos-before-blank (progn (goto-char block-end-line
)
1156 (end (progn (skip-chars-forward " \r\t\n" limit
)
1157 (if (eobp) (point) (point-at-bol)))))
1163 :contents-begin contents-begin
1164 :contents-end contents-end
1165 :post-blank
(count-lines pos-before-blank end
))
1166 (cadr keywords
)))))))))
1168 (defun org-element-quote-block-interpreter (quote-block contents
)
1169 "Interpret QUOTE-BLOCK element as Org syntax.
1170 CONTENTS is the contents of the element."
1171 (format "#+BEGIN_QUOTE\n%s#+END_QUOTE" contents
))
1176 (defun org-element-section-parser (limit)
1179 LIMIT bounds the search.
1181 Return a list whose CAR is `section' and CDR is a plist
1182 containing `:begin', `:end', `:contents-begin', `contents-end'
1183 and `:post-blank' keywords."
1185 ;; Beginning of section is the beginning of the first non-blank
1186 ;; line after previous headline.
1187 (let ((begin (point))
1188 (end (progn (org-with-limited-levels (outline-next-heading))
1190 (pos-before-blank (progn (skip-chars-backward " \r\t\n")
1196 :contents-begin begin
1197 :contents-end pos-before-blank
1198 :post-blank
(count-lines pos-before-blank end
))))))
1200 (defun org-element-section-interpreter (section contents
)
1201 "Interpret SECTION element as Org syntax.
1202 CONTENTS is the contents of the element."
1208 (defun org-element-special-block-parser (limit)
1209 "Parse a special block.
1211 LIMIT bounds the search.
1213 Return a list whose CAR is `special-block' and CDR is a plist
1214 containing `:type', `:begin', `:end', `:hiddenp',
1215 `:contents-begin', `:contents-end' and `:post-blank' keywords.
1217 Assume point is at the beginning of the block."
1218 (let* ((case-fold-search t
)
1219 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(S-+\\)")
1220 (upcase (match-string-no-properties 1)))))
1221 (if (not (save-excursion
1222 (re-search-forward (concat "^[ \t]*#\\+END_" type
) limit t
)))
1223 ;; Incomplete block: parse it as a paragraph.
1224 (org-element-paragraph-parser limit
)
1225 (let ((block-end-line (match-beginning 0)))
1227 (let* ((keywords (org-element--collect-affiliated-keywords))
1228 (begin (car keywords
))
1229 ;; Empty blocks have no contents.
1230 (contents-begin (progn (forward-line)
1231 (and (< (point) block-end-line
)
1233 (contents-end (and contents-begin block-end-line
))
1234 (hidden (org-invisible-p2))
1235 (pos-before-blank (progn (goto-char block-end-line
)
1238 (end (progn (org-skip-whitespace)
1239 (if (eobp) (point) (point-at-bol)))))
1240 (list 'special-block
1246 :contents-begin contents-begin
1247 :contents-end contents-end
1248 :post-blank
(count-lines pos-before-blank end
))
1249 (cadr keywords
)))))))))
1251 (defun org-element-special-block-interpreter (special-block contents
)
1252 "Interpret SPECIAL-BLOCK element as Org syntax.
1253 CONTENTS is the contents of the element."
1254 (let ((block-type (org-element-property :type special-block
)))
1255 (format "#+BEGIN_%s\n%s#+END_%s" block-type contents block-type
)))
1261 ;; For each element, a parser and an interpreter are also defined.
1262 ;; Both follow the same naming convention used for greater elements.
1264 ;; Also, as for greater elements, adding a new element type is done
1265 ;; through the following steps: implement a parser and an interpreter,
1266 ;; tweak `org-element--current-element' so that it recognizes the new
1267 ;; type and add that new type to `org-element-all-elements'.
1269 ;; As a special case, when the newly defined type is a block type,
1270 ;; `org-element-block-name-alist' has to be modified accordingly.
1275 (defun org-element-babel-call-parser (limit)
1276 "Parse a babel call.
1278 LIMIT bounds the search.
1280 Return a list whose CAR is `babel-call' and CDR is a plist
1281 containing `:begin', `:end', `:info' and `:post-blank' as
1284 (let ((case-fold-search t
)
1285 (info (progn (looking-at org-babel-block-lob-one-liner-regexp
)
1286 (org-babel-lob-get-info)))
1287 (begin (point-at-bol))
1288 (pos-before-blank (progn (forward-line) (point)))
1289 (end (progn (skip-chars-forward " \r\t\n" limit
)
1290 (if (eobp) (point) (point-at-bol)))))
1295 :post-blank
(count-lines pos-before-blank end
))))))
1297 (defun org-element-babel-call-interpreter (babel-call contents
)
1298 "Interpret BABEL-CALL element as Org syntax.
1300 (let* ((babel-info (org-element-property :info babel-call
))
1301 (main (car babel-info
))
1302 (post-options (nth 1 babel-info
)))
1304 (if (not (string-match "\\[\\(\\[.*?\\]\\)\\]" main
)) main
1305 ;; Remove redundant square brackets.
1306 (replace-match (match-string 1 main
) nil nil main
))
1307 (and post-options
(format "[%s]" post-options
)))))
1312 (defun org-element-clock-parser (limit)
1315 LIMIT bounds the search.
1317 Return a list whose CAR is `clock' and CDR is a plist containing
1318 `:status', `:value', `:time', `:begin', `:end' and `:post-blank'
1321 (let* ((case-fold-search nil
)
1323 (value (progn (search-forward org-clock-string
(line-end-position) t
)
1324 (org-skip-whitespace)
1325 (looking-at "\\[.*\\]")
1326 (org-match-string-no-properties 0)))
1327 (time (and (progn (goto-char (match-end 0))
1328 (looking-at " +=> +\\(\\S-+\\)[ \t]*$"))
1329 (org-match-string-no-properties 1)))
1330 (status (if time
'closed
'running
))
1331 (post-blank (let ((before-blank (progn (forward-line) (point))))
1332 (skip-chars-forward " \r\t\n" limit
)
1333 (unless (eobp) (beginning-of-line))
1334 (count-lines before-blank
(point))))
1337 (list :status status
1342 :post-blank post-blank
)))))
1344 (defun org-element-clock-interpreter (clock contents
)
1345 "Interpret CLOCK element as Org syntax.
1347 (concat org-clock-string
" "
1348 (org-element-property :value clock
)
1349 (let ((time (org-element-property :time clock
)))
1354 (org-split-string time
":")))))))
1359 (defun org-element-comment-parser (limit)
1362 LIMIT bounds the search.
1364 Return a list whose CAR is `comment' and CDR is a plist
1365 containing `:begin', `:end', `:value' and `:post-blank'
1368 Assume point is at comment beginning."
1370 (let* ((keywords (org-element--collect-affiliated-keywords))
1371 (begin (car keywords
))
1372 (value (prog2 (looking-at "[ \t]*# ?")
1373 (buffer-substring-no-properties
1374 (match-end 0) (line-end-position))
1377 ;; Get comments ending.
1379 (while (and (< (point) limit
) (looking-at "[ \t]*#\\( \\|$\\)"))
1380 ;; Accumulate lines without leading hash and first
1385 (buffer-substring-no-properties
1386 (match-end 0) (line-end-position))))
1389 (end (progn (goto-char com-end
)
1390 (skip-chars-forward " \r\t\n" limit
)
1391 (if (eobp) (point) (point-at-bol)))))
1397 :post-blank
(count-lines com-end end
))
1398 (cadr keywords
))))))
1400 (defun org-element-comment-interpreter (comment contents
)
1401 "Interpret COMMENT element as Org syntax.
1403 (replace-regexp-in-string "^" "# " (org-element-property :value comment
)))
1408 (defun org-element-comment-block-parser (limit)
1409 "Parse an export block.
1411 LIMIT bounds the search.
1413 Return a list whose CAR is `comment-block' and CDR is a plist
1414 containing `:begin', `:end', `:hiddenp', `:value' and
1415 `:post-blank' keywords.
1417 Assume point is at comment block beginning."
1418 (let ((case-fold-search t
))
1419 (if (not (save-excursion
1420 (re-search-forward "^[ \t]*#\\+END_COMMENT" limit t
)))
1421 ;; Incomplete block: parse it as a paragraph.
1422 (org-element-paragraph-parser limit
)
1423 (let ((contents-end (match-beginning 0)))
1425 (let* ((keywords (org-element--collect-affiliated-keywords))
1426 (begin (car keywords
))
1427 (contents-begin (progn (forward-line) (point)))
1428 (hidden (org-invisible-p2))
1429 (pos-before-blank (progn (goto-char contents-end
)
1432 (end (progn (skip-chars-forward " \r\t\n" limit
)
1433 (if (eobp) (point) (point-at-bol))))
1434 (value (buffer-substring-no-properties
1435 contents-begin contents-end
)))
1436 (list 'comment-block
1442 :post-blank
(count-lines pos-before-blank end
))
1443 (cadr keywords
)))))))))
1445 (defun org-element-comment-block-interpreter (comment-block contents
)
1446 "Interpret COMMENT-BLOCK element as Org syntax.
1448 (format "#+BEGIN_COMMENT\n%s#+END_COMMENT"
1449 (org-remove-indentation (org-element-property :value comment-block
))))
1454 (defun org-element-example-block-parser (limit)
1455 "Parse an example block.
1457 LIMIT bounds the search.
1459 Return a list whose CAR is `example-block' and CDR is a plist
1460 containing `:begin', `:end', `:number-lines', `:preserve-indent',
1461 `:retain-labels', `:use-labels', `:label-fmt', `:hiddenp',
1462 `:switches', `:value' and `:post-blank' keywords."
1463 (let ((case-fold-search t
))
1464 (if (not (save-excursion
1465 (re-search-forward "^[ \t]*#\\+END_EXAMPLE" limit t
)))
1466 ;; Incomplete block: parse it as a paragraph.
1467 (org-element-paragraph-parser limit
)
1468 (let ((contents-end (match-beginning 0)))
1471 (progn (looking-at "^[ \t]*#\\+BEGIN_EXAMPLE\\(?: +\\(.*\\)\\)?")
1472 (org-match-string-no-properties 1)))
1473 ;; Switches analysis
1474 (number-lines (cond ((not switches
) nil
)
1475 ((string-match "-n\\>" switches
) 'new
)
1476 ((string-match "+n\\>" switches
) 'continued
)))
1477 (preserve-indent (and switches
(string-match "-i\\>" switches
)))
1478 ;; Should labels be retained in (or stripped from) example
1482 (not (string-match "-r\\>" switches
))
1483 (and number-lines
(string-match "-k\\>" switches
))))
1484 ;; What should code-references use - labels or
1488 (and retain-labels
(not (string-match "-k\\>" switches
)))))
1489 (label-fmt (and switches
1490 (string-match "-l +\"\\([^\"\n]+\\)\"" switches
)
1491 (match-string 1 switches
)))
1492 ;; Standard block parsing.
1493 (keywords (org-element--collect-affiliated-keywords))
1494 (begin (car keywords
))
1495 (contents-begin (progn (forward-line) (point)))
1496 (hidden (org-invisible-p2))
1497 (value (buffer-substring-no-properties contents-begin contents-end
))
1498 (pos-before-blank (progn (goto-char contents-end
)
1501 (end (progn (skip-chars-forward " \r\t\n" limit
)
1502 (if (eobp) (point) (point-at-bol)))))
1503 (list 'example-block
1509 :number-lines number-lines
1510 :preserve-indent preserve-indent
1511 :retain-labels retain-labels
1512 :use-labels use-labels
1513 :label-fmt label-fmt
1515 :post-blank
(count-lines pos-before-blank end
))
1516 (cadr keywords
)))))))))
1518 (defun org-element-example-block-interpreter (example-block contents
)
1519 "Interpret EXAMPLE-BLOCK element as Org syntax.
1521 (let ((switches (org-element-property :switches example-block
)))
1522 (concat "#+BEGIN_EXAMPLE" (and switches
(concat " " switches
)) "\n"
1523 (org-remove-indentation
1524 (org-element-property :value example-block
))
1530 (defun org-element-export-block-parser (limit)
1531 "Parse an export block.
1533 LIMIT bounds the search.
1535 Return a list whose CAR is `export-block' and CDR is a plist
1536 containing `:begin', `:end', `:type', `:hiddenp', `:value' and
1537 `:post-blank' keywords.
1539 Assume point is at export-block beginning."
1540 (let* ((case-fold-search t
)
1541 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
1542 (upcase (org-match-string-no-properties 1)))))
1543 (if (not (save-excursion
1544 (re-search-forward (concat "^[ \t]*#\\+END_" type
) limit t
)))
1545 ;; Incomplete block: parse it as a paragraph.
1546 (org-element-paragraph-parser limit
)
1547 (let ((contents-end (match-beginning 0)))
1549 (let* ((keywords (org-element--collect-affiliated-keywords))
1550 (begin (car keywords
))
1551 (contents-begin (progn (forward-line) (point)))
1552 (hidden (org-invisible-p2))
1553 (pos-before-blank (progn (goto-char contents-end
)
1556 (end (progn (skip-chars-forward " \r\t\n" limit
)
1557 (if (eobp) (point) (point-at-bol))))
1558 (value (buffer-substring-no-properties contents-begin
1567 :post-blank
(count-lines pos-before-blank end
))
1568 (cadr keywords
)))))))))
1570 (defun org-element-export-block-interpreter (export-block contents
)
1571 "Interpret EXPORT-BLOCK element as Org syntax.
1573 (let ((type (org-element-property :type export-block
)))
1574 (concat (format "#+BEGIN_%s\n" type
)
1575 (org-element-property :value export-block
)
1576 (format "#+END_%s" type
))))
1581 (defun org-element-fixed-width-parser (limit)
1582 "Parse a fixed-width section.
1584 LIMIT bounds the search.
1586 Return a list whose CAR is `fixed-width' and CDR is a plist
1587 containing `:begin', `:end', `:value' and `:post-blank' keywords.
1589 Assume point is at the beginning of the fixed-width area."
1591 (let* ((keywords (org-element--collect-affiliated-keywords))
1592 (begin (car keywords
))
1596 (while (and (< (point) limit
)
1597 (looking-at "[ \t]*:\\( \\|$\\)"))
1598 ;; Accumulate text without starting colons.
1601 (buffer-substring-no-properties
1602 (match-end 0) (point-at-eol))
1606 (end (progn (skip-chars-forward " \r\t\n" limit
)
1607 (if (eobp) (point) (point-at-bol)))))
1613 :post-blank
(count-lines end-area end
))
1614 (cadr keywords
))))))
1616 (defun org-element-fixed-width-interpreter (fixed-width contents
)
1617 "Interpret FIXED-WIDTH element as Org syntax.
1619 (replace-regexp-in-string
1620 "^" ": " (substring (org-element-property :value fixed-width
) 0 -
1)))
1623 ;;;; Horizontal Rule
1625 (defun org-element-horizontal-rule-parser (limit)
1626 "Parse an horizontal rule.
1628 LIMIT bounds the search.
1630 Return a list whose CAR is `horizontal-rule' and CDR is a plist
1631 containing `:begin', `:end' and `:post-blank' keywords."
1633 (let* ((keywords (org-element--collect-affiliated-keywords))
1634 (begin (car keywords
))
1635 (post-hr (progn (forward-line) (point)))
1636 (end (progn (skip-chars-forward " \r\t\n" limit
)
1637 (if (eobp) (point) (point-at-bol)))))
1638 (list 'horizontal-rule
1642 :post-blank
(count-lines post-hr end
))
1643 (cadr keywords
))))))
1645 (defun org-element-horizontal-rule-interpreter (horizontal-rule contents
)
1646 "Interpret HORIZONTAL-RULE element as Org syntax.
1653 (defun org-element-keyword-parser (limit)
1654 "Parse a keyword at point.
1656 LIMIT bounds the search.
1658 Return a list whose CAR is `keyword' and CDR is a plist
1659 containing `:key', `:value', `:begin', `:end' and `:post-blank'
1662 (let* ((case-fold-search t
)
1664 (key (progn (looking-at "[ \t]*#\\+\\(\\S-+\\):")
1665 (upcase (org-match-string-no-properties 1))))
1666 (value (org-trim (buffer-substring-no-properties
1667 (match-end 0) (point-at-eol))))
1668 (pos-before-blank (progn (forward-line) (point)))
1669 (end (progn (skip-chars-forward " \r\t\n" limit
)
1670 (if (eobp) (point) (point-at-bol)))))
1676 :post-blank
(count-lines pos-before-blank end
))))))
1678 (defun org-element-keyword-interpreter (keyword contents
)
1679 "Interpret KEYWORD element as Org syntax.
1682 (org-element-property :key keyword
)
1683 (org-element-property :value keyword
)))
1686 ;;;; Latex Environment
1688 (defun org-element-latex-environment-parser (limit)
1689 "Parse a LaTeX environment.
1691 LIMIT bounds the search.
1693 Return a list whose CAR is `latex-environment' and CDR is a plist
1694 containing `:begin', `:end', `:value' and `:post-blank'
1697 Assume point is at the beginning of the latex environment."
1699 (let* ((case-fold-search t
)
1700 (code-begin (point))
1701 (keywords (org-element--collect-affiliated-keywords))
1702 (begin (car keywords
))
1703 (env (progn (looking-at "^[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
1704 (regexp-quote (match-string 1))))
1706 (progn (re-search-forward (format "^[ \t]*\\\\end{%s}" env
) limit t
)
1709 (value (buffer-substring-no-properties code-begin code-end
))
1710 (end (progn (skip-chars-forward " \r\t\n" limit
)
1711 (if (eobp) (point) (point-at-bol)))))
1712 (list 'latex-environment
1717 :post-blank
(count-lines code-end end
))
1718 (cadr keywords
))))))
1720 (defun org-element-latex-environment-interpreter (latex-environment contents
)
1721 "Interpret LATEX-ENVIRONMENT element as Org syntax.
1723 (org-element-property :value latex-environment
))
1728 (defun org-element-paragraph-parser (limit)
1731 LIMIT bounds the search.
1733 Return a list whose CAR is `paragraph' and CDR is a plist
1734 containing `:begin', `:end', `:contents-begin' and
1735 `:contents-end' and `:post-blank' keywords.
1737 Assume point is at the beginning of the paragraph."
1739 (let* (;; INNER-PAR-P is non-nil when paragraph is at the
1740 ;; beginning of an item or a footnote reference. In that
1741 ;; case, we mustn't look for affiliated keywords since they
1742 ;; belong to the container.
1743 (inner-par-p (not (bolp)))
1744 (contents-begin (point))
1745 (keywords (unless inner-par-p
1746 (org-element--collect-affiliated-keywords)))
1747 (begin (if inner-par-p contents-begin
(car keywords
)))
1749 (let ((case-fold-search t
))
1751 (re-search-forward org-element-paragraph-separate limit
'm
)
1752 (while (and (/= (point) limit
)
1754 ;; Skip non-existent or incomplete drawer.
1757 (and (looking-at "[ \t]*:\\S-")
1758 (or (not (looking-at org-drawer-regexp
))
1759 (not (save-excursion
1761 "^[ \t]*:END:" limit t
)))))))
1762 ;; Stop at comments.
1765 (not (looking-at "[ \t]*#\\S-"))) nil
)
1766 ;; Skip incomplete dynamic blocks.
1769 (looking-at "[ \t]*#\\+BEGIN: "))
1770 (not (save-excursion
1772 "^[ \t]*\\+END:" limit t
))))
1773 ;; Skip incomplete blocks.
1776 (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)"))
1777 (not (save-excursion
1779 (concat "^[ \t]*#\\+END_"
1782 ;; Skip incomplete latex environments.
1785 (looking-at "^[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}"))
1786 (not (save-excursion
1788 (format "^[ \t]*\\\\end{%s}"
1791 ;; Skip ill-formed keywords.
1792 ((not (save-excursion
1794 (looking-at "[ \t]*#\\+\\S-+:"))))))
1795 (re-search-forward org-element-paragraph-separate limit
'm
))
1796 (if (eobp) (point) (goto-char (line-beginning-position)))))
1797 (contents-end (progn (skip-chars-backward " \r\t\n" contents-begin
)
1800 (end (progn (skip-chars-forward " \r\t\n" limit
)
1801 (if (eobp) (point) (point-at-bol)))))
1806 :contents-begin contents-begin
1807 :contents-end contents-end
1808 :post-blank
(count-lines before-blank end
))
1809 (cadr keywords
))))))
1811 (defun org-element-paragraph-interpreter (paragraph contents
)
1812 "Interpret PARAGRAPH element as Org syntax.
1813 CONTENTS is the contents of the element."
1819 (defun org-element-planning-parser (limit)
1822 LIMIT bounds the search.
1824 Return a list whose CAR is `planning' and CDR is a plist
1825 containing `:closed', `:deadline', `:scheduled', `:begin', `:end'
1826 and `:post-blank' keywords."
1828 (let* ((case-fold-search nil
)
1830 (post-blank (let ((before-blank (progn (forward-line) (point))))
1831 (skip-chars-forward " \r\t\n" limit
)
1832 (unless (eobp) (beginning-of-line))
1833 (count-lines before-blank
(point))))
1835 closed deadline scheduled
)
1837 (while (re-search-forward org-keyword-time-not-clock-regexp
1838 (line-end-position) t
)
1839 (goto-char (match-end 1))
1840 (org-skip-whitespace)
1841 (let ((time (buffer-substring-no-properties
1842 (1+ (point)) (1- (match-end 0))))
1843 (keyword (match-string 1)))
1844 (cond ((equal keyword org-closed-string
) (setq closed time
))
1845 ((equal keyword org-deadline-string
) (setq deadline time
))
1846 (t (setq scheduled time
)))))
1848 (list :closed closed
1850 :scheduled scheduled
1853 :post-blank post-blank
)))))
1855 (defun org-element-planning-interpreter (planning contents
)
1856 "Interpret PLANNING element as Org syntax.
1861 (list (let ((closed (org-element-property :closed planning
)))
1862 (when closed
(concat org-closed-string
" [" closed
"]")))
1863 (let ((deadline (org-element-property :deadline planning
)))
1864 (when deadline
(concat org-deadline-string
" <" deadline
">")))
1865 (let ((scheduled (org-element-property :scheduled planning
)))
1867 (concat org-scheduled-string
" <" scheduled
">")))))
1871 ;;;; Property Drawer
1873 (defun org-element-property-drawer-parser (limit)
1874 "Parse a property drawer.
1876 LIMIT bounds the search.
1878 Return a list whose CAR is `property-drawer' and CDR is a plist
1879 containing `:begin', `:end', `:hiddenp', `:contents-begin',
1880 `:contents-end', `:properties' and `:post-blank' keywords.
1882 Assume point is at the beginning of the property drawer."
1884 (let ((case-fold-search t
)
1886 (prop-begin (progn (forward-line) (point)))
1887 (hidden (org-invisible-p2))
1890 (while (not (looking-at "^[ \t]*:END:"))
1891 (when (looking-at "[ \t]*:\\([A-Za-z][-_A-Za-z0-9]*\\):")
1892 (push (cons (org-match-string-no-properties 1)
1894 (buffer-substring-no-properties
1895 (match-end 0) (point-at-eol))))
1899 (prop-end (progn (re-search-forward "^[ \t]*:END:" limit t
)
1901 (pos-before-blank (progn (forward-line) (point)))
1902 (end (progn (skip-chars-forward " \r\t\n" limit
)
1903 (if (eobp) (point) (point-at-bol)))))
1904 (list 'property-drawer
1908 :properties properties
1909 :post-blank
(count-lines pos-before-blank end
))))))
1911 (defun org-element-property-drawer-interpreter (property-drawer contents
)
1912 "Interpret PROPERTY-DRAWER element as Org syntax.
1914 (let ((props (org-element-property :properties property-drawer
)))
1917 (mapconcat (lambda (p)
1918 (format org-property-format
(format ":%s:" (car p
)) (cdr p
)))
1919 (nreverse props
) "\n")
1925 (defun org-element-quote-section-parser (limit)
1926 "Parse a quote section.
1928 LIMIT bounds the search.
1930 Return a list whose CAR is `quote-section' and CDR is a plist
1931 containing `:begin', `:end', `:value' and `:post-blank' keywords.
1933 Assume point is at beginning of the section."
1935 (let* ((begin (point))
1936 (end (progn (org-with-limited-levels (outline-next-heading))
1938 (pos-before-blank (progn (skip-chars-backward " \r\t\n")
1941 (value (buffer-substring-no-properties begin pos-before-blank
)))
1942 (list 'quote-section
1946 :post-blank
(count-lines pos-before-blank end
))))))
1948 (defun org-element-quote-section-interpreter (quote-section contents
)
1949 "Interpret QUOTE-SECTION element as Org syntax.
1951 (org-element-property :value quote-section
))
1956 (defun org-element-src-block-parser (limit)
1959 LIMIT bounds the search.
1961 Return a list whose CAR is `src-block' and CDR is a plist
1962 containing `:language', `:switches', `:parameters', `:begin',
1963 `:end', `:hiddenp', `:number-lines', `:retain-labels',
1964 `:use-labels', `:label-fmt', `:preserve-indent', `:value' and
1965 `:post-blank' keywords.
1967 Assume point is at the beginning of the block."
1968 (let ((case-fold-search t
))
1969 (if (not (save-excursion (re-search-forward "^[ \t]*#\\+END_SRC" limit t
)))
1970 ;; Incomplete block: parse it as a paragraph.
1971 (org-element-paragraph-parser limit
)
1972 (let ((contents-end (match-beginning 0)))
1974 (let* ((keywords (org-element--collect-affiliated-keywords))
1975 ;; Get beginning position.
1976 (begin (car keywords
))
1977 ;; Get language as a string.
1981 (concat "^[ \t]*#\\+BEGIN_SRC"
1982 "\\(?: +\\(\\S-+\\)\\)?"
1983 "\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?"
1985 (org-match-string-no-properties 1)))
1987 (switches (org-match-string-no-properties 2))
1989 (parameters (org-match-string-no-properties 3))
1990 ;; Switches analysis
1991 (number-lines (cond ((not switches
) nil
)
1992 ((string-match "-n\\>" switches
) 'new
)
1993 ((string-match "+n\\>" switches
) 'continued
)))
1994 (preserve-indent (and switches
(string-match "-i\\>" switches
)))
1995 (label-fmt (and switches
1996 (string-match "-l +\"\\([^\"\n]+\\)\"" switches
)
1997 (match-string 1 switches
)))
1998 ;; Should labels be retained in (or stripped from)
2002 (not (string-match "-r\\>" switches
))
2003 (and number-lines
(string-match "-k\\>" switches
))))
2004 ;; What should code-references use - labels or
2008 (and retain-labels
(not (string-match "-k\\>" switches
)))))
2009 ;; Get visibility status.
2010 (hidden (progn (forward-line) (org-invisible-p2)))
2012 (value (buffer-substring-no-properties (point) contents-end
))
2013 (pos-before-blank (progn (goto-char contents-end
)
2016 ;; Get position after ending blank lines.
2017 (end (progn (skip-chars-forward " \r\t\n" limit
)
2018 (if (eobp) (point) (point-at-bol)))))
2021 (list :language language
2022 :switches
(and (org-string-nw-p switches
)
2023 (org-trim switches
))
2024 :parameters
(and (org-string-nw-p parameters
)
2025 (org-trim parameters
))
2028 :number-lines number-lines
2029 :preserve-indent preserve-indent
2030 :retain-labels retain-labels
2031 :use-labels use-labels
2032 :label-fmt label-fmt
2035 :post-blank
(count-lines pos-before-blank end
))
2036 (cadr keywords
)))))))))
2038 (defun org-element-src-block-interpreter (src-block contents
)
2039 "Interpret SRC-BLOCK element as Org syntax.
2041 (let ((lang (org-element-property :language src-block
))
2042 (switches (org-element-property :switches src-block
))
2043 (params (org-element-property :parameters src-block
))
2044 (value (let ((val (org-element-property :value src-block
)))
2047 (org-src-preserve-indentation val
)
2048 ((zerop org-edit-src-content-indentation
)
2049 (org-remove-indentation val
))
2051 (let ((ind (make-string
2052 org-edit-src-content-indentation
32)))
2053 (replace-regexp-in-string
2054 "\\(^\\)[ \t]*\\S-" ind
2055 (org-remove-indentation val
) nil nil
1)))))))
2056 (concat (format "#+BEGIN_SRC%s\n"
2057 (concat (and lang
(concat " " lang
))
2058 (and switches
(concat " " switches
))
2059 (and params
(concat " " params
))))
2066 (defun org-element-table-parser (limit)
2067 "Parse a table at point.
2069 LIMIT bounds the search.
2071 Return a list whose CAR is `table' and CDR is a plist containing
2072 `:begin', `:end', `:tblfm', `:type', `:contents-begin',
2073 `:contents-end', `:value' and `:post-blank' keywords.
2075 Assume point is at the beginning of the table."
2077 (let* ((case-fold-search t
)
2078 (table-begin (point))
2079 (type (if (org-at-table.el-p
) 'table.el
'org
))
2080 (keywords (org-element--collect-affiliated-keywords))
2081 (begin (car keywords
))
2082 (table-end (goto-char (marker-position (org-table-end t
))))
2084 (while (looking-at "[ \t]*#\\+TBLFM: +\\(.*\\)[ \t]*$")
2085 (push (org-match-string-no-properties 1) acc
)
2088 (pos-before-blank (point))
2089 (end (progn (skip-chars-forward " \r\t\n" limit
)
2090 (if (eobp) (point) (point-at-bol)))))
2097 ;; Only `org' tables have contents. `table.el' tables
2098 ;; use a `:value' property to store raw table as
2100 :contents-begin
(and (eq type
'org
) table-begin
)
2101 :contents-end
(and (eq type
'org
) table-end
)
2102 :value
(and (eq type
'table.el
)
2103 (buffer-substring-no-properties
2104 table-begin table-end
))
2105 :post-blank
(count-lines pos-before-blank end
))
2106 (cadr keywords
))))))
2108 (defun org-element-table-interpreter (table contents
)
2109 "Interpret TABLE element as Org syntax.
2111 (if (eq (org-element-property :type table
) 'table.el
)
2112 (org-remove-indentation (org-element-property :value table
))
2113 (concat (with-temp-buffer (insert contents
)
2116 (mapconcat (lambda (fm) (concat "#+TBLFM: " fm
))
2117 (reverse (org-element-property :tblfm table
))
2123 (defun org-element-table-row-parser (limit)
2124 "Parse table row at point.
2126 LIMIT bounds the search.
2128 Return a list whose CAR is `table-row' and CDR is a plist
2129 containing `:begin', `:end', `:contents-begin', `:contents-end',
2130 `:type' and `:post-blank' keywords."
2132 (let* ((type (if (looking-at "^[ \t]*|-") 'rule
'standard
))
2134 ;; A table rule has no contents. In that case, ensure
2135 ;; CONTENTS-BEGIN matches CONTENTS-END.
2136 (contents-begin (and (eq type
'standard
)
2137 (search-forward "|")
2139 (contents-end (and (eq type
'standard
)
2142 (skip-chars-backward " \t")
2144 (end (progn (forward-line) (point))))
2149 :contents-begin contents-begin
2150 :contents-end contents-end
2153 (defun org-element-table-row-interpreter (table-row contents
)
2154 "Interpret TABLE-ROW element as Org syntax.
2155 CONTENTS is the contents of the table row."
2156 (if (eq (org-element-property :type table-row
) 'rule
) "|-"
2157 (concat "| " contents
)))
2162 (defun org-element-verse-block-parser (limit)
2163 "Parse a verse block.
2165 LIMIT bounds the search.
2167 Return a list whose CAR is `verse-block' and CDR is a plist
2168 containing `:begin', `:end', `:contents-begin', `:contents-end',
2169 `:hiddenp' and `:post-blank' keywords.
2171 Assume point is at beginning of the block."
2172 (let ((case-fold-search t
))
2173 (if (not (save-excursion
2174 (re-search-forward "^[ \t]*#\\+END_VERSE" limit t
)))
2175 ;; Incomplete block: parse it as a paragraph.
2176 (org-element-paragraph-parser limit
)
2177 (let ((contents-end (match-beginning 0)))
2179 (let* ((keywords (org-element--collect-affiliated-keywords))
2180 (begin (car keywords
))
2181 (hidden (progn (forward-line) (org-invisible-p2)))
2182 (contents-begin (point))
2183 (pos-before-blank (progn (goto-char contents-end
)
2186 (end (progn (skip-chars-forward " \r\t\n" limit
)
2187 (if (eobp) (point) (point-at-bol)))))
2192 :contents-begin contents-begin
2193 :contents-end contents-end
2195 :post-blank
(count-lines pos-before-blank end
))
2196 (cadr keywords
)))))))))
2198 (defun org-element-verse-block-interpreter (verse-block contents
)
2199 "Interpret VERSE-BLOCK element as Org syntax.
2200 CONTENTS is verse block contents."
2201 (format "#+BEGIN_VERSE\n%s#+END_VERSE" contents
))
2207 ;; Unlike to elements, interstices can be found between objects.
2208 ;; That's why, along with the parser, successor functions are provided
2209 ;; for each object. Some objects share the same successor (i.e. `code'
2210 ;; and `verbatim' objects).
2212 ;; A successor must accept a single argument bounding the search. It
2213 ;; will return either a cons cell whose CAR is the object's type, as
2214 ;; a symbol, and CDR the position of its next occurrence, or nil.
2216 ;; Successors follow the naming convention:
2217 ;; org-element-NAME-successor, where NAME is the name of the
2218 ;; successor, as defined in `org-element-all-successors'.
2220 ;; Some object types (i.e. `italic') are recursive. Restrictions on
2221 ;; object types they can contain will be specified in
2222 ;; `org-element-object-restrictions'.
2224 ;; Adding a new type of object is simple. Implement a successor,
2225 ;; a parser, and an interpreter for it, all following the naming
2226 ;; convention. Register type in `org-element-all-objects' and
2227 ;; successor in `org-element-all-successors'. Maybe tweak
2228 ;; restrictions about it, and that's it.
2233 (defun org-element-bold-parser ()
2234 "Parse bold object at point.
2236 Return a list whose CAR is `bold' and CDR is a plist with
2237 `:begin', `:end', `:contents-begin' and `:contents-end' and
2238 `:post-blank' keywords.
2240 Assume point is at the first star marker."
2242 (unless (bolp) (backward-char 1))
2243 (looking-at org-emph-re
)
2244 (let ((begin (match-beginning 2))
2245 (contents-begin (match-beginning 4))
2246 (contents-end (match-end 4))
2247 (post-blank (progn (goto-char (match-end 2))
2248 (skip-chars-forward " \t")))
2253 :contents-begin contents-begin
2254 :contents-end contents-end
2255 :post-blank post-blank
)))))
2257 (defun org-element-bold-interpreter (bold contents
)
2258 "Interpret BOLD object as Org syntax.
2259 CONTENTS is the contents of the object."
2260 (format "*%s*" contents
))
2262 (defun org-element-text-markup-successor (limit)
2263 "Search for the next text-markup object.
2265 LIMIT bounds the search.
2267 Return value is a cons cell whose CAR is a symbol among `bold',
2268 `italic', `underline', `strike-through', `code' and `verbatim'
2269 and CDR is beginning position."
2271 (unless (bolp) (backward-char))
2272 (when (re-search-forward org-emph-re limit t
)
2273 (let ((marker (match-string 3)))
2275 ((equal marker
"*") 'bold
)
2276 ((equal marker
"/") 'italic
)
2277 ((equal marker
"_") 'underline
)
2278 ((equal marker
"+") 'strike-through
)
2279 ((equal marker
"~") 'code
)
2280 ((equal marker
"=") 'verbatim
)
2281 (t (error "Unknown marker at %d" (match-beginning 3))))
2282 (match-beginning 2))))))
2287 (defun org-element-code-parser ()
2288 "Parse code object at point.
2290 Return a list whose CAR is `code' and CDR is a plist with
2291 `:value', `:begin', `:end' and `:post-blank' keywords.
2293 Assume point is at the first tilde marker."
2295 (unless (bolp) (backward-char 1))
2296 (looking-at org-emph-re
)
2297 (let ((begin (match-beginning 2))
2298 (value (org-match-string-no-properties 4))
2299 (post-blank (progn (goto-char (match-end 2))
2300 (skip-chars-forward " \t")))
2306 :post-blank post-blank
)))))
2308 (defun org-element-code-interpreter (code contents
)
2309 "Interpret CODE object as Org syntax.
2311 (format "~%s~" (org-element-property :value code
)))
2316 (defun org-element-entity-parser ()
2317 "Parse entity at point.
2319 Return a list whose CAR is `entity' and CDR a plist with
2320 `:begin', `:end', `:latex', `:latex-math-p', `:html', `:latin1',
2321 `:utf-8', `:ascii', `:use-brackets-p' and `:post-blank' as
2324 Assume point is at the beginning of the entity."
2326 (looking-at "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\)")
2327 (let* ((value (org-entity-get (match-string 1)))
2328 (begin (match-beginning 0))
2329 (bracketsp (string= (match-string 2) "{}"))
2330 (post-blank (progn (goto-char (match-end 1))
2331 (when bracketsp
(forward-char 2))
2332 (skip-chars-forward " \t")))
2335 (list :name
(car value
)
2336 :latex
(nth 1 value
)
2337 :latex-math-p
(nth 2 value
)
2339 :ascii
(nth 4 value
)
2340 :latin1
(nth 5 value
)
2341 :utf-8
(nth 6 value
)
2344 :use-brackets-p bracketsp
2345 :post-blank post-blank
)))))
2347 (defun org-element-entity-interpreter (entity contents
)
2348 "Interpret ENTITY object as Org syntax.
2351 (org-element-property :name entity
)
2352 (when (org-element-property :use-brackets-p entity
) "{}")))
2354 (defun org-element-latex-or-entity-successor (limit)
2355 "Search for the next latex-fragment or entity object.
2357 LIMIT bounds the search.
2359 Return value is a cons cell whose CAR is `entity' or
2360 `latex-fragment' and CDR is beginning position."
2363 (remove "begin" (plist-get org-format-latex-options
:matchers
)))
2364 ;; ENTITY-RE matches both LaTeX commands and Org entities.
2366 "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\)"))
2367 (when (re-search-forward
2368 (concat (mapconcat (lambda (e) (nth 1 (assoc e org-latex-regexps
)))
2372 (goto-char (match-beginning 0))
2373 (if (looking-at entity-re
)
2374 ;; Determine if it's a real entity or a LaTeX command.
2375 (cons (if (org-entity-get (match-string 1)) 'entity
'latex-fragment
)
2376 (match-beginning 0))
2377 ;; No entity nor command: point is at a LaTeX fragment.
2378 ;; Determine its type to get the correct beginning position.
2379 (cons 'latex-fragment
2382 (when (looking-at (nth 1 (assoc e org-latex-regexps
)))
2385 (nth 2 (assoc e org-latex-regexps
))))))
2392 (defun org-element-export-snippet-parser ()
2393 "Parse export snippet at point.
2395 Return a list whose CAR is `export-snippet' and CDR a plist with
2396 `:begin', `:end', `:back-end', `:value' and `:post-blank' as
2399 Assume point is at the beginning of the snippet."
2401 (re-search-forward "@@\\([-A-Za-z0-9]+\\):" nil t
)
2402 (let* ((begin (match-beginning 0))
2403 (back-end (org-match-string-no-properties 1))
2404 (value (buffer-substring-no-properties
2406 (progn (re-search-forward "@@" nil t
) (match-beginning 0))))
2407 (post-blank (skip-chars-forward " \t"))
2409 (list 'export-snippet
2410 (list :back-end back-end
2414 :post-blank post-blank
)))))
2416 (defun org-element-export-snippet-interpreter (export-snippet contents
)
2417 "Interpret EXPORT-SNIPPET object as Org syntax.
2420 (org-element-property :back-end export-snippet
)
2421 (org-element-property :value export-snippet
)))
2423 (defun org-element-export-snippet-successor (limit)
2424 "Search for the next export-snippet object.
2426 LIMIT bounds the search.
2428 Return value is a cons cell whose CAR is `export-snippet' and CDR
2429 its beginning position."
2432 (when (and (re-search-forward "@@[-A-Za-z0-9]+:" limit t
)
2433 (setq beg
(match-beginning 0))
2434 (search-forward "@@" limit t
))
2435 (cons 'export-snippet beg
)))))
2438 ;;;; Footnote Reference
2440 (defun org-element-footnote-reference-parser ()
2441 "Parse footnote reference at point.
2443 Return a list whose CAR is `footnote-reference' and CDR a plist
2444 with `:label', `:type', `:inline-definition', `:begin', `:end'
2445 and `:post-blank' as keywords."
2447 (looking-at org-footnote-re
)
2448 (let* ((begin (point))
2449 (label (or (org-match-string-no-properties 2)
2450 (org-match-string-no-properties 3)
2451 (and (match-string 1)
2452 (concat "fn:" (org-match-string-no-properties 1)))))
2453 (type (if (or (not label
) (match-string 1)) 'inline
'standard
))
2454 (inner-begin (match-end 0))
2458 (while (and (> count
0) (re-search-forward "[][]" nil t
))
2459 (if (equal (match-string 0) "[") (incf count
) (decf count
)))
2461 (post-blank (progn (goto-char (1+ inner-end
))
2462 (skip-chars-forward " \t")))
2465 (list 'footnote-reference
2470 :post-blank post-blank
))))
2471 (org-element-put-property
2472 footnote-reference
:inline-definition
2473 (and (eq type
'inline
)
2474 (org-element-parse-secondary-string
2475 (buffer-substring inner-begin inner-end
)
2476 (org-element-restriction 'footnote-reference
)
2477 footnote-reference
))))))
2479 (defun org-element-footnote-reference-interpreter (footnote-reference contents
)
2480 "Interpret FOOTNOTE-REFERENCE object as Org syntax.
2482 (let ((label (or (org-element-property :label footnote-reference
) "fn:"))
2485 (org-element-property :inline-definition footnote-reference
)))
2486 (if (not inline-def
) ""
2487 (concat ":" (org-element-interpret-data inline-def
))))))
2488 (format "[%s]" (concat label def
))))
2490 (defun org-element-footnote-reference-successor (limit)
2491 "Search for the next footnote-reference object.
2493 LIMIT bounds the search.
2495 Return value is a cons cell whose CAR is `footnote-reference' and
2496 CDR is beginning position."
2499 (while (re-search-forward org-footnote-re limit t
)
2501 (let ((beg (match-beginning 0))
2504 (while (re-search-forward "[][]" limit t
)
2505 (if (equal (match-string 0) "[") (incf count
) (decf count
))
2507 (throw 'exit
(cons 'footnote-reference beg
))))))))))
2510 ;;;; Inline Babel Call
2512 (defun org-element-inline-babel-call-parser ()
2513 "Parse inline babel call at point.
2515 Return a list whose CAR is `inline-babel-call' and CDR a plist
2516 with `:begin', `:end', `:info' and `:post-blank' as keywords.
2518 Assume point is at the beginning of the babel call."
2520 (unless (bolp) (backward-char))
2521 (looking-at org-babel-inline-lob-one-liner-regexp
)
2522 (let ((info (save-match-data (org-babel-lob-get-info)))
2523 (begin (match-end 1))
2524 (post-blank (progn (goto-char (match-end 0))
2525 (skip-chars-forward " \t")))
2527 (list 'inline-babel-call
2531 :post-blank post-blank
)))))
2533 (defun org-element-inline-babel-call-interpreter (inline-babel-call contents
)
2534 "Interpret INLINE-BABEL-CALL object as Org syntax.
2536 (let* ((babel-info (org-element-property :info inline-babel-call
))
2537 (main-source (car babel-info
))
2538 (post-options (nth 1 babel-info
)))
2540 (if (string-match "\\[\\(\\[.*?\\]\\)\\]" main-source
)
2541 ;; Remove redundant square brackets.
2543 (match-string 1 main-source
) nil nil main-source
)
2545 (and post-options
(format "[%s]" post-options
)))))
2547 (defun org-element-inline-babel-call-successor (limit)
2548 "Search for the next inline-babel-call object.
2550 LIMIT bounds the search.
2552 Return value is a cons cell whose CAR is `inline-babel-call' and
2553 CDR is beginning position."
2555 ;; Use a simplified version of
2556 ;; `org-babel-inline-lob-one-liner-regexp'.
2557 (when (re-search-forward
2558 "call_\\([^()\n]+?\\)\\(?:\\[.*?\\]\\)?([^\n]*?)\\(\\[.*?\\]\\)?"
2560 (cons 'inline-babel-call
(match-beginning 0)))))
2563 ;;;; Inline Src Block
2565 (defun org-element-inline-src-block-parser ()
2566 "Parse inline source block at point.
2568 LIMIT bounds the search.
2570 Return a list whose CAR is `inline-src-block' and CDR a plist
2571 with `:begin', `:end', `:language', `:value', `:parameters' and
2572 `:post-blank' as keywords.
2574 Assume point is at the beginning of the inline src block."
2576 (unless (bolp) (backward-char))
2577 (looking-at org-babel-inline-src-block-regexp
)
2578 (let ((begin (match-beginning 1))
2579 (language (org-match-string-no-properties 2))
2580 (parameters (org-match-string-no-properties 4))
2581 (value (org-match-string-no-properties 5))
2582 (post-blank (progn (goto-char (match-end 0))
2583 (skip-chars-forward " \t")))
2585 (list 'inline-src-block
2586 (list :language language
2588 :parameters parameters
2591 :post-blank post-blank
)))))
2593 (defun org-element-inline-src-block-interpreter (inline-src-block contents
)
2594 "Interpret INLINE-SRC-BLOCK object as Org syntax.
2596 (let ((language (org-element-property :language inline-src-block
))
2597 (arguments (org-element-property :parameters inline-src-block
))
2598 (body (org-element-property :value inline-src-block
)))
2599 (format "src_%s%s{%s}"
2601 (if arguments
(format "[%s]" arguments
) "")
2604 (defun org-element-inline-src-block-successor (limit)
2605 "Search for the next inline-babel-call element.
2607 LIMIT bounds the search.
2609 Return value is a cons cell whose CAR is `inline-babel-call' and
2610 CDR is beginning position."
2612 (when (re-search-forward org-babel-inline-src-block-regexp limit t
)
2613 (cons 'inline-src-block
(match-beginning 1)))))
2617 (defun org-element-italic-parser ()
2618 "Parse italic object at point.
2620 Return a list whose CAR is `italic' and CDR is a plist with
2621 `:begin', `:end', `:contents-begin' and `:contents-end' and
2622 `:post-blank' keywords.
2624 Assume point is at the first slash marker."
2626 (unless (bolp) (backward-char 1))
2627 (looking-at org-emph-re
)
2628 (let ((begin (match-beginning 2))
2629 (contents-begin (match-beginning 4))
2630 (contents-end (match-end 4))
2631 (post-blank (progn (goto-char (match-end 2))
2632 (skip-chars-forward " \t")))
2637 :contents-begin contents-begin
2638 :contents-end contents-end
2639 :post-blank post-blank
)))))
2641 (defun org-element-italic-interpreter (italic contents
)
2642 "Interpret ITALIC object as Org syntax.
2643 CONTENTS is the contents of the object."
2644 (format "/%s/" contents
))
2649 (defun org-element-latex-fragment-parser ()
2650 "Parse latex fragment at point.
2652 Return a list whose CAR is `latex-fragment' and CDR a plist with
2653 `:value', `:begin', `:end', and `:post-blank' as keywords.
2655 Assume point is at the beginning of the latex fragment."
2657 (let* ((begin (point))
2661 (let ((latex-regexp (nth 1 (assoc e org-latex-regexps
))))
2662 (when (or (looking-at latex-regexp
)
2666 (looking-at latex-regexp
))))
2667 (throw 'exit
(nth 2 (assoc e org-latex-regexps
))))))
2668 (plist-get org-format-latex-options
:matchers
))
2669 ;; None found: it's a macro.
2670 (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")
2672 (value (match-string-no-properties substring-match
))
2673 (post-blank (progn (goto-char (match-end substring-match
))
2674 (skip-chars-forward " \t")))
2676 (list 'latex-fragment
2680 :post-blank post-blank
)))))
2682 (defun org-element-latex-fragment-interpreter (latex-fragment contents
)
2683 "Interpret LATEX-FRAGMENT object as Org syntax.
2685 (org-element-property :value latex-fragment
))
2689 (defun org-element-line-break-parser ()
2690 "Parse line break at point.
2692 Return a list whose CAR is `line-break', and CDR a plist with
2693 `:begin', `:end' and `:post-blank' keywords.
2695 Assume point is at the beginning of the line break."
2696 (list 'line-break
(list :begin
(point) :end
(point-at-eol) :post-blank
0)))
2698 (defun org-element-line-break-interpreter (line-break contents
)
2699 "Interpret LINE-BREAK object as Org syntax.
2703 (defun org-element-line-break-successor (limit)
2704 "Search for the next line-break object.
2706 LIMIT bounds the search.
2708 Return value is a cons cell whose CAR is `line-break' and CDR is
2709 beginning position."
2711 (let ((beg (and (re-search-forward "[^\\\\]\\(\\\\\\\\\\)[ \t]*$" limit t
)
2712 (goto-char (match-beginning 1)))))
2713 ;; A line break can only happen on a non-empty line.
2714 (when (and beg
(re-search-backward "\\S-" (point-at-bol) t
))
2715 (cons 'line-break beg
)))))
2720 (defun org-element-link-parser ()
2721 "Parse link at point.
2723 Return a list whose CAR is `link' and CDR a plist with `:type',
2724 `:path', `:raw-link', `:begin', `:end', `:contents-begin',
2725 `:contents-end' and `:post-blank' as keywords.
2727 Assume point is at the beginning of the link."
2729 (let ((begin (point))
2730 end contents-begin contents-end link-end post-blank path type
2733 ;; Type 1: Text targeted from a radio target.
2734 ((and org-target-link-regexp
(looking-at org-target-link-regexp
))
2736 link-end
(match-end 0)
2737 path
(org-match-string-no-properties 0)))
2738 ;; Type 2: Standard link, i.e. [[http://orgmode.org][homepage]]
2739 ((looking-at org-bracket-link-regexp
)
2740 (setq contents-begin
(match-beginning 3)
2741 contents-end
(match-end 3)
2742 link-end
(match-end 0)
2743 ;; RAW-LINK is the original link.
2744 raw-link
(org-match-string-no-properties 1)
2745 link
(org-translate-link
2746 (org-link-expand-abbrev
2747 (org-link-unescape raw-link
))))
2748 ;; Determine TYPE of link and set PATH accordingly.
2751 ((or (file-name-absolute-p link
) (string-match "^\\.\\.?/" link
))
2752 (setq type
"file" path link
))
2753 ;; Explicit type (http, irc, bbdb...). See `org-link-types'.
2754 ((string-match org-link-re-with-space3 link
)
2755 (setq type
(match-string 1 link
) path
(match-string 2 link
)))
2756 ;; Id type: PATH is the id.
2757 ((string-match "^id:\\([-a-f0-9]+\\)" link
)
2758 (setq type
"id" path
(match-string 1 link
)))
2759 ;; Code-ref type: PATH is the name of the reference.
2760 ((string-match "^(\\(.*\\))$" link
)
2761 (setq type
"coderef" path
(match-string 1 link
)))
2762 ;; Custom-id type: PATH is the name of the custom id.
2763 ((= (aref link
0) ?
#)
2764 (setq type
"custom-id" path
(substring link
1)))
2765 ;; Fuzzy type: Internal link either matches a target, an
2766 ;; headline name or nothing. PATH is the target or
2768 (t (setq type
"fuzzy" path link
))))
2769 ;; Type 3: Plain link, i.e. http://orgmode.org
2770 ((looking-at org-plain-link-re
)
2771 (setq raw-link
(org-match-string-no-properties 0)
2772 type
(org-match-string-no-properties 1)
2773 path
(org-match-string-no-properties 2)
2774 link-end
(match-end 0)))
2775 ;; Type 4: Angular link, i.e. <http://orgmode.org>
2776 ((looking-at org-angle-link-re
)
2777 (setq raw-link
(buffer-substring-no-properties
2778 (match-beginning 1) (match-end 2))
2779 type
(org-match-string-no-properties 1)
2780 path
(org-match-string-no-properties 2)
2781 link-end
(match-end 0))))
2782 ;; In any case, deduce end point after trailing white space from
2783 ;; LINK-END variable.
2784 (setq post-blank
(progn (goto-char link-end
) (skip-chars-forward " \t"))
2789 :raw-link
(or raw-link path
)
2792 :contents-begin contents-begin
2793 :contents-end contents-end
2794 :post-blank post-blank
)))))
2796 (defun org-element-link-interpreter (link contents
)
2797 "Interpret LINK object as Org syntax.
2798 CONTENTS is the contents of the object, or nil."
2799 (let ((type (org-element-property :type link
))
2800 (raw-link (org-element-property :raw-link link
)))
2801 (if (string= type
"radio") raw-link
2804 (if contents
(format "[%s]" contents
) "")))))
2806 (defun org-element-link-successor (limit)
2807 "Search for the next link object.
2809 LIMIT bounds the search.
2811 Return value is a cons cell whose CAR is `link' and CDR is
2812 beginning position."
2815 (if (not org-target-link-regexp
) org-any-link-re
2816 (concat org-any-link-re
"\\|" org-target-link-regexp
))))
2817 (when (re-search-forward link-regexp limit t
)
2818 (cons 'link
(match-beginning 0))))))
2823 (defun org-element-macro-parser ()
2824 "Parse macro at point.
2826 Return a list whose CAR is `macro' and CDR a plist with `:key',
2827 `:args', `:begin', `:end', `:value' and `:post-blank' as
2830 Assume point is at the macro."
2832 (looking-at "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}")
2833 (let ((begin (point))
2834 (key (downcase (org-match-string-no-properties 1)))
2835 (value (org-match-string-no-properties 0))
2836 (post-blank (progn (goto-char (match-end 0))
2837 (skip-chars-forward " \t")))
2839 (args (let ((args (org-match-string-no-properties 3)) args2
)
2841 (setq args
(org-split-string args
","))
2843 (while (string-match "\\\\\\'" (car args
))
2844 ;; Repair bad splits.
2845 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2848 (push (pop args
) args2
))
2849 (mapcar 'org-trim
(nreverse args2
))))))
2856 :post-blank post-blank
)))))
2858 (defun org-element-macro-interpreter (macro contents
)
2859 "Interpret MACRO object as Org syntax.
2861 (org-element-property :value macro
))
2863 (defun org-element-macro-successor (limit)
2864 "Search for the next macro object.
2866 LIMIT bounds the search.
2868 Return value is cons cell whose CAR is `macro' and CDR is
2869 beginning position."
2871 (when (re-search-forward
2872 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2874 (cons 'macro
(match-beginning 0)))))
2879 (defun org-element-radio-target-parser ()
2880 "Parse radio target at point.
2882 Return a list whose CAR is `radio-target' and CDR a plist with
2883 `:begin', `:end', `:contents-begin', `:contents-end', `:value'
2884 and `:post-blank' as keywords.
2886 Assume point is at the radio target."
2888 (looking-at org-radio-target-regexp
)
2889 (let ((begin (point))
2890 (contents-begin (match-beginning 1))
2891 (contents-end (match-end 1))
2892 (value (org-match-string-no-properties 1))
2893 (post-blank (progn (goto-char (match-end 0))
2894 (skip-chars-forward " \t")))
2899 :contents-begin contents-begin
2900 :contents-end contents-end
2901 :post-blank post-blank
2904 (defun org-element-radio-target-interpreter (target contents
)
2905 "Interpret TARGET object as Org syntax.
2906 CONTENTS is the contents of the object."
2907 (concat "<<<" contents
">>>"))
2909 (defun org-element-radio-target-successor (limit)
2910 "Search for the next radio-target object.
2912 LIMIT bounds the search.
2914 Return value is a cons cell whose CAR is `radio-target' and CDR
2915 is beginning position."
2917 (when (re-search-forward org-radio-target-regexp limit t
)
2918 (cons 'radio-target
(match-beginning 0)))))
2921 ;;;; Statistics Cookie
2923 (defun org-element-statistics-cookie-parser ()
2924 "Parse statistics cookie at point.
2926 Return a list whose CAR is `statistics-cookie', and CDR a plist
2927 with `:begin', `:end', `:value' and `:post-blank' keywords.
2929 Assume point is at the beginning of the statistics-cookie."
2931 (looking-at "\\[[0-9]*\\(%\\|/[0-9]*\\)\\]")
2932 (let* ((begin (point))
2933 (value (buffer-substring-no-properties
2934 (match-beginning 0) (match-end 0)))
2935 (post-blank (progn (goto-char (match-end 0))
2936 (skip-chars-forward " \t")))
2938 (list 'statistics-cookie
2942 :post-blank post-blank
)))))
2944 (defun org-element-statistics-cookie-interpreter (statistics-cookie contents
)
2945 "Interpret STATISTICS-COOKIE object as Org syntax.
2947 (org-element-property :value statistics-cookie
))
2949 (defun org-element-statistics-cookie-successor (limit)
2950 "Search for the next statistics cookie object.
2952 LIMIT bounds the search.
2954 Return value is a cons cell whose CAR is `statistics-cookie' and
2955 CDR is beginning position."
2957 (when (re-search-forward "\\[[0-9]*\\(%\\|/[0-9]*\\)\\]" limit t
)
2958 (cons 'statistics-cookie
(match-beginning 0)))))
2963 (defun org-element-strike-through-parser ()
2964 "Parse strike-through object at point.
2966 Return a list whose CAR is `strike-through' and CDR is a plist
2967 with `:begin', `:end', `:contents-begin' and `:contents-end' and
2968 `:post-blank' keywords.
2970 Assume point is at the first plus sign marker."
2972 (unless (bolp) (backward-char 1))
2973 (looking-at org-emph-re
)
2974 (let ((begin (match-beginning 2))
2975 (contents-begin (match-beginning 4))
2976 (contents-end (match-end 4))
2977 (post-blank (progn (goto-char (match-end 2))
2978 (skip-chars-forward " \t")))
2980 (list 'strike-through
2983 :contents-begin contents-begin
2984 :contents-end contents-end
2985 :post-blank post-blank
)))))
2987 (defun org-element-strike-through-interpreter (strike-through contents
)
2988 "Interpret STRIKE-THROUGH object as Org syntax.
2989 CONTENTS is the contents of the object."
2990 (format "+%s+" contents
))
2995 (defun org-element-subscript-parser ()
2996 "Parse subscript at point.
2998 Return a list whose CAR is `subscript' and CDR a plist with
2999 `:begin', `:end', `:contents-begin', `:contents-end',
3000 `:use-brackets-p' and `:post-blank' as keywords.
3002 Assume point is at the underscore."
3004 (unless (bolp) (backward-char))
3005 (let ((bracketsp (if (looking-at org-match-substring-with-braces-regexp
)
3007 (not (looking-at org-match-substring-regexp
))))
3008 (begin (match-beginning 2))
3009 (contents-begin (or (match-beginning 5)
3010 (match-beginning 3)))
3011 (contents-end (or (match-end 5) (match-end 3)))
3012 (post-blank (progn (goto-char (match-end 0))
3013 (skip-chars-forward " \t")))
3018 :use-brackets-p bracketsp
3019 :contents-begin contents-begin
3020 :contents-end contents-end
3021 :post-blank post-blank
)))))
3023 (defun org-element-subscript-interpreter (subscript contents
)
3024 "Interpret SUBSCRIPT object as Org syntax.
3025 CONTENTS is the contents of the object."
3027 (if (org-element-property :use-brackets-p subscript
) "_{%s}" "_%s")
3030 (defun org-element-sub/superscript-successor
(limit)
3031 "Search for the next sub/superscript object.
3033 LIMIT bounds the search.
3035 Return value is a cons cell whose CAR is either `subscript' or
3036 `superscript' and CDR is beginning position."
3038 (when (re-search-forward org-match-substring-regexp limit t
)
3039 (cons (if (string= (match-string 2) "_") 'subscript
'superscript
)
3040 (match-beginning 2)))))
3045 (defun org-element-superscript-parser ()
3046 "Parse superscript at point.
3048 Return a list whose CAR is `superscript' and CDR a plist with
3049 `:begin', `:end', `:contents-begin', `:contents-end',
3050 `:use-brackets-p' and `:post-blank' as keywords.
3052 Assume point is at the caret."
3054 (unless (bolp) (backward-char))
3055 (let ((bracketsp (if (looking-at org-match-substring-with-braces-regexp
) t
3056 (not (looking-at org-match-substring-regexp
))))
3057 (begin (match-beginning 2))
3058 (contents-begin (or (match-beginning 5)
3059 (match-beginning 3)))
3060 (contents-end (or (match-end 5) (match-end 3)))
3061 (post-blank (progn (goto-char (match-end 0))
3062 (skip-chars-forward " \t")))
3067 :use-brackets-p bracketsp
3068 :contents-begin contents-begin
3069 :contents-end contents-end
3070 :post-blank post-blank
)))))
3072 (defun org-element-superscript-interpreter (superscript contents
)
3073 "Interpret SUPERSCRIPT object as Org syntax.
3074 CONTENTS is the contents of the object."
3076 (if (org-element-property :use-brackets-p superscript
) "^{%s}" "^%s")
3082 (defun org-element-table-cell-parser ()
3083 "Parse table cell at point.
3085 Return a list whose CAR is `table-cell' and CDR is a plist
3086 containing `:begin', `:end', `:contents-begin', `:contents-end'
3087 and `:post-blank' keywords."
3088 (looking-at "[ \t]*\\(.*?\\)[ \t]*|")
3089 (let* ((begin (match-beginning 0))
3091 (contents-begin (match-beginning 1))
3092 (contents-end (match-end 1)))
3096 :contents-begin contents-begin
3097 :contents-end contents-end
3100 (defun org-element-table-cell-interpreter (table-cell contents
)
3101 "Interpret TABLE-CELL element as Org syntax.
3102 CONTENTS is the contents of the cell, or nil."
3103 (concat " " contents
" |"))
3105 (defun org-element-table-cell-successor (limit)
3106 "Search for the next table-cell object.
3108 LIMIT bounds the search.
3110 Return value is a cons cell whose CAR is `table-cell' and CDR is
3111 beginning position."
3112 (when (looking-at "[ \t]*.*?[ \t]+|") (cons 'table-cell
(point))))
3117 (defun org-element-target-parser ()
3118 "Parse target at point.
3120 Return a list whose CAR is `target' and CDR a plist with
3121 `:begin', `:end', `:value' and `:post-blank' as keywords.
3123 Assume point is at the target."
3125 (looking-at org-target-regexp
)
3126 (let ((begin (point))
3127 (value (org-match-string-no-properties 1))
3128 (post-blank (progn (goto-char (match-end 0))
3129 (skip-chars-forward " \t")))
3135 :post-blank post-blank
)))))
3137 (defun org-element-target-interpreter (target contents
)
3138 "Interpret TARGET object as Org syntax.
3140 (format "<<%s>>" (org-element-property :value target
)))
3142 (defun org-element-target-successor (limit)
3143 "Search for the next target object.
3145 LIMIT bounds the search.
3147 Return value is a cons cell whose CAR is `target' and CDR is
3148 beginning position."
3150 (when (re-search-forward org-target-regexp limit t
)
3151 (cons 'target
(match-beginning 0)))))
3156 (defun org-element-timestamp-parser ()
3157 "Parse time stamp at point.
3159 Return a list whose CAR is `timestamp', and CDR a plist with
3160 `:type', `:begin', `:end', `:value' and `:post-blank' keywords.
3162 Assume point is at the beginning of the timestamp."
3164 (let* ((begin (point))
3165 (activep (eq (char-after) ?
<))
3168 (looking-at "[<[]\\(\\(%%\\)?.*?\\)[]>]\\(?:--[<[]\\(.*?\\)[]>]\\)?")
3169 (match-string-no-properties 1)))
3170 (range-end (match-string-no-properties 3))
3171 (type (cond ((match-string 2) 'diary
)
3172 ((and activep range-end
) 'active-range
)
3174 (range-end 'inactive-range
)
3176 (post-blank (progn (goto-char (match-end 0))
3177 (skip-chars-forward " \t")))
3182 :range-end range-end
3185 :post-blank post-blank
)))))
3187 (defun org-element-timestamp-interpreter (timestamp contents
)
3188 "Interpret TIMESTAMP object as Org syntax.
3190 (let ((type (org-element-property :type timestamp
) ))
3192 (format (if (memq type
'(inactive inactive-range
)) "[%s]" "<%s>")
3193 (org-element-property :value timestamp
))
3194 (let ((range-end (org-element-property :range-end timestamp
)))
3197 (format (if (eq type
'inactive-range
) "[%s]" "<%s>")
3200 (defun org-element-timestamp-successor (limit)
3201 "Search for the next timestamp object.
3203 LIMIT bounds the search.
3205 Return value is a cons cell whose CAR is `timestamp' and CDR is
3206 beginning position."
3208 (when (re-search-forward
3209 (concat org-ts-regexp-both
3211 "\\(?:<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3213 "\\(?:<%%\\(?:([^>\n]+)\\)>\\)")
3215 (cons 'timestamp
(match-beginning 0)))))
3220 (defun org-element-underline-parser ()
3221 "Parse underline object at point.
3223 Return a list whose CAR is `underline' and CDR is a plist with
3224 `:begin', `:end', `:contents-begin' and `:contents-end' and
3225 `:post-blank' keywords.
3227 Assume point is at the first underscore marker."
3229 (unless (bolp) (backward-char 1))
3230 (looking-at org-emph-re
)
3231 (let ((begin (match-beginning 2))
3232 (contents-begin (match-beginning 4))
3233 (contents-end (match-end 4))
3234 (post-blank (progn (goto-char (match-end 2))
3235 (skip-chars-forward " \t")))
3240 :contents-begin contents-begin
3241 :contents-end contents-end
3242 :post-blank post-blank
)))))
3244 (defun org-element-underline-interpreter (underline contents
)
3245 "Interpret UNDERLINE object as Org syntax.
3246 CONTENTS is the contents of the object."
3247 (format "_%s_" contents
))
3252 (defun org-element-verbatim-parser ()
3253 "Parse verbatim object at point.
3255 Return a list whose CAR is `verbatim' and CDR is a plist with
3256 `:value', `:begin', `:end' and `:post-blank' keywords.
3258 Assume point is at the first equal sign marker."
3260 (unless (bolp) (backward-char 1))
3261 (looking-at org-emph-re
)
3262 (let ((begin (match-beginning 2))
3263 (value (org-match-string-no-properties 4))
3264 (post-blank (progn (goto-char (match-end 2))
3265 (skip-chars-forward " \t")))
3271 :post-blank post-blank
)))))
3273 (defun org-element-verbatim-interpreter (verbatim contents
)
3274 "Interpret VERBATIM object as Org syntax.
3276 (format "=%s=" (org-element-property :value verbatim
)))
3280 ;;; Parsing Element Starting At Point
3282 ;; `org-element--current-element' is the core function of this section.
3283 ;; It returns the Lisp representation of the element starting at
3286 ;; `org-element--current-element' makes use of special modes. They
3287 ;; are activated for fixed element chaining (i.e. `plain-list' >
3288 ;; `item') or fixed conditional element chaining (i.e. `headline' >
3289 ;; `section'). Special modes are: `first-section', `section',
3290 ;; `quote-section', `item' and `table-row'.
3292 (defun org-element--current-element
3293 (limit &optional granularity special structure
)
3294 "Parse the element starting at point.
3296 LIMIT bounds the search.
3298 Return value is a list like (TYPE PROPS) where TYPE is the type
3299 of the element and PROPS a plist of properties associated to the
3302 Possible types are defined in `org-element-all-elements'.
3304 Optional argument GRANULARITY determines the depth of the
3305 recursion. Allowed values are `headline', `greater-element',
3306 `element', `object' or nil. When it is broader than `object' (or
3307 nil), secondary values will not be parsed, since they only
3310 Optional argument SPECIAL, when non-nil, can be either
3311 `first-section', `section', `quote-section', `table-row' and
3314 If STRUCTURE isn't provided but SPECIAL is set to `item', it will
3317 This function assumes point is always at the beginning of the
3318 element it has to parse."
3320 ;; If point is at an affiliated keyword, try moving to the
3321 ;; beginning of the associated element. If none is found, the
3322 ;; keyword is orphaned and will be treated as plain text.
3323 (when (looking-at org-element--affiliated-re
)
3324 (let ((opoint (point)))
3325 (while (looking-at org-element--affiliated-re
) (forward-line))
3326 (when (looking-at "[ \t]*$") (goto-char opoint
))))
3327 (let ((case-fold-search t
)
3328 ;; Determine if parsing depth allows for secondary strings
3329 ;; parsing. It only applies to elements referenced in
3330 ;; `org-element-secondary-value-alist'.
3331 (raw-secondary-p (and granularity
(not (eq granularity
'object
)))))
3335 (org-element-item-parser limit structure raw-secondary-p
))
3337 ((eq special
'table-row
) (org-element-table-row-parser limit
))
3339 ((org-with-limited-levels (org-at-heading-p))
3340 (org-element-headline-parser limit raw-secondary-p
))
3341 ;; Sections (must be checked after headline).
3342 ((eq special
'section
) (org-element-section-parser limit
))
3343 ((eq special
'quote-section
) (org-element-quote-section-parser limit
))
3344 ((eq special
'first-section
)
3345 (org-element-section-parser
3346 (or (save-excursion (org-with-limited-levels (outline-next-heading)))
3348 ;; Planning and Clock.
3349 ((and (looking-at org-planning-or-clock-line-re
))
3350 (if (equal (match-string 1) org-clock-string
)
3351 (org-element-clock-parser limit
)
3352 (org-element-planning-parser limit
)))
3355 (org-element-inlinetask-parser limit raw-secondary-p
))
3356 ;; LaTeX Environment.
3357 ((looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}")
3360 (format "[ \t]*\\\\end{%s}[ \t]*"
3361 (regexp-quote (match-string 1)))
3363 (org-element-latex-environment-parser limit
)
3364 (org-element-paragraph-parser limit
)))
3365 ;; Drawer and Property Drawer.
3366 ((looking-at org-drawer-regexp
)
3367 (let ((name (match-string 1)))
3369 ((not (save-excursion
3370 (re-search-forward "^[ \t]*:END:[ \t]*$" nil t
)))
3371 (org-element-paragraph-parser limit
))
3372 ((equal "PROPERTIES" name
)
3373 (org-element-property-drawer-parser limit
))
3374 (t (org-element-drawer-parser limit
)))))
3376 ((looking-at "[ \t]*:\\( \\|$\\)")
3377 (org-element-fixed-width-parser limit
))
3378 ;; Inline Comments, Blocks, Babel Calls, Dynamic Blocks and
3380 ((looking-at "[ \t]*#")
3381 (goto-char (match-end 0))
3382 (cond ((looking-at "\\(?: \\|$\\)")
3384 (org-element-comment-parser limit
))
3385 ((looking-at "\\+BEGIN_\\(\\S-+\\)")
3387 (let ((parser (assoc (upcase (match-string 1))
3388 org-element-block-name-alist
)))
3389 (if parser
(funcall (cdr parser
) limit
)
3390 (org-element-special-block-parser limit
))))
3391 ((looking-at "\\+CALL:")
3393 (org-element-babel-call-parser limit
))
3394 ((looking-at "\\+BEGIN:? ")
3396 (org-element-dynamic-block-parser limit
))
3397 ((looking-at "\\+\\S-+:")
3399 (org-element-keyword-parser limit
))
3402 (org-element-paragraph-parser limit
))))
3403 ;; Footnote Definition.
3404 ((looking-at org-footnote-definition-re
)
3405 (org-element-footnote-definition-parser limit
))
3407 ((looking-at "[ \t]*-\\{5,\\}[ \t]*$")
3408 (org-element-horizontal-rule-parser limit
))
3410 ((org-at-table-p t
) (org-element-table-parser limit
))
3412 ((looking-at (org-item-re))
3413 (org-element-plain-list-parser limit
(or structure
(org-list-struct))))
3414 ;; Default element: Paragraph.
3415 (t (org-element-paragraph-parser limit
))))))
3418 ;; Most elements can have affiliated keywords. When looking for an
3419 ;; element beginning, we want to move before them, as they belong to
3420 ;; that element, and, in the meantime, collect information they give
3421 ;; into appropriate properties. Hence the following function.
3423 ;; Usage of optional arguments may not be obvious at first glance:
3425 ;; - TRANS-LIST is used to polish keywords names that have evolved
3426 ;; during Org history. In example, even though =result= and
3427 ;; =results= coexist, we want to have them under the same =result=
3428 ;; property. It's also true for "srcname" and "name", where the
3429 ;; latter seems to be preferred nowadays (thus the "name" property).
3431 ;; - CONSED allows to regroup multi-lines keywords under the same
3432 ;; property, while preserving their own identity. This is mostly
3433 ;; used for "attr_latex" and al.
3435 ;; - PARSED prepares a keyword value for export. This is useful for
3436 ;; "caption". Objects restrictions for such keywords are defined in
3437 ;; `org-element-object-restrictions'.
3439 ;; - DUALS is used to take care of keywords accepting a main and an
3440 ;; optional secondary values. For example "results" has its
3441 ;; source's name as the main value, and may have an hash string in
3442 ;; optional square brackets as the secondary one.
3444 ;; A keyword may belong to more than one category.
3446 (defun org-element--collect-affiliated-keywords
3447 (&optional key-re trans-list consed parsed duals
)
3448 "Collect affiliated keywords before point.
3450 Optional argument KEY-RE is a regexp matching keywords, which
3451 puts matched keyword in group 1. It defaults to
3452 `org-element--affiliated-re'.
3454 TRANS-LIST is an alist where key is the keyword and value the
3455 property name it should be translated to, without the colons. It
3456 defaults to `org-element-keyword-translation-alist'.
3458 CONSED is a list of strings. Any keyword belonging to that list
3459 will have its value consed. The check is done after keyword
3460 translation. It defaults to `org-element-multiple-keywords'.
3462 PARSED is a list of strings. Any keyword member of this list
3463 will have its value parsed. The check is done after keyword
3464 translation. If a keyword is a member of both CONSED and PARSED,
3465 it's value will be a list of parsed strings. It defaults to
3466 `org-element-parsed-keywords'.
3468 DUALS is a list of strings. Any keyword member of this list can
3469 have two parts: one mandatory and one optional. Its value is
3470 a cons cell whose CAR is the former, and the CDR the latter. If
3471 a keyword is a member of both PARSED and DUALS, both values will
3472 be parsed. It defaults to `org-element-dual-keywords'.
3474 Return a list whose CAR is the position at the first of them and
3475 CDR a plist of keywords and values."
3477 (let ((case-fold-search t
)
3478 (key-re (or key-re org-element--affiliated-re
))
3479 (trans-list (or trans-list org-element-keyword-translation-alist
))
3480 (consed (or consed org-element-multiple-keywords
))
3481 (parsed (or parsed org-element-parsed-keywords
))
3482 (duals (or duals org-element-dual-keywords
))
3483 ;; RESTRICT is the list of objects allowed in parsed
3485 (restrict (org-element-restriction 'keyword
))
3488 (while (and (not (bobp)) (progn (forward-line -
1) (looking-at key-re
)))
3489 (let* ((raw-kwd (upcase (or (match-string 2) (match-string 1))))
3490 ;; Apply translation to RAW-KWD. From there, KWD is
3491 ;; the official keyword.
3492 (kwd (or (cdr (assoc raw-kwd trans-list
)) raw-kwd
))
3493 ;; Find main value for any keyword.
3497 (buffer-substring-no-properties
3498 (match-end 0) (point-at-eol)))))
3499 ;; If KWD is a dual keyword, find its secondary
3500 ;; value. Maybe parse it.
3502 (and (member kwd duals
)
3503 (let ((sec (org-match-string-no-properties 3)))
3504 (if (or (not sec
) (not (member kwd parsed
))) sec
3505 (org-element-parse-secondary-string sec restrict
)))))
3506 ;; Attribute a property name to KWD.
3507 (kwd-sym (and kwd
(intern (concat ":" (downcase kwd
))))))
3508 ;; Now set final shape for VALUE.
3509 (when (member kwd parsed
)
3510 (setq value
(org-element-parse-secondary-string value restrict
)))
3511 (when (member kwd duals
)
3512 ;; VALUE is mandatory. Set it to nil if there is none.
3513 (setq value
(and value
(cons value dual-value
))))
3514 ;; Attributes are always consed.
3515 (when (or (member kwd consed
) (string-match "^ATTR_" kwd
))
3516 (setq value
(cons value
(plist-get output kwd-sym
))))
3517 ;; Eventually store the new value in OUTPUT.
3518 (setq output
(plist-put output kwd-sym value
))))
3519 (unless (looking-at key-re
) (forward-line 1)))
3520 (list (point) output
))))
3526 ;; The two major functions here are `org-element-parse-buffer', which
3527 ;; parses Org syntax inside the current buffer, taking into account
3528 ;; region, narrowing, or even visibility if specified, and
3529 ;; `org-element-parse-secondary-string', which parses objects within
3532 ;; The (almost) almighty `org-element-map' allows to apply a function
3533 ;; on elements or objects matching some type, and accumulate the
3534 ;; resulting values. In an export situation, it also skips unneeded
3535 ;; parts of the parse tree.
3537 (defun org-element-parse-buffer (&optional granularity visible-only
)
3538 "Recursively parse the buffer and return structure.
3539 If narrowing is in effect, only parse the visible part of the
3542 Optional argument GRANULARITY determines the depth of the
3543 recursion. It can be set to the following symbols:
3545 `headline' Only parse headlines.
3546 `greater-element' Don't recurse into greater elements excepted
3547 headlines and sections. Thus, elements
3548 parsed are the top-level ones.
3549 `element' Parse everything but objects and plain text.
3550 `object' Parse the complete buffer (default).
3552 When VISIBLE-ONLY is non-nil, don't parse contents of hidden
3555 Assume buffer is in Org mode."
3557 (goto-char (point-min))
3558 (org-skip-whitespace)
3559 (org-element--parse-elements
3560 (point-at-bol) (point-max)
3561 ;; Start in `first-section' mode so text before the first
3562 ;; headline belongs to a section.
3563 'first-section nil granularity visible-only
(list 'org-data nil
))))
3565 (defun org-element-parse-secondary-string (string restriction
&optional parent
)
3566 "Recursively parse objects in STRING and return structure.
3568 RESTRICTION is a symbol limiting the object types that will be
3571 Optional argument PARENT, when non-nil, is the element or object
3572 containing the secondary string. It is used to set correctly
3573 `:parent' property within the string."
3576 (let ((secondary (org-element--parse-objects
3577 (point-min) (point-max) nil restriction
)))
3578 (mapc (lambda (obj) (org-element-put-property obj
:parent parent
))
3581 (defun org-element-map (data types fun
&optional info first-match no-recursion
)
3582 "Map a function on selected elements or objects.
3584 DATA is the parsed tree, as returned by, i.e,
3585 `org-element-parse-buffer'. TYPES is a symbol or list of symbols
3586 of elements or objects types. FUN is the function called on the
3587 matching element or object. It must accept one arguments: the
3588 element or object itself.
3590 When optional argument INFO is non-nil, it should be a plist
3591 holding export options. In that case, parts of the parse tree
3592 not exportable according to that property list will be skipped.
3594 When optional argument FIRST-MATCH is non-nil, stop at the first
3595 match for which FUN doesn't return nil, and return that value.
3597 Optional argument NO-RECURSION is a symbol or a list of symbols
3598 representing elements or objects types. `org-element-map' won't
3599 enter any recursive element or object whose type belongs to that
3600 list. Though, FUN can still be applied on them.
3602 Nil values returned from FUN do not appear in the results."
3603 ;; Ensure TYPES and NO-RECURSION are a list, even of one element.
3604 (unless (listp types
) (setq types
(list types
)))
3605 (unless (listp no-recursion
) (setq no-recursion
(list no-recursion
)))
3606 ;; Recursion depth is determined by --CATEGORY.
3609 (let ((category 'greater-elements
))
3610 (mapc (lambda (type)
3611 (cond ((or (memq type org-element-all-objects
)
3612 (eq type
'plain-text
))
3613 ;; If one object is found, the function
3614 ;; has to recurse into every object.
3615 (throw 'found
'objects
))
3616 ((not (memq type org-element-greater-elements
))
3617 ;; If one regular element is found, the
3618 ;; function has to recurse, at least,
3619 ;; into every element it encounters.
3620 (and (not (eq category
'elements
))
3621 (setq category
'elements
)))))
3629 ;; Recursively walk DATA. INFO, if non-nil, is a plist
3630 ;; holding contextual information.
3631 (let ((--type (org-element-type --data
)))
3634 ;; Ignored element in an export context.
3635 ((and info
(memq --data
(plist-get info
:ignore-list
))))
3636 ;; Secondary string: only objects can be found there.
3638 (when (eq --category
'objects
) (mapc --walk-tree --data
)))
3639 ;; Unconditionally enter parse trees.
3640 ((eq --type
'org-data
)
3641 (mapc --walk-tree
(org-element-contents --data
)))
3643 ;; Check if TYPE is matching among TYPES. If so,
3644 ;; apply FUN to --DATA and accumulate return value
3645 ;; into --ACC (or exit if FIRST-MATCH is non-nil).
3646 (when (memq --type types
)
3647 (let ((result (funcall fun --data
)))
3648 (cond ((not result
))
3649 (first-match (throw '--map-first-match result
))
3650 (t (push result --acc
)))))
3651 ;; If --DATA has a secondary string that can contain
3652 ;; objects with their type among TYPES, look into it.
3653 (when (eq --category
'objects
)
3655 (assq --type org-element-secondary-value-alist
)))
3657 (funcall --walk-tree
3658 (org-element-property (cdr sec-prop
) --data
)))))
3659 ;; Determine if a recursion into --DATA is possible.
3661 ;; --TYPE is explicitly removed from recursion.
3662 ((memq --type no-recursion
))
3663 ;; --DATA has no contents.
3664 ((not (org-element-contents --data
)))
3665 ;; Looking for greater elements but --DATA is simply
3666 ;; an element or an object.
3667 ((and (eq --category
'greater-elements
)
3668 (not (memq --type org-element-greater-elements
))))
3669 ;; Looking for elements but --DATA is an object.
3670 ((and (eq --category
'elements
)
3671 (memq --type org-element-all-objects
)))
3672 ;; In any other case, map contents.
3673 (t (mapc --walk-tree
(org-element-contents --data
)))))))))))
3674 (catch '--map-first-match
3675 (funcall --walk-tree data
)
3676 ;; Return value in a proper order.
3679 ;; The following functions are internal parts of the parser.
3681 ;; The first one, `org-element--parse-elements' acts at the element's
3684 ;; The second one, `org-element--parse-objects' applies on all objects
3685 ;; of a paragraph or a secondary string. It uses
3686 ;; `org-element--get-next-object-candidates' to optimize the search of
3687 ;; the next object in the buffer.
3689 ;; More precisely, that function looks for every allowed object type
3690 ;; first. Then, it discards failed searches, keeps further matches,
3691 ;; and searches again types matched behind point, for subsequent
3692 ;; calls. Thus, searching for a given type fails only once, and every
3693 ;; object is searched only once at top level (but sometimes more for
3696 (defun org-element--parse-elements
3697 (beg end special structure granularity visible-only acc
)
3698 "Parse elements between BEG and END positions.
3700 SPECIAL prioritize some elements over the others. It can be set
3701 to `first-section', `quote-section', `section' `item' or
3704 When value is `item', STRUCTURE will be used as the current list
3707 GRANULARITY determines the depth of the recursion. See
3708 `org-element-parse-buffer' for more information.
3710 When VISIBLE-ONLY is non-nil, don't parse contents of hidden
3713 Elements are accumulated into ACC."
3716 ;; When parsing only headlines, skip any text before first one.
3717 (when (and (eq granularity
'headline
) (not (org-at-heading-p)))
3718 (org-with-limited-levels (outline-next-heading)))
3720 (while (< (point) end
)
3721 ;; Find current element's type and parse it accordingly to
3723 (let* ((element (org-element--current-element
3724 end granularity special structure
))
3725 (type (org-element-type element
))
3726 (cbeg (org-element-property :contents-begin element
)))
3727 (goto-char (org-element-property :end element
))
3728 ;; Fill ELEMENT contents by side-effect.
3730 ;; If VISIBLE-ONLY is true and element is hidden or if it has
3731 ;; no contents, don't modify it.
3732 ((or (and visible-only
(org-element-property :hiddenp element
))
3734 ;; Greater element: parse it between `contents-begin' and
3735 ;; `contents-end'. Make sure GRANULARITY allows the
3736 ;; recursion, or ELEMENT is an headline, in which case going
3737 ;; inside is mandatory, in order to get sub-level headings.
3738 ((and (memq type org-element-greater-elements
)
3739 (or (memq granularity
'(element object nil
))
3740 (and (eq granularity
'greater-element
)
3742 (eq type
'headline
)))
3743 (org-element--parse-elements
3744 cbeg
(org-element-property :contents-end element
)
3745 ;; Possibly switch to a special mode.
3748 (if (org-element-property :quotedp element
) 'quote-section
3752 (org-element-property :structure element
)
3753 granularity visible-only element
))
3754 ;; ELEMENT has contents. Parse objects inside, if
3755 ;; GRANULARITY allows it.
3756 ((memq granularity
'(object nil
))
3757 (org-element--parse-objects
3758 cbeg
(org-element-property :contents-end element
) element
3759 (org-element-restriction type
))))
3760 (org-element-adopt-elements acc element
)))
3764 (defun org-element--parse-objects (beg end acc restriction
)
3765 "Parse objects between BEG and END and return recursive structure.
3767 Objects are accumulated in ACC.
3769 RESTRICTION is a list of object types which are allowed in the
3774 (while (and (< (point) end
)
3775 (setq candidates
(org-element--get-next-object-candidates
3776 end restriction candidates
)))
3778 (let ((pos (apply 'min
(mapcar 'cdr candidates
))))
3781 (funcall (intern (format "org-element-%s-parser"
3782 (car (rassq pos candidates
)))))))))
3783 ;; 1. Text before any object. Untabify it.
3784 (let ((obj-beg (org-element-property :begin next-object
)))
3785 (unless (= (point) obj-beg
)
3787 (org-element-adopt-elements
3789 (replace-regexp-in-string
3790 "\t" (make-string tab-width ?
)
3791 (buffer-substring-no-properties (point) obj-beg
))))))
3793 (let ((obj-end (org-element-property :end next-object
))
3794 (cont-beg (org-element-property :contents-begin next-object
)))
3795 ;; Fill contents of NEXT-OBJECT by side-effect, if it has
3796 ;; a recursive type.
3798 (memq (car next-object
) org-element-recursive-objects
))
3802 (org-element-property :contents-end next-object
))
3803 (org-element--parse-objects
3804 (point-min) (point-max) next-object
3805 (org-element-restriction next-object
))))
3806 (setq acc
(org-element-adopt-elements acc next-object
))
3807 (goto-char obj-end
))))
3808 ;; 3. Text after last object. Untabify it.
3809 (unless (= (point) end
)
3811 (org-element-adopt-elements
3813 (replace-regexp-in-string
3814 "\t" (make-string tab-width ?
)
3815 (buffer-substring-no-properties (point) end
)))))
3819 (defun org-element--get-next-object-candidates (limit restriction objects
)
3820 "Return an alist of candidates for the next object.
3822 LIMIT bounds the search, and RESTRICTION narrows candidates to
3825 Return value is an alist whose CAR is position and CDR the object
3828 OBJECTS is the previous candidates alist."
3829 (let (next-candidates types-to-search
)
3830 ;; If no previous result, search every object type in RESTRICTION.
3831 ;; Otherwise, keep potential candidates (old objects located after
3832 ;; point) and ask to search again those which had matched before.
3833 (if (not objects
) (setq types-to-search restriction
)
3835 (if (< (cdr obj
) (point)) (push (car obj
) types-to-search
)
3836 (push obj next-candidates
)))
3838 ;; Call the appropriate successor function for each type to search
3839 ;; and accumulate matches.
3842 (let* ((successor-fun
3844 (format "org-element-%s-successor"
3845 (or (cdr (assq type org-element-object-successor-alist
))
3847 (obj (funcall successor-fun limit
)))
3848 (and obj
(push obj next-candidates
))))
3855 ;;; Towards A Bijective Process
3857 ;; The parse tree obtained with `org-element-parse-buffer' is really
3858 ;; a snapshot of the corresponding Org buffer. Therefore, it can be
3859 ;; interpreted and expanded into a string with canonical Org syntax.
3860 ;; Hence `org-element-interpret-data'.
3862 ;; The function relies internally on
3863 ;; `org-element--interpret-affiliated-keywords'.
3866 (defun org-element-interpret-data (data &optional parent
)
3867 "Interpret DATA as Org syntax.
3869 DATA is a parse tree, an element, an object or a secondary string
3872 Optional argument PARENT is used for recursive calls. It contains
3873 the element or object containing data, or nil.
3875 Return Org syntax as a string."
3876 (let* ((type (org-element-type data
))
3879 ;; Secondary string.
3882 (lambda (obj) (org-element-interpret-data obj parent
))
3884 ;; Full Org document.
3885 ((eq type
'org-data
)
3887 (lambda (obj) (org-element-interpret-data obj parent
))
3888 (org-element-contents data
) ""))
3890 ((stringp data
) data
)
3891 ;; Element/Object without contents.
3892 ((not (org-element-contents data
))
3893 (funcall (intern (format "org-element-%s-interpreter" type
))
3895 ;; Element/Object with contents.
3897 (let* ((greaterp (memq type org-element-greater-elements
))
3898 (objectp (and (not greaterp
)
3899 (memq type org-element-recursive-objects
)))
3902 (lambda (obj) (org-element-interpret-data obj data
))
3903 (org-element-contents
3904 (if (or greaterp objectp
) data
3905 ;; Elements directly containing objects must
3906 ;; have their indentation normalized first.
3907 (org-element-normalize-contents
3909 ;; When normalizing first paragraph of an
3910 ;; item or a footnote-definition, ignore
3911 ;; first line's indentation.
3912 (and (eq type
'paragraph
)
3913 (equal data
(car (org-element-contents parent
)))
3914 (memq (org-element-type parent
)
3915 '(footnote-definiton item
))))))
3917 (funcall (intern (format "org-element-%s-interpreter" type
))
3919 (if greaterp
(org-element-normalize-contents contents
)
3921 (if (memq type
'(org-data plain-text nil
)) results
3922 ;; Build white spaces. If no `:post-blank' property is
3923 ;; specified, assume its value is 0.
3924 (let ((post-blank (or (org-element-property :post-blank data
) 0)))
3925 (if (memq type org-element-all-objects
)
3926 (concat results
(make-string post-blank
32))
3928 (org-element--interpret-affiliated-keywords data
)
3929 (org-element-normalize-string results
)
3930 (make-string post-blank
10)))))))
3932 (defun org-element--interpret-affiliated-keywords (element)
3933 "Return ELEMENT's affiliated keywords as Org syntax.
3934 If there is no affiliated keyword, return the empty string."
3935 (let ((keyword-to-org
3939 (when (member key org-element-dual-keywords
)
3940 (setq dual
(cdr value
) value
(car value
)))
3943 (format "[%s]" (org-element-interpret-data dual
)))
3945 (if (member key org-element-parsed-keywords
)
3946 (org-element-interpret-data value
)
3951 (let ((value (org-element-property prop element
))
3952 (keyword (upcase (substring (symbol-name prop
) 1))))
3954 (if (or (member keyword org-element-multiple-keywords
)
3955 ;; All attribute keywords can have multiple lines.
3956 (string-match "^ATTR_" keyword
))
3957 (mapconcat (lambda (line) (funcall keyword-to-org keyword line
))
3960 (funcall keyword-to-org keyword value
)))))
3961 ;; List all ELEMENT's properties matching an attribute line or an
3962 ;; affiliated keyword, but ignore translated keywords since they
3963 ;; cannot belong to the property list.
3964 (loop for prop in
(nth 1 element
) by
'cddr
3965 when
(let ((keyword (upcase (substring (symbol-name prop
) 1))))
3966 (or (string-match "^ATTR_" keyword
)
3968 (member keyword org-element-affiliated-keywords
)
3970 org-element-keyword-translation-alist
)))))
3974 ;; Because interpretation of the parse tree must return the same
3975 ;; number of blank lines between elements and the same number of white
3976 ;; space after objects, some special care must be given to white
3979 ;; The first function, `org-element-normalize-string', ensures any
3980 ;; string different from the empty string will end with a single
3981 ;; newline character.
3983 ;; The second function, `org-element-normalize-contents', removes
3984 ;; global indentation from the contents of the current element.
3986 (defun org-element-normalize-string (s)
3987 "Ensure string S ends with a single newline character.
3989 If S isn't a string return it unchanged. If S is the empty
3990 string, return it. Otherwise, return a new string with a single
3991 newline character at its end."
3993 ((not (stringp s
)) s
)
3995 (t (and (string-match "\\(\n[ \t]*\\)*\\'" s
)
3996 (replace-match "\n" nil nil s
)))))
3998 (defun org-element-normalize-contents (element &optional ignore-first
)
3999 "Normalize plain text in ELEMENT's contents.
4001 ELEMENT must only contain plain text and objects.
4003 If optional argument IGNORE-FIRST is non-nil, ignore first line's
4004 indentation to compute maximal common indentation.
4006 Return the normalized element that is element with global
4007 indentation removed from its contents. The function assumes that
4008 indentation is not done with TAB characters."
4009 (let* (ind-list ; for byte-compiler
4010 collect-inds
; for byte-compiler
4013 ;; Return list of indentations within BLOB. This is done by
4014 ;; walking recursively BLOB and updating IND-LIST along the
4015 ;; way. FIRST-FLAG is non-nil when the first string hasn't
4016 ;; been seen yet. It is required as this string is the only
4017 ;; one whose indentation doesn't happen after a newline
4019 (lambda (blob first-flag
)
4022 (when (and first-flag
(stringp object
))
4023 (setq first-flag nil
)
4024 (string-match "\\`\\( *\\)" object
)
4025 (let ((len (length (match-string 1 object
))))
4026 ;; An indentation of zero means no string will be
4027 ;; modified. Quit the process.
4028 (if (zerop len
) (throw 'zero
(setq ind-list nil
))
4029 (push len ind-list
))))
4033 ;; Avoid matching blank or empty lines.
4034 (while (and (string-match "\n\\( *\\)\\(.\\)" object start
)
4035 (not (equal (match-string 2 object
) " ")))
4036 (setq start
(match-end 0))
4037 (push (length (match-string 1 object
)) ind-list
))))
4038 ((memq (org-element-type object
) org-element-recursive-objects
)
4039 (funcall collect-inds object first-flag
))))
4040 (org-element-contents blob
))))))
4041 ;; Collect indentation list in ELEMENT. Possibly remove first
4042 ;; value if IGNORE-FIRST is non-nil.
4043 (catch 'zero
(funcall collect-inds element
(not ignore-first
)))
4044 (if (not ind-list
) element
4045 ;; Build ELEMENT back, replacing each string with the same
4046 ;; string minus common indentation.
4047 (let* (build ; For byte compiler.
4050 (lambda (blob mci first-flag
)
4051 ;; Return BLOB with all its strings indentation
4052 ;; shortened from MCI white spaces. FIRST-FLAG is
4053 ;; non-nil when the first string hasn't been seen
4058 (when (and first-flag
(stringp object
))
4059 (setq first-flag nil
)
4061 (replace-regexp-in-string
4062 (format "\\` \\{%d\\}" mci
) "" object
)))
4065 (replace-regexp-in-string
4066 (format "\n \\{%d\\}" mci
) "\n" object
))
4067 ((memq (org-element-type object
)
4068 org-element-recursive-objects
)
4069 (funcall build object mci first-flag
))
4071 (org-element-contents blob
)))
4073 (funcall build element
(apply 'min ind-list
) (not ignore-first
))))))
4079 ;; The first move is to implement a way to obtain the smallest element
4080 ;; containing point. This is the job of `org-element-at-point'. It
4081 ;; basically jumps back to the beginning of section containing point
4082 ;; and moves, element after element, with
4083 ;; `org-element--current-element' until the container is found. Note:
4084 ;; When using `org-element-at-point', secondary values are never
4085 ;; parsed since the function focuses on elements, not on objects.
4087 ;; At a deeper level, `org-element-context' lists all elements and
4088 ;; objects containing point.
4090 ;; `org-element-nested-p' and `org-element-swap-A-B' may be used
4091 ;; internally by navigation and manipulation tools.
4094 (defun org-element-at-point (&optional keep-trail
)
4095 "Determine closest element around point.
4097 Return value is a list like (TYPE PROPS) where TYPE is the type
4098 of the element and PROPS a plist of properties associated to the
4101 Possible types are defined in `org-element-all-elements'.
4102 Properties depend on element or object type, but always
4103 include :begin, :end, :parent and :post-blank properties.
4105 As a special case, if point is at the very beginning of a list or
4106 sub-list, returned element will be that list instead of the first
4107 item. In the same way, if point is at the beginning of the first
4108 row of a table, returned element will be the table instead of the
4111 If optional argument KEEP-TRAIL is non-nil, the function returns
4112 a list of of elements leading to element at point. The list's
4113 CAR is always the element at point. Following positions contain
4114 element's siblings, then parents, siblings of parents, until the
4115 first element of current section."
4116 (org-with-wide-buffer
4117 ;; If at an headline, parse it. It is the sole element that
4118 ;; doesn't require to know about context. Be sure to disallow
4119 ;; secondary string parsing, though.
4120 (if (org-with-limited-levels (org-at-heading-p))
4123 (if (not keep-trail
) (org-element-headline-parser (point-max) t
)
4124 (list (org-element-headline-parser (point-max) t
))))
4125 ;; Otherwise move at the beginning of the section containing
4127 (let ((origin (point))
4128 (end (save-excursion
4129 (org-with-limited-levels (outline-next-heading)) (point)))
4130 element type special-flag trail struct prevs parent
)
4131 (org-with-limited-levels
4132 (if (org-with-limited-levels (org-before-first-heading-p))
4133 (goto-char (point-min))
4134 (org-back-to-heading)
4136 (org-skip-whitespace)
4138 ;; Parse successively each element, skipping those ending
4139 ;; before original position.
4143 (org-element--current-element end
'element special-flag struct
)
4145 (org-element-put-property element
:parent parent
)
4146 (when keep-trail
(push element trail
))
4148 ;; 1. Skip any element ending before point. Also skip
4149 ;; element ending at point when we're sure that another
4150 ;; element has started.
4151 ((let ((elem-end (org-element-property :end element
)))
4152 (when (or (< elem-end origin
)
4153 (and (= elem-end origin
) (/= elem-end end
)))
4154 (goto-char elem-end
))))
4155 ;; 2. An element containing point is always the element at
4157 ((not (memq type org-element-greater-elements
))
4158 (throw 'exit
(if keep-trail trail element
)))
4159 ;; 3. At any other greater element type, if point is
4160 ;; within contents, move into it.
4162 (let ((cbeg (org-element-property :contents-begin element
))
4163 (cend (org-element-property :contents-end element
)))
4164 (if (or (not cbeg
) (not cend
) (> cbeg origin
) (< cend origin
)
4165 ;; Create an anchor for tables and plain lists:
4166 ;; when point is at the very beginning of these
4167 ;; elements, ignoring affiliated keywords,
4168 ;; target them instead of their contents.
4169 (and (= cbeg origin
) (memq type
'(plain-list table
)))
4170 ;; When point is at contents end, do not move
4171 ;; into elements with an explicit ending, but
4172 ;; return that element instead.
4173 (and (= cend origin
)
4176 drawer dynamic-block inlinetask item
4177 plain-list quote-block special-block
))))
4178 (throw 'exit
(if keep-trail trail element
))
4179 (setq parent element
)
4182 (setq special-flag
'item
4183 struct
(org-element-property :structure element
)))
4184 (table (setq special-flag
'table-row
))
4185 (otherwise (setq special-flag nil
)))
4187 (goto-char cbeg
)))))))))))
4190 (defun org-element-context ()
4191 "Return closest element or object around point.
4193 Return value is a list like (TYPE PROPS) where TYPE is the type
4194 of the element or object and PROPS a plist of properties
4197 Possible types are defined in `org-element-all-elements' and
4198 `org-element-all-objects'. Properties depend on element or
4199 object type, but always include :begin, :end, :parent
4200 and :post-blank properties."
4201 (org-with-wide-buffer
4202 (let* ((origin (point))
4203 (element (org-element-at-point))
4204 (type (car element
))
4206 ;; Check if point is inside an element containing objects or at
4207 ;; a secondary string. In that case, move to beginning of the
4208 ;; element or secondary string and set END to the other side.
4209 (if (not (or (and (eq type
'item
)
4210 (let ((tag (org-element-property :tag element
)))
4214 (search-forward tag
(point-at-eol))
4215 (goto-char (match-beginning 0))
4216 (and (>= origin
(point))
4218 ;; `1+' is required so some
4219 ;; successors can match
4220 ;; properly their object.
4221 (setq end
(1+ (match-end 0)))))))))
4222 (and (memq type
'(headline inlinetask
))
4223 (progn (beginning-of-line)
4224 (skip-chars-forward "* ")
4225 (setq end
(point-at-eol))))
4226 (and (memq type
'(paragraph table-cell verse-block
))
4227 (let ((cbeg (org-element-property
4228 :contents-begin element
))
4229 (cend (org-element-property
4230 :contents-end element
)))
4231 (and (>= origin cbeg
)
4233 (progn (goto-char cbeg
) (setq end cend
)))))))
4235 (let ((restriction (org-element-restriction element
))
4239 (while (setq candidates
(org-element--get-next-object-candidates
4240 end restriction candidates
))
4241 (let ((closest-cand (rassq (apply 'min
(mapcar 'cdr candidates
))
4243 ;; If ORIGIN is before next object in element, there's
4244 ;; no point in looking further.
4245 (if (> (cdr closest-cand
) origin
) (throw 'exit element
)
4247 (progn (goto-char (cdr closest-cand
))
4248 (funcall (intern (format "org-element-%s-parser"
4249 (car closest-cand
))))))
4250 (cbeg (org-element-property :contents-begin object
))
4251 (cend (org-element-property :contents-end object
)))
4253 ;; ORIGIN is after OBJECT, so skip it.
4254 ((< (org-element-property :end object
) origin
)
4255 (goto-char (org-element-property :end object
)))
4256 ;; ORIGIN is within a non-recursive object or at an
4257 ;; object boundaries: Return that object.
4258 ((or (not cbeg
) (> cbeg origin
) (< cend origin
))
4260 (org-element-put-property object
:parent parent
)))
4261 ;; Otherwise, move within current object and restrict
4262 ;; search to the end of its contents.
4264 (org-element-put-property object
:parent parent
)
4265 (setq parent object end cend
)))))))
4268 (defsubst org-element-nested-p
(elem-A elem-B
)
4269 "Non-nil when elements ELEM-A and ELEM-B are nested."
4270 (let ((beg-A (org-element-property :begin elem-A
))
4271 (beg-B (org-element-property :begin elem-B
))
4272 (end-A (org-element-property :end elem-A
))
4273 (end-B (org-element-property :end elem-B
)))
4274 (or (and (>= beg-A beg-B
) (<= end-A end-B
))
4275 (and (>= beg-B beg-A
) (<= end-B end-A
)))))
4277 (defun org-element-swap-A-B (elem-A elem-B
)
4278 "Swap elements ELEM-A and ELEM-B.
4279 Assume ELEM-B is after ELEM-A in the buffer. Leave point at the
4281 (goto-char (org-element-property :begin elem-A
))
4282 ;; There are two special cases when an element doesn't start at bol:
4283 ;; the first paragraph in an item or in a footnote definition.
4284 (let ((specialp (not (bolp))))
4285 ;; Only a paragraph without any affiliated keyword can be moved at
4286 ;; ELEM-A position in such a situation. Note that the case of
4287 ;; a footnote definition is impossible: it cannot contain two
4288 ;; paragraphs in a row because it cannot contain a blank line.
4290 (or (not (eq (org-element-type elem-B
) 'paragraph
))
4291 (/= (org-element-property :begin elem-B
)
4292 (org-element-property :contents-begin elem-B
))))
4293 (error "Cannot swap elements"))
4294 ;; In a special situation, ELEM-A will have no indentation. We'll
4295 ;; give it ELEM-B's (which will in, in turn, have no indentation).
4296 (let* ((ind-B (when specialp
4297 (goto-char (org-element-property :begin elem-B
))
4298 (org-get-indentation)))
4299 (beg-A (org-element-property :begin elem-A
))
4300 (end-A (save-excursion
4301 (goto-char (org-element-property :end elem-A
))
4302 (skip-chars-backward " \r\t\n")
4304 (beg-B (org-element-property :begin elem-B
))
4305 (end-B (save-excursion
4306 (goto-char (org-element-property :end elem-B
))
4307 (skip-chars-backward " \r\t\n")
4309 ;; Store overlays responsible for visibility status. We
4310 ;; also need to store their boundaries as they will be
4311 ;; removed from buffer.
4314 (mapcar (lambda (ov) (list ov
(overlay-start ov
) (overlay-end ov
)))
4315 (overlays-in beg-A end-A
))
4316 (mapcar (lambda (ov) (list ov
(overlay-start ov
) (overlay-end ov
)))
4317 (overlays-in beg-B end-B
))))
4319 (body-A (buffer-substring beg-A end-A
))
4320 (body-B (delete-and-extract-region beg-B end-B
)))
4323 (setq body-B
(replace-regexp-in-string "\\`[ \t]*" "" body-B
))
4324 (org-indent-to-column ind-B
))
4326 ;; Restore ex ELEM-A overlays.
4327 (let ((offset (- beg-B beg-A
)))
4330 (car ov
) (+ (nth 1 ov
) offset
) (+ (nth 2 ov
) offset
)))
4333 (delete-region beg-A end-A
)
4335 ;; Restore ex ELEM-B overlays.
4338 (car ov
) (- (nth 1 ov
) offset
) (- (nth 2 ov
) offset
)))
4340 (goto-char (org-element-property :end elem-B
)))))
4343 (provide 'org-element
)
4344 ;;; org-element.el ends here