2012-07-28 01:02:21 -04:00
|
|
|
|
;;; org-element.el --- Parser And Applications for Org syntax
|
|
|
|
|
|
2013-01-08 09:26:04 -05:00
|
|
|
|
;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
|
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
|
|
2012-09-24 13:15:42 -04:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
2012-09-24 13:15:42 -04:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2012-09-24 13:15:42 -04:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;
|
|
|
|
|
;; Org syntax can be divided into three categories: "Greater
|
|
|
|
|
;; elements", "Elements" and "Objects".
|
|
|
|
|
;;
|
|
|
|
|
;; Elements are related to the structure of the document. Indeed, all
|
|
|
|
|
;; elements are a cover for the document: each position within belongs
|
|
|
|
|
;; to at least one element.
|
|
|
|
|
;;
|
|
|
|
|
;; An element always starts and ends at the beginning of a line. With
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; a few exceptions (`clock', `headline', `inlinetask', `item',
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;; `planning', `node-property', `quote-section' `section' and
|
|
|
|
|
;; `table-row' types), it can also accept a fixed set of keywords as
|
|
|
|
|
;; attributes. Those are called "affiliated keywords" to distinguish
|
|
|
|
|
;; them from other keywords, which are full-fledged elements. Almost
|
|
|
|
|
;; all affiliated keywords are referenced in
|
|
|
|
|
;; `org-element-affiliated-keywords'; the others are export attributes
|
|
|
|
|
;; and start with "ATTR_" prefix.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;
|
|
|
|
|
;; Element containing other elements (and only elements) are called
|
|
|
|
|
;; greater elements. Concerned types are: `center-block', `drawer',
|
|
|
|
|
;; `dynamic-block', `footnote-definition', `headline', `inlinetask',
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;; `item', `plain-list', `property-drawer', `quote-block', `section'
|
|
|
|
|
;; and `special-block'.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;
|
|
|
|
|
;; Other element types are: `babel-call', `clock', `comment',
|
2012-10-27 08:23:37 -04:00
|
|
|
|
;; `comment-block', `diary-sexp', `example-block', `export-block',
|
|
|
|
|
;; `fixed-width', `horizontal-rule', `keyword', `latex-environment',
|
|
|
|
|
;; `node-property', `paragraph', `planning', `quote-section',
|
|
|
|
|
;; `src-block', `table', `table-row' and `verse-block'. Among them,
|
|
|
|
|
;; `paragraph' and `verse-block' types can contain Org objects and
|
|
|
|
|
;; plain text.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;
|
|
|
|
|
;; Objects are related to document's contents. Some of them are
|
|
|
|
|
;; recursive. Associated types are of the following: `bold', `code',
|
|
|
|
|
;; `entity', `export-snippet', `footnote-reference',
|
|
|
|
|
;; `inline-babel-call', `inline-src-block', `italic',
|
|
|
|
|
;; `latex-fragment', `line-break', `link', `macro', `radio-target',
|
|
|
|
|
;; `statistics-cookie', `strike-through', `subscript', `superscript',
|
|
|
|
|
;; `table-cell', `target', `timestamp', `underline' and `verbatim'.
|
|
|
|
|
;;
|
|
|
|
|
;; Some elements also have special properties whose value can hold
|
2013-02-23 07:47:44 -05:00
|
|
|
|
;; objects themselves (i.e. an item tag or a headline name). Such
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; values are called "secondary strings". Any object belongs to
|
|
|
|
|
;; either an element or a secondary string.
|
|
|
|
|
;;
|
|
|
|
|
;; Notwithstanding affiliated keywords, each greater element, element
|
|
|
|
|
;; and object has a fixed set of properties attached to it. Among
|
|
|
|
|
;; them, four are shared by all types: `:begin' and `:end', which
|
|
|
|
|
;; refer to the beginning and ending buffer positions of the
|
|
|
|
|
;; considered element or object, `:post-blank', which holds the number
|
|
|
|
|
;; of blank lines, or white spaces, at its end and `:parent' which
|
2012-10-29 16:57:46 -04:00
|
|
|
|
;; refers to the element or object containing it. Greater elements,
|
|
|
|
|
;; elements and objects containing objects will also have
|
|
|
|
|
;; `:contents-begin' and `:contents-end' properties to delimit
|
|
|
|
|
;; contents. Eventually, greater elements and elements accepting
|
|
|
|
|
;; affiliated keywords will have a `:post-affiliated' property,
|
|
|
|
|
;; referring to the buffer position after all such keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;
|
2012-10-25 15:33:57 -04:00
|
|
|
|
;; At the lowest level, a `:parent' property is also attached to any
|
|
|
|
|
;; string, as a text property.
|
|
|
|
|
;;
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Lisp-wise, an element or an object can be represented as a list.
|
|
|
|
|
;; It follows the pattern (TYPE PROPERTIES CONTENTS), where:
|
|
|
|
|
;; TYPE is a symbol describing the Org element or object.
|
|
|
|
|
;; PROPERTIES is the property list attached to it. See docstring of
|
|
|
|
|
;; appropriate parsing function to get an exhaustive
|
|
|
|
|
;; list.
|
|
|
|
|
;; CONTENTS is a list of elements, objects or raw strings contained
|
|
|
|
|
;; in the current element or object, when applicable.
|
|
|
|
|
;;
|
|
|
|
|
;; An Org buffer is a nested list of such elements and objects, whose
|
|
|
|
|
;; type is `org-data' and properties is nil.
|
|
|
|
|
;;
|
|
|
|
|
;; The first part of this file defines Org syntax, while the second
|
|
|
|
|
;; one provide accessors and setters functions.
|
|
|
|
|
;;
|
|
|
|
|
;; The next part implements a parser and an interpreter for each
|
|
|
|
|
;; element and object type in Org syntax.
|
|
|
|
|
;;
|
|
|
|
|
;; The following part creates a fully recursive buffer parser. It
|
|
|
|
|
;; also provides a tool to map a function to elements or objects
|
|
|
|
|
;; matching some criteria in the parse tree. Functions of interest
|
|
|
|
|
;; are `org-element-parse-buffer', `org-element-map' and, to a lesser
|
|
|
|
|
;; extent, `org-element-parse-secondary-string'.
|
|
|
|
|
;;
|
|
|
|
|
;; The penultimate part is the cradle of an interpreter for the
|
|
|
|
|
;; obtained parse tree: `org-element-interpret-data'.
|
|
|
|
|
;;
|
2012-08-08 07:55:18 -04:00
|
|
|
|
;; The library ends by furnishing `org-element-at-point' function, and
|
|
|
|
|
;; a way to give information about document structure around point
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
;; with `org-element-context'. A simple cache mechanism is also
|
|
|
|
|
;; provided for these functions.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(eval-when-compile (require 'cl))
|
2012-08-06 13:13:43 -04:00
|
|
|
|
(require 'org)
|
2012-08-06 11:06:13 -04:00
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
;;; Definitions And Rules
|
|
|
|
|
;;
|
|
|
|
|
;; Define elements, greater elements and specify recursive objects,
|
|
|
|
|
;; along with the affiliated keywords recognized. Also set up
|
|
|
|
|
;; restrictions on recursive objects combinations.
|
|
|
|
|
;;
|
|
|
|
|
;; These variables really act as a control center for the parsing
|
|
|
|
|
;; process.
|
|
|
|
|
|
|
|
|
|
(defconst org-element-paragraph-separate
|
2012-08-11 11:31:31 -04:00
|
|
|
|
(concat "^\\(?:"
|
|
|
|
|
;; Headlines, inlinetasks.
|
|
|
|
|
org-outline-regexp "\\|"
|
|
|
|
|
;; Footnote definitions.
|
|
|
|
|
"\\[\\(?:[0-9]+\\|fn:[-_[:word:]]+\\)\\]" "\\|"
|
2012-10-27 08:23:37 -04:00
|
|
|
|
;; Diary sexps.
|
|
|
|
|
"%%(" "\\|"
|
2012-08-11 11:31:31 -04:00
|
|
|
|
"[ \t]*\\(?:"
|
|
|
|
|
;; Empty lines.
|
|
|
|
|
"$" "\\|"
|
2012-08-17 09:22:36 -04:00
|
|
|
|
;; Tables (any type).
|
|
|
|
|
"\\(?:|\\|\\+-[-+]\\)" "\\|"
|
|
|
|
|
;; Blocks (any type), Babel calls, drawers (any type),
|
|
|
|
|
;; fixed-width areas and keywords. Note: this is only an
|
|
|
|
|
;; indication and need some thorough check.
|
|
|
|
|
"[#:]" "\\|"
|
2012-08-11 11:31:31 -04:00
|
|
|
|
;; Horizontal rules.
|
|
|
|
|
"-\\{5,\\}[ \t]*$" "\\|"
|
|
|
|
|
;; LaTeX environments.
|
2012-08-24 06:15:53 -04:00
|
|
|
|
"\\\\begin{\\([A-Za-z0-9]+\\*?\\)}" "\\|"
|
2012-08-11 11:31:31 -04:00
|
|
|
|
;; Planning and Clock lines.
|
|
|
|
|
(regexp-opt (list org-scheduled-string
|
|
|
|
|
org-deadline-string
|
|
|
|
|
org-closed-string
|
|
|
|
|
org-clock-string))
|
|
|
|
|
"\\|"
|
|
|
|
|
;; Lists.
|
|
|
|
|
(let ((term (case org-plain-list-ordered-item-terminator
|
2012-08-26 16:24:15 -04:00
|
|
|
|
(?\) ")") (?. "\\.") (otherwise "[.)]")))
|
2013-03-23 12:42:09 -04:00
|
|
|
|
(alpha (and org-list-allow-alphabetical "\\|[A-Za-z]")))
|
2012-08-11 11:31:31 -04:00
|
|
|
|
(concat "\\(?:[-+*]\\|\\(?:[0-9]+" alpha "\\)" term "\\)"
|
|
|
|
|
"\\(?:[ \t]\\|$\\)"))
|
|
|
|
|
"\\)\\)")
|
2012-08-17 09:22:36 -04:00
|
|
|
|
"Regexp to separate paragraphs in an Org buffer.
|
|
|
|
|
In the case of lines starting with \"#\" and \":\", this regexp
|
|
|
|
|
is not sufficient to know if point is at a paragraph ending. See
|
|
|
|
|
`org-element-paragraph-parser' for more information.")
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defconst org-element-all-elements
|
2012-10-27 08:23:37 -04:00
|
|
|
|
'(babel-call center-block clock comment comment-block diary-sexp drawer
|
|
|
|
|
dynamic-block example-block export-block fixed-width
|
|
|
|
|
footnote-definition headline horizontal-rule inlinetask item
|
|
|
|
|
keyword latex-environment node-property paragraph plain-list
|
|
|
|
|
planning property-drawer quote-block quote-section section
|
|
|
|
|
special-block src-block table table-row verse-block)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Complete list of element types.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-greater-elements
|
|
|
|
|
'(center-block drawer dynamic-block footnote-definition headline inlinetask
|
2012-09-23 09:52:02 -04:00
|
|
|
|
item plain-list property-drawer quote-block section
|
|
|
|
|
special-block table)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"List of recursive element types aka Greater Elements.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-all-successors
|
|
|
|
|
'(export-snippet footnote-reference inline-babel-call inline-src-block
|
2013-02-25 15:32:15 -05:00
|
|
|
|
latex-or-entity line-break link macro plain-link radio-target
|
2012-07-28 01:02:21 -04:00
|
|
|
|
statistics-cookie sub/superscript table-cell target
|
|
|
|
|
text-markup timestamp)
|
|
|
|
|
"Complete list of successors.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-object-successor-alist
|
|
|
|
|
'((subscript . sub/superscript) (superscript . sub/superscript)
|
|
|
|
|
(bold . text-markup) (code . text-markup) (italic . text-markup)
|
|
|
|
|
(strike-through . text-markup) (underline . text-markup)
|
|
|
|
|
(verbatim . text-markup) (entity . latex-or-entity)
|
|
|
|
|
(latex-fragment . latex-or-entity))
|
|
|
|
|
"Alist of translations between object type and successor name.
|
|
|
|
|
Sharing the same successor comes handy when, for example, the
|
|
|
|
|
regexp matching one object can also match the other object.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-all-objects
|
|
|
|
|
'(bold code entity export-snippet footnote-reference inline-babel-call
|
|
|
|
|
inline-src-block italic line-break latex-fragment link macro
|
|
|
|
|
radio-target statistics-cookie strike-through subscript superscript
|
|
|
|
|
table-cell target timestamp underline verbatim)
|
|
|
|
|
"Complete list of object types.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-recursive-objects
|
2012-09-01 07:04:59 -04:00
|
|
|
|
'(bold italic link subscript radio-target strike-through superscript
|
2012-07-28 01:02:21 -04:00
|
|
|
|
table-cell underline)
|
|
|
|
|
"List of recursive object types.")
|
|
|
|
|
|
2012-11-19 16:57:17 -05:00
|
|
|
|
(defvar org-element-block-name-alist
|
2012-07-28 01:02:21 -04:00
|
|
|
|
'(("CENTER" . org-element-center-block-parser)
|
|
|
|
|
("COMMENT" . org-element-comment-block-parser)
|
|
|
|
|
("EXAMPLE" . org-element-example-block-parser)
|
|
|
|
|
("QUOTE" . org-element-quote-block-parser)
|
|
|
|
|
("SRC" . org-element-src-block-parser)
|
|
|
|
|
("VERSE" . org-element-verse-block-parser))
|
|
|
|
|
"Alist between block names and the associated parsing function.
|
|
|
|
|
Names must be uppercase. Any block whose name has no association
|
|
|
|
|
is parsed with `org-element-special-block-parser'.")
|
|
|
|
|
|
2012-08-25 04:38:25 -04:00
|
|
|
|
(defconst org-element-link-type-is-file
|
|
|
|
|
'("file" "file+emacs" "file+sys" "docview")
|
|
|
|
|
"List of link types equivalent to \"file\".
|
|
|
|
|
Only these types can accept search options and an explicit
|
|
|
|
|
application to open them.")
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(defconst org-element-affiliated-keywords
|
|
|
|
|
'("CAPTION" "DATA" "HEADER" "HEADERS" "LABEL" "NAME" "PLOT" "RESNAME" "RESULT"
|
|
|
|
|
"RESULTS" "SOURCE" "SRCNAME" "TBLNAME")
|
|
|
|
|
"List of affiliated keywords as strings.
|
|
|
|
|
By default, all keywords setting attributes (i.e. \"ATTR_LATEX\")
|
|
|
|
|
are affiliated keywords and need not to be in this list.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element--affiliated-re
|
|
|
|
|
(format "[ \t]*#\\+%s:"
|
|
|
|
|
;; Regular affiliated keywords.
|
|
|
|
|
(format "\\(%s\\|ATTR_[-_A-Za-z0-9]+\\)\\(?:\\[\\(.*\\)\\]\\)?"
|
|
|
|
|
(regexp-opt org-element-affiliated-keywords)))
|
|
|
|
|
"Regexp matching any affiliated keyword.
|
|
|
|
|
|
|
|
|
|
Keyword name is put in match group 1. Moreover, if keyword
|
|
|
|
|
belongs to `org-element-dual-keywords', put the dual value in
|
|
|
|
|
match group 2.
|
|
|
|
|
|
|
|
|
|
Don't modify it, set `org-element-affiliated-keywords' instead.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-keyword-translation-alist
|
|
|
|
|
'(("DATA" . "NAME") ("LABEL" . "NAME") ("RESNAME" . "NAME")
|
|
|
|
|
("SOURCE" . "NAME") ("SRCNAME" . "NAME") ("TBLNAME" . "NAME")
|
|
|
|
|
("RESULT" . "RESULTS") ("HEADERS" . "HEADER"))
|
|
|
|
|
"Alist of usual translations for keywords.
|
|
|
|
|
The key is the old name and the value the new one. The property
|
|
|
|
|
holding their value will be named after the translated name.")
|
|
|
|
|
|
2012-09-13 10:51:54 -04:00
|
|
|
|
(defconst org-element-multiple-keywords '("CAPTION" "HEADER")
|
|
|
|
|
"List of affiliated keywords that can occur more than once in an element.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Their value will be consed into a list of strings, which will be
|
|
|
|
|
returned as the value of the property.
|
|
|
|
|
|
|
|
|
|
This list is checked after translations have been applied. See
|
|
|
|
|
`org-element-keyword-translation-alist'.
|
|
|
|
|
|
|
|
|
|
By default, all keywords setting attributes (i.e. \"ATTR_LATEX\")
|
|
|
|
|
allow multiple occurrences and need not to be in this list.")
|
|
|
|
|
|
2012-09-30 14:02:28 -04:00
|
|
|
|
(defconst org-element-parsed-keywords '("CAPTION")
|
|
|
|
|
"List of affiliated keywords whose value can be parsed.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Their value will be stored as a secondary string: a list of
|
|
|
|
|
strings and objects.
|
|
|
|
|
|
|
|
|
|
This list is checked after translations have been applied. See
|
|
|
|
|
`org-element-keyword-translation-alist'.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-dual-keywords '("CAPTION" "RESULTS")
|
2012-09-30 14:02:28 -04:00
|
|
|
|
"List of affiliated keywords which can have a secondary value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
In Org syntax, they can be written with optional square brackets
|
2012-09-30 14:02:28 -04:00
|
|
|
|
before the colons. For example, RESULTS keyword can be
|
2012-07-28 01:02:21 -04:00
|
|
|
|
associated to a hash value with the following:
|
|
|
|
|
|
|
|
|
|
#+RESULTS[hash-string]: some-source
|
|
|
|
|
|
|
|
|
|
This list is checked after translations have been applied. See
|
|
|
|
|
`org-element-keyword-translation-alist'.")
|
|
|
|
|
|
2012-09-30 14:02:28 -04:00
|
|
|
|
(defconst org-element-document-properties '("AUTHOR" "DATE" "TITLE")
|
|
|
|
|
"List of properties associated to the whole document.
|
|
|
|
|
Any keyword in this list will have its value parsed and stored as
|
|
|
|
|
a secondary string.")
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(defconst org-element-object-restrictions
|
2013-03-04 02:34:46 -05:00
|
|
|
|
(let* ((standard-set
|
|
|
|
|
(remq 'plain-link (remq 'table-cell org-element-all-successors)))
|
|
|
|
|
(standard-set-no-line-break (remq 'line-break standard-set)))
|
|
|
|
|
`((bold ,@standard-set)
|
|
|
|
|
(footnote-reference ,@standard-set)
|
|
|
|
|
(headline ,@standard-set-no-line-break)
|
|
|
|
|
(inlinetask ,@standard-set-no-line-break)
|
|
|
|
|
(italic ,@standard-set)
|
|
|
|
|
(item ,@standard-set-no-line-break)
|
|
|
|
|
(keyword ,@standard-set)
|
|
|
|
|
;; Ignore all links excepted plain links in a link description.
|
|
|
|
|
;; Also ignore radio-targets and line breaks.
|
|
|
|
|
(link export-snippet inline-babel-call inline-src-block latex-or-entity
|
|
|
|
|
macro plain-link statistics-cookie sub/superscript text-markup)
|
|
|
|
|
(paragraph ,@standard-set)
|
|
|
|
|
;; Remove any variable object from radio target as it would
|
|
|
|
|
;; prevent it from being properly recognized.
|
|
|
|
|
(radio-target latex-or-entity sub/superscript)
|
|
|
|
|
(strike-through ,@standard-set)
|
|
|
|
|
(subscript ,@standard-set)
|
|
|
|
|
(superscript ,@standard-set)
|
|
|
|
|
;; Ignore inline babel call and inline src block as formulas are
|
|
|
|
|
;; possible. Also ignore line breaks and statistics cookies.
|
|
|
|
|
(table-cell export-snippet footnote-reference latex-or-entity link macro
|
|
|
|
|
radio-target sub/superscript target text-markup timestamp)
|
|
|
|
|
(table-row table-cell)
|
|
|
|
|
(underline ,@standard-set)
|
|
|
|
|
(verse-block ,@standard-set)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Alist of objects restrictions.
|
|
|
|
|
|
|
|
|
|
CAR is an element or object type containing objects and CDR is
|
|
|
|
|
a list of successors that will be called within an element or
|
|
|
|
|
object of such type.
|
|
|
|
|
|
|
|
|
|
For example, in a `radio-target' object, one can only find
|
2013-03-04 02:34:46 -05:00
|
|
|
|
entities, latex-fragments, subscript and superscript.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
This alist also applies to secondary string. For example, an
|
|
|
|
|
`headline' type element doesn't directly contain objects, but
|
|
|
|
|
still has an entry since one of its properties (`:title') does.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element-secondary-value-alist
|
|
|
|
|
'((headline . :title)
|
|
|
|
|
(inlinetask . :title)
|
|
|
|
|
(item . :tag)
|
|
|
|
|
(footnote-reference . :inline-definition))
|
|
|
|
|
"Alist between element types and location of secondary value.")
|
|
|
|
|
|
2012-12-18 15:52:06 -05:00
|
|
|
|
(defconst org-element-object-variables '(org-link-abbrev-alist-local)
|
|
|
|
|
"List of buffer-local variables used when parsing objects.
|
|
|
|
|
These variables are copied to the temporary buffer created by
|
|
|
|
|
`org-export-secondary-string'.")
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Accessors and Setters
|
|
|
|
|
;;
|
|
|
|
|
;; Provide four accessors: `org-element-type', `org-element-property'
|
|
|
|
|
;; `org-element-contents' and `org-element-restriction'.
|
|
|
|
|
;;
|
|
|
|
|
;; Setter functions allow to modify elements by side effect. There is
|
|
|
|
|
;; `org-element-put-property', `org-element-set-contents',
|
|
|
|
|
;; `org-element-set-element' and `org-element-adopt-element'. Note
|
2012-08-18 04:13:35 -04:00
|
|
|
|
;; that `org-element-set-element' and `org-element-adopt-elements' are
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; higher level functions since also update `:parent' property.
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-type (element)
|
|
|
|
|
"Return type of ELEMENT.
|
|
|
|
|
|
|
|
|
|
The function returns the type of the element or object provided.
|
|
|
|
|
It can also return the following special value:
|
|
|
|
|
`plain-text' for a string
|
|
|
|
|
`org-data' for a complete document
|
|
|
|
|
nil in any other case."
|
|
|
|
|
(cond
|
|
|
|
|
((not (consp element)) (and (stringp element) 'plain-text))
|
|
|
|
|
((symbolp (car element)) (car element))))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-property (property element)
|
|
|
|
|
"Extract the value from the PROPERTY of an ELEMENT."
|
2012-10-25 15:33:57 -04:00
|
|
|
|
(if (stringp element) (get-text-property 0 property element)
|
|
|
|
|
(plist-get (nth 1 element) property)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defsubst org-element-contents (element)
|
|
|
|
|
"Extract contents from an ELEMENT."
|
2012-10-29 14:03:54 -04:00
|
|
|
|
(cond ((not (consp element)) nil)
|
|
|
|
|
((symbolp (car element)) (nthcdr 2 element))
|
|
|
|
|
(t element)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defsubst org-element-restriction (element)
|
|
|
|
|
"Return restriction associated to ELEMENT.
|
|
|
|
|
ELEMENT can be an element, an object or a symbol representing an
|
|
|
|
|
element or object type."
|
|
|
|
|
(cdr (assq (if (symbolp element) element (org-element-type element))
|
|
|
|
|
org-element-object-restrictions)))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-put-property (element property value)
|
|
|
|
|
"In ELEMENT set PROPERTY to VALUE.
|
|
|
|
|
Return modified element."
|
2012-10-25 15:33:57 -04:00
|
|
|
|
(if (stringp element) (org-add-props element nil property value)
|
|
|
|
|
(setcar (cdr element) (plist-put (nth 1 element) property value))
|
|
|
|
|
element))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defsubst org-element-set-contents (element &rest contents)
|
|
|
|
|
"Set ELEMENT contents to CONTENTS.
|
|
|
|
|
Return modified element."
|
|
|
|
|
(cond ((not element) (list contents))
|
2012-10-29 14:03:54 -04:00
|
|
|
|
((not (symbolp (car element))) contents)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
((cdr element) (setcdr (cdr element) contents))
|
|
|
|
|
(t (nconc element contents))))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-set-element (old new)
|
|
|
|
|
"Replace element or object OLD with element or object NEW.
|
|
|
|
|
The function takes care of setting `:parent' property for NEW."
|
2012-08-18 04:13:35 -04:00
|
|
|
|
;; Since OLD is going to be changed into NEW by side-effect, first
|
|
|
|
|
;; make sure that every element or object within NEW has OLD as
|
|
|
|
|
;; parent.
|
|
|
|
|
(mapc (lambda (blob) (org-element-put-property blob :parent old))
|
|
|
|
|
(org-element-contents new))
|
|
|
|
|
;; Transfer contents.
|
|
|
|
|
(apply 'org-element-set-contents old (org-element-contents new))
|
|
|
|
|
;; Ensure NEW has same parent as OLD, then overwrite OLD properties
|
|
|
|
|
;; with NEW's.
|
|
|
|
|
(org-element-put-property new :parent (org-element-property :parent old))
|
|
|
|
|
(setcar (cdr old) (nth 1 new))
|
|
|
|
|
;; Transfer type.
|
|
|
|
|
(setcar old (car new)))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-adopt-elements (parent &rest children)
|
|
|
|
|
"Append elements to the contents of another element.
|
|
|
|
|
|
|
|
|
|
PARENT is an element or object. CHILDREN can be elements,
|
|
|
|
|
objects, or a strings.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
The function takes care of setting `:parent' property for CHILD.
|
|
|
|
|
Return parent element."
|
2012-10-29 14:03:54 -04:00
|
|
|
|
;; Link every child to PARENT. If PARENT is nil, it is a secondary
|
|
|
|
|
;; string: parent is the list itself.
|
|
|
|
|
(mapc (lambda (child)
|
|
|
|
|
(org-element-put-property child :parent (or parent children)))
|
|
|
|
|
children)
|
|
|
|
|
;; Add CHILDREN at the end of PARENT contents.
|
|
|
|
|
(when parent
|
2012-08-18 04:13:35 -04:00
|
|
|
|
(apply 'org-element-set-contents
|
|
|
|
|
parent
|
2012-10-29 14:03:54 -04:00
|
|
|
|
(nconc (org-element-contents parent) children)))
|
|
|
|
|
;; Return modified PARENT element.
|
|
|
|
|
(or parent children))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Greater elements
|
|
|
|
|
;;
|
|
|
|
|
;; For each greater element type, we define a parser and an
|
|
|
|
|
;; interpreter.
|
|
|
|
|
;;
|
|
|
|
|
;; A parser returns the element or object as the list described above.
|
|
|
|
|
;; Most of them accepts no argument. Though, exceptions exist. Hence
|
|
|
|
|
;; every element containing a secondary string (see
|
|
|
|
|
;; `org-element-secondary-value-alist') will accept an optional
|
|
|
|
|
;; argument to toggle parsing of that secondary string. Moreover,
|
|
|
|
|
;; `item' parser requires current list's structure as its first
|
|
|
|
|
;; element.
|
|
|
|
|
;;
|
|
|
|
|
;; An interpreter accepts two arguments: the list representation of
|
|
|
|
|
;; the element or object, and its contents. The latter may be nil,
|
|
|
|
|
;; depending on the element or object considered. It returns the
|
|
|
|
|
;; appropriate Org syntax, as a string.
|
|
|
|
|
;;
|
|
|
|
|
;; Parsing functions must follow the naming convention:
|
|
|
|
|
;; org-element-TYPE-parser, where TYPE is greater element's type, as
|
|
|
|
|
;; defined in `org-element-greater-elements'.
|
|
|
|
|
;;
|
|
|
|
|
;; Similarly, interpreting functions must follow the naming
|
|
|
|
|
;; convention: org-element-TYPE-interpreter.
|
|
|
|
|
;;
|
|
|
|
|
;; With the exception of `headline' and `item' types, greater elements
|
|
|
|
|
;; cannot contain other greater elements of their own type.
|
|
|
|
|
;;
|
|
|
|
|
;; Beside implementing a parser and an interpreter, adding a new
|
|
|
|
|
;; greater element requires to tweak `org-element--current-element'.
|
|
|
|
|
;; Moreover, the newly defined type must be added to both
|
|
|
|
|
;; `org-element-all-elements' and `org-element-greater-elements'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Center Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-center-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a center block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `center-block' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:begin', `:end', `:contents-begin', `:contents-end',
|
|
|
|
|
`:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the block."
|
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward "^[ \t]*#\\+END_CENTER[ \t]*$" limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(let ((block-end-line (match-beginning 0)))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
;; Empty blocks have no contents.
|
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and (< (point) block-end-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(contents-end (and contents-begin block-end-line))
|
|
|
|
|
(pos-before-blank (progn (goto-char block-end-line)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(end (save-excursion
|
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(list 'center-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-center-block-interpreter (center-block contents)
|
|
|
|
|
"Interpret CENTER-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
(format "#+BEGIN_CENTER\n%s#+END_CENTER" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Drawer
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-drawer-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a drawer.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `drawer' and CDR is a plist containing
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
`:drawer-name', `:begin', `:end', `:contents-begin',
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
`:contents-end', `:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at beginning of drawer."
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(let ((case-fold-search t))
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(if (not (save-excursion (re-search-forward "^[ \t]*:END:[ \t]*$" limit t)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
;; Incomplete drawer: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((drawer-end-line (match-beginning 0))
|
|
|
|
|
(name (progn (looking-at org-drawer-regexp)
|
|
|
|
|
(org-match-string-no-properties 1)))
|
|
|
|
|
(begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;; Empty drawers have no contents.
|
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and (< (point) drawer-end-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(contents-end (and contents-begin drawer-end-line))
|
|
|
|
|
(pos-before-blank (progn (goto-char drawer-end-line)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(list 'drawer
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:drawer-name name
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(cdr affiliated))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-drawer-interpreter (drawer contents)
|
|
|
|
|
"Interpret DRAWER element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
(format ":%s:\n%s:END:"
|
|
|
|
|
(org-element-property :drawer-name drawer)
|
|
|
|
|
contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Dynamic Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-dynamic-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a dynamic block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `dynamic-block' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:block-name', `:begin', `:end', `:contents-begin',
|
|
|
|
|
`:contents-end', `:arguments', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at beginning of dynamic block."
|
|
|
|
|
(let ((case-fold-search t))
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(if (not (save-excursion
|
|
|
|
|
(re-search-forward "^[ \t]*#\\+END:?[ \t]*$" limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(let ((block-end-line (match-beginning 0)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((name (progn (looking-at org-dblock-start-re)
|
|
|
|
|
(org-match-string-no-properties 1)))
|
|
|
|
|
(arguments (org-match-string-no-properties 3))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
;; Empty blocks have no contents.
|
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and (< (point) block-end-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(contents-end (and contents-begin block-end-line))
|
|
|
|
|
(pos-before-blank (progn (goto-char block-end-line)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'dynamic-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:block-name name
|
|
|
|
|
:arguments arguments
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-dynamic-block-interpreter (dynamic-block contents)
|
|
|
|
|
"Interpret DYNAMIC-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
(format "#+BEGIN: %s%s\n%s#+END:"
|
|
|
|
|
(org-element-property :block-name dynamic-block)
|
|
|
|
|
(let ((args (org-element-property :arguments dynamic-block)))
|
|
|
|
|
(and args (concat " " args)))
|
|
|
|
|
contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Footnote Definition
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-footnote-definition-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a footnote definition.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `footnote-definition' and CDR is
|
|
|
|
|
a plist containing `:label', `:begin' `:end', `:contents-begin',
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
`:contents-end', `:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the footnote definition."
|
|
|
|
|
(save-excursion
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(let* ((label (progn (looking-at org-footnote-definition-re)
|
|
|
|
|
(org-match-string-no-properties 1)))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(ending (save-excursion
|
|
|
|
|
(if (progn
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(re-search-forward
|
|
|
|
|
(concat org-outline-regexp-bol "\\|"
|
|
|
|
|
org-footnote-definition-re "\\|"
|
2013-02-21 09:30:16 -05:00
|
|
|
|
"^\\([ \t]*\n\\)\\{2,\\}") limit 'move))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(match-beginning 0)
|
|
|
|
|
(point))))
|
2013-09-11 11:07:09 -04:00
|
|
|
|
(contents-begin (progn
|
|
|
|
|
(search-forward "]")
|
|
|
|
|
(skip-chars-forward " \r\t\n" ending)
|
|
|
|
|
(cond ((= (point) ending) nil)
|
|
|
|
|
((= (line-beginning-position) begin) (point))
|
|
|
|
|
(t (line-beginning-position)))))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(contents-end (and contents-begin ending))
|
|
|
|
|
(end (progn (goto-char ending)
|
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'footnote-definition
|
|
|
|
|
(nconc
|
|
|
|
|
(list :label label
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines ending end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-footnote-definition-interpreter (footnote-definition contents)
|
|
|
|
|
"Interpret FOOTNOTE-DEFINITION element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the footnote-definition."
|
|
|
|
|
(concat (format "[%s]" (org-element-property :label footnote-definition))
|
|
|
|
|
" "
|
|
|
|
|
contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Headline
|
|
|
|
|
|
|
|
|
|
(defun org-element-headline-parser (limit &optional raw-secondary-p)
|
2013-02-23 07:47:44 -05:00
|
|
|
|
"Parse a headline.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `headline' and CDR is a plist
|
2013-02-26 18:00:33 -05:00
|
|
|
|
containing `:raw-value', `:title', `:alt-title', `:begin',
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
`:end', `:pre-blank', `:contents-begin' and `:contents-end',
|
|
|
|
|
`:level', `:priority', `:tags', `:todo-keyword',`:todo-type',
|
|
|
|
|
`:scheduled', `:deadline', `:closed', `:quotedp', `:archivedp',
|
|
|
|
|
`:commentedp' and `:footnote-section-p' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
The plist also contains any property set in the property drawer,
|
2013-02-18 02:58:59 -05:00
|
|
|
|
with its name in upper cases and colons added at the
|
|
|
|
|
beginning (i.e. `:CUSTOM_ID').
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
When RAW-SECONDARY-P is non-nil, headline's title will not be
|
|
|
|
|
parsed as a secondary string, but as a plain string instead.
|
|
|
|
|
|
|
|
|
|
Assume point is at beginning of the headline."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((components (org-heading-components))
|
|
|
|
|
(level (nth 1 components))
|
|
|
|
|
(todo (nth 2 components))
|
|
|
|
|
(todo-type
|
|
|
|
|
(and todo (if (member todo org-done-keywords) 'done 'todo)))
|
|
|
|
|
(tags (let ((raw-tags (nth 5 components)))
|
|
|
|
|
(and raw-tags (org-split-string raw-tags ":"))))
|
2012-09-09 08:13:24 -04:00
|
|
|
|
(raw-value (or (nth 4 components) ""))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(quotedp
|
|
|
|
|
(let ((case-fold-search nil))
|
2012-09-29 02:54:46 -04:00
|
|
|
|
(string-match (format "^%s\\( \\|$\\)" org-quote-string)
|
|
|
|
|
raw-value)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(commentedp
|
|
|
|
|
(let ((case-fold-search nil))
|
2012-09-29 02:54:46 -04:00
|
|
|
|
(string-match (format "^%s\\( \\|$\\)" org-comment-string)
|
|
|
|
|
raw-value)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(archivedp (member org-archive-tag tags))
|
|
|
|
|
(footnote-section-p (and org-footnote-section
|
|
|
|
|
(string= org-footnote-section raw-value)))
|
2013-02-17 17:36:44 -05:00
|
|
|
|
;; Upcase property names. It avoids confusion between
|
|
|
|
|
;; properties obtained through property drawer and default
|
|
|
|
|
;; properties from the parser (e.g. `:end' and :END:)
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(standard-props
|
|
|
|
|
(let (plist)
|
|
|
|
|
(mapc
|
|
|
|
|
(lambda (p)
|
|
|
|
|
(setq plist
|
|
|
|
|
(plist-put plist
|
2013-02-17 17:36:44 -05:00
|
|
|
|
(intern (concat ":" (upcase (car p))))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(cdr p))))
|
|
|
|
|
(org-entry-properties nil 'standard))
|
|
|
|
|
plist))
|
|
|
|
|
(time-props
|
|
|
|
|
;; Read time properties on the line below the headline.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (progn (forward-line)
|
|
|
|
|
(looking-at org-planning-or-clock-line-re))
|
|
|
|
|
(let ((end (line-end-position)) plist)
|
|
|
|
|
(while (re-search-forward
|
|
|
|
|
org-keyword-time-not-clock-regexp end t)
|
|
|
|
|
(goto-char (match-end 1))
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(let ((keyword (match-string 1))
|
|
|
|
|
(time (org-element-timestamp-parser)))
|
|
|
|
|
(cond ((equal keyword org-scheduled-string)
|
|
|
|
|
(setq plist (plist-put plist :scheduled time)))
|
|
|
|
|
((equal keyword org-deadline-string)
|
|
|
|
|
(setq plist (plist-put plist :deadline time)))
|
|
|
|
|
(t (setq plist (plist-put plist :closed time))))))
|
|
|
|
|
plist))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(begin (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (save-excursion (goto-char (org-end-of-subtree t t))))
|
|
|
|
|
(pos-after-head (progn (forward-line) (point)))
|
|
|
|
|
(contents-begin (save-excursion
|
|
|
|
|
(skip-chars-forward " \r\t\n" end)
|
|
|
|
|
(and (/= (point) end) (line-beginning-position))))
|
|
|
|
|
(contents-end (and contents-begin
|
|
|
|
|
(progn (goto-char end)
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(forward-line)
|
2012-10-30 08:13:47 -04:00
|
|
|
|
(point)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Clean RAW-VALUE from any quote or comment string.
|
|
|
|
|
(when (or quotedp commentedp)
|
2012-09-29 03:46:09 -04:00
|
|
|
|
(let ((case-fold-search nil))
|
|
|
|
|
(setq raw-value
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
(concat
|
|
|
|
|
(regexp-opt (list org-quote-string org-comment-string))
|
|
|
|
|
"\\(?: \\|$\\)")
|
|
|
|
|
""
|
|
|
|
|
raw-value))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Clean TAGS from archive tag, if any.
|
|
|
|
|
(when archivedp (setq tags (delete org-archive-tag tags)))
|
|
|
|
|
(let ((headline
|
|
|
|
|
(list 'headline
|
|
|
|
|
(nconc
|
|
|
|
|
(list :raw-value raw-value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
2012-07-28 17:21:38 -04:00
|
|
|
|
:pre-blank
|
|
|
|
|
(if (not contents-begin) 0
|
|
|
|
|
(count-lines pos-after-head contents-begin))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:level level
|
|
|
|
|
:priority (nth 3 components)
|
|
|
|
|
:tags tags
|
|
|
|
|
:todo-keyword todo
|
|
|
|
|
:todo-type todo-type
|
2012-07-28 17:21:38 -04:00
|
|
|
|
:post-blank (count-lines
|
|
|
|
|
(if (not contents-end) pos-after-head
|
|
|
|
|
(goto-char contents-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point))
|
|
|
|
|
end)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:footnote-section-p footnote-section-p
|
|
|
|
|
:archivedp archivedp
|
|
|
|
|
:commentedp commentedp
|
|
|
|
|
:quotedp quotedp)
|
2012-09-28 08:50:21 -04:00
|
|
|
|
time-props
|
2012-07-28 01:02:21 -04:00
|
|
|
|
standard-props))))
|
2013-02-26 18:00:33 -05:00
|
|
|
|
(let ((alt-title (org-element-property :ALT_TITLE headline)))
|
|
|
|
|
(when alt-title
|
2013-02-23 15:33:03 -05:00
|
|
|
|
(org-element-put-property
|
2013-02-26 18:00:33 -05:00
|
|
|
|
headline :alt-title
|
|
|
|
|
(if raw-secondary-p alt-title
|
2013-02-23 15:33:03 -05:00
|
|
|
|
(org-element-parse-secondary-string
|
2013-02-26 18:00:33 -05:00
|
|
|
|
alt-title (org-element-restriction 'headline) headline)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(org-element-put-property
|
|
|
|
|
headline :title
|
|
|
|
|
(if raw-secondary-p raw-value
|
|
|
|
|
(org-element-parse-secondary-string
|
|
|
|
|
raw-value (org-element-restriction 'headline) headline)))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-headline-interpreter (headline contents)
|
|
|
|
|
"Interpret HEADLINE element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
(let* ((level (org-element-property :level headline))
|
|
|
|
|
(todo (org-element-property :todo-keyword headline))
|
|
|
|
|
(priority (org-element-property :priority headline))
|
|
|
|
|
(title (org-element-interpret-data
|
|
|
|
|
(org-element-property :title headline)))
|
|
|
|
|
(tags (let ((tag-list (if (org-element-property :archivedp headline)
|
|
|
|
|
(cons org-archive-tag
|
|
|
|
|
(org-element-property :tags headline))
|
|
|
|
|
(org-element-property :tags headline))))
|
|
|
|
|
(and tag-list
|
|
|
|
|
(format ":%s:" (mapconcat 'identity tag-list ":")))))
|
|
|
|
|
(commentedp (org-element-property :commentedp headline))
|
|
|
|
|
(quotedp (org-element-property :quotedp headline))
|
|
|
|
|
(pre-blank (or (org-element-property :pre-blank headline) 0))
|
2013-11-06 13:14:14 -05:00
|
|
|
|
(heading (concat (make-string (org-reduced-level level) ?*)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(and todo (concat " " todo))
|
|
|
|
|
(and quotedp (concat " " org-quote-string))
|
|
|
|
|
(and commentedp (concat " " org-comment-string))
|
|
|
|
|
(and priority
|
|
|
|
|
(format " [#%s]" (char-to-string priority)))
|
|
|
|
|
(cond ((and org-footnote-section
|
|
|
|
|
(org-element-property
|
|
|
|
|
:footnote-section-p headline))
|
|
|
|
|
(concat " " org-footnote-section))
|
|
|
|
|
(title (concat " " title))))))
|
|
|
|
|
(concat heading
|
|
|
|
|
;; Align tags.
|
|
|
|
|
(when tags
|
|
|
|
|
(cond
|
|
|
|
|
((zerop org-tags-column) (format " %s" tags))
|
|
|
|
|
((< org-tags-column 0)
|
|
|
|
|
(concat
|
|
|
|
|
(make-string
|
|
|
|
|
(max (- (+ org-tags-column (length heading) (length tags))) 1)
|
|
|
|
|
? )
|
|
|
|
|
tags))
|
|
|
|
|
(t
|
|
|
|
|
(concat
|
|
|
|
|
(make-string (max (- org-tags-column (length heading)) 1) ? )
|
|
|
|
|
tags))))
|
|
|
|
|
(make-string (1+ pre-blank) 10)
|
|
|
|
|
contents)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Inlinetask
|
|
|
|
|
|
|
|
|
|
(defun org-element-inlinetask-parser (limit &optional raw-secondary-p)
|
|
|
|
|
"Parse an inline task.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `inlinetask' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:title', `:begin', `:end', `:contents-begin' and
|
|
|
|
|
`:contents-end', `:level', `:priority', `:raw-value', `:tags',
|
|
|
|
|
`:todo-keyword', `:todo-type', `:scheduled', `:deadline',
|
|
|
|
|
`:closed' and `:post-blank' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
The plist also contains any property set in the property drawer,
|
2013-02-18 02:58:59 -05:00
|
|
|
|
with its name in upper cases and colons added at the
|
|
|
|
|
beginning (i.e. `:CUSTOM_ID').
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
When optional argument RAW-SECONDARY-P is non-nil, inline-task's
|
|
|
|
|
title will not be parsed as a secondary string, but as a plain
|
|
|
|
|
string instead.
|
|
|
|
|
|
|
|
|
|
Assume point is at beginning of the inline task."
|
|
|
|
|
(save-excursion
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(let* ((begin (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(components (org-heading-components))
|
|
|
|
|
(todo (nth 2 components))
|
|
|
|
|
(todo-type (and todo
|
|
|
|
|
(if (member todo org-done-keywords) 'done 'todo)))
|
|
|
|
|
(tags (let ((raw-tags (nth 5 components)))
|
|
|
|
|
(and raw-tags (org-split-string raw-tags ":"))))
|
2012-09-09 08:13:24 -04:00
|
|
|
|
(raw-value (or (nth 4 components) ""))
|
2013-02-17 17:36:44 -05:00
|
|
|
|
;; Upcase property names. It avoids confusion between
|
|
|
|
|
;; properties obtained through property drawer and default
|
|
|
|
|
;; properties from the parser (e.g. `:end' and :END:)
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(standard-props
|
|
|
|
|
(let (plist)
|
|
|
|
|
(mapc
|
|
|
|
|
(lambda (p)
|
|
|
|
|
(setq plist
|
|
|
|
|
(plist-put plist
|
2013-02-17 17:36:44 -05:00
|
|
|
|
(intern (concat ":" (upcase (car p))))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(cdr p))))
|
|
|
|
|
(org-entry-properties nil 'standard))
|
|
|
|
|
plist))
|
|
|
|
|
(time-props
|
|
|
|
|
;; Read time properties on the line below the inlinetask
|
|
|
|
|
;; opening string.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (progn (forward-line)
|
|
|
|
|
(looking-at org-planning-or-clock-line-re))
|
|
|
|
|
(let ((end (line-end-position)) plist)
|
|
|
|
|
(while (re-search-forward
|
|
|
|
|
org-keyword-time-not-clock-regexp end t)
|
|
|
|
|
(goto-char (match-end 1))
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(let ((keyword (match-string 1))
|
|
|
|
|
(time (org-element-timestamp-parser)))
|
|
|
|
|
(cond ((equal keyword org-scheduled-string)
|
|
|
|
|
(setq plist (plist-put plist :scheduled time)))
|
|
|
|
|
((equal keyword org-deadline-string)
|
|
|
|
|
(setq plist (plist-put plist :deadline time)))
|
|
|
|
|
(t (setq plist (plist-put plist :closed time))))))
|
|
|
|
|
plist))))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(task-end (save-excursion
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(and (re-search-forward "^\\*+ END" limit t)
|
|
|
|
|
(match-beginning 0))))
|
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and task-end (< (point) task-end) (point))))
|
|
|
|
|
(contents-end (and contents-begin task-end))
|
|
|
|
|
(before-blank (if (not task-end) (point)
|
|
|
|
|
(goto-char task-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(inlinetask
|
|
|
|
|
(list 'inlinetask
|
|
|
|
|
(nconc
|
2012-09-09 08:13:24 -04:00
|
|
|
|
(list :raw-value raw-value
|
|
|
|
|
:begin begin
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:level (nth 1 components)
|
|
|
|
|
:priority (nth 3 components)
|
|
|
|
|
:tags tags
|
|
|
|
|
:todo-keyword todo
|
|
|
|
|
:todo-type todo-type
|
2012-07-28 17:21:38 -04:00
|
|
|
|
:post-blank (count-lines before-blank end))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
time-props
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
standard-props))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(org-element-put-property
|
|
|
|
|
inlinetask :title
|
2012-09-09 08:13:24 -04:00
|
|
|
|
(if raw-secondary-p raw-value
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(org-element-parse-secondary-string
|
2012-09-09 08:13:24 -04:00
|
|
|
|
raw-value
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(org-element-restriction 'inlinetask)
|
|
|
|
|
inlinetask))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-inlinetask-interpreter (inlinetask contents)
|
|
|
|
|
"Interpret INLINETASK element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of inlinetask."
|
|
|
|
|
(let* ((level (org-element-property :level inlinetask))
|
|
|
|
|
(todo (org-element-property :todo-keyword inlinetask))
|
|
|
|
|
(priority (org-element-property :priority inlinetask))
|
|
|
|
|
(title (org-element-interpret-data
|
|
|
|
|
(org-element-property :title inlinetask)))
|
|
|
|
|
(tags (let ((tag-list (org-element-property :tags inlinetask)))
|
|
|
|
|
(and tag-list
|
|
|
|
|
(format ":%s:" (mapconcat 'identity tag-list ":")))))
|
|
|
|
|
(task (concat (make-string level ?*)
|
|
|
|
|
(and todo (concat " " todo))
|
|
|
|
|
(and priority
|
|
|
|
|
(format " [#%s]" (char-to-string priority)))
|
|
|
|
|
(and title (concat " " title)))))
|
|
|
|
|
(concat task
|
|
|
|
|
;; Align tags.
|
|
|
|
|
(when tags
|
|
|
|
|
(cond
|
|
|
|
|
((zerop org-tags-column) (format " %s" tags))
|
|
|
|
|
((< org-tags-column 0)
|
|
|
|
|
(concat
|
|
|
|
|
(make-string
|
|
|
|
|
(max (- (+ org-tags-column (length task) (length tags))) 1)
|
|
|
|
|
? )
|
|
|
|
|
tags))
|
|
|
|
|
(t
|
|
|
|
|
(concat
|
|
|
|
|
(make-string (max (- org-tags-column (length task)) 1) ? )
|
|
|
|
|
tags))))
|
|
|
|
|
;; Prefer degenerate inlinetasks when there are no
|
|
|
|
|
;; contents.
|
|
|
|
|
(when contents
|
|
|
|
|
(concat "\n"
|
|
|
|
|
contents
|
|
|
|
|
(make-string level ?*) " END")))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Item
|
|
|
|
|
|
|
|
|
|
(defun org-element-item-parser (limit struct &optional raw-secondary-p)
|
|
|
|
|
"Parse an item.
|
|
|
|
|
|
|
|
|
|
STRUCT is the structure of the plain list.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `item' and CDR is a plist containing
|
|
|
|
|
`:bullet', `:begin', `:end', `:contents-begin', `:contents-end',
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
`:checkbox', `:counter', `:tag', `:structure' and `:post-blank'
|
|
|
|
|
keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
When optional argument RAW-SECONDARY-P is non-nil, item's tag, if
|
|
|
|
|
any, will not be parsed as a secondary string, but as a plain
|
|
|
|
|
string instead.
|
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the item."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
2012-08-18 06:37:39 -04:00
|
|
|
|
(looking-at org-list-full-item-re)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let* ((begin (point))
|
2012-08-18 06:37:39 -04:00
|
|
|
|
(bullet (org-match-string-no-properties 1))
|
|
|
|
|
(checkbox (let ((box (org-match-string-no-properties 3)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cond ((equal "[ ]" box) 'off)
|
|
|
|
|
((equal "[X]" box) 'on)
|
|
|
|
|
((equal "[-]" box) 'trans))))
|
2012-08-18 06:37:39 -04:00
|
|
|
|
(counter (let ((c (org-match-string-no-properties 2)))
|
|
|
|
|
(save-match-data
|
|
|
|
|
(cond
|
|
|
|
|
((not c) nil)
|
|
|
|
|
((string-match "[A-Za-z]" c)
|
|
|
|
|
(- (string-to-char (upcase (match-string 0 c)))
|
|
|
|
|
64))
|
|
|
|
|
((string-match "[0-9]+" c)
|
|
|
|
|
(string-to-number (match-string 0 c)))))))
|
2013-11-04 12:16:28 -05:00
|
|
|
|
(end (progn (goto-char (nth 6 (assq (point) struct)))
|
|
|
|
|
(unless (bolp) (forward-line))
|
|
|
|
|
(point)))
|
2012-08-18 06:37:39 -04:00
|
|
|
|
(contents-begin
|
|
|
|
|
(progn (goto-char
|
|
|
|
|
;; Ignore tags in un-ordered lists: they are just
|
|
|
|
|
;; a part of item's body.
|
|
|
|
|
(if (and (match-beginning 4)
|
|
|
|
|
(save-match-data (string-match "[.)]" bullet)))
|
|
|
|
|
(match-beginning 4)
|
|
|
|
|
(match-end 0)))
|
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
|
|
|
|
;; If first line isn't empty, contents really start
|
|
|
|
|
;; at the text after item's meta-data.
|
|
|
|
|
(if (= (point-at-bol) begin) (point) (point-at-bol))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(contents-end (progn (goto-char end)
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
|
|
|
|
(item
|
|
|
|
|
(list 'item
|
|
|
|
|
(list :bullet bullet
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
;; CONTENTS-BEGIN and CONTENTS-END may be
|
|
|
|
|
;; mixed up in the case of an empty item
|
|
|
|
|
;; separated from the next by a blank line.
|
|
|
|
|
;; Thus ensure the former is always the
|
|
|
|
|
;; smallest.
|
|
|
|
|
:contents-begin (min contents-begin contents-end)
|
|
|
|
|
:contents-end (max contents-begin contents-end)
|
|
|
|
|
:checkbox checkbox
|
|
|
|
|
:counter counter
|
|
|
|
|
:structure struct
|
|
|
|
|
:post-blank (count-lines contents-end end)))))
|
|
|
|
|
(org-element-put-property
|
|
|
|
|
item :tag
|
|
|
|
|
(let ((raw-tag (org-list-get-tag begin struct)))
|
|
|
|
|
(and raw-tag
|
|
|
|
|
(if raw-secondary-p raw-tag
|
|
|
|
|
(org-element-parse-secondary-string
|
|
|
|
|
raw-tag (org-element-restriction 'item) item))))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-item-interpreter (item contents)
|
|
|
|
|
"Interpret ITEM element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
2013-07-05 15:09:23 -04:00
|
|
|
|
(let* ((bullet (let ((bullet (org-element-property :bullet item)))
|
|
|
|
|
(org-list-bullet-string
|
|
|
|
|
(cond ((not (string-match "[0-9a-zA-Z]" bullet)) "- ")
|
|
|
|
|
((eq org-plain-list-ordered-item-terminator ?\)) "1)")
|
|
|
|
|
(t "1.")))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(checkbox (org-element-property :checkbox item))
|
|
|
|
|
(counter (org-element-property :counter item))
|
|
|
|
|
(tag (let ((tag (org-element-property :tag item)))
|
|
|
|
|
(and tag (org-element-interpret-data tag))))
|
|
|
|
|
;; Compute indentation.
|
|
|
|
|
(ind (make-string (length bullet) 32))
|
|
|
|
|
(item-starts-with-par-p
|
|
|
|
|
(eq (org-element-type (car (org-element-contents item)))
|
|
|
|
|
'paragraph)))
|
|
|
|
|
;; Indent contents.
|
|
|
|
|
(concat
|
|
|
|
|
bullet
|
|
|
|
|
(and counter (format "[@%d] " counter))
|
2012-08-08 03:54:56 -04:00
|
|
|
|
(case checkbox
|
|
|
|
|
(on "[X] ")
|
|
|
|
|
(off "[ ] ")
|
|
|
|
|
(trans "[-] "))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(and tag (format "%s :: " tag))
|
2013-07-05 18:39:28 -04:00
|
|
|
|
(when contents
|
|
|
|
|
(let ((contents (replace-regexp-in-string
|
|
|
|
|
"\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))
|
|
|
|
|
(if item-starts-with-par-p (org-trim contents)
|
|
|
|
|
(concat "\n" contents)))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Plain List
|
|
|
|
|
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(defun org-element--list-struct (limit)
|
2013-06-01 15:38:15 -04:00
|
|
|
|
;; Return structure of list at point. Internal function. See
|
|
|
|
|
;; `org-list-struct' for details.
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(let ((case-fold-search t)
|
2013-06-01 15:38:15 -04:00
|
|
|
|
(top-ind limit)
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(item-re (org-item-re))
|
|
|
|
|
(inlinetask-re (and (featurep 'org-inlinetask) "^\\*+ "))
|
|
|
|
|
items struct)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(catch 'exit
|
|
|
|
|
(while t
|
|
|
|
|
(cond
|
|
|
|
|
;; At limit: end all items.
|
|
|
|
|
((>= (point) limit)
|
|
|
|
|
(throw 'exit
|
|
|
|
|
(let ((end (progn (skip-chars-backward " \r\t\n")
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(dolist (item items (sort (nconc items struct)
|
|
|
|
|
'car-less-than-car))
|
|
|
|
|
(setcar (nthcdr 6 item) end)))))
|
|
|
|
|
;; At list end: end all items.
|
|
|
|
|
((looking-at org-list-end-re)
|
|
|
|
|
(throw 'exit (dolist (item items (sort (nconc items struct)
|
|
|
|
|
'car-less-than-car))
|
|
|
|
|
(setcar (nthcdr 6 item) (point)))))
|
|
|
|
|
;; At a new item: end previous sibling.
|
|
|
|
|
((looking-at item-re)
|
|
|
|
|
(let ((ind (save-excursion (skip-chars-forward " \t")
|
|
|
|
|
(current-column))))
|
2013-06-01 15:38:15 -04:00
|
|
|
|
(setq top-ind (min top-ind ind))
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(while (and items (<= ind (nth 1 (car items))))
|
|
|
|
|
(let ((item (pop items)))
|
|
|
|
|
(setcar (nthcdr 6 item) (point))
|
|
|
|
|
(push item struct)))
|
|
|
|
|
(push (progn (looking-at org-list-full-item-re)
|
|
|
|
|
(let ((bullet (match-string-no-properties 1)))
|
|
|
|
|
(list (point)
|
|
|
|
|
ind
|
|
|
|
|
bullet
|
|
|
|
|
(match-string-no-properties 2) ; counter
|
|
|
|
|
(match-string-no-properties 3) ; checkbox
|
|
|
|
|
;; Description tag.
|
|
|
|
|
(and (save-match-data
|
|
|
|
|
(string-match "[-+*]" bullet))
|
|
|
|
|
(match-string-no-properties 4))
|
|
|
|
|
;; Ending position, unknown so far.
|
|
|
|
|
nil)))
|
|
|
|
|
items))
|
|
|
|
|
(forward-line 1))
|
|
|
|
|
;; Skip empty lines.
|
|
|
|
|
((looking-at "^[ \t]*$") (forward-line))
|
|
|
|
|
;; Skip inline tasks and blank lines along the way.
|
|
|
|
|
((and inlinetask-re (looking-at inlinetask-re))
|
|
|
|
|
(forward-line)
|
|
|
|
|
(let ((origin (point)))
|
|
|
|
|
(when (re-search-forward inlinetask-re limit t)
|
|
|
|
|
(if (looking-at "^\\*+ END[ \t]*$") (forward-line)
|
|
|
|
|
(goto-char origin)))))
|
|
|
|
|
;; At some text line. Check if it ends any previous item.
|
|
|
|
|
(t
|
|
|
|
|
(let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
2013-06-01 15:38:15 -04:00
|
|
|
|
(when (<= ind top-ind)
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(forward-line))
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(while (<= ind (nth 1 (car items)))
|
|
|
|
|
(let ((item (pop items)))
|
2013-06-01 15:38:15 -04:00
|
|
|
|
(setcar (nthcdr 6 item) (line-beginning-position))
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(push item struct)
|
|
|
|
|
(unless items
|
|
|
|
|
(throw 'exit (sort struct 'car-less-than-car))))))
|
|
|
|
|
;; Skip blocks (any type) and drawers contents.
|
|
|
|
|
(cond
|
2013-10-16 04:36:48 -04:00
|
|
|
|
((and (looking-at "#\\+BEGIN\\(:\\|_\\S-+\\)")
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(re-search-forward
|
2013-10-16 04:36:48 -04:00
|
|
|
|
(format "^[ \t]*#\\+END%s[ \t]*$"
|
2013-10-16 15:26:19 -04:00
|
|
|
|
(org-match-string-no-properties 1))
|
2013-05-31 14:13:29 -04:00
|
|
|
|
limit t)))
|
2013-10-20 08:40:09 -04:00
|
|
|
|
((and (looking-at org-drawer-regexp)
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(re-search-forward "^[ \t]*:END:[ \t]*$" limit t))))
|
|
|
|
|
(forward-line))))))))
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-plain-list-parser (limit affiliated structure)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a plain list.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value. STRUCTURE is the structure of the plain list being
|
|
|
|
|
parsed.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `plain-list' and CDR is a plist
|
|
|
|
|
containing `:type', `:begin', `:end', `:contents-begin' and
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
`:contents-end', `:structure', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the list."
|
|
|
|
|
(save-excursion
|
2013-05-31 14:13:29 -04:00
|
|
|
|
(let* ((struct (or structure (org-element--list-struct limit)))
|
2013-11-04 12:16:28 -05:00
|
|
|
|
(type (cond ((org-looking-at-p "[ \t]*[A-Za-z0-9]") 'ordered)
|
|
|
|
|
((nth 5 (assq (point) struct)) 'descriptive)
|
|
|
|
|
(t 'unordered)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(contents-begin (point))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(begin (car affiliated))
|
2013-11-04 12:16:28 -05:00
|
|
|
|
(contents-end (let* ((item (assq contents-begin struct))
|
|
|
|
|
(ind (nth 1 item))
|
|
|
|
|
(pos (nth 6 item)))
|
|
|
|
|
(while (and (setq item (assq pos struct))
|
|
|
|
|
(= (nth 1 item) ind))
|
|
|
|
|
(setq pos (nth 6 item)))
|
|
|
|
|
pos))
|
|
|
|
|
(end (progn (goto-char contents-end)
|
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
2013-07-21 09:51:14 -04:00
|
|
|
|
(if (= (point) limit) limit (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Return value.
|
|
|
|
|
(list 'plain-list
|
|
|
|
|
(nconc
|
|
|
|
|
(list :type type
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:structure struct
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines contents-end end)
|
|
|
|
|
:post-affiliated contents-begin)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-plain-list-interpreter (plain-list contents)
|
|
|
|
|
"Interpret PLAIN-LIST element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
2012-08-02 15:56:39 -04:00
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert contents)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(org-list-repair)
|
|
|
|
|
(buffer-string)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;;;; Property Drawer
|
|
|
|
|
|
|
|
|
|
(defun org-element-property-drawer-parser (limit affiliated)
|
|
|
|
|
"Parse a property drawer.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `property-drawer' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:begin', `:end', `:contents-begin', `:contents-end',
|
|
|
|
|
`:post-blank' and `:post-affiliated' keywords.
|
2012-09-23 09:52:02 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the property drawer."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(if (not (save-excursion
|
|
|
|
|
(re-search-forward "^[ \t]*:END:[ \t]*$" limit t)))
|
|
|
|
|
;; Incomplete drawer: parse it as a paragraph.
|
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((drawer-end-line (match-beginning 0))
|
|
|
|
|
(begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and (< (point) drawer-end-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(contents-end (and contents-begin drawer-end-line))
|
|
|
|
|
(pos-before-blank (progn (goto-char drawer-end-line)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(list 'property-drawer
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-property-drawer-interpreter (property-drawer contents)
|
|
|
|
|
"Interpret PROPERTY-DRAWER element as Org syntax.
|
|
|
|
|
CONTENTS is the properties within the drawer."
|
|
|
|
|
(format ":PROPERTIES:\n%s:END:" contents))
|
|
|
|
|
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;;; Quote Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-quote-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a quote block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `quote-block' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:begin', `:end', `:contents-begin', `:contents-end',
|
|
|
|
|
`:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the block."
|
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward "^[ \t]*#\\+END_QUOTE[ \t]*$" limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(let ((block-end-line (match-beginning 0)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
;; Empty blocks have no contents.
|
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and (< (point) block-end-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(contents-end (and contents-begin block-end-line))
|
|
|
|
|
(pos-before-blank (progn (goto-char block-end-line)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'quote-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-quote-block-interpreter (quote-block contents)
|
|
|
|
|
"Interpret QUOTE-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
(format "#+BEGIN_QUOTE\n%s#+END_QUOTE" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Section
|
|
|
|
|
|
|
|
|
|
(defun org-element-section-parser (limit)
|
|
|
|
|
"Parse a section.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `section' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:contents-begin', `contents-end'
|
|
|
|
|
and `:post-blank' keywords."
|
|
|
|
|
(save-excursion
|
|
|
|
|
;; Beginning of section is the beginning of the first non-blank
|
|
|
|
|
;; line after previous headline.
|
2012-09-01 16:52:43 -04:00
|
|
|
|
(let ((begin (point))
|
|
|
|
|
(end (progn (org-with-limited-levels (outline-next-heading))
|
|
|
|
|
(point)))
|
|
|
|
|
(pos-before-blank (progn (skip-chars-backward " \r\t\n")
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(list 'section
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin begin
|
|
|
|
|
:contents-end pos-before-blank
|
|
|
|
|
:post-blank (count-lines pos-before-blank end))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-section-interpreter (section contents)
|
|
|
|
|
"Interpret SECTION element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
contents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Special Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-special-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a special block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `special-block' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:type', `:begin', `:end', `:contents-begin',
|
|
|
|
|
`:contents-end', `:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the block."
|
|
|
|
|
(let* ((case-fold-search t)
|
2013-06-17 11:08:53 -04:00
|
|
|
|
(type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(upcase (match-string-no-properties 1)))))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward
|
2013-06-17 11:08:53 -04:00
|
|
|
|
(format "^[ \t]*#\\+END_%s[ \t]*$" (regexp-quote type))
|
|
|
|
|
limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(let ((block-end-line (match-beginning 0)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
;; Empty blocks have no contents.
|
|
|
|
|
(contents-begin (progn (forward-line)
|
|
|
|
|
(and (< (point) block-end-line)
|
|
|
|
|
(point))))
|
|
|
|
|
(contents-end (and contents-begin block-end-line))
|
|
|
|
|
(pos-before-blank (progn (goto-char block-end-line)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
org-element: Fix parsing with trailing spaces at eob
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, , org-element-footnote-definition-parser,
org-element-inlinetask-parser, org-element-plain-list-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-clock-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-planning-parser,
org-element-property-drawer-parser, org-element-src-block-parser,
org-element-table-parser,
org-element-verse-block-parserorg-element-dynamic-block-parser):
Make sure element never ends at the end of a blank non-empty line.
* testing/lisp/test-org-element.el: Add test.
2012-10-05 19:02:03 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'special-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :type type
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-special-block-interpreter (special-block contents)
|
|
|
|
|
"Interpret SPECIAL-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
(let ((block-type (org-element-property :type special-block)))
|
|
|
|
|
(format "#+BEGIN_%s\n%s#+END_%s" block-type contents block-type)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Elements
|
|
|
|
|
;;
|
|
|
|
|
;; For each element, a parser and an interpreter are also defined.
|
|
|
|
|
;; Both follow the same naming convention used for greater elements.
|
|
|
|
|
;;
|
|
|
|
|
;; Also, as for greater elements, adding a new element type is done
|
|
|
|
|
;; through the following steps: implement a parser and an interpreter,
|
|
|
|
|
;; tweak `org-element--current-element' so that it recognizes the new
|
|
|
|
|
;; type and add that new type to `org-element-all-elements'.
|
|
|
|
|
;;
|
|
|
|
|
;; As a special case, when the newly defined type is a block type,
|
|
|
|
|
;; `org-element-block-name-alist' has to be modified accordingly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Babel Call
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-babel-call-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a babel call.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `babel-call' and CDR is a plist
|
2013-10-20 07:14:23 -04:00
|
|
|
|
containing `:begin', `:end', `:value', `:post-blank' and
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
`:post-affiliated' as keywords."
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
2013-10-20 07:14:23 -04:00
|
|
|
|
(let ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2013-10-20 07:14:23 -04:00
|
|
|
|
(value (progn (let ((case-fold-search t))
|
|
|
|
|
(re-search-forward "call:[ \t]*" nil t))
|
|
|
|
|
(buffer-substring-no-properties (point)
|
|
|
|
|
(line-end-position))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(pos-before-blank (progn (forward-line) (point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'babel-call
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
2013-10-20 07:14:23 -04:00
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-babel-call-interpreter (babel-call contents)
|
|
|
|
|
"Interpret BABEL-CALL element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2013-10-20 07:14:23 -04:00
|
|
|
|
(concat "#+CALL: " (org-element-property :value babel-call)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Clock
|
|
|
|
|
|
|
|
|
|
(defun org-element-clock-parser (limit)
|
|
|
|
|
"Parse a clock.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `clock' and CDR is a plist containing
|
|
|
|
|
`:status', `:value', `:time', `:begin', `:end' and `:post-blank'
|
|
|
|
|
as keywords."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((case-fold-search nil)
|
|
|
|
|
(begin (point))
|
|
|
|
|
(value (progn (search-forward org-clock-string (line-end-position) t)
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(org-element-timestamp-parser)))
|
|
|
|
|
(duration (and (search-forward " => " (line-end-position) t)
|
|
|
|
|
(progn (skip-chars-forward " \t")
|
|
|
|
|
(looking-at "\\(\\S-+\\)[ \t]*$"))
|
|
|
|
|
(org-match-string-no-properties 1)))
|
|
|
|
|
(status (if duration 'closed 'running))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(post-blank (let ((before-blank (progn (forward-line) (point))))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
org-element: Fix parsing with trailing spaces at eob
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, , org-element-footnote-definition-parser,
org-element-inlinetask-parser, org-element-plain-list-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-clock-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-planning-parser,
org-element-property-drawer-parser, org-element-src-block-parser,
org-element-table-parser,
org-element-verse-block-parserorg-element-dynamic-block-parser):
Make sure element never ends at the end of a blank non-empty line.
* testing/lisp/test-org-element.el: Add test.
2012-10-05 19:02:03 -04:00
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(unless (bolp) (end-of-line))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(count-lines before-blank (point))))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'clock
|
|
|
|
|
(list :status status
|
|
|
|
|
:value value
|
2012-09-28 08:50:21 -04:00
|
|
|
|
:duration duration
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-clock-interpreter (clock contents)
|
|
|
|
|
"Interpret CLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(concat org-clock-string " "
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
(org-element-property :value clock) nil)
|
|
|
|
|
(let ((duration (org-element-property :duration clock)))
|
|
|
|
|
(and duration
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(concat " => "
|
|
|
|
|
(apply 'format
|
|
|
|
|
"%2s:%02s"
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(org-split-string duration ":")))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Comment
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-comment-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a comment.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `comment' and CDR is a plist
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
containing `:begin', `:end', `:value', `:post-blank',
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at comment beginning."
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-08-04 04:16:12 -04:00
|
|
|
|
(value (prog2 (looking-at "[ \t]*# ?")
|
2012-08-02 13:47:14 -04:00
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
(match-end 0) (line-end-position))
|
|
|
|
|
(forward-line)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(com-end
|
|
|
|
|
;; Get comments ending.
|
|
|
|
|
(progn
|
2012-08-02 13:47:14 -04:00
|
|
|
|
(while (and (< (point) limit) (looking-at "[ \t]*#\\( \\|$\\)"))
|
2012-07-31 19:27:27 -04:00
|
|
|
|
;; Accumulate lines without leading hash and first
|
|
|
|
|
;; whitespace.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(setq value
|
|
|
|
|
(concat value
|
2012-08-02 13:47:14 -04:00
|
|
|
|
"\n"
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(buffer-substring-no-properties
|
2012-08-02 13:47:14 -04:00
|
|
|
|
(match-end 0) (line-end-position))))
|
|
|
|
|
(forward-line))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(point)))
|
|
|
|
|
(end (progn (goto-char com-end)
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
2013-11-10 04:18:17 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'comment
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines com-end end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-comment-interpreter (comment contents)
|
|
|
|
|
"Interpret COMMENT element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2012-07-31 19:27:27 -04:00
|
|
|
|
(replace-regexp-in-string "^" "# " (org-element-property :value comment)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Comment Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-comment-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse an export block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `comment-block' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:begin', `:end', `:value', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at comment block beginning."
|
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward "^[ \t]*#\\+END_COMMENT[ \t]*$" limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((contents-end (match-beginning 0)))
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(contents-begin (progn (forward-line) (point)))
|
|
|
|
|
(pos-before-blank (progn (goto-char contents-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(value (buffer-substring-no-properties
|
|
|
|
|
contents-begin contents-end)))
|
|
|
|
|
(list 'comment-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-comment-block-interpreter (comment-block contents)
|
|
|
|
|
"Interpret COMMENT-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format "#+BEGIN_COMMENT\n%s#+END_COMMENT"
|
|
|
|
|
(org-remove-indentation (org-element-property :value comment-block))))
|
|
|
|
|
|
|
|
|
|
|
2012-10-27 08:23:37 -04:00
|
|
|
|
;;;; Diary Sexp
|
|
|
|
|
|
|
|
|
|
(defun org-element-diary-sexp-parser (limit affiliated)
|
|
|
|
|
"Parse a diary sexp.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `diary-sexp' and CDR is a plist
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
containing `:begin', `:end', `:value', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords."
|
2012-10-27 08:23:37 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-10-27 08:23:37 -04:00
|
|
|
|
(value (progn (looking-at "\\(%%(.*\\)[ \t]*$")
|
|
|
|
|
(org-match-string-no-properties 1)))
|
|
|
|
|
(pos-before-blank (progn (forward-line) (point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-10-27 08:23:37 -04:00
|
|
|
|
(list 'diary-sexp
|
|
|
|
|
(nconc
|
|
|
|
|
(list :value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
2012-10-27 08:23:37 -04:00
|
|
|
|
(cdr affiliated))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-diary-sexp-interpreter (diary-sexp contents)
|
|
|
|
|
"Interpret DIARY-SEXP as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(org-element-property :value diary-sexp))
|
|
|
|
|
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;;; Example Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-example-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse an example block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `example-block' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:number-lines', `:preserve-indent',
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
`:retain-labels', `:use-labels', `:label-fmt', `:switches',
|
|
|
|
|
`:value', `:post-blank' and `:post-affiliated' keywords."
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward "^[ \t]*#\\+END_EXAMPLE[ \t]*$" limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((contents-end (match-beginning 0)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((switches
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(progn
|
|
|
|
|
(looking-at "^[ \t]*#\\+BEGIN_EXAMPLE\\(?: +\\(.*\\)\\)?")
|
|
|
|
|
(org-match-string-no-properties 1)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Switches analysis
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(number-lines
|
|
|
|
|
(cond ((not switches) nil)
|
|
|
|
|
((string-match "-n\\>" switches) 'new)
|
|
|
|
|
((string-match "+n\\>" switches) 'continued)))
|
|
|
|
|
(preserve-indent
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(and switches (string-match "-i\\>" switches)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Should labels be retained in (or stripped from) example
|
|
|
|
|
;; blocks?
|
|
|
|
|
(retain-labels
|
|
|
|
|
(or (not switches)
|
|
|
|
|
(not (string-match "-r\\>" switches))
|
|
|
|
|
(and number-lines (string-match "-k\\>" switches))))
|
|
|
|
|
;; What should code-references use - labels or
|
|
|
|
|
;; line-numbers?
|
|
|
|
|
(use-labels
|
|
|
|
|
(or (not switches)
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(and retain-labels
|
|
|
|
|
(not (string-match "-k\\>" switches)))))
|
|
|
|
|
(label-fmt
|
|
|
|
|
(and switches
|
|
|
|
|
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
|
|
|
|
(match-string 1 switches)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Standard block parsing.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(block-ind (progn (skip-chars-forward " \t") (current-column)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(contents-begin (progn (forward-line) (point)))
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(value (org-element-remove-indentation
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(org-unescape-code-in-string
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
contents-begin contents-end))
|
2013-10-27 06:03:05 -04:00
|
|
|
|
block-ind))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(pos-before-blank (progn (goto-char contents-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'example-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
|
|
|
|
:switches switches
|
|
|
|
|
:number-lines number-lines
|
|
|
|
|
:preserve-indent preserve-indent
|
|
|
|
|
:retain-labels retain-labels
|
|
|
|
|
:use-labels use-labels
|
|
|
|
|
:label-fmt label-fmt
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-example-block-interpreter (example-block contents)
|
|
|
|
|
"Interpret EXAMPLE-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(let ((switches (org-element-property :switches example-block))
|
|
|
|
|
(value (org-element-property :value example-block)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(concat "#+BEGIN_EXAMPLE" (and switches (concat " " switches)) "\n"
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(org-escape-code-in-string
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(if (or org-src-preserve-indentation
|
|
|
|
|
(org-element-property :preserve-indent example-block))
|
|
|
|
|
value
|
|
|
|
|
(org-element-remove-indentation value)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"#+END_EXAMPLE")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Export Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-export-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse an export block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `export-block' and CDR is a plist
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
containing `:begin', `:end', `:type', `:value', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at export-block beginning."
|
|
|
|
|
(let* ((case-fold-search t)
|
|
|
|
|
(type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
|
|
|
|
|
(upcase (org-match-string-no-properties 1)))))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward
|
|
|
|
|
(format "^[ \t]*#\\+END_%s[ \t]*$" type) limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((contents-end (match-beginning 0)))
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(contents-begin (progn (forward-line) (point)))
|
|
|
|
|
(pos-before-blank (progn (goto-char contents-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(value (buffer-substring-no-properties contents-begin
|
|
|
|
|
contents-end)))
|
|
|
|
|
(list 'export-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:type type
|
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-export-block-interpreter (export-block contents)
|
|
|
|
|
"Interpret EXPORT-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(let ((type (org-element-property :type export-block)))
|
|
|
|
|
(concat (format "#+BEGIN_%s\n" type)
|
|
|
|
|
(org-element-property :value export-block)
|
|
|
|
|
(format "#+END_%s" type))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Fixed-width
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-fixed-width-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a fixed-width section.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `fixed-width' and CDR is a plist
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
containing `:begin', `:end', `:value', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the fixed-width area."
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
value
|
|
|
|
|
(end-area
|
|
|
|
|
(progn
|
|
|
|
|
(while (and (< (point) limit)
|
|
|
|
|
(looking-at "[ \t]*:\\( \\|$\\)"))
|
|
|
|
|
;; Accumulate text without starting colons.
|
|
|
|
|
(setq value
|
|
|
|
|
(concat value
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
(match-end 0) (point-at-eol))
|
|
|
|
|
"\n"))
|
|
|
|
|
(forward-line))
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'fixed-width
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines end-area end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-fixed-width-interpreter (fixed-width contents)
|
|
|
|
|
"Interpret FIXED-WIDTH element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2013-04-26 04:38:05 -04:00
|
|
|
|
(let ((value (org-element-property :value fixed-width)))
|
|
|
|
|
(and value
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"^" ": "
|
|
|
|
|
(if (string-match "\n\\'" value) (substring value 0 -1) value)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Horizontal Rule
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-horizontal-rule-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse an horizontal rule.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `horizontal-rule' and CDR is a plist
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
containing `:begin', `:end', `:post-blank' and `:post-affiliated'
|
|
|
|
|
keywords."
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(post-hr (progn (forward-line) (point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'horizontal-rule
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines post-hr end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-horizontal-rule-interpreter (horizontal-rule contents)
|
|
|
|
|
"Interpret HORIZONTAL-RULE element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
"-----")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Keyword
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-keyword-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a keyword at point.
|
|
|
|
|
|
2012-09-23 09:52:02 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `keyword' and CDR is a plist
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
containing `:key', `:value', `:begin', `:end', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords."
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
2012-10-27 08:19:58 -04:00
|
|
|
|
(let ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(key (progn (looking-at "[ \t]*#\\+\\(\\S-+*\\):")
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(upcase (org-match-string-no-properties 1))))
|
|
|
|
|
(value (org-trim (buffer-substring-no-properties
|
|
|
|
|
(match-end 0) (point-at-eol))))
|
|
|
|
|
(pos-before-blank (progn (forward-line) (point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'keyword
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(nconc
|
|
|
|
|
(list :key key
|
|
|
|
|
:value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-keyword-interpreter (keyword contents)
|
|
|
|
|
"Interpret KEYWORD element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format "#+%s: %s"
|
|
|
|
|
(org-element-property :key keyword)
|
|
|
|
|
(org-element-property :value keyword)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Latex Environment
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-latex-environment-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a LaTeX environment.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `latex-environment' and CDR is a plist
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
containing `:begin', `:end', `:value', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the latex environment."
|
|
|
|
|
(save-excursion
|
2012-10-27 08:19:58 -04:00
|
|
|
|
(let ((case-fold-search t)
|
|
|
|
|
(code-begin (point)))
|
|
|
|
|
(looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
|
|
|
|
|
(if (not (re-search-forward (format "^[ \t]*\\\\end{%s}[ \t]*$"
|
|
|
|
|
(regexp-quote (match-string 1)))
|
|
|
|
|
limit t))
|
|
|
|
|
;; Incomplete latex environment: parse it as a paragraph.
|
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
|
|
|
|
(let* ((code-end (progn (forward-line) (point)))
|
|
|
|
|
(begin (car affiliated))
|
|
|
|
|
(value (buffer-substring-no-properties code-begin code-end))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-10-27 08:19:58 -04:00
|
|
|
|
(list 'latex-environment
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines code-end end)
|
2013-02-22 08:31:05 -05:00
|
|
|
|
:post-affiliated code-begin)
|
2012-10-27 08:19:58 -04:00
|
|
|
|
(cdr affiliated))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-latex-environment-interpreter (latex-environment contents)
|
|
|
|
|
"Interpret LATEX-ENVIRONMENT element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(org-element-property :value latex-environment))
|
|
|
|
|
|
|
|
|
|
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;;;; Node Property
|
|
|
|
|
|
|
|
|
|
(defun org-element-node-property-parser (limit)
|
|
|
|
|
"Parse a node-property at point.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `node-property' and CDR is a plist
|
|
|
|
|
containing `:key', `:value', `:begin', `:end' and `:post-blank'
|
|
|
|
|
keywords."
|
|
|
|
|
(save-excursion
|
2013-05-09 13:47:59 -04:00
|
|
|
|
(looking-at org-property-re)
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(let ((case-fold-search t)
|
|
|
|
|
(begin (point))
|
2013-05-09 13:47:59 -04:00
|
|
|
|
(key (org-match-string-no-properties 2))
|
|
|
|
|
(value (org-match-string-no-properties 3))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(pos-before-blank (progn (forward-line) (point)))
|
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
|
|
|
|
(if (eobp) (point) (point-at-bol)))))
|
|
|
|
|
(list 'node-property
|
|
|
|
|
(list :key key
|
|
|
|
|
:value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank (count-lines pos-before-blank end))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-node-property-interpreter (node-property contents)
|
|
|
|
|
"Interpret NODE-PROPERTY element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format org-property-format
|
|
|
|
|
(format ":%s:" (org-element-property :key node-property))
|
|
|
|
|
(org-element-property :value node-property)))
|
|
|
|
|
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;;; Paragraph
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-paragraph-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a paragraph.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `paragraph' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:contents-begin' and
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
`:contents-end', `:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the paragraph."
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
2012-08-25 09:26:33 -04:00
|
|
|
|
(contents-begin (point))
|
2012-07-28 08:35:35 -04:00
|
|
|
|
(before-blank
|
2012-08-17 09:22:36 -04:00
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(end-of-line)
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(if (not (re-search-forward
|
|
|
|
|
org-element-paragraph-separate limit 'm))
|
|
|
|
|
limit
|
|
|
|
|
;; A matching `org-element-paragraph-separate' is not
|
|
|
|
|
;; necessarily the end of the paragraph. In
|
|
|
|
|
;; particular, lines starting with # or : as a first
|
|
|
|
|
;; non-space character are ambiguous. We have check
|
|
|
|
|
;; if they are valid Org syntax (i.e. not an
|
|
|
|
|
;; incomplete keyword).
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(while (not
|
|
|
|
|
(or
|
|
|
|
|
;; There's no ambiguity for other symbols or
|
|
|
|
|
;; empty lines: stop here.
|
|
|
|
|
(looking-at "[ \t]*\\(?:[^:#]\\|$\\)")
|
|
|
|
|
;; Stop at valid fixed-width areas.
|
|
|
|
|
(looking-at "[ \t]*:\\(?: \\|$\\)")
|
|
|
|
|
;; Stop at drawers.
|
|
|
|
|
(and (looking-at org-drawer-regexp)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-forward
|
|
|
|
|
"^[ \t]*:END:[ \t]*$" limit t)))
|
|
|
|
|
;; Stop at valid comments.
|
|
|
|
|
(looking-at "[ \t]*#\\(?: \\|$\\)")
|
|
|
|
|
;; Stop at valid dynamic blocks.
|
|
|
|
|
(and (looking-at org-dblock-start-re)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-forward
|
|
|
|
|
"^[ \t]*#\\+END:?[ \t]*$" limit t)))
|
|
|
|
|
;; Stop at valid blocks.
|
2013-09-08 17:24:42 -04:00
|
|
|
|
(and (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-forward
|
|
|
|
|
(format "^[ \t]*#\\+END_%s[ \t]*$"
|
2013-09-08 17:24:42 -04:00
|
|
|
|
(regexp-quote
|
2013-09-08 17:50:53 -04:00
|
|
|
|
(org-match-string-no-properties 1)))
|
2012-09-30 06:22:40 -04:00
|
|
|
|
limit t)))
|
|
|
|
|
;; Stop at valid latex environments.
|
|
|
|
|
(and (looking-at
|
2013-09-08 17:24:42 -04:00
|
|
|
|
"[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-forward
|
|
|
|
|
(format "^[ \t]*\\\\end{%s}[ \t]*$"
|
2013-09-08 17:24:42 -04:00
|
|
|
|
(regexp-quote
|
2013-09-08 17:50:53 -04:00
|
|
|
|
(org-match-string-no-properties 1)))
|
2012-09-30 06:22:40 -04:00
|
|
|
|
limit t)))
|
|
|
|
|
;; Stop at valid keywords.
|
|
|
|
|
(looking-at "[ \t]*#\\+\\S-+:")
|
|
|
|
|
;; Skip everything else.
|
|
|
|
|
(not
|
|
|
|
|
(progn
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(re-search-forward org-element-paragraph-separate
|
|
|
|
|
limit 'm)))))
|
|
|
|
|
(beginning-of-line)))
|
|
|
|
|
(if (= (point) limit) limit
|
|
|
|
|
(goto-char (line-beginning-position)))))
|
2012-07-28 08:35:35 -04:00
|
|
|
|
(contents-end (progn (skip-chars-backward " \r\t\n" contents-begin)
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 08:35:35 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'paragraph
|
|
|
|
|
(nconc
|
2012-08-25 09:26:33 -04:00
|
|
|
|
(list :begin begin
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines before-blank end)
|
|
|
|
|
:post-affiliated contents-begin)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-paragraph-interpreter (paragraph contents)
|
|
|
|
|
"Interpret PARAGRAPH element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the element."
|
|
|
|
|
contents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Planning
|
|
|
|
|
|
|
|
|
|
(defun org-element-planning-parser (limit)
|
|
|
|
|
"Parse a planning.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `planning' and CDR is a plist
|
|
|
|
|
containing `:closed', `:deadline', `:scheduled', `:begin', `:end'
|
|
|
|
|
and `:post-blank' keywords."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((case-fold-search nil)
|
|
|
|
|
(begin (point))
|
|
|
|
|
(post-blank (let ((before-blank (progn (forward-line) (point))))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(skip-chars-forward " \r\t\n" limit)
|
org-element: Fix parsing with trailing spaces at eob
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, , org-element-footnote-definition-parser,
org-element-inlinetask-parser, org-element-plain-list-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-clock-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-planning-parser,
org-element-property-drawer-parser, org-element-src-block-parser,
org-element-table-parser,
org-element-verse-block-parserorg-element-dynamic-block-parser):
Make sure element never ends at the end of a blank non-empty line.
* testing/lisp/test-org-element.el: Add test.
2012-10-05 19:02:03 -04:00
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(unless (bolp) (end-of-line))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(count-lines before-blank (point))))
|
|
|
|
|
(end (point))
|
|
|
|
|
closed deadline scheduled)
|
|
|
|
|
(goto-char begin)
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(while (re-search-forward org-keyword-time-not-clock-regexp end t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(goto-char (match-end 1))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(skip-chars-forward " \t" end)
|
|
|
|
|
(let ((keyword (match-string 1))
|
|
|
|
|
(time (org-element-timestamp-parser)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cond ((equal keyword org-closed-string) (setq closed time))
|
|
|
|
|
((equal keyword org-deadline-string) (setq deadline time))
|
|
|
|
|
(t (setq scheduled time)))))
|
|
|
|
|
(list 'planning
|
|
|
|
|
(list :closed closed
|
|
|
|
|
:deadline deadline
|
|
|
|
|
:scheduled scheduled
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-planning-interpreter (planning contents)
|
|
|
|
|
"Interpret PLANNING element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(mapconcat
|
|
|
|
|
'identity
|
|
|
|
|
(delq nil
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(list (let ((deadline (org-element-property :deadline planning)))
|
|
|
|
|
(when deadline
|
|
|
|
|
(concat org-deadline-string " "
|
|
|
|
|
(org-element-timestamp-interpreter deadline nil))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((scheduled (org-element-property :scheduled planning)))
|
|
|
|
|
(when scheduled
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(concat org-scheduled-string " "
|
|
|
|
|
(org-element-timestamp-interpreter scheduled nil))))
|
|
|
|
|
(let ((closed (org-element-property :closed planning)))
|
|
|
|
|
(when closed
|
|
|
|
|
(concat org-closed-string " "
|
|
|
|
|
(org-element-timestamp-interpreter closed nil))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
" "))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Quote Section
|
|
|
|
|
|
|
|
|
|
(defun org-element-quote-section-parser (limit)
|
|
|
|
|
"Parse a quote section.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `quote-section' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:value' and `:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at beginning of the section."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((begin (point))
|
|
|
|
|
(end (progn (org-with-limited-levels (outline-next-heading))
|
|
|
|
|
(point)))
|
|
|
|
|
(pos-before-blank (progn (skip-chars-backward " \r\t\n")
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
|
|
|
|
(value (buffer-substring-no-properties begin pos-before-blank)))
|
|
|
|
|
(list 'quote-section
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
|
|
|
|
:post-blank (count-lines pos-before-blank end))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-quote-section-interpreter (quote-section contents)
|
|
|
|
|
"Interpret QUOTE-SECTION element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(org-element-property :value quote-section))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Src Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-src-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a src block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `src-block' and CDR is a plist
|
|
|
|
|
containing `:language', `:switches', `:parameters', `:begin',
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
`:end', `:number-lines', `:retain-labels', `:use-labels',
|
|
|
|
|
`:label-fmt', `:preserve-indent', `:value', `:post-blank' and
|
|
|
|
|
`:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the block."
|
|
|
|
|
(let ((case-fold-search t))
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(if (not (save-excursion (re-search-forward "^[ \t]*#\\+END_SRC[ \t]*$"
|
|
|
|
|
limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((contents-end (match-beginning 0)))
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Get language as a string.
|
|
|
|
|
(language
|
|
|
|
|
(progn
|
|
|
|
|
(looking-at
|
|
|
|
|
(concat "^[ \t]*#\\+BEGIN_SRC"
|
|
|
|
|
"\\(?: +\\(\\S-+\\)\\)?"
|
|
|
|
|
"\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?"
|
|
|
|
|
"\\(.*\\)[ \t]*$"))
|
|
|
|
|
(org-match-string-no-properties 1)))
|
|
|
|
|
;; Get switches.
|
|
|
|
|
(switches (org-match-string-no-properties 2))
|
|
|
|
|
;; Get parameters.
|
|
|
|
|
(parameters (org-match-string-no-properties 3))
|
|
|
|
|
;; Switches analysis
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(number-lines
|
|
|
|
|
(cond ((not switches) nil)
|
|
|
|
|
((string-match "-n\\>" switches) 'new)
|
|
|
|
|
((string-match "+n\\>" switches) 'continued)))
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(preserve-indent (and switches
|
|
|
|
|
(string-match "-i\\>" switches)))
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(label-fmt
|
|
|
|
|
(and switches
|
|
|
|
|
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
|
|
|
|
(match-string 1 switches)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Should labels be retained in (or stripped from)
|
|
|
|
|
;; src blocks?
|
|
|
|
|
(retain-labels
|
|
|
|
|
(or (not switches)
|
|
|
|
|
(not (string-match "-r\\>" switches))
|
|
|
|
|
(and number-lines (string-match "-k\\>" switches))))
|
|
|
|
|
;; What should code-references use - labels or
|
|
|
|
|
;; line-numbers?
|
|
|
|
|
(use-labels
|
|
|
|
|
(or (not switches)
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(and retain-labels
|
|
|
|
|
(not (string-match "-k\\>" switches)))))
|
|
|
|
|
;; Indentation.
|
|
|
|
|
(block-ind (progn (skip-chars-forward " \t") (current-column)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Retrieve code.
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(value (org-element-remove-indentation
|
2013-05-25 08:18:48 -04:00
|
|
|
|
(org-unescape-code-in-string
|
|
|
|
|
(buffer-substring-no-properties
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
(progn (forward-line) (point)) contents-end))
|
2013-10-27 06:03:05 -04:00
|
|
|
|
block-ind))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(pos-before-blank (progn (goto-char contents-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
|
|
|
|
;; Get position after ending blank lines.
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'src-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :language language
|
|
|
|
|
:switches (and (org-string-nw-p switches)
|
|
|
|
|
(org-trim switches))
|
|
|
|
|
:parameters (and (org-string-nw-p parameters)
|
|
|
|
|
(org-trim parameters))
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:number-lines number-lines
|
|
|
|
|
:preserve-indent preserve-indent
|
|
|
|
|
:retain-labels retain-labels
|
|
|
|
|
:use-labels use-labels
|
|
|
|
|
:label-fmt label-fmt
|
|
|
|
|
:value value
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-src-block-interpreter (src-block contents)
|
|
|
|
|
"Interpret SRC-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(let ((lang (org-element-property :language src-block))
|
|
|
|
|
(switches (org-element-property :switches src-block))
|
|
|
|
|
(params (org-element-property :parameters src-block))
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(value
|
|
|
|
|
(let ((val (org-element-property :value src-block)))
|
|
|
|
|
(cond
|
|
|
|
|
((or org-src-preserve-indentation
|
|
|
|
|
(org-element-property :preserve-indent src-block))
|
|
|
|
|
val)
|
|
|
|
|
((zerop org-edit-src-content-indentation) val)
|
|
|
|
|
(t
|
|
|
|
|
(let ((ind (make-string org-edit-src-content-indentation ?\s)))
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\\(^\\)[ \t]*\\S-" ind val nil nil 1)))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(concat (format "#+BEGIN_SRC%s\n"
|
|
|
|
|
(concat (and lang (concat " " lang))
|
|
|
|
|
(and switches (concat " " switches))
|
|
|
|
|
(and params (concat " " params))))
|
2012-09-30 11:45:21 -04:00
|
|
|
|
(org-escape-code-in-string value)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"#+END_SRC")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Table
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-table-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a table at point.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `table' and CDR is a plist containing
|
|
|
|
|
`:begin', `:end', `:tblfm', `:type', `:contents-begin',
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
`:contents-end', `:value', `:post-blank' and `:post-affiliated'
|
|
|
|
|
keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the table."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((case-fold-search t)
|
|
|
|
|
(table-begin (point))
|
|
|
|
|
(type (if (org-at-table.el-p) 'table.el 'org))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(begin (car affiliated))
|
org-element: Fix parsing with trailing spaces at eob
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, , org-element-footnote-definition-parser,
org-element-inlinetask-parser, org-element-plain-list-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-clock-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-planning-parser,
org-element-property-drawer-parser, org-element-src-block-parser,
org-element-table-parser,
org-element-verse-block-parserorg-element-dynamic-block-parser):
Make sure element never ends at the end of a blank non-empty line.
* testing/lisp/test-org-element.el: Add test.
2012-10-05 19:02:03 -04:00
|
|
|
|
(table-end
|
|
|
|
|
(if (re-search-forward org-table-any-border-regexp limit 'm)
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(point)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(tblfm (let (acc)
|
|
|
|
|
(while (looking-at "[ \t]*#\\+TBLFM: +\\(.*\\)[ \t]*$")
|
|
|
|
|
(push (org-match-string-no-properties 1) acc)
|
|
|
|
|
(forward-line))
|
|
|
|
|
acc))
|
|
|
|
|
(pos-before-blank (point))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'table
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:type type
|
|
|
|
|
:tblfm tblfm
|
|
|
|
|
;; Only `org' tables have contents. `table.el' tables
|
|
|
|
|
;; use a `:value' property to store raw table as
|
|
|
|
|
;; a string.
|
|
|
|
|
:contents-begin (and (eq type 'org) table-begin)
|
|
|
|
|
:contents-end (and (eq type 'org) table-end)
|
|
|
|
|
:value (and (eq type 'table.el)
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
table-begin table-end))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated table-begin)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-table-interpreter (table contents)
|
|
|
|
|
"Interpret TABLE element as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(if (eq (org-element-property :type table) 'table.el)
|
|
|
|
|
(org-remove-indentation (org-element-property :value table))
|
|
|
|
|
(concat (with-temp-buffer (insert contents)
|
|
|
|
|
(org-table-align)
|
|
|
|
|
(buffer-string))
|
|
|
|
|
(mapconcat (lambda (fm) (concat "#+TBLFM: " fm))
|
|
|
|
|
(reverse (org-element-property :tblfm table))
|
|
|
|
|
"\n"))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Table Row
|
|
|
|
|
|
|
|
|
|
(defun org-element-table-row-parser (limit)
|
|
|
|
|
"Parse table row at point.
|
|
|
|
|
|
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `table-row' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:contents-begin', `:contents-end',
|
|
|
|
|
`:type' and `:post-blank' keywords."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((type (if (looking-at "^[ \t]*|-") 'rule 'standard))
|
|
|
|
|
(begin (point))
|
|
|
|
|
;; A table rule has no contents. In that case, ensure
|
|
|
|
|
;; CONTENTS-BEGIN matches CONTENTS-END.
|
|
|
|
|
(contents-begin (and (eq type 'standard)
|
|
|
|
|
(search-forward "|")
|
|
|
|
|
(point)))
|
|
|
|
|
(contents-end (and (eq type 'standard)
|
|
|
|
|
(progn
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(point))))
|
|
|
|
|
(end (progn (forward-line) (point))))
|
|
|
|
|
(list 'table-row
|
|
|
|
|
(list :type type
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank 0)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-table-row-interpreter (table-row contents)
|
|
|
|
|
"Interpret TABLE-ROW element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the table row."
|
|
|
|
|
(if (eq (org-element-property :type table-row) 'rule) "|-"
|
|
|
|
|
(concat "| " contents)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Verse Block
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(defun org-element-verse-block-parser (limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Parse a verse block.
|
|
|
|
|
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
LIMIT bounds the search. AFFILIATED is a list of which CAR is
|
|
|
|
|
the buffer position at the beginning of the first affiliated
|
|
|
|
|
keyword and CDR is a plist of affiliated keywords along with
|
|
|
|
|
their value.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `verse-block' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:contents-begin', `:contents-end',
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
`:post-blank' and `:post-affiliated' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at beginning of the block."
|
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(if (not (save-excursion
|
2012-09-30 06:22:40 -04:00
|
|
|
|
(re-search-forward "^[ \t]*#\\+END_VERSE[ \t]*$" limit t)))
|
2012-08-18 07:34:27 -04:00
|
|
|
|
;; Incomplete block: parse it as a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(org-element-paragraph-parser limit affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((contents-end (match-beginning 0)))
|
|
|
|
|
(save-excursion
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((begin (car affiliated))
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
(post-affiliated (point))
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 16:57:02 -04:00
|
|
|
|
(contents-begin (progn (forward-line) (point)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(pos-before-blank (progn (goto-char contents-end)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(point)))
|
2012-07-28 17:21:38 -04:00
|
|
|
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
2013-11-10 05:28:14 -05:00
|
|
|
|
(if (eobp) (point) (line-beginning-position)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'verse-block
|
|
|
|
|
(nconc
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
org-element: Add `:post-affiliated' property to elements when applicable
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-property-drawer-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-babel-call-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-diary-sexp-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-src-block-parser,
org-element-table-parser, org-element-verse-block-parser): Add
`:post-affiliated' property to elements.
(org-element-inlinetask-parser): Remove affilated keywords.
* lisp/org.el (org-adaptive-fill-function): Use new property.
This property is cheap to compute during parsing and allows to
determine if point is on an affiliated keyword or not by checking if
it is between :begin and :post-affiliated positions.
2012-10-29 05:58:52 -04:00
|
|
|
|
:post-blank (count-lines pos-before-blank end)
|
|
|
|
|
:post-affiliated post-affiliated)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cdr affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-verse-block-interpreter (verse-block contents)
|
|
|
|
|
"Interpret VERSE-BLOCK element as Org syntax.
|
|
|
|
|
CONTENTS is verse block contents."
|
|
|
|
|
(format "#+BEGIN_VERSE\n%s#+END_VERSE" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Objects
|
|
|
|
|
;;
|
|
|
|
|
;; Unlike to elements, interstices can be found between objects.
|
|
|
|
|
;; That's why, along with the parser, successor functions are provided
|
2012-08-11 13:10:44 -04:00
|
|
|
|
;; for each object. Some objects share the same successor (i.e. `code'
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; and `verbatim' objects).
|
|
|
|
|
;;
|
|
|
|
|
;; A successor must accept a single argument bounding the search. It
|
|
|
|
|
;; will return either a cons cell whose CAR is the object's type, as
|
|
|
|
|
;; a symbol, and CDR the position of its next occurrence, or nil.
|
|
|
|
|
;;
|
|
|
|
|
;; Successors follow the naming convention:
|
|
|
|
|
;; org-element-NAME-successor, where NAME is the name of the
|
|
|
|
|
;; successor, as defined in `org-element-all-successors'.
|
|
|
|
|
;;
|
2012-08-04 04:16:12 -04:00
|
|
|
|
;; Some object types (i.e. `italic') are recursive. Restrictions on
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; object types they can contain will be specified in
|
|
|
|
|
;; `org-element-object-restrictions'.
|
|
|
|
|
;;
|
|
|
|
|
;; Adding a new type of object is simple. Implement a successor,
|
|
|
|
|
;; a parser, and an interpreter for it, all following the naming
|
|
|
|
|
;; convention. Register type in `org-element-all-objects' and
|
|
|
|
|
;; successor in `org-element-all-successors'. Maybe tweak
|
|
|
|
|
;; restrictions about it, and that's it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Bold
|
|
|
|
|
|
|
|
|
|
(defun org-element-bold-parser ()
|
|
|
|
|
"Parse bold object at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `bold' and CDR is a plist with
|
|
|
|
|
`:begin', `:end', `:contents-begin' and `:contents-end' and
|
|
|
|
|
`:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the first star marker."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char 1))
|
|
|
|
|
(looking-at org-emph-re)
|
|
|
|
|
(let ((begin (match-beginning 2))
|
|
|
|
|
(contents-begin (match-beginning 4))
|
|
|
|
|
(contents-end (match-end 4))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'bold
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-bold-interpreter (bold contents)
|
|
|
|
|
"Interpret BOLD object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(format "*%s*" contents))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-text-markup-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next text-markup object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is a symbol among `bold',
|
|
|
|
|
`italic', `underline', `strike-through', `code' and `verbatim'
|
|
|
|
|
and CDR is beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward org-emph-re nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((marker (match-string 3)))
|
|
|
|
|
(cons (cond
|
|
|
|
|
((equal marker "*") 'bold)
|
|
|
|
|
((equal marker "/") 'italic)
|
|
|
|
|
((equal marker "_") 'underline)
|
|
|
|
|
((equal marker "+") 'strike-through)
|
|
|
|
|
((equal marker "~") 'code)
|
|
|
|
|
((equal marker "=") 'verbatim)
|
|
|
|
|
(t (error "Unknown marker at %d" (match-beginning 3))))
|
|
|
|
|
(match-beginning 2))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Code
|
|
|
|
|
|
|
|
|
|
(defun org-element-code-parser ()
|
|
|
|
|
"Parse code object at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `code' and CDR is a plist with
|
|
|
|
|
`:value', `:begin', `:end' and `:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the first tilde marker."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char 1))
|
|
|
|
|
(looking-at org-emph-re)
|
|
|
|
|
(let ((begin (match-beginning 2))
|
|
|
|
|
(value (org-match-string-no-properties 4))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'code
|
|
|
|
|
(list :value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-code-interpreter (code contents)
|
|
|
|
|
"Interpret CODE object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format "~%s~" (org-element-property :value code)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Entity
|
|
|
|
|
|
|
|
|
|
(defun org-element-entity-parser ()
|
|
|
|
|
"Parse entity at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `entity' and CDR a plist with
|
|
|
|
|
`:begin', `:end', `:latex', `:latex-math-p', `:html', `:latin1',
|
|
|
|
|
`:utf-8', `:ascii', `:use-brackets-p' and `:post-blank' as
|
|
|
|
|
keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the entity."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\)")
|
|
|
|
|
(let* ((value (org-entity-get (match-string 1)))
|
|
|
|
|
(begin (match-beginning 0))
|
|
|
|
|
(bracketsp (string= (match-string 2) "{}"))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 1))
|
|
|
|
|
(when bracketsp (forward-char 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'entity
|
|
|
|
|
(list :name (car value)
|
|
|
|
|
:latex (nth 1 value)
|
|
|
|
|
:latex-math-p (nth 2 value)
|
|
|
|
|
:html (nth 3 value)
|
|
|
|
|
:ascii (nth 4 value)
|
|
|
|
|
:latin1 (nth 5 value)
|
|
|
|
|
:utf-8 (nth 6 value)
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:use-brackets-p bracketsp
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-entity-interpreter (entity contents)
|
|
|
|
|
"Interpret ENTITY object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(concat "\\"
|
|
|
|
|
(org-element-property :name entity)
|
|
|
|
|
(when (org-element-property :use-brackets-p entity) "{}")))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-latex-or-entity-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next latex-fragment or entity object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `entity' or
|
|
|
|
|
`latex-fragment' and CDR is beginning position."
|
|
|
|
|
(save-excursion
|
2012-10-14 15:34:22 -04:00
|
|
|
|
(unless (bolp) (backward-char))
|
2013-10-24 11:15:23 -04:00
|
|
|
|
(let ((matchers (cdr org-latex-regexps))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; ENTITY-RE matches both LaTeX commands and Org entities.
|
|
|
|
|
(entity-re
|
|
|
|
|
"\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\)"))
|
|
|
|
|
(when (re-search-forward
|
2013-10-24 11:15:23 -04:00
|
|
|
|
(concat (mapconcat #'cadr matchers "\\|") "\\|" entity-re) nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(if (looking-at entity-re)
|
|
|
|
|
;; Determine if it's a real entity or a LaTeX command.
|
|
|
|
|
(cons (if (org-entity-get (match-string 1)) 'entity 'latex-fragment)
|
|
|
|
|
(match-beginning 0))
|
|
|
|
|
;; No entity nor command: point is at a LaTeX fragment.
|
|
|
|
|
;; Determine its type to get the correct beginning position.
|
|
|
|
|
(cons 'latex-fragment
|
|
|
|
|
(catch 'return
|
2013-10-24 11:15:23 -04:00
|
|
|
|
(dolist (e matchers)
|
|
|
|
|
(when (looking-at (nth 1 e))
|
|
|
|
|
(throw 'return (match-beginning (nth 2 e)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(point))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Export Snippet
|
|
|
|
|
|
|
|
|
|
(defun org-element-export-snippet-parser ()
|
|
|
|
|
"Parse export snippet at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `export-snippet' and CDR a plist with
|
|
|
|
|
`:begin', `:end', `:back-end', `:value' and `:post-blank' as
|
|
|
|
|
keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the snippet."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-forward "@@\\([-A-Za-z0-9]+\\):" nil t)
|
|
|
|
|
(let* ((begin (match-beginning 0))
|
|
|
|
|
(back-end (org-match-string-no-properties 1))
|
|
|
|
|
(value (buffer-substring-no-properties
|
|
|
|
|
(point)
|
|
|
|
|
(progn (re-search-forward "@@" nil t) (match-beginning 0))))
|
|
|
|
|
(post-blank (skip-chars-forward " \t"))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'export-snippet
|
|
|
|
|
(list :back-end back-end
|
|
|
|
|
:value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-export-snippet-interpreter (export-snippet contents)
|
|
|
|
|
"Interpret EXPORT-SNIPPET object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format "@@%s:%s@@"
|
|
|
|
|
(org-element-property :back-end export-snippet)
|
|
|
|
|
(org-element-property :value export-snippet)))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-export-snippet-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next export-snippet object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `export-snippet' and CDR
|
|
|
|
|
its beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let (beg)
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (and (re-search-forward "@@[-A-Za-z0-9]+:" nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(setq beg (match-beginning 0))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(search-forward "@@" nil t))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'export-snippet beg)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Footnote Reference
|
|
|
|
|
|
|
|
|
|
(defun org-element-footnote-reference-parser ()
|
|
|
|
|
"Parse footnote reference at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `footnote-reference' and CDR a plist
|
|
|
|
|
with `:label', `:type', `:inline-definition', `:begin', `:end'
|
|
|
|
|
and `:post-blank' as keywords."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at org-footnote-re)
|
|
|
|
|
(let* ((begin (point))
|
|
|
|
|
(label (or (org-match-string-no-properties 2)
|
|
|
|
|
(org-match-string-no-properties 3)
|
|
|
|
|
(and (match-string 1)
|
|
|
|
|
(concat "fn:" (org-match-string-no-properties 1)))))
|
|
|
|
|
(type (if (or (not label) (match-string 1)) 'inline 'standard))
|
|
|
|
|
(inner-begin (match-end 0))
|
|
|
|
|
(inner-end
|
|
|
|
|
(let ((count 1))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(while (and (> count 0) (re-search-forward "[][]" nil t))
|
|
|
|
|
(if (equal (match-string 0) "[") (incf count) (decf count)))
|
|
|
|
|
(1- (point))))
|
|
|
|
|
(post-blank (progn (goto-char (1+ inner-end))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point))
|
|
|
|
|
(footnote-reference
|
|
|
|
|
(list 'footnote-reference
|
|
|
|
|
(list :label label
|
|
|
|
|
:type type
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank))))
|
|
|
|
|
(org-element-put-property
|
|
|
|
|
footnote-reference :inline-definition
|
|
|
|
|
(and (eq type 'inline)
|
|
|
|
|
(org-element-parse-secondary-string
|
|
|
|
|
(buffer-substring inner-begin inner-end)
|
|
|
|
|
(org-element-restriction 'footnote-reference)
|
|
|
|
|
footnote-reference))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-footnote-reference-interpreter (footnote-reference contents)
|
|
|
|
|
"Interpret FOOTNOTE-REFERENCE object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(let ((label (or (org-element-property :label footnote-reference) "fn:"))
|
|
|
|
|
(def
|
|
|
|
|
(let ((inline-def
|
|
|
|
|
(org-element-property :inline-definition footnote-reference)))
|
|
|
|
|
(if (not inline-def) ""
|
|
|
|
|
(concat ":" (org-element-interpret-data inline-def))))))
|
|
|
|
|
(format "[%s]" (concat label def))))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-footnote-reference-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next footnote-reference object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `footnote-reference' and
|
|
|
|
|
CDR is beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(catch 'exit
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(while (re-search-forward org-footnote-re nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((beg (match-beginning 0))
|
|
|
|
|
(count 1))
|
|
|
|
|
(backward-char)
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(while (re-search-forward "[][]" nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(if (equal (match-string 0) "[") (incf count) (decf count))
|
|
|
|
|
(when (zerop count)
|
|
|
|
|
(throw 'exit (cons 'footnote-reference beg))))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Inline Babel Call
|
|
|
|
|
|
|
|
|
|
(defun org-element-inline-babel-call-parser ()
|
|
|
|
|
"Parse inline babel call at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `inline-babel-call' and CDR a plist
|
2013-10-20 07:14:23 -04:00
|
|
|
|
with `:begin', `:end', `:value' and `:post-blank' as keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the babel call."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char))
|
2013-10-20 07:14:23 -04:00
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
(looking-at org-babel-inline-lob-one-liner-regexp))
|
|
|
|
|
(let ((begin (match-end 1))
|
|
|
|
|
(value (buffer-substring-no-properties (match-end 1) (match-end 0)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'inline-babel-call
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
2013-10-20 07:14:23 -04:00
|
|
|
|
:value value
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-inline-babel-call-interpreter (inline-babel-call contents)
|
|
|
|
|
"Interpret INLINE-BABEL-CALL object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2013-10-20 07:14:23 -04:00
|
|
|
|
(org-element-property :value inline-babel-call))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-inline-babel-call-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next inline-babel-call object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `inline-babel-call' and
|
|
|
|
|
CDR is beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
;; Use a simplified version of
|
2012-08-25 17:35:22 -04:00
|
|
|
|
;; `org-babel-inline-lob-one-liner-regexp'.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(when (re-search-forward
|
2012-08-25 17:35:22 -04:00
|
|
|
|
"call_\\([^()\n]+?\\)\\(?:\\[.*?\\]\\)?([^\n]*?)\\(\\[.*?\\]\\)?"
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'inline-babel-call (match-beginning 0)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Inline Src Block
|
|
|
|
|
|
|
|
|
|
(defun org-element-inline-src-block-parser ()
|
|
|
|
|
"Parse inline source block at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `inline-src-block' and CDR a plist
|
|
|
|
|
with `:begin', `:end', `:language', `:value', `:parameters' and
|
|
|
|
|
`:post-blank' as keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the inline src block."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char))
|
|
|
|
|
(looking-at org-babel-inline-src-block-regexp)
|
|
|
|
|
(let ((begin (match-beginning 1))
|
|
|
|
|
(language (org-match-string-no-properties 2))
|
|
|
|
|
(parameters (org-match-string-no-properties 4))
|
|
|
|
|
(value (org-match-string-no-properties 5))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'inline-src-block
|
|
|
|
|
(list :language language
|
|
|
|
|
:value value
|
|
|
|
|
:parameters parameters
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-inline-src-block-interpreter (inline-src-block contents)
|
|
|
|
|
"Interpret INLINE-SRC-BLOCK object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(let ((language (org-element-property :language inline-src-block))
|
|
|
|
|
(arguments (org-element-property :parameters inline-src-block))
|
|
|
|
|
(body (org-element-property :value inline-src-block)))
|
|
|
|
|
(format "src_%s%s{%s}"
|
|
|
|
|
language
|
|
|
|
|
(if arguments (format "[%s]" arguments) "")
|
|
|
|
|
body)))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-inline-src-block-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next inline-babel-call element.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `inline-babel-call' and
|
|
|
|
|
CDR is beginning position."
|
|
|
|
|
(save-excursion
|
2012-09-20 13:12:39 -04:00
|
|
|
|
(unless (bolp) (backward-char))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward org-babel-inline-src-block-regexp nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'inline-src-block (match-beginning 1)))))
|
|
|
|
|
|
|
|
|
|
;;;; Italic
|
|
|
|
|
|
|
|
|
|
(defun org-element-italic-parser ()
|
|
|
|
|
"Parse italic object at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `italic' and CDR is a plist with
|
|
|
|
|
`:begin', `:end', `:contents-begin' and `:contents-end' and
|
|
|
|
|
`:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the first slash marker."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char 1))
|
|
|
|
|
(looking-at org-emph-re)
|
|
|
|
|
(let ((begin (match-beginning 2))
|
|
|
|
|
(contents-begin (match-beginning 4))
|
|
|
|
|
(contents-end (match-end 4))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'italic
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-italic-interpreter (italic contents)
|
|
|
|
|
"Interpret ITALIC object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(format "/%s/" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Latex Fragment
|
|
|
|
|
|
|
|
|
|
(defun org-element-latex-fragment-parser ()
|
2013-10-24 11:15:23 -04:00
|
|
|
|
"Parse LaTeX fragment at point.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `latex-fragment' and CDR a plist with
|
|
|
|
|
`:value', `:begin', `:end', and `:post-blank' as keywords.
|
|
|
|
|
|
2013-10-24 11:15:23 -04:00
|
|
|
|
Assume point is at the beginning of the LaTeX fragment."
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((begin (point))
|
|
|
|
|
(substring-match
|
|
|
|
|
(catch 'exit
|
2013-10-24 11:15:23 -04:00
|
|
|
|
(dolist (e (cdr org-latex-regexps))
|
|
|
|
|
(let ((latex-regexp (nth 1 e)))
|
|
|
|
|
(when (or (looking-at latex-regexp)
|
|
|
|
|
(and (not (bobp))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(backward-char)
|
|
|
|
|
(looking-at latex-regexp))))
|
|
|
|
|
(throw 'exit (nth 2 e)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; None found: it's a macro.
|
|
|
|
|
(looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")
|
|
|
|
|
0))
|
2013-10-24 11:15:23 -04:00
|
|
|
|
(value (org-match-string-no-properties substring-match))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(post-blank (progn (goto-char (match-end substring-match))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'latex-fragment
|
|
|
|
|
(list :value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-latex-fragment-interpreter (latex-fragment contents)
|
|
|
|
|
"Interpret LATEX-FRAGMENT object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(org-element-property :value latex-fragment))
|
|
|
|
|
|
|
|
|
|
;;;; Line Break
|
|
|
|
|
|
|
|
|
|
(defun org-element-line-break-parser ()
|
|
|
|
|
"Parse line break at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `line-break', and CDR a plist with
|
|
|
|
|
`:begin', `:end' and `:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the line break."
|
2012-12-12 16:47:12 -05:00
|
|
|
|
(list 'line-break
|
|
|
|
|
(list :begin (point)
|
|
|
|
|
:end (progn (forward-line) (point))
|
|
|
|
|
:post-blank 0)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-line-break-interpreter (line-break contents)
|
|
|
|
|
"Interpret LINE-BREAK object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2012-12-12 16:47:12 -05:00
|
|
|
|
"\\\\\n")
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-line-break-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next line-break object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `line-break' and CDR is
|
|
|
|
|
beginning position."
|
|
|
|
|
(save-excursion
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(let ((beg (and (re-search-forward "[^\\\\]\\(\\\\\\\\\\)[ \t]*$" nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(goto-char (match-beginning 1)))))
|
|
|
|
|
;; A line break can only happen on a non-empty line.
|
|
|
|
|
(when (and beg (re-search-backward "\\S-" (point-at-bol) t))
|
|
|
|
|
(cons 'line-break beg)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Link
|
|
|
|
|
|
|
|
|
|
(defun org-element-link-parser ()
|
|
|
|
|
"Parse link at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `link' and CDR a plist with `:type',
|
2012-08-25 04:38:25 -04:00
|
|
|
|
`:path', `:raw-link', `:application', `:search-option', `:begin',
|
|
|
|
|
`:end', `:contents-begin', `:contents-end' and `:post-blank' as
|
|
|
|
|
keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the link."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((begin (point))
|
|
|
|
|
end contents-begin contents-end link-end post-blank path type
|
2012-08-25 04:38:25 -04:00
|
|
|
|
raw-link link search-option application)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cond
|
|
|
|
|
;; Type 1: Text targeted from a radio target.
|
|
|
|
|
((and org-target-link-regexp (looking-at org-target-link-regexp))
|
|
|
|
|
(setq type "radio"
|
|
|
|
|
link-end (match-end 0)
|
|
|
|
|
path (org-match-string-no-properties 0)))
|
|
|
|
|
;; Type 2: Standard link, i.e. [[http://orgmode.org][homepage]]
|
|
|
|
|
((looking-at org-bracket-link-regexp)
|
|
|
|
|
(setq contents-begin (match-beginning 3)
|
|
|
|
|
contents-end (match-end 3)
|
|
|
|
|
link-end (match-end 0)
|
2013-02-11 17:16:25 -05:00
|
|
|
|
;; RAW-LINK is the original link. Expand any
|
|
|
|
|
;; abbreviation in it.
|
2012-12-18 15:52:06 -05:00
|
|
|
|
raw-link (org-translate-link
|
|
|
|
|
(org-link-expand-abbrev
|
2013-07-20 06:45:58 -04:00
|
|
|
|
(org-match-string-no-properties 1))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Determine TYPE of link and set PATH accordingly.
|
|
|
|
|
(cond
|
|
|
|
|
;; File type.
|
2013-07-20 06:45:58 -04:00
|
|
|
|
((or (file-name-absolute-p raw-link)
|
|
|
|
|
(string-match "^\\.\\.?/" raw-link))
|
|
|
|
|
(setq type "file" path raw-link))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Explicit type (http, irc, bbdb...). See `org-link-types'.
|
2013-07-20 06:45:58 -04:00
|
|
|
|
((string-match org-link-re-with-space3 raw-link)
|
|
|
|
|
(setq type (match-string 1 raw-link) path (match-string 2 raw-link)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Id type: PATH is the id.
|
2013-07-20 06:45:58 -04:00
|
|
|
|
((string-match "^id:\\([-a-f0-9]+\\)" raw-link)
|
|
|
|
|
(setq type "id" path (match-string 1 raw-link)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Code-ref type: PATH is the name of the reference.
|
2013-07-20 06:45:58 -04:00
|
|
|
|
((string-match "^(\\(.*\\))$" raw-link)
|
|
|
|
|
(setq type "coderef" path (match-string 1 raw-link)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Custom-id type: PATH is the name of the custom id.
|
2013-07-20 06:45:58 -04:00
|
|
|
|
((= (aref raw-link 0) ?#)
|
|
|
|
|
(setq type "custom-id" path (substring raw-link 1)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Fuzzy type: Internal link either matches a target, an
|
|
|
|
|
;; headline name or nothing. PATH is the target or
|
|
|
|
|
;; headline's name.
|
2013-07-20 06:45:58 -04:00
|
|
|
|
(t (setq type "fuzzy" path raw-link))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Type 3: Plain link, i.e. http://orgmode.org
|
|
|
|
|
((looking-at org-plain-link-re)
|
|
|
|
|
(setq raw-link (org-match-string-no-properties 0)
|
|
|
|
|
type (org-match-string-no-properties 1)
|
2013-07-20 06:45:58 -04:00
|
|
|
|
link-end (match-end 0)
|
|
|
|
|
path (org-match-string-no-properties 2)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Type 4: Angular link, i.e. <http://orgmode.org>
|
|
|
|
|
((looking-at org-angle-link-re)
|
|
|
|
|
(setq raw-link (buffer-substring-no-properties
|
|
|
|
|
(match-beginning 1) (match-end 2))
|
|
|
|
|
type (org-match-string-no-properties 1)
|
2013-07-20 06:45:58 -04:00
|
|
|
|
link-end (match-end 0)
|
|
|
|
|
path (org-match-string-no-properties 2))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; In any case, deduce end point after trailing white space from
|
|
|
|
|
;; LINK-END variable.
|
|
|
|
|
(setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t"))
|
|
|
|
|
end (point))
|
2012-08-25 04:38:25 -04:00
|
|
|
|
;; Extract search option and opening application out of
|
|
|
|
|
;; "file"-type links.
|
|
|
|
|
(when (member type org-element-link-type-is-file)
|
|
|
|
|
;; Application.
|
|
|
|
|
(cond ((string-match "^file\\+\\(.*\\)$" type)
|
|
|
|
|
(setq application (match-string 1 type)))
|
|
|
|
|
((not (string-match "^file" type))
|
|
|
|
|
(setq application type)))
|
|
|
|
|
;; Extract search option from PATH.
|
|
|
|
|
(when (string-match "::\\(.*\\)$" path)
|
|
|
|
|
(setq search-option (match-string 1 path)
|
|
|
|
|
path (replace-match "" nil nil path)))
|
2013-07-20 06:45:58 -04:00
|
|
|
|
;; Make sure TYPE always reports "file".
|
2012-08-25 04:38:25 -04:00
|
|
|
|
(setq type "file"))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'link
|
|
|
|
|
(list :type type
|
|
|
|
|
:path path
|
|
|
|
|
:raw-link (or raw-link path)
|
2012-08-25 04:38:25 -04:00
|
|
|
|
:application application
|
|
|
|
|
:search-option search-option
|
2012-07-28 01:02:21 -04:00
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-link-interpreter (link contents)
|
|
|
|
|
"Interpret LINK object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object, or nil."
|
|
|
|
|
(let ((type (org-element-property :type link))
|
|
|
|
|
(raw-link (org-element-property :raw-link link)))
|
|
|
|
|
(if (string= type "radio") raw-link
|
|
|
|
|
(format "[[%s]%s]"
|
|
|
|
|
raw-link
|
|
|
|
|
(if contents (format "[%s]" contents) "")))))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-link-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next link object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `link' and CDR is
|
|
|
|
|
beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((link-regexp
|
|
|
|
|
(if (not org-target-link-regexp) org-any-link-re
|
|
|
|
|
(concat org-any-link-re "\\|" org-target-link-regexp))))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward link-regexp nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'link (match-beginning 0))))))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-plain-link-successor ()
|
2013-02-25 15:32:15 -05:00
|
|
|
|
"Search for the next plain link object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `link' and CDR is
|
|
|
|
|
beginning position."
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(and (save-excursion (re-search-forward org-plain-link-re nil t))
|
2013-02-25 15:32:15 -05:00
|
|
|
|
(cons 'link (match-beginning 0))))
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
;;;; Macro
|
|
|
|
|
|
|
|
|
|
(defun org-element-macro-parser ()
|
|
|
|
|
"Parse macro at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `macro' and CDR a plist with `:key',
|
|
|
|
|
`:args', `:begin', `:end', `:value' and `:post-blank' as
|
|
|
|
|
keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the macro."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}")
|
|
|
|
|
(let ((begin (point))
|
|
|
|
|
(key (downcase (org-match-string-no-properties 1)))
|
|
|
|
|
(value (org-match-string-no-properties 0))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point))
|
org-element: Allow to escape escaping character before a comma
* lisp/org-element.el (org-element-macro-parser): Allow to escape
escaping character before a comma. Also do not trim spaces at
argument boundaries.
* doc/org.texi (Macro replacement): Update documentation about
possible locations and escaping mechanism.
* testing/lisp/test-org-element.el: Add tests.
With this patch, macro's arguments are read as the following:
"a,b" -> '("a" "b")
"a\,b" -> '("a,b")
"a\\,b" -> '("a\" "b")
"a\\\,b" -> '("a\,b")
"a\\\\,b" -> '(a"\\" "b")
Note that with the patch, you only need to escape backslashes before
a comma:
"a\\b\,c" -> '("a\\b,c")
2013-03-23 14:10:41 -04:00
|
|
|
|
(args (let ((args (org-match-string-no-properties 3)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(when args
|
2013-01-31 16:15:15 -05:00
|
|
|
|
;; Do not use `org-split-string' since empty
|
|
|
|
|
;; strings are meaningful here.
|
org-element: Allow to escape escaping character before a comma
* lisp/org-element.el (org-element-macro-parser): Allow to escape
escaping character before a comma. Also do not trim spaces at
argument boundaries.
* doc/org.texi (Macro replacement): Update documentation about
possible locations and escaping mechanism.
* testing/lisp/test-org-element.el: Add tests.
With this patch, macro's arguments are read as the following:
"a,b" -> '("a" "b")
"a\,b" -> '("a,b")
"a\\,b" -> '("a\" "b")
"a\\\,b" -> '("a\,b")
"a\\\\,b" -> '(a"\\" "b")
Note that with the patch, you only need to escape backslashes before
a comma:
"a\\b\,c" -> '("a\\b,c")
2013-03-23 14:10:41 -04:00
|
|
|
|
(split-string
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\\(\\\\*\\)\\(,\\)"
|
|
|
|
|
(lambda (str)
|
|
|
|
|
(let ((len (length (match-string 1 str))))
|
|
|
|
|
(concat (make-string (/ len 2) ?\\)
|
|
|
|
|
(if (zerop (mod len 2)) "\000" ","))))
|
|
|
|
|
args nil t)
|
|
|
|
|
"\000")))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'macro
|
|
|
|
|
(list :key key
|
|
|
|
|
:value value
|
|
|
|
|
:args args
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-macro-interpreter (macro contents)
|
|
|
|
|
"Interpret MACRO object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(org-element-property :value macro))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-macro-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next macro object.
|
|
|
|
|
|
|
|
|
|
Return value is cons cell whose CAR is `macro' and CDR is
|
|
|
|
|
beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (re-search-forward
|
|
|
|
|
"{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'macro (match-beginning 0)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Radio-target
|
|
|
|
|
|
|
|
|
|
(defun org-element-radio-target-parser ()
|
|
|
|
|
"Parse radio target at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `radio-target' and CDR a plist with
|
|
|
|
|
`:begin', `:end', `:contents-begin', `:contents-end', `:value'
|
|
|
|
|
and `:post-blank' as keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the radio target."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at org-radio-target-regexp)
|
|
|
|
|
(let ((begin (point))
|
|
|
|
|
(contents-begin (match-beginning 1))
|
|
|
|
|
(contents-end (match-end 1))
|
|
|
|
|
(value (org-match-string-no-properties 1))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'radio-target
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank
|
|
|
|
|
:value value)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-radio-target-interpreter (target contents)
|
|
|
|
|
"Interpret TARGET object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(concat "<<<" contents ">>>"))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-radio-target-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next radio-target object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `radio-target' and CDR
|
|
|
|
|
is beginning position."
|
|
|
|
|
(save-excursion
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward org-radio-target-regexp nil t)
|
2012-08-11 13:10:44 -04:00
|
|
|
|
(cons 'radio-target (match-beginning 0)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Statistics Cookie
|
|
|
|
|
|
|
|
|
|
(defun org-element-statistics-cookie-parser ()
|
|
|
|
|
"Parse statistics cookie at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `statistics-cookie', and CDR a plist
|
|
|
|
|
with `:begin', `:end', `:value' and `:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the statistics-cookie."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at "\\[[0-9]*\\(%\\|/[0-9]*\\)\\]")
|
|
|
|
|
(let* ((begin (point))
|
|
|
|
|
(value (buffer-substring-no-properties
|
|
|
|
|
(match-beginning 0) (match-end 0)))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'statistics-cookie
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-statistics-cookie-interpreter (statistics-cookie contents)
|
|
|
|
|
"Interpret STATISTICS-COOKIE object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(org-element-property :value statistics-cookie))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-statistics-cookie-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next statistics cookie object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `statistics-cookie' and
|
|
|
|
|
CDR is beginning position."
|
|
|
|
|
(save-excursion
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward "\\[[0-9]*\\(%\\|/[0-9]*\\)\\]" nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'statistics-cookie (match-beginning 0)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Strike-Through
|
|
|
|
|
|
|
|
|
|
(defun org-element-strike-through-parser ()
|
|
|
|
|
"Parse strike-through object at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `strike-through' and CDR is a plist
|
|
|
|
|
with `:begin', `:end', `:contents-begin' and `:contents-end' and
|
|
|
|
|
`:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the first plus sign marker."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char 1))
|
|
|
|
|
(looking-at org-emph-re)
|
|
|
|
|
(let ((begin (match-beginning 2))
|
|
|
|
|
(contents-begin (match-beginning 4))
|
|
|
|
|
(contents-end (match-end 4))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'strike-through
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-strike-through-interpreter (strike-through contents)
|
|
|
|
|
"Interpret STRIKE-THROUGH object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(format "+%s+" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Subscript
|
|
|
|
|
|
|
|
|
|
(defun org-element-subscript-parser ()
|
|
|
|
|
"Parse subscript at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `subscript' and CDR a plist with
|
|
|
|
|
`:begin', `:end', `:contents-begin', `:contents-end',
|
|
|
|
|
`:use-brackets-p' and `:post-blank' as keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the underscore."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char))
|
|
|
|
|
(let ((bracketsp (if (looking-at org-match-substring-with-braces-regexp)
|
|
|
|
|
t
|
|
|
|
|
(not (looking-at org-match-substring-regexp))))
|
|
|
|
|
(begin (match-beginning 2))
|
|
|
|
|
(contents-begin (or (match-beginning 5)
|
|
|
|
|
(match-beginning 3)))
|
|
|
|
|
(contents-end (or (match-end 5) (match-end 3)))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'subscript
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:use-brackets-p bracketsp
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-subscript-interpreter (subscript contents)
|
|
|
|
|
"Interpret SUBSCRIPT object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(format
|
|
|
|
|
(if (org-element-property :use-brackets-p subscript) "_{%s}" "_%s")
|
|
|
|
|
contents))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-sub/superscript-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next sub/superscript object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is either `subscript' or
|
|
|
|
|
`superscript' and CDR is beginning position."
|
|
|
|
|
(save-excursion
|
2012-10-14 15:34:22 -04:00
|
|
|
|
(unless (bolp) (backward-char))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward org-match-substring-regexp nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons (if (string= (match-string 2) "_") 'subscript 'superscript)
|
|
|
|
|
(match-beginning 2)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Superscript
|
|
|
|
|
|
|
|
|
|
(defun org-element-superscript-parser ()
|
|
|
|
|
"Parse superscript at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `superscript' and CDR a plist with
|
|
|
|
|
`:begin', `:end', `:contents-begin', `:contents-end',
|
|
|
|
|
`:use-brackets-p' and `:post-blank' as keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the caret."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char))
|
|
|
|
|
(let ((bracketsp (if (looking-at org-match-substring-with-braces-regexp) t
|
|
|
|
|
(not (looking-at org-match-substring-regexp))))
|
|
|
|
|
(begin (match-beginning 2))
|
|
|
|
|
(contents-begin (or (match-beginning 5)
|
|
|
|
|
(match-beginning 3)))
|
|
|
|
|
(contents-end (or (match-end 5) (match-end 3)))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'superscript
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:use-brackets-p bracketsp
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-superscript-interpreter (superscript contents)
|
|
|
|
|
"Interpret SUPERSCRIPT object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(format
|
|
|
|
|
(if (org-element-property :use-brackets-p superscript) "^{%s}" "^%s")
|
|
|
|
|
contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Table Cell
|
|
|
|
|
|
|
|
|
|
(defun org-element-table-cell-parser ()
|
|
|
|
|
"Parse table cell at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `table-cell' and CDR is a plist
|
|
|
|
|
containing `:begin', `:end', `:contents-begin', `:contents-end'
|
|
|
|
|
and `:post-blank' keywords."
|
|
|
|
|
(looking-at "[ \t]*\\(.*?\\)[ \t]*|")
|
|
|
|
|
(let* ((begin (match-beginning 0))
|
|
|
|
|
(end (match-end 0))
|
|
|
|
|
(contents-begin (match-beginning 1))
|
|
|
|
|
(contents-end (match-end 1)))
|
|
|
|
|
(list 'table-cell
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank 0))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-table-cell-interpreter (table-cell contents)
|
|
|
|
|
"Interpret TABLE-CELL element as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the cell, or nil."
|
|
|
|
|
(concat " " contents " |"))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-table-cell-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next table-cell object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `table-cell' and CDR is
|
|
|
|
|
beginning position."
|
2013-04-09 10:16:04 -04:00
|
|
|
|
(when (looking-at "[ \t]*.*?[ \t]*|") (cons 'table-cell (point))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Target
|
|
|
|
|
|
|
|
|
|
(defun org-element-target-parser ()
|
|
|
|
|
"Parse target at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `target' and CDR a plist with
|
|
|
|
|
`:begin', `:end', `:value' and `:post-blank' as keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the target."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at org-target-regexp)
|
|
|
|
|
(let ((begin (point))
|
|
|
|
|
(value (org-match-string-no-properties 1))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'target
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:value value
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-target-interpreter (target contents)
|
|
|
|
|
"Interpret TARGET object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format "<<%s>>" (org-element-property :value target)))
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-target-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next target object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `target' and CDR is
|
|
|
|
|
beginning position."
|
|
|
|
|
(save-excursion
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(when (re-search-forward org-target-regexp nil t)
|
2012-08-11 13:10:44 -04:00
|
|
|
|
(cons 'target (match-beginning 0)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Timestamp
|
|
|
|
|
|
|
|
|
|
(defun org-element-timestamp-parser ()
|
|
|
|
|
"Parse time stamp at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `timestamp', and CDR a plist with
|
2013-10-13 04:17:16 -04:00
|
|
|
|
`:type', `:raw-value', `:year-start', `:month-start',
|
|
|
|
|
`:day-start', `:hour-start', `:minute-start', `:year-end',
|
|
|
|
|
`:month-end', `:day-end', `:hour-end', `:minute-end',
|
|
|
|
|
`:repeater-type', `:repeater-value', `:repeater-unit',
|
|
|
|
|
`:warning-type', `:warning-value', `:warning-unit', `:begin',
|
|
|
|
|
`:end', `:value' and `:post-blank' keywords.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Assume point is at the beginning of the timestamp."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((begin (point))
|
|
|
|
|
(activep (eq (char-after) ?<))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(raw-value
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(progn
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(looking-at "\\([<[]\\(%%\\)?.*?\\)[]>]\\(?:--\\([<[].*?[]>]\\)\\)?")
|
|
|
|
|
(match-string-no-properties 0)))
|
|
|
|
|
(date-start (match-string-no-properties 1))
|
|
|
|
|
(date-end (match-string 3))
|
|
|
|
|
(diaryp (match-beginning 2))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(post-blank (progn (goto-char (match-end 0))
|
|
|
|
|
(skip-chars-forward " \t")))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(end (point))
|
2012-11-15 15:46:08 -05:00
|
|
|
|
(time-range
|
|
|
|
|
(and (not diaryp)
|
|
|
|
|
(string-match
|
|
|
|
|
"[012]?[0-9]:[0-5][0-9]\\(-\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)"
|
|
|
|
|
date-start)
|
|
|
|
|
(cons (string-to-number (match-string 2 date-start))
|
|
|
|
|
(string-to-number (match-string 3 date-start)))))
|
|
|
|
|
(type (cond (diaryp 'diary)
|
|
|
|
|
((and activep (or date-end time-range)) 'active-range)
|
|
|
|
|
(activep 'active)
|
|
|
|
|
((or date-end time-range) 'inactive-range)
|
|
|
|
|
(t 'inactive)))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(repeater-props
|
|
|
|
|
(and (not diaryp)
|
2013-10-13 04:17:16 -04:00
|
|
|
|
(string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)"
|
2012-09-28 08:50:21 -04:00
|
|
|
|
raw-value)
|
|
|
|
|
(list
|
|
|
|
|
:repeater-type
|
|
|
|
|
(let ((type (match-string 1 raw-value)))
|
|
|
|
|
(cond ((equal "++" type) 'catch-up)
|
|
|
|
|
((equal ".+" type) 'restart)
|
|
|
|
|
(t 'cumulate)))
|
|
|
|
|
:repeater-value (string-to-number (match-string 2 raw-value))
|
|
|
|
|
:repeater-unit
|
|
|
|
|
(case (string-to-char (match-string 3 raw-value))
|
|
|
|
|
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (t 'year)))))
|
2013-10-13 04:17:16 -04:00
|
|
|
|
(warning-props
|
|
|
|
|
(and (not diaryp)
|
|
|
|
|
(string-match "\\(-\\)?-\\([0-9]+\\)\\([hdwmy]\\)" raw-value)
|
|
|
|
|
(list
|
|
|
|
|
:warning-type (if (match-string 1 raw-value) 'first 'all)
|
|
|
|
|
:warning-value (string-to-number (match-string 2 raw-value))
|
|
|
|
|
:warning-unit
|
|
|
|
|
(case (string-to-char (match-string 3 raw-value))
|
|
|
|
|
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (t 'year)))))
|
2012-11-15 15:46:08 -05:00
|
|
|
|
year-start month-start day-start hour-start minute-start year-end
|
|
|
|
|
month-end day-end hour-end minute-end)
|
2012-09-28 08:50:21 -04:00
|
|
|
|
;; Parse date-start.
|
|
|
|
|
(unless diaryp
|
2012-11-15 15:02:26 -05:00
|
|
|
|
(let ((date (org-parse-time-string date-start t)))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(setq year-start (nth 5 date)
|
|
|
|
|
month-start (nth 4 date)
|
|
|
|
|
day-start (nth 3 date)
|
2012-11-15 15:02:26 -05:00
|
|
|
|
hour-start (nth 2 date)
|
|
|
|
|
minute-start (nth 1 date))))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
;; Compute date-end. It can be provided directly in time-stamp,
|
|
|
|
|
;; or extracted from time range. Otherwise, it defaults to the
|
|
|
|
|
;; same values as date-start.
|
|
|
|
|
(unless diaryp
|
2012-11-15 15:02:26 -05:00
|
|
|
|
(let ((date (and date-end (org-parse-time-string date-end t))))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(setq year-end (or (nth 5 date) year-start)
|
|
|
|
|
month-end (or (nth 4 date) month-start)
|
|
|
|
|
day-end (or (nth 3 date) day-start)
|
|
|
|
|
hour-end (or (nth 2 date) (car time-range) hour-start)
|
|
|
|
|
minute-end (or (nth 1 date) (cdr time-range) minute-start))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(list 'timestamp
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(nconc (list :type type
|
|
|
|
|
:raw-value raw-value
|
|
|
|
|
:year-start year-start
|
|
|
|
|
:month-start month-start
|
|
|
|
|
:day-start day-start
|
|
|
|
|
:hour-start hour-start
|
|
|
|
|
:minute-start minute-start
|
|
|
|
|
:year-end year-end
|
|
|
|
|
:month-end month-end
|
|
|
|
|
:day-end day-end
|
|
|
|
|
:hour-end hour-end
|
|
|
|
|
:minute-end minute-end
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)
|
2013-10-13 04:17:16 -04:00
|
|
|
|
repeater-props
|
|
|
|
|
warning-props)))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element-timestamp-interpreter (timestamp contents)
|
|
|
|
|
"Interpret TIMESTAMP object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
2012-09-28 08:50:21 -04:00
|
|
|
|
;; Use `:raw-value' if specified.
|
|
|
|
|
(or (org-element-property :raw-value timestamp)
|
|
|
|
|
;; Otherwise, build timestamp string.
|
2013-01-10 07:57:37 -05:00
|
|
|
|
(let* ((repeat-string
|
|
|
|
|
(concat
|
|
|
|
|
(case (org-element-property :repeater-type timestamp)
|
|
|
|
|
(cumulate "+") (catch-up "++") (restart ".+"))
|
|
|
|
|
(let ((val (org-element-property :repeater-value timestamp)))
|
|
|
|
|
(and val (number-to-string val)))
|
|
|
|
|
(case (org-element-property :repeater-unit timestamp)
|
|
|
|
|
(hour "h") (day "d") (week "w") (month "m") (year "y"))))
|
2013-10-13 04:17:16 -04:00
|
|
|
|
(warning-string
|
|
|
|
|
(concat
|
2013-10-13 12:13:35 -04:00
|
|
|
|
(case (org-element-property :warning-type timestamp)
|
|
|
|
|
(first "--")
|
|
|
|
|
(all "-"))
|
|
|
|
|
(let ((val (org-element-property :warning-value timestamp)))
|
2013-10-13 04:17:16 -04:00
|
|
|
|
(and val (number-to-string val)))
|
2013-10-13 12:13:35 -04:00
|
|
|
|
(case (org-element-property :warning-unit timestamp)
|
2013-10-13 04:17:16 -04:00
|
|
|
|
(hour "h") (day "d") (week "w") (month "m") (year "y"))))
|
2013-01-10 07:57:37 -05:00
|
|
|
|
(build-ts-string
|
|
|
|
|
;; Build an Org timestamp string from TIME. ACTIVEP is
|
|
|
|
|
;; non-nil when time stamp is active. If WITH-TIME-P is
|
|
|
|
|
;; non-nil, add a time part. HOUR-END and MINUTE-END
|
|
|
|
|
;; specify a time range in the timestamp. REPEAT-STRING
|
|
|
|
|
;; is the repeater string, if any.
|
|
|
|
|
(lambda (time activep &optional with-time-p hour-end minute-end)
|
|
|
|
|
(let ((ts (format-time-string
|
|
|
|
|
(funcall (if with-time-p 'cdr 'car)
|
|
|
|
|
org-time-stamp-formats)
|
|
|
|
|
time)))
|
|
|
|
|
(when (and hour-end minute-end)
|
|
|
|
|
(string-match "[012]?[0-9]:[0-5][0-9]" ts)
|
|
|
|
|
(setq ts
|
|
|
|
|
(replace-match
|
|
|
|
|
(format "\\&-%02d:%02d" hour-end minute-end)
|
|
|
|
|
nil nil ts)))
|
|
|
|
|
(unless activep (setq ts (format "[%s]" (substring ts 1 -1))))
|
2013-10-13 12:13:35 -04:00
|
|
|
|
(dolist (s (list repeat-string warning-string))
|
|
|
|
|
(when (org-string-nw-p s)
|
|
|
|
|
(setq ts (concat (substring ts 0 -1)
|
|
|
|
|
" "
|
|
|
|
|
s
|
|
|
|
|
(substring ts -1)))))
|
2013-01-10 07:57:37 -05:00
|
|
|
|
;; Return value.
|
|
|
|
|
ts)))
|
|
|
|
|
(type (org-element-property :type timestamp)))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
(case type
|
|
|
|
|
((active inactive)
|
|
|
|
|
(let* ((minute-start (org-element-property :minute-start timestamp))
|
|
|
|
|
(minute-end (org-element-property :minute-end timestamp))
|
|
|
|
|
(hour-start (org-element-property :hour-start timestamp))
|
|
|
|
|
(hour-end (org-element-property :hour-end timestamp))
|
|
|
|
|
(time-range-p (and hour-start hour-end minute-start minute-end
|
|
|
|
|
(or (/= hour-start hour-end)
|
|
|
|
|
(/= minute-start minute-end)))))
|
|
|
|
|
(funcall
|
|
|
|
|
build-ts-string
|
|
|
|
|
(encode-time 0
|
|
|
|
|
(or minute-start 0)
|
|
|
|
|
(or hour-start 0)
|
|
|
|
|
(org-element-property :day-start timestamp)
|
|
|
|
|
(org-element-property :month-start timestamp)
|
|
|
|
|
(org-element-property :year-start timestamp))
|
|
|
|
|
(eq type 'active)
|
|
|
|
|
(and hour-start minute-start)
|
|
|
|
|
(and time-range-p hour-end)
|
2013-01-10 07:57:37 -05:00
|
|
|
|
(and time-range-p minute-end))))
|
2012-09-28 08:50:21 -04:00
|
|
|
|
((active-range inactive-range)
|
|
|
|
|
(let ((minute-start (org-element-property :minute-start timestamp))
|
|
|
|
|
(minute-end (org-element-property :minute-end timestamp))
|
|
|
|
|
(hour-start (org-element-property :hour-start timestamp))
|
|
|
|
|
(hour-end (org-element-property :hour-end timestamp)))
|
|
|
|
|
(concat
|
|
|
|
|
(funcall
|
|
|
|
|
build-ts-string (encode-time
|
|
|
|
|
0
|
|
|
|
|
(or minute-start 0)
|
|
|
|
|
(or hour-start 0)
|
|
|
|
|
(org-element-property :day-start timestamp)
|
|
|
|
|
(org-element-property :month-start timestamp)
|
|
|
|
|
(org-element-property :year-start timestamp))
|
|
|
|
|
(eq type 'active-range)
|
|
|
|
|
(and hour-start minute-start))
|
|
|
|
|
"--"
|
|
|
|
|
(funcall build-ts-string
|
|
|
|
|
(encode-time 0
|
|
|
|
|
(or minute-end 0)
|
|
|
|
|
(or hour-end 0)
|
|
|
|
|
(org-element-property :day-end timestamp)
|
|
|
|
|
(org-element-property :month-end timestamp)
|
|
|
|
|
(org-element-property :year-end timestamp))
|
|
|
|
|
(eq type 'active-range)
|
|
|
|
|
(and hour-end minute-end)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(defun org-element-timestamp-successor ()
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Search for the next timestamp object.
|
|
|
|
|
|
|
|
|
|
Return value is a cons cell whose CAR is `timestamp' and CDR is
|
|
|
|
|
beginning position."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (re-search-forward
|
|
|
|
|
(concat org-ts-regexp-both
|
|
|
|
|
"\\|"
|
|
|
|
|
"\\(?:<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
|
|
|
|
|
"\\|"
|
|
|
|
|
"\\(?:<%%\\(?:([^>\n]+)\\)>\\)")
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
nil t)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(cons 'timestamp (match-beginning 0)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Underline
|
|
|
|
|
|
|
|
|
|
(defun org-element-underline-parser ()
|
|
|
|
|
"Parse underline object at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `underline' and CDR is a plist with
|
|
|
|
|
`:begin', `:end', `:contents-begin' and `:contents-end' and
|
|
|
|
|
`:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the first underscore marker."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char 1))
|
|
|
|
|
(looking-at org-emph-re)
|
|
|
|
|
(let ((begin (match-beginning 2))
|
|
|
|
|
(contents-begin (match-beginning 4))
|
|
|
|
|
(contents-end (match-end 4))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'underline
|
|
|
|
|
(list :begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:contents-begin contents-begin
|
|
|
|
|
:contents-end contents-end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-underline-interpreter (underline contents)
|
|
|
|
|
"Interpret UNDERLINE object as Org syntax.
|
|
|
|
|
CONTENTS is the contents of the object."
|
|
|
|
|
(format "_%s_" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Verbatim
|
|
|
|
|
|
|
|
|
|
(defun org-element-verbatim-parser ()
|
|
|
|
|
"Parse verbatim object at point.
|
|
|
|
|
|
|
|
|
|
Return a list whose CAR is `verbatim' and CDR is a plist with
|
|
|
|
|
`:value', `:begin', `:end' and `:post-blank' keywords.
|
|
|
|
|
|
|
|
|
|
Assume point is at the first equal sign marker."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless (bolp) (backward-char 1))
|
|
|
|
|
(looking-at org-emph-re)
|
|
|
|
|
(let ((begin (match-beginning 2))
|
|
|
|
|
(value (org-match-string-no-properties 4))
|
|
|
|
|
(post-blank (progn (goto-char (match-end 2))
|
|
|
|
|
(skip-chars-forward " \t")))
|
|
|
|
|
(end (point)))
|
|
|
|
|
(list 'verbatim
|
|
|
|
|
(list :value value
|
|
|
|
|
:begin begin
|
|
|
|
|
:end end
|
|
|
|
|
:post-blank post-blank)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-verbatim-interpreter (verbatim contents)
|
|
|
|
|
"Interpret VERBATIM object as Org syntax.
|
|
|
|
|
CONTENTS is nil."
|
|
|
|
|
(format "=%s=" (org-element-property :value verbatim)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Parsing Element Starting At Point
|
|
|
|
|
;;
|
|
|
|
|
;; `org-element--current-element' is the core function of this section.
|
|
|
|
|
;; It returns the Lisp representation of the element starting at
|
|
|
|
|
;; point.
|
|
|
|
|
;;
|
|
|
|
|
;; `org-element--current-element' makes use of special modes. They
|
|
|
|
|
;; are activated for fixed element chaining (i.e. `plain-list' >
|
|
|
|
|
;; `item') or fixed conditional element chaining (i.e. `headline' >
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;; `section'). Special modes are: `first-section', `item',
|
|
|
|
|
;; `node-property', `quote-section', `section' and `table-row'.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element--current-element
|
|
|
|
|
(limit &optional granularity special structure)
|
|
|
|
|
"Parse the element starting at point.
|
|
|
|
|
|
|
|
|
|
Return value is a list like (TYPE PROPS) where TYPE is the type
|
|
|
|
|
of the element and PROPS a plist of properties associated to the
|
|
|
|
|
element.
|
|
|
|
|
|
|
|
|
|
Possible types are defined in `org-element-all-elements'.
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
LIMIT bounds the search.
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
Optional argument GRANULARITY determines the depth of the
|
|
|
|
|
recursion. Allowed values are `headline', `greater-element',
|
|
|
|
|
`element', `object' or nil. When it is broader than `object' (or
|
|
|
|
|
nil), secondary values will not be parsed, since they only
|
|
|
|
|
contain objects.
|
|
|
|
|
|
|
|
|
|
Optional argument SPECIAL, when non-nil, can be either
|
2012-09-23 09:52:02 -04:00
|
|
|
|
`first-section', `item', `node-property', `quote-section',
|
|
|
|
|
`section', and `table-row'.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
If STRUCTURE isn't provided but SPECIAL is set to `item', it will
|
|
|
|
|
be computed.
|
|
|
|
|
|
|
|
|
|
This function assumes point is always at the beginning of the
|
|
|
|
|
element it has to parse."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((case-fold-search t)
|
|
|
|
|
;; Determine if parsing depth allows for secondary strings
|
|
|
|
|
;; parsing. It only applies to elements referenced in
|
|
|
|
|
;; `org-element-secondary-value-alist'.
|
|
|
|
|
(raw-secondary-p (and granularity (not (eq granularity 'object)))))
|
|
|
|
|
(cond
|
|
|
|
|
;; Item.
|
|
|
|
|
((eq special 'item)
|
|
|
|
|
(org-element-item-parser limit structure raw-secondary-p))
|
|
|
|
|
;; Table Row.
|
|
|
|
|
((eq special 'table-row) (org-element-table-row-parser limit))
|
2012-09-23 09:52:02 -04:00
|
|
|
|
;; Node Property.
|
|
|
|
|
((eq special 'node-property) (org-element-node-property-parser limit))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Headline.
|
|
|
|
|
((org-with-limited-levels (org-at-heading-p))
|
|
|
|
|
(org-element-headline-parser limit raw-secondary-p))
|
2012-09-01 16:52:43 -04:00
|
|
|
|
;; Sections (must be checked after headline).
|
2012-07-28 01:02:21 -04:00
|
|
|
|
((eq special 'section) (org-element-section-parser limit))
|
2012-09-01 16:52:43 -04:00
|
|
|
|
((eq special 'quote-section) (org-element-quote-section-parser limit))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
((eq special 'first-section)
|
|
|
|
|
(org-element-section-parser
|
|
|
|
|
(or (save-excursion (org-with-limited-levels (outline-next-heading)))
|
|
|
|
|
limit)))
|
2012-09-12 09:40:13 -04:00
|
|
|
|
;; When not at bol, point is at the beginning of an item or
|
|
|
|
|
;; a footnote definition: next item is always a paragraph.
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
((not (bolp)) (org-element-paragraph-parser limit (list (point))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Planning and Clock.
|
2012-09-28 08:50:21 -04:00
|
|
|
|
((looking-at org-planning-or-clock-line-re)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(if (equal (match-string 1) org-clock-string)
|
|
|
|
|
(org-element-clock-parser limit)
|
|
|
|
|
(org-element-planning-parser limit)))
|
|
|
|
|
;; Inlinetask.
|
|
|
|
|
((org-at-heading-p)
|
|
|
|
|
(org-element-inlinetask-parser limit raw-secondary-p))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; From there, elements can have affiliated keywords.
|
2013-02-11 08:42:16 -05:00
|
|
|
|
(t (let ((affiliated (org-element--collect-affiliated-keywords limit)))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(cond
|
2013-02-11 08:42:16 -05:00
|
|
|
|
;; Jumping over affiliated keywords put point off-limits.
|
|
|
|
|
;; Parse them as regular keywords.
|
2013-06-25 11:32:26 -04:00
|
|
|
|
((and (cdr affiliated) (>= (point) limit))
|
2013-02-11 08:42:16 -05:00
|
|
|
|
(goto-char (car affiliated))
|
|
|
|
|
(org-element-keyword-parser limit nil))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; LaTeX Environment.
|
2013-05-12 11:15:06 -04:00
|
|
|
|
((looking-at
|
|
|
|
|
"[ \t]*\\\\begin{[A-Za-z0-9*]+}\\(\\[.*?\\]\\|{.*?}\\)*[ \t]*$")
|
2012-10-27 08:19:58 -04:00
|
|
|
|
(org-element-latex-environment-parser limit affiliated))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; Drawer and Property Drawer.
|
|
|
|
|
((looking-at org-drawer-regexp)
|
2012-10-27 08:19:58 -04:00
|
|
|
|
(if (equal (match-string 1) "PROPERTIES")
|
|
|
|
|
(org-element-property-drawer-parser limit affiliated)
|
|
|
|
|
(org-element-drawer-parser limit affiliated)))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; Fixed Width
|
|
|
|
|
((looking-at "[ \t]*:\\( \\|$\\)")
|
|
|
|
|
(org-element-fixed-width-parser limit affiliated))
|
|
|
|
|
;; Inline Comments, Blocks, Babel Calls, Dynamic Blocks and
|
|
|
|
|
;; Keywords.
|
|
|
|
|
((looking-at "[ \t]*#")
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(cond ((looking-at "\\(?: \\|$\\)")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-comment-parser limit affiliated))
|
|
|
|
|
((looking-at "\\+BEGIN_\\(\\S-+\\)")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((parser (assoc (upcase (match-string 1))
|
|
|
|
|
org-element-block-name-alist)))
|
|
|
|
|
(if parser (funcall (cdr parser) limit affiliated)
|
|
|
|
|
(org-element-special-block-parser limit affiliated))))
|
|
|
|
|
((looking-at "\\+CALL:")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-babel-call-parser limit affiliated))
|
|
|
|
|
((looking-at "\\+BEGIN:? ")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-dynamic-block-parser limit affiliated))
|
|
|
|
|
((looking-at "\\+\\S-+:")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-keyword-parser limit affiliated))
|
|
|
|
|
(t
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-paragraph-parser limit affiliated))))
|
|
|
|
|
;; Footnote Definition.
|
|
|
|
|
((looking-at org-footnote-definition-re)
|
|
|
|
|
(org-element-footnote-definition-parser limit affiliated))
|
|
|
|
|
;; Horizontal Rule.
|
|
|
|
|
((looking-at "[ \t]*-\\{5,\\}[ \t]*$")
|
|
|
|
|
(org-element-horizontal-rule-parser limit affiliated))
|
2012-10-27 08:23:37 -04:00
|
|
|
|
;; Diary Sexp.
|
|
|
|
|
((looking-at "%%(")
|
|
|
|
|
(org-element-diary-sexp-parser limit affiliated))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; Table.
|
|
|
|
|
((org-at-table-p t) (org-element-table-parser limit affiliated))
|
|
|
|
|
;; List.
|
|
|
|
|
((looking-at (org-item-re))
|
|
|
|
|
(org-element-plain-list-parser
|
2013-05-31 14:13:29 -04:00
|
|
|
|
limit affiliated
|
|
|
|
|
(or structure (org-element--list-struct limit))))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
;; Default element: Paragraph.
|
|
|
|
|
(t (org-element-paragraph-parser limit affiliated)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Most elements can have affiliated keywords. When looking for an
|
|
|
|
|
;; element beginning, we want to move before them, as they belong to
|
|
|
|
|
;; that element, and, in the meantime, collect information they give
|
|
|
|
|
;; into appropriate properties. Hence the following function.
|
|
|
|
|
|
2013-02-11 08:42:16 -05:00
|
|
|
|
(defun org-element--collect-affiliated-keywords (limit)
|
|
|
|
|
"Collect affiliated keywords from point down to LIMIT.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return a list whose CAR is the position at the first of them and
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
CDR a plist of keywords and values and move point to the
|
|
|
|
|
beginning of the first line after them.
|
|
|
|
|
|
|
|
|
|
As a special case, if element doesn't start at the beginning of
|
|
|
|
|
the line (i.e. a paragraph starting an item), CAR is current
|
|
|
|
|
position of point and CDR is nil."
|
|
|
|
|
(if (not (bolp)) (list (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((case-fold-search t)
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(origin (point))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; RESTRICT is the list of objects allowed in parsed
|
|
|
|
|
;; keywords value.
|
|
|
|
|
(restrict (org-element-restriction 'keyword))
|
|
|
|
|
output)
|
2013-02-11 08:42:16 -05:00
|
|
|
|
(while (and (< (point) limit) (looking-at org-element--affiliated-re))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(let* ((raw-kwd (upcase (match-string 1)))
|
|
|
|
|
;; Apply translation to RAW-KWD. From there, KWD is
|
|
|
|
|
;; the official keyword.
|
|
|
|
|
(kwd (or (cdr (assoc raw-kwd
|
|
|
|
|
org-element-keyword-translation-alist))
|
|
|
|
|
raw-kwd))
|
|
|
|
|
;; Find main value for any keyword.
|
|
|
|
|
(value
|
|
|
|
|
(save-match-data
|
|
|
|
|
(org-trim
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
(match-end 0) (point-at-eol)))))
|
|
|
|
|
;; PARSEDP is non-nil when keyword should have its
|
|
|
|
|
;; value parsed.
|
|
|
|
|
(parsedp (member kwd org-element-parsed-keywords))
|
|
|
|
|
;; If KWD is a dual keyword, find its secondary
|
|
|
|
|
;; value. Maybe parse it.
|
|
|
|
|
(dualp (member kwd org-element-dual-keywords))
|
|
|
|
|
(dual-value
|
|
|
|
|
(and dualp
|
|
|
|
|
(let ((sec (org-match-string-no-properties 2)))
|
|
|
|
|
(if (or (not sec) (not parsedp)) sec
|
|
|
|
|
(org-element-parse-secondary-string sec restrict)))))
|
|
|
|
|
;; Attribute a property name to KWD.
|
|
|
|
|
(kwd-sym (and kwd (intern (concat ":" (downcase kwd))))))
|
|
|
|
|
;; Now set final shape for VALUE.
|
|
|
|
|
(when parsedp
|
|
|
|
|
(setq value (org-element-parse-secondary-string value restrict)))
|
2012-10-28 17:43:50 -04:00
|
|
|
|
(when dualp
|
|
|
|
|
(setq value (and (or value dual-value) (cons value dual-value))))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(when (or (member kwd org-element-multiple-keywords)
|
|
|
|
|
;; Attributes can always appear on multiple lines.
|
|
|
|
|
(string-match "^ATTR_" kwd))
|
|
|
|
|
(setq value (cons value (plist-get output kwd-sym))))
|
|
|
|
|
;; Eventually store the new value in OUTPUT.
|
|
|
|
|
(setq output (plist-put output kwd-sym value))
|
|
|
|
|
;; Move to next keyword.
|
|
|
|
|
(forward-line)))
|
|
|
|
|
;; If affiliated keywords are orphaned: move back to first one.
|
|
|
|
|
;; They will be parsed as a paragraph.
|
|
|
|
|
(when (looking-at "[ \t]*$") (goto-char origin) (setq output nil))
|
|
|
|
|
;; Return value.
|
2012-09-23 03:49:32 -04:00
|
|
|
|
(cons origin output))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; The Org Parser
|
|
|
|
|
;;
|
|
|
|
|
;; The two major functions here are `org-element-parse-buffer', which
|
|
|
|
|
;; parses Org syntax inside the current buffer, taking into account
|
|
|
|
|
;; region, narrowing, or even visibility if specified, and
|
|
|
|
|
;; `org-element-parse-secondary-string', which parses objects within
|
|
|
|
|
;; a given string.
|
|
|
|
|
;;
|
|
|
|
|
;; The (almost) almighty `org-element-map' allows to apply a function
|
|
|
|
|
;; on elements or objects matching some type, and accumulate the
|
|
|
|
|
;; resulting values. In an export situation, it also skips unneeded
|
|
|
|
|
;; parts of the parse tree.
|
|
|
|
|
|
|
|
|
|
(defun org-element-parse-buffer (&optional granularity visible-only)
|
|
|
|
|
"Recursively parse the buffer and return structure.
|
|
|
|
|
If narrowing is in effect, only parse the visible part of the
|
|
|
|
|
buffer.
|
|
|
|
|
|
|
|
|
|
Optional argument GRANULARITY determines the depth of the
|
|
|
|
|
recursion. It can be set to the following symbols:
|
|
|
|
|
|
|
|
|
|
`headline' Only parse headlines.
|
|
|
|
|
`greater-element' Don't recurse into greater elements excepted
|
|
|
|
|
headlines and sections. Thus, elements
|
|
|
|
|
parsed are the top-level ones.
|
|
|
|
|
`element' Parse everything but objects and plain text.
|
|
|
|
|
`object' Parse the complete buffer (default).
|
|
|
|
|
|
|
|
|
|
When VISIBLE-ONLY is non-nil, don't parse contents of hidden
|
|
|
|
|
elements.
|
|
|
|
|
|
2013-01-20 03:43:58 -05:00
|
|
|
|
An element or an objects is represented as a list with the
|
|
|
|
|
pattern (TYPE PROPERTIES CONTENTS), where :
|
|
|
|
|
|
|
|
|
|
TYPE is a symbol describing the element or object. See
|
|
|
|
|
`org-element-all-elements' and `org-element-all-objects' for an
|
|
|
|
|
exhaustive list of such symbols. One can retrieve it with
|
|
|
|
|
`org-element-type' function.
|
|
|
|
|
|
|
|
|
|
PROPERTIES is the list of attributes attached to the element or
|
|
|
|
|
object, as a plist. Although most of them are specific to the
|
|
|
|
|
element or object type, all types share `:begin', `:end',
|
|
|
|
|
`:post-blank' and `:parent' properties, which respectively
|
|
|
|
|
refer to buffer position where the element or object starts,
|
|
|
|
|
ends, the number of white spaces or blank lines after it, and
|
|
|
|
|
the element or object containing it. Properties values can be
|
|
|
|
|
obtained by using `org-element-property' function.
|
|
|
|
|
|
|
|
|
|
CONTENTS is a list of elements, objects or raw strings
|
|
|
|
|
contained in the current element or object, when applicable.
|
|
|
|
|
One can access them with `org-element-contents' function.
|
|
|
|
|
|
|
|
|
|
The Org buffer has `org-data' as type and nil as properties.
|
|
|
|
|
`org-element-map' function can be used to find specific elements
|
|
|
|
|
or objects within the parse tree.
|
|
|
|
|
|
|
|
|
|
This function assumes that current major mode is `org-mode'."
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(org-skip-whitespace)
|
|
|
|
|
(org-element--parse-elements
|
|
|
|
|
(point-at-bol) (point-max)
|
|
|
|
|
;; Start in `first-section' mode so text before the first
|
|
|
|
|
;; headline belongs to a section.
|
|
|
|
|
'first-section nil granularity visible-only (list 'org-data nil))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-parse-secondary-string (string restriction &optional parent)
|
|
|
|
|
"Recursively parse objects in STRING and return structure.
|
|
|
|
|
|
|
|
|
|
RESTRICTION is a symbol limiting the object types that will be
|
|
|
|
|
looked after.
|
|
|
|
|
|
|
|
|
|
Optional argument PARENT, when non-nil, is the element or object
|
|
|
|
|
containing the secondary string. It is used to set correctly
|
|
|
|
|
`:parent' property within the string."
|
2012-12-18 15:52:06 -05:00
|
|
|
|
;; Copy buffer-local variables listed in
|
|
|
|
|
;; `org-element-object-variables' into temporary buffer. This is
|
|
|
|
|
;; required since object parsing is dependent on these variables.
|
|
|
|
|
(let ((pairs (delq nil (mapcar (lambda (var)
|
|
|
|
|
(when (boundp var)
|
|
|
|
|
(cons var (symbol-value var))))
|
|
|
|
|
org-element-object-variables))))
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(mapc (lambda (pair) (org-set-local (car pair) (cdr pair))) pairs)
|
|
|
|
|
(insert string)
|
|
|
|
|
(let ((secondary (org-element--parse-objects
|
|
|
|
|
(point-min) (point-max) nil restriction)))
|
|
|
|
|
(when parent
|
|
|
|
|
(mapc (lambda (obj) (org-element-put-property obj :parent parent))
|
|
|
|
|
secondary))
|
|
|
|
|
secondary))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
2012-09-30 16:13:47 -04:00
|
|
|
|
(defun org-element-map
|
|
|
|
|
(data types fun &optional info first-match no-recursion with-affiliated)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Map a function on selected elements or objects.
|
|
|
|
|
|
2013-02-16 18:49:13 -05:00
|
|
|
|
DATA is a parse tree, an element, an object, a string, or a list
|
|
|
|
|
of such constructs. TYPES is a symbol or list of symbols of
|
|
|
|
|
elements or objects types (see `org-element-all-elements' and
|
2013-01-20 03:43:58 -05:00
|
|
|
|
`org-element-all-objects' for a complete list of types). FUN is
|
|
|
|
|
the function called on the matching element or object. It has to
|
|
|
|
|
accept one argument: the element or object itself.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
When optional argument INFO is non-nil, it should be a plist
|
|
|
|
|
holding export options. In that case, parts of the parse tree
|
|
|
|
|
not exportable according to that property list will be skipped.
|
|
|
|
|
|
|
|
|
|
When optional argument FIRST-MATCH is non-nil, stop at the first
|
|
|
|
|
match for which FUN doesn't return nil, and return that value.
|
|
|
|
|
|
|
|
|
|
Optional argument NO-RECURSION is a symbol or a list of symbols
|
|
|
|
|
representing elements or objects types. `org-element-map' won't
|
|
|
|
|
enter any recursive element or object whose type belongs to that
|
|
|
|
|
list. Though, FUN can still be applied on them.
|
|
|
|
|
|
2013-01-30 08:42:24 -05:00
|
|
|
|
When optional argument WITH-AFFILIATED is non-nil, FUN will also
|
|
|
|
|
apply to matching objects within parsed affiliated keywords (see
|
|
|
|
|
`org-element-parsed-keywords').
|
|
|
|
|
|
2013-01-20 03:43:58 -05:00
|
|
|
|
Nil values returned from FUN do not appear in the results.
|
2012-09-30 16:13:47 -04:00
|
|
|
|
|
2013-01-20 03:43:58 -05:00
|
|
|
|
|
|
|
|
|
Examples:
|
2013-03-08 09:28:25 -05:00
|
|
|
|
---------
|
2013-01-20 03:43:58 -05:00
|
|
|
|
|
|
|
|
|
Assuming TREE is a variable containing an Org buffer parse tree,
|
|
|
|
|
the following example will return a flat list of all `src-block'
|
|
|
|
|
and `example-block' elements in it:
|
|
|
|
|
|
|
|
|
|
\(org-element-map tree '(example-block src-block) 'identity)
|
|
|
|
|
|
|
|
|
|
The following snippet will find the first headline with a level
|
|
|
|
|
of 1 and a \"phone\" tag, and will return its beginning position:
|
|
|
|
|
|
2013-01-30 08:42:24 -05:00
|
|
|
|
\(org-element-map tree 'headline
|
2013-01-20 03:43:58 -05:00
|
|
|
|
\(lambda (hl)
|
|
|
|
|
\(and (= (org-element-property :level hl) 1)
|
|
|
|
|
\(member \"phone\" (org-element-property :tags hl))
|
|
|
|
|
\(org-element-property :begin hl)))
|
|
|
|
|
nil t)
|
|
|
|
|
|
2013-01-30 08:42:24 -05:00
|
|
|
|
The next example will return a flat list of all `plain-list' type
|
|
|
|
|
elements in TREE that are not a sub-list themselves:
|
|
|
|
|
|
|
|
|
|
\(org-element-map tree 'plain-list 'identity nil nil 'plain-list)
|
|
|
|
|
|
|
|
|
|
Eventually, this example will return a flat list of all `bold'
|
|
|
|
|
type objects containing a `latex-snippet' type object, even
|
|
|
|
|
looking into captions:
|
2013-01-20 03:43:58 -05:00
|
|
|
|
|
2013-01-30 08:42:24 -05:00
|
|
|
|
\(org-element-map tree 'bold
|
2013-01-20 03:43:58 -05:00
|
|
|
|
\(lambda (b)
|
2013-01-30 08:42:24 -05:00
|
|
|
|
\(and (org-element-map b 'latex-snippet 'identity nil t) b))
|
|
|
|
|
nil nil nil t)"
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Ensure TYPES and NO-RECURSION are a list, even of one element.
|
|
|
|
|
(unless (listp types) (setq types (list types)))
|
|
|
|
|
(unless (listp no-recursion) (setq no-recursion (list no-recursion)))
|
|
|
|
|
;; Recursion depth is determined by --CATEGORY.
|
|
|
|
|
(let* ((--category
|
|
|
|
|
(catch 'found
|
|
|
|
|
(let ((category 'greater-elements))
|
|
|
|
|
(mapc (lambda (type)
|
|
|
|
|
(cond ((or (memq type org-element-all-objects)
|
|
|
|
|
(eq type 'plain-text))
|
|
|
|
|
;; If one object is found, the function
|
|
|
|
|
;; has to recurse into every object.
|
|
|
|
|
(throw 'found 'objects))
|
|
|
|
|
((not (memq type org-element-greater-elements))
|
|
|
|
|
;; If one regular element is found, the
|
2012-08-20 05:21:16 -04:00
|
|
|
|
;; function has to recurse, at least,
|
|
|
|
|
;; into every element it encounters.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(and (not (eq category 'elements))
|
|
|
|
|
(setq category 'elements)))))
|
|
|
|
|
types)
|
|
|
|
|
category)))
|
2012-09-30 16:13:47 -04:00
|
|
|
|
;; Compute properties for affiliated keywords if necessary.
|
|
|
|
|
(--affiliated-alist
|
|
|
|
|
(and with-affiliated
|
|
|
|
|
(mapcar (lambda (kwd)
|
|
|
|
|
(cons kwd (intern (concat ":" (downcase kwd)))))
|
|
|
|
|
org-element-affiliated-keywords)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
--acc
|
|
|
|
|
--walk-tree
|
|
|
|
|
(--walk-tree
|
|
|
|
|
(function
|
|
|
|
|
(lambda (--data)
|
|
|
|
|
;; Recursively walk DATA. INFO, if non-nil, is a plist
|
|
|
|
|
;; holding contextual information.
|
|
|
|
|
(let ((--type (org-element-type --data)))
|
|
|
|
|
(cond
|
|
|
|
|
((not --data))
|
|
|
|
|
;; Ignored element in an export context.
|
|
|
|
|
((and info (memq --data (plist-get info :ignore-list))))
|
2013-02-16 18:49:13 -05:00
|
|
|
|
;; List of elements or objects.
|
|
|
|
|
((not --type) (mapc --walk-tree --data))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Unconditionally enter parse trees.
|
|
|
|
|
((eq --type 'org-data)
|
|
|
|
|
(mapc --walk-tree (org-element-contents --data)))
|
|
|
|
|
(t
|
|
|
|
|
;; Check if TYPE is matching among TYPES. If so,
|
|
|
|
|
;; apply FUN to --DATA and accumulate return value
|
|
|
|
|
;; into --ACC (or exit if FIRST-MATCH is non-nil).
|
|
|
|
|
(when (memq --type types)
|
|
|
|
|
(let ((result (funcall fun --data)))
|
|
|
|
|
(cond ((not result))
|
|
|
|
|
(first-match (throw '--map-first-match result))
|
|
|
|
|
(t (push result --acc)))))
|
|
|
|
|
;; If --DATA has a secondary string that can contain
|
|
|
|
|
;; objects with their type among TYPES, look into it.
|
2012-09-30 16:13:47 -04:00
|
|
|
|
(when (and (eq --category 'objects) (not (stringp --data)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(let ((sec-prop
|
|
|
|
|
(assq --type org-element-secondary-value-alist)))
|
|
|
|
|
(when sec-prop
|
|
|
|
|
(funcall --walk-tree
|
|
|
|
|
(org-element-property (cdr sec-prop) --data)))))
|
2012-09-30 16:13:47 -04:00
|
|
|
|
;; If --DATA has any affiliated keywords and
|
|
|
|
|
;; WITH-AFFILIATED is non-nil, look for objects in
|
|
|
|
|
;; them.
|
|
|
|
|
(when (and with-affiliated
|
|
|
|
|
(eq --category 'objects)
|
|
|
|
|
(memq --type org-element-all-elements))
|
|
|
|
|
(mapc (lambda (kwd-pair)
|
|
|
|
|
(let ((kwd (car kwd-pair))
|
|
|
|
|
(value (org-element-property
|
|
|
|
|
(cdr kwd-pair) --data)))
|
|
|
|
|
;; Pay attention to the type of value.
|
|
|
|
|
;; Preserve order for multiple keywords.
|
|
|
|
|
(cond
|
|
|
|
|
((not value))
|
|
|
|
|
((and (member kwd org-element-multiple-keywords)
|
|
|
|
|
(member kwd org-element-dual-keywords))
|
|
|
|
|
(mapc (lambda (line)
|
|
|
|
|
(funcall --walk-tree (cdr line))
|
|
|
|
|
(funcall --walk-tree (car line)))
|
|
|
|
|
(reverse value)))
|
|
|
|
|
((member kwd org-element-multiple-keywords)
|
|
|
|
|
(mapc (lambda (line) (funcall --walk-tree line))
|
|
|
|
|
(reverse value)))
|
|
|
|
|
((member kwd org-element-dual-keywords)
|
|
|
|
|
(funcall --walk-tree (cdr value))
|
|
|
|
|
(funcall --walk-tree (car value)))
|
|
|
|
|
(t (funcall --walk-tree value)))))
|
|
|
|
|
--affiliated-alist))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Determine if a recursion into --DATA is possible.
|
|
|
|
|
(cond
|
|
|
|
|
;; --TYPE is explicitly removed from recursion.
|
|
|
|
|
((memq --type no-recursion))
|
|
|
|
|
;; --DATA has no contents.
|
|
|
|
|
((not (org-element-contents --data)))
|
|
|
|
|
;; Looking for greater elements but --DATA is simply
|
|
|
|
|
;; an element or an object.
|
|
|
|
|
((and (eq --category 'greater-elements)
|
|
|
|
|
(not (memq --type org-element-greater-elements))))
|
|
|
|
|
;; Looking for elements but --DATA is an object.
|
|
|
|
|
((and (eq --category 'elements)
|
|
|
|
|
(memq --type org-element-all-objects)))
|
|
|
|
|
;; In any other case, map contents.
|
|
|
|
|
(t (mapc --walk-tree (org-element-contents --data)))))))))))
|
|
|
|
|
(catch '--map-first-match
|
|
|
|
|
(funcall --walk-tree data)
|
|
|
|
|
;; Return value in a proper order.
|
|
|
|
|
(nreverse --acc))))
|
2013-01-30 08:42:24 -05:00
|
|
|
|
(put 'org-element-map 'lisp-indent-function 2)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
;; The following functions are internal parts of the parser.
|
|
|
|
|
;;
|
|
|
|
|
;; The first one, `org-element--parse-elements' acts at the element's
|
|
|
|
|
;; level.
|
|
|
|
|
;;
|
|
|
|
|
;; The second one, `org-element--parse-objects' applies on all objects
|
|
|
|
|
;; of a paragraph or a secondary string. It uses
|
|
|
|
|
;; `org-element--get-next-object-candidates' to optimize the search of
|
|
|
|
|
;; the next object in the buffer.
|
|
|
|
|
;;
|
|
|
|
|
;; More precisely, that function looks for every allowed object type
|
|
|
|
|
;; first. Then, it discards failed searches, keeps further matches,
|
|
|
|
|
;; and searches again types matched behind point, for subsequent
|
|
|
|
|
;; calls. Thus, searching for a given type fails only once, and every
|
|
|
|
|
;; object is searched only once at top level (but sometimes more for
|
|
|
|
|
;; nested types).
|
|
|
|
|
|
|
|
|
|
(defun org-element--parse-elements
|
|
|
|
|
(beg end special structure granularity visible-only acc)
|
|
|
|
|
"Parse elements between BEG and END positions.
|
|
|
|
|
|
|
|
|
|
SPECIAL prioritize some elements over the others. It can be set
|
|
|
|
|
to `first-section', `quote-section', `section' `item' or
|
|
|
|
|
`table-row'.
|
|
|
|
|
|
|
|
|
|
When value is `item', STRUCTURE will be used as the current list
|
|
|
|
|
structure.
|
|
|
|
|
|
|
|
|
|
GRANULARITY determines the depth of the recursion. See
|
|
|
|
|
`org-element-parse-buffer' for more information.
|
|
|
|
|
|
|
|
|
|
When VISIBLE-ONLY is non-nil, don't parse contents of hidden
|
|
|
|
|
elements.
|
|
|
|
|
|
|
|
|
|
Elements are accumulated into ACC."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char beg)
|
2013-05-08 03:56:26 -04:00
|
|
|
|
;; Visible only: skip invisible parts at the beginning of the
|
|
|
|
|
;; element.
|
|
|
|
|
(when (and visible-only (org-invisible-p2))
|
|
|
|
|
(goto-char (min (1+ (org-find-visible)) end)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; When parsing only headlines, skip any text before first one.
|
|
|
|
|
(when (and (eq granularity 'headline) (not (org-at-heading-p)))
|
|
|
|
|
(org-with-limited-levels (outline-next-heading)))
|
|
|
|
|
;; Main loop start.
|
|
|
|
|
(while (< (point) end)
|
|
|
|
|
;; Find current element's type and parse it accordingly to
|
|
|
|
|
;; its category.
|
|
|
|
|
(let* ((element (org-element--current-element
|
|
|
|
|
end granularity special structure))
|
|
|
|
|
(type (org-element-type element))
|
|
|
|
|
(cbeg (org-element-property :contents-begin element)))
|
|
|
|
|
(goto-char (org-element-property :end element))
|
2013-05-08 03:56:26 -04:00
|
|
|
|
;; Visible only: skip invisible parts between siblings.
|
|
|
|
|
(when (and visible-only (org-invisible-p2))
|
|
|
|
|
(goto-char (min (1+ (org-find-visible)) end)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Fill ELEMENT contents by side-effect.
|
|
|
|
|
(cond
|
2013-05-08 03:56:26 -04:00
|
|
|
|
;; If element has no contents, don't modify it.
|
|
|
|
|
((not cbeg))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Greater element: parse it between `contents-begin' and
|
|
|
|
|
;; `contents-end'. Make sure GRANULARITY allows the
|
2013-02-23 07:47:44 -05:00
|
|
|
|
;; recursion, or ELEMENT is a headline, in which case going
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; inside is mandatory, in order to get sub-level headings.
|
|
|
|
|
((and (memq type org-element-greater-elements)
|
|
|
|
|
(or (memq granularity '(element object nil))
|
|
|
|
|
(and (eq granularity 'greater-element)
|
|
|
|
|
(eq type 'section))
|
|
|
|
|
(eq type 'headline)))
|
|
|
|
|
(org-element--parse-elements
|
|
|
|
|
cbeg (org-element-property :contents-end element)
|
|
|
|
|
;; Possibly switch to a special mode.
|
|
|
|
|
(case type
|
|
|
|
|
(headline
|
|
|
|
|
(if (org-element-property :quotedp element) 'quote-section
|
|
|
|
|
'section))
|
|
|
|
|
(plain-list 'item)
|
2012-09-23 09:52:02 -04:00
|
|
|
|
(property-drawer 'node-property)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(table 'table-row))
|
2012-12-15 18:37:49 -05:00
|
|
|
|
(and (memq type '(item plain-list))
|
|
|
|
|
(org-element-property :structure element))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
granularity visible-only element))
|
|
|
|
|
;; ELEMENT has contents. Parse objects inside, if
|
|
|
|
|
;; GRANULARITY allows it.
|
|
|
|
|
((memq granularity '(object nil))
|
|
|
|
|
(org-element--parse-objects
|
|
|
|
|
cbeg (org-element-property :contents-end element) element
|
|
|
|
|
(org-element-restriction type))))
|
2012-08-18 04:13:35 -04:00
|
|
|
|
(org-element-adopt-elements acc element)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; Return result.
|
|
|
|
|
acc))
|
|
|
|
|
|
|
|
|
|
(defun org-element--parse-objects (beg end acc restriction)
|
|
|
|
|
"Parse objects between BEG and END and return recursive structure.
|
|
|
|
|
|
|
|
|
|
Objects are accumulated in ACC.
|
|
|
|
|
|
2013-02-25 15:28:18 -05:00
|
|
|
|
RESTRICTION is a list of object successors which are allowed in
|
|
|
|
|
the current object."
|
|
|
|
|
(let ((candidates 'initial))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(save-excursion
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region beg end)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (and (not (eobp))
|
|
|
|
|
(setq candidates
|
|
|
|
|
(org-element--get-next-object-candidates
|
|
|
|
|
restriction candidates)))
|
|
|
|
|
(let ((next-object
|
|
|
|
|
(let ((pos (apply 'min (mapcar 'cdr candidates))))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(funcall (intern (format "org-element-%s-parser"
|
|
|
|
|
(car (rassq pos candidates)))))))))
|
|
|
|
|
;; 1. Text before any object. Untabify it.
|
|
|
|
|
(let ((obj-beg (org-element-property :begin next-object)))
|
|
|
|
|
(unless (= (point) obj-beg)
|
|
|
|
|
(setq acc
|
|
|
|
|
(org-element-adopt-elements
|
|
|
|
|
acc
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\t" (make-string tab-width ? )
|
|
|
|
|
(buffer-substring-no-properties (point) obj-beg))))))
|
|
|
|
|
;; 2. Object...
|
|
|
|
|
(let ((obj-end (org-element-property :end next-object))
|
|
|
|
|
(cont-beg (org-element-property :contents-begin next-object)))
|
|
|
|
|
;; Fill contents of NEXT-OBJECT by side-effect, if it has
|
|
|
|
|
;; a recursive type.
|
|
|
|
|
(when (and cont-beg
|
|
|
|
|
(memq (car next-object) org-element-recursive-objects))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(org-element--parse-objects
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
cont-beg (org-element-property :contents-end next-object)
|
|
|
|
|
next-object (org-element-restriction next-object)))
|
|
|
|
|
(setq acc (org-element-adopt-elements acc next-object))
|
|
|
|
|
(goto-char obj-end))))
|
|
|
|
|
;; 3. Text after last object. Untabify it.
|
|
|
|
|
(unless (eobp)
|
|
|
|
|
(setq acc
|
|
|
|
|
(org-element-adopt-elements
|
|
|
|
|
acc
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\t" (make-string tab-width ? )
|
|
|
|
|
(buffer-substring-no-properties (point) end)))))
|
|
|
|
|
;; Result.
|
|
|
|
|
acc))))
|
|
|
|
|
|
|
|
|
|
(defun org-element--get-next-object-candidates (restriction objects)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Return an alist of candidates for the next object.
|
|
|
|
|
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
RESTRICTION is a list of object types, as symbols. Only
|
|
|
|
|
candidates with such types are looked after.
|
2013-02-25 15:28:18 -05:00
|
|
|
|
|
|
|
|
|
OBJECTS is the previous candidates alist. If it is set to
|
|
|
|
|
`initial', no search has been done before, and all symbols in
|
|
|
|
|
RESTRICTION should be looked after.
|
|
|
|
|
|
|
|
|
|
Return value is an alist whose CAR is the object type and CDR its
|
|
|
|
|
beginning position."
|
|
|
|
|
(delq
|
|
|
|
|
nil
|
|
|
|
|
(if (eq objects 'initial)
|
|
|
|
|
;; When searching for the first time, look for every successor
|
|
|
|
|
;; allowed in RESTRICTION.
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (res)
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(funcall (intern (format "org-element-%s-successor" res))))
|
2013-02-25 15:28:18 -05:00
|
|
|
|
restriction)
|
|
|
|
|
;; Focus on objects returned during last search. Keep those
|
|
|
|
|
;; still after point. Search again objects before it.
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (obj)
|
|
|
|
|
(if (>= (cdr obj) (point)) obj
|
|
|
|
|
(let* ((type (car obj))
|
|
|
|
|
(succ (or (cdr (assq type org-element-object-successor-alist))
|
|
|
|
|
type)))
|
|
|
|
|
(and succ
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(funcall (intern (format "org-element-%s-successor" succ)))))))
|
2013-02-25 15:28:18 -05:00
|
|
|
|
objects))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Towards A Bijective Process
|
|
|
|
|
;;
|
|
|
|
|
;; The parse tree obtained with `org-element-parse-buffer' is really
|
|
|
|
|
;; a snapshot of the corresponding Org buffer. Therefore, it can be
|
|
|
|
|
;; interpreted and expanded into a string with canonical Org syntax.
|
|
|
|
|
;; Hence `org-element-interpret-data'.
|
|
|
|
|
;;
|
|
|
|
|
;; The function relies internally on
|
|
|
|
|
;; `org-element--interpret-affiliated-keywords'.
|
|
|
|
|
|
2012-08-20 04:16:21 -04:00
|
|
|
|
;;;###autoload
|
2013-11-11 07:16:43 -05:00
|
|
|
|
(defun org-element-interpret-data (data &optional pseudo-objects)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Interpret DATA as Org syntax.
|
|
|
|
|
|
|
|
|
|
DATA is a parse tree, an element, an object or a secondary string
|
|
|
|
|
to interpret.
|
|
|
|
|
|
2013-11-11 07:16:43 -05:00
|
|
|
|
Optional argument PSEUDO-OBJECTS is a list of symbols defining
|
|
|
|
|
new types that should be treated as objects. An unknown type not
|
|
|
|
|
belonging to this list is seen as a pseudo-element instead. Both
|
|
|
|
|
pseudo-objects and pseudo-elements are transparent entities, i.e.
|
|
|
|
|
only their contents are interpreted.
|
|
|
|
|
|
|
|
|
|
Return Org syntax as a string."
|
|
|
|
|
(org-element--interpret-data-1 data nil pseudo-objects))
|
|
|
|
|
|
|
|
|
|
(defun org-element--interpret-data-1 (data parent pseudo-objects)
|
|
|
|
|
"Interpret DATA as Org syntax.
|
|
|
|
|
|
|
|
|
|
DATA is a parse tree, an element, an object or a secondary string
|
|
|
|
|
to interpret. PARENT is used for recursive calls. It contains
|
|
|
|
|
the element or object containing data, or nil. PSEUDO-OBJECTS
|
|
|
|
|
are list of symbols defining new element or object types.
|
|
|
|
|
Unknown types that don't belong to this list are treated as
|
|
|
|
|
pseudo-elements instead.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return Org syntax as a string."
|
|
|
|
|
(let* ((type (org-element-type data))
|
2013-11-11 07:16:43 -05:00
|
|
|
|
;; Find interpreter for current object or element. If it
|
|
|
|
|
;; doesn't exist (e.g. this is a pseudo object or element),
|
|
|
|
|
;; return contents, if any.
|
|
|
|
|
(interpret
|
|
|
|
|
(let ((fun (intern (format "org-element-%s-interpreter" type))))
|
|
|
|
|
(if (fboundp fun) fun (lambda (data contents) contents))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(results
|
|
|
|
|
(cond
|
|
|
|
|
;; Secondary string.
|
|
|
|
|
((not type)
|
|
|
|
|
(mapconcat
|
2013-11-11 07:16:43 -05:00
|
|
|
|
(lambda (obj)
|
|
|
|
|
(org-element--interpret-data-1 obj parent pseudo-objects))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
data ""))
|
|
|
|
|
;; Full Org document.
|
|
|
|
|
((eq type 'org-data)
|
|
|
|
|
(mapconcat
|
2013-11-11 07:16:43 -05:00
|
|
|
|
(lambda (obj)
|
|
|
|
|
(org-element--interpret-data-1 obj parent pseudo-objects))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(org-element-contents data) ""))
|
2012-11-11 17:47:34 -05:00
|
|
|
|
;; Plain text: remove `:parent' text property from output.
|
|
|
|
|
((stringp data) (org-no-properties data))
|
2013-11-11 07:16:43 -05:00
|
|
|
|
;; Element or object without contents.
|
|
|
|
|
((not (org-element-contents data)) (funcall interpret data nil))
|
|
|
|
|
;; Element or object with contents.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(t
|
2013-11-11 07:16:43 -05:00
|
|
|
|
(funcall interpret data
|
|
|
|
|
;; Recursively interpret contents.
|
|
|
|
|
(mapconcat
|
|
|
|
|
(lambda (obj)
|
|
|
|
|
(org-element--interpret-data-1 obj data pseudo-objects))
|
|
|
|
|
(org-element-contents
|
|
|
|
|
(if (not (memq type '(paragraph verse-block)))
|
|
|
|
|
data
|
|
|
|
|
;; Fix indentation of elements containing
|
|
|
|
|
;; objects. We ignore `table-row' elements
|
|
|
|
|
;; as they are one line long anyway.
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
data
|
|
|
|
|
;; When normalizing first paragraph of an
|
|
|
|
|
;; item or a footnote-definition, ignore
|
|
|
|
|
;; first line's indentation.
|
|
|
|
|
(and (eq type 'paragraph)
|
|
|
|
|
(equal data (car (org-element-contents parent)))
|
|
|
|
|
(memq (org-element-type parent)
|
|
|
|
|
'(footnote-definition item))))))
|
|
|
|
|
""))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(if (memq type '(org-data plain-text nil)) results
|
|
|
|
|
;; Build white spaces. If no `:post-blank' property is
|
|
|
|
|
;; specified, assume its value is 0.
|
|
|
|
|
(let ((post-blank (or (org-element-property :post-blank data) 0)))
|
2013-11-11 07:16:43 -05:00
|
|
|
|
(if (or (memq type org-element-all-objects)
|
|
|
|
|
(memq type pseudo-objects))
|
|
|
|
|
(concat results (make-string post-blank ?\s))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(concat
|
|
|
|
|
(org-element--interpret-affiliated-keywords data)
|
|
|
|
|
(org-element-normalize-string results)
|
2013-11-11 07:16:43 -05:00
|
|
|
|
(make-string post-blank ?\n)))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
(defun org-element--interpret-affiliated-keywords (element)
|
|
|
|
|
"Return ELEMENT's affiliated keywords as Org syntax.
|
|
|
|
|
If there is no affiliated keyword, return the empty string."
|
|
|
|
|
(let ((keyword-to-org
|
|
|
|
|
(function
|
|
|
|
|
(lambda (key value)
|
|
|
|
|
(let (dual)
|
|
|
|
|
(when (member key org-element-dual-keywords)
|
|
|
|
|
(setq dual (cdr value) value (car value)))
|
|
|
|
|
(concat "#+" key
|
|
|
|
|
(and dual
|
|
|
|
|
(format "[%s]" (org-element-interpret-data dual)))
|
|
|
|
|
": "
|
|
|
|
|
(if (member key org-element-parsed-keywords)
|
|
|
|
|
(org-element-interpret-data value)
|
|
|
|
|
value)
|
|
|
|
|
"\n"))))))
|
|
|
|
|
(mapconcat
|
|
|
|
|
(lambda (prop)
|
|
|
|
|
(let ((value (org-element-property prop element))
|
|
|
|
|
(keyword (upcase (substring (symbol-name prop) 1))))
|
|
|
|
|
(when value
|
|
|
|
|
(if (or (member keyword org-element-multiple-keywords)
|
|
|
|
|
;; All attribute keywords can have multiple lines.
|
|
|
|
|
(string-match "^ATTR_" keyword))
|
|
|
|
|
(mapconcat (lambda (line) (funcall keyword-to-org keyword line))
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 13:10:39 -04:00
|
|
|
|
(reverse value)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"")
|
|
|
|
|
(funcall keyword-to-org keyword value)))))
|
|
|
|
|
;; List all ELEMENT's properties matching an attribute line or an
|
|
|
|
|
;; affiliated keyword, but ignore translated keywords since they
|
|
|
|
|
;; cannot belong to the property list.
|
|
|
|
|
(loop for prop in (nth 1 element) by 'cddr
|
|
|
|
|
when (let ((keyword (upcase (substring (symbol-name prop) 1))))
|
|
|
|
|
(or (string-match "^ATTR_" keyword)
|
|
|
|
|
(and
|
|
|
|
|
(member keyword org-element-affiliated-keywords)
|
|
|
|
|
(not (assoc keyword
|
|
|
|
|
org-element-keyword-translation-alist)))))
|
|
|
|
|
collect prop)
|
|
|
|
|
"")))
|
|
|
|
|
|
|
|
|
|
;; Because interpretation of the parse tree must return the same
|
|
|
|
|
;; number of blank lines between elements and the same number of white
|
|
|
|
|
;; space after objects, some special care must be given to white
|
|
|
|
|
;; spaces.
|
|
|
|
|
;;
|
|
|
|
|
;; The first function, `org-element-normalize-string', ensures any
|
|
|
|
|
;; string different from the empty string will end with a single
|
|
|
|
|
;; newline character.
|
|
|
|
|
;;
|
|
|
|
|
;; The second function, `org-element-normalize-contents', removes
|
|
|
|
|
;; global indentation from the contents of the current element.
|
|
|
|
|
|
|
|
|
|
(defun org-element-normalize-string (s)
|
|
|
|
|
"Ensure string S ends with a single newline character.
|
|
|
|
|
|
|
|
|
|
If S isn't a string return it unchanged. If S is the empty
|
|
|
|
|
string, return it. Otherwise, return a new string with a single
|
|
|
|
|
newline character at its end."
|
|
|
|
|
(cond
|
|
|
|
|
((not (stringp s)) s)
|
|
|
|
|
((string= "" s) "")
|
|
|
|
|
(t (and (string-match "\\(\n[ \t]*\\)*\\'" s)
|
|
|
|
|
(replace-match "\n" nil nil s)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-normalize-contents (element &optional ignore-first)
|
|
|
|
|
"Normalize plain text in ELEMENT's contents.
|
|
|
|
|
|
|
|
|
|
ELEMENT must only contain plain text and objects.
|
|
|
|
|
|
|
|
|
|
If optional argument IGNORE-FIRST is non-nil, ignore first line's
|
|
|
|
|
indentation to compute maximal common indentation.
|
|
|
|
|
|
|
|
|
|
Return the normalized element that is element with global
|
|
|
|
|
indentation removed from its contents. The function assumes that
|
|
|
|
|
indentation is not done with TAB characters."
|
|
|
|
|
(let* (ind-list ; for byte-compiler
|
|
|
|
|
collect-inds ; for byte-compiler
|
|
|
|
|
(collect-inds
|
|
|
|
|
(function
|
|
|
|
|
;; Return list of indentations within BLOB. This is done by
|
|
|
|
|
;; walking recursively BLOB and updating IND-LIST along the
|
|
|
|
|
;; way. FIRST-FLAG is non-nil when the first string hasn't
|
|
|
|
|
;; been seen yet. It is required as this string is the only
|
|
|
|
|
;; one whose indentation doesn't happen after a newline
|
|
|
|
|
;; character.
|
|
|
|
|
(lambda (blob first-flag)
|
|
|
|
|
(mapc
|
|
|
|
|
(lambda (object)
|
|
|
|
|
(when (and first-flag (stringp object))
|
|
|
|
|
(setq first-flag nil)
|
|
|
|
|
(string-match "\\`\\( *\\)" object)
|
|
|
|
|
(let ((len (length (match-string 1 object))))
|
|
|
|
|
;; An indentation of zero means no string will be
|
|
|
|
|
;; modified. Quit the process.
|
|
|
|
|
(if (zerop len) (throw 'zero (setq ind-list nil))
|
|
|
|
|
(push len ind-list))))
|
|
|
|
|
(cond
|
|
|
|
|
((stringp object)
|
|
|
|
|
(let ((start 0))
|
|
|
|
|
;; Avoid matching blank or empty lines.
|
|
|
|
|
(while (and (string-match "\n\\( *\\)\\(.\\)" object start)
|
|
|
|
|
(not (equal (match-string 2 object) " ")))
|
|
|
|
|
(setq start (match-end 0))
|
|
|
|
|
(push (length (match-string 1 object)) ind-list))))
|
|
|
|
|
((memq (org-element-type object) org-element-recursive-objects)
|
|
|
|
|
(funcall collect-inds object first-flag))))
|
|
|
|
|
(org-element-contents blob))))))
|
|
|
|
|
;; Collect indentation list in ELEMENT. Possibly remove first
|
|
|
|
|
;; value if IGNORE-FIRST is non-nil.
|
|
|
|
|
(catch 'zero (funcall collect-inds element (not ignore-first)))
|
|
|
|
|
(if (not ind-list) element
|
|
|
|
|
;; Build ELEMENT back, replacing each string with the same
|
|
|
|
|
;; string minus common indentation.
|
|
|
|
|
(let* (build ; For byte compiler.
|
|
|
|
|
(build
|
|
|
|
|
(function
|
|
|
|
|
(lambda (blob mci first-flag)
|
|
|
|
|
;; Return BLOB with all its strings indentation
|
|
|
|
|
;; shortened from MCI white spaces. FIRST-FLAG is
|
|
|
|
|
;; non-nil when the first string hasn't been seen
|
|
|
|
|
;; yet.
|
|
|
|
|
(setcdr (cdr blob)
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (object)
|
|
|
|
|
(when (and first-flag (stringp object))
|
|
|
|
|
(setq first-flag nil)
|
|
|
|
|
(setq object
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
(format "\\` \\{%d\\}" mci) "" object)))
|
|
|
|
|
(cond
|
|
|
|
|
((stringp object)
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
(format "\n \\{%d\\}" mci) "\n" object))
|
|
|
|
|
((memq (org-element-type object)
|
|
|
|
|
org-element-recursive-objects)
|
|
|
|
|
(funcall build object mci first-flag))
|
|
|
|
|
(t object)))
|
|
|
|
|
(org-element-contents blob)))
|
|
|
|
|
blob))))
|
|
|
|
|
(funcall build element (apply 'min ind-list) (not ignore-first))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; The Toolbox
|
|
|
|
|
;;
|
|
|
|
|
;; The first move is to implement a way to obtain the smallest element
|
|
|
|
|
;; containing point. This is the job of `org-element-at-point'. It
|
|
|
|
|
;; basically jumps back to the beginning of section containing point
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
;; and proceed, one element after the other, with
|
2012-08-08 07:55:18 -04:00
|
|
|
|
;; `org-element--current-element' until the container is found. Note:
|
|
|
|
|
;; When using `org-element-at-point', secondary values are never
|
|
|
|
|
;; parsed since the function focuses on elements, not on objects.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;
|
|
|
|
|
;; At a deeper level, `org-element-context' lists all elements and
|
|
|
|
|
;; objects containing point.
|
|
|
|
|
;;
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
;; Both functions benefit from a simple caching mechanism. It is
|
|
|
|
|
;; enabled by default, but can be disabled globally with
|
|
|
|
|
;; `org-element-use-cache'. Also `org-element-cache-reset' clears or
|
|
|
|
|
;; initializes cache for current buffer. Values are retrieved and put
|
|
|
|
|
;; into cache with respectively, `org-element-cache-get' and
|
|
|
|
|
;; `org-element-cache-put'. `org-element--cache-sync-idle-time' and
|
|
|
|
|
;; `org-element--cache-merge-changes-threshold' are used internally to
|
|
|
|
|
;; control caching behaviour.
|
|
|
|
|
;;
|
|
|
|
|
;; Eventually `org-element-nested-p' and `org-element-swap-A-B' may be
|
|
|
|
|
;; used internally by navigation and manipulation tools.
|
|
|
|
|
|
|
|
|
|
(defvar org-element-use-cache t
|
|
|
|
|
"Non nil when Org parser should cache its results.")
|
|
|
|
|
|
|
|
|
|
(defvar org-element--cache nil
|
|
|
|
|
"Hash table used as a cache for parser.
|
|
|
|
|
Key is a buffer position and value is a cons cell with the
|
|
|
|
|
pattern:
|
|
|
|
|
|
|
|
|
|
\(ELEMENT . OBJECTS-DATA)
|
|
|
|
|
|
|
|
|
|
where ELEMENT is the element starting at the key and OBJECTS-DATA
|
|
|
|
|
is an alist where each association is:
|
|
|
|
|
|
|
|
|
|
\(POS CANDIDATES . OBJECTS)
|
|
|
|
|
|
|
|
|
|
where POS is a buffer position, CANDIDATES is the last know list
|
|
|
|
|
of successors (see `org-element--get-next-object-candidates') in
|
|
|
|
|
container starting at POS and OBJECTS is a list of objects known
|
|
|
|
|
to live within that container, from farthest to closest.
|
|
|
|
|
|
|
|
|
|
In the following example, \\alpha, bold object and \\beta start
|
|
|
|
|
at, respectively, positions 1, 7 and 8,
|
|
|
|
|
|
|
|
|
|
\\alpha *\\beta*
|
|
|
|
|
|
|
|
|
|
If the paragraph is completely parsed, OBJECTS-DATA will be
|
|
|
|
|
|
|
|
|
|
\((1 nil BOLD-OBJECT ENTITY-OBJECT)
|
|
|
|
|
\(8 nil ENTITY-OBJECT))
|
|
|
|
|
|
|
|
|
|
whereas in a partially parsed paragraph, it could be
|
|
|
|
|
|
|
|
|
|
\((1 ((entity . 1) (bold . 7)) ENTITY-OBJECT))
|
|
|
|
|
|
|
|
|
|
This cache is used in both `org-element-at-point' and
|
|
|
|
|
`org-element-context'. The former uses ELEMENT only and the
|
|
|
|
|
latter OBJECTS-DATA only.")
|
|
|
|
|
|
|
|
|
|
(defvar org-element--cache-sync-idle-time 0.5
|
|
|
|
|
"Number of seconds of idle time wait before syncing buffer cache.
|
|
|
|
|
Syncing also happens when current modification is too distant
|
|
|
|
|
from the stored one (for more information, see
|
|
|
|
|
`org-element--cache-merge-changes-threshold').")
|
|
|
|
|
|
|
|
|
|
(defvar org-element--cache-merge-changes-threshold 200
|
|
|
|
|
"Number of characters triggering cache syncing.
|
|
|
|
|
|
|
|
|
|
The cache mechanism only stores one buffer modification at any
|
|
|
|
|
given time. When another change happens, it replaces it with
|
|
|
|
|
a change containing both the stored modification and the current
|
|
|
|
|
one. This is a trade-off, as merging them prevents another
|
|
|
|
|
syncing, but every element between them is then lost.
|
|
|
|
|
|
|
|
|
|
This variable determines the maximum size, in characters, we
|
|
|
|
|
accept to lose in order to avoid syncing the cache.")
|
|
|
|
|
|
|
|
|
|
(defvar org-element--cache-status nil
|
|
|
|
|
"Contains data about cache validity for current buffer.
|
|
|
|
|
|
|
|
|
|
Value is a vector of seven elements,
|
|
|
|
|
|
|
|
|
|
[ACTIVEP BEGIN END OFFSET TIMER PREVIOUS-STATE]
|
|
|
|
|
|
|
|
|
|
ACTIVEP is a boolean non-nil when changes described in the other
|
|
|
|
|
slots are valid for current buffer.
|
|
|
|
|
|
|
|
|
|
BEGIN and END are the beginning and ending position of the area
|
|
|
|
|
for which cache cannot be trusted.
|
|
|
|
|
|
|
|
|
|
OFFSET it an integer specifying the number to add to position of
|
|
|
|
|
elements after that area.
|
|
|
|
|
|
|
|
|
|
TIMER is a timer used to apply these changes to cache when Emacs
|
|
|
|
|
is idle.
|
|
|
|
|
|
|
|
|
|
PREVIOUS-STATE is a symbol referring to the state of the buffer
|
|
|
|
|
before a change happens. It is used to know if sensitive
|
|
|
|
|
areas (block boundaries, headlines) were modified. It can be set
|
|
|
|
|
to nil, `headline' or `other'.")
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun org-element-cache-reset (&optional all)
|
|
|
|
|
"Reset cache in current buffer.
|
|
|
|
|
When optional argument ALL is non-nil, reset cache in all Org
|
|
|
|
|
buffers. This function will do nothing if
|
|
|
|
|
`org-element-use-cache' is nil."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(when org-element-use-cache
|
|
|
|
|
(dolist (buffer (if all (buffer-list) (list (current-buffer))))
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(when (derived-mode-p 'org-mode)
|
|
|
|
|
(if (org-bound-and-true-p org-element--cache)
|
|
|
|
|
(clrhash org-element--cache)
|
|
|
|
|
(org-set-local 'org-element--cache
|
|
|
|
|
(make-hash-table :size 5003 :test 'eq)))
|
|
|
|
|
(org-set-local 'org-element--cache-status (make-vector 6 nil))
|
|
|
|
|
(add-hook 'before-change-functions
|
|
|
|
|
'org-element--cache-before-change nil t)
|
|
|
|
|
(add-hook 'after-change-functions
|
|
|
|
|
'org-element--cache-record-change nil t))))))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element--cache-pending-changes-p ()
|
|
|
|
|
"Non-nil when changes are not integrated in cache yet."
|
|
|
|
|
(and org-element--cache-status
|
|
|
|
|
(aref org-element--cache-status 0)))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element--cache-push-change (beg end offset)
|
|
|
|
|
"Push change to current buffer staging area.
|
|
|
|
|
BEG and END and the beginning and ending position of the
|
|
|
|
|
modification area. OFFSET is the size of the change, as an
|
|
|
|
|
integer."
|
|
|
|
|
(aset org-element--cache-status 1 beg)
|
|
|
|
|
(aset org-element--cache-status 2 end)
|
|
|
|
|
(aset org-element--cache-status 3 offset)
|
|
|
|
|
(let ((timer (aref org-element--cache-status 4)))
|
|
|
|
|
(if timer (timer-activate-when-idle timer t)
|
|
|
|
|
(aset org-element--cache-status 4
|
|
|
|
|
(run-with-idle-timer org-element--cache-sync-idle-time
|
|
|
|
|
nil
|
|
|
|
|
#'org-element--cache-sync
|
|
|
|
|
(current-buffer)))))
|
|
|
|
|
(aset org-element--cache-status 0 t))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element--cache-cancel-changes ()
|
|
|
|
|
"Remove any cache change set for current buffer."
|
|
|
|
|
(let ((timer (aref org-element--cache-status 4)))
|
|
|
|
|
(and timer (cancel-timer timer)))
|
|
|
|
|
(aset org-element--cache-status 0 nil))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element--cache-get-key (element)
|
|
|
|
|
"Return expected key for ELEMENT in cache."
|
|
|
|
|
(let ((begin (org-element-property :begin element)))
|
|
|
|
|
(if (and (memq (org-element-type element) '(item table-row))
|
|
|
|
|
(= (org-element-property :contents-begin
|
|
|
|
|
(org-element-property :parent element))
|
|
|
|
|
begin))
|
|
|
|
|
;; Special key for first item (resp. table-row) in a plain
|
|
|
|
|
;; list (resp. table).
|
|
|
|
|
(1+ begin)
|
|
|
|
|
begin)))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-cache-get (pos &optional type)
|
|
|
|
|
"Return data stored at key POS in current buffer cache.
|
|
|
|
|
When optional argument TYPE is `element', retrieve the element
|
|
|
|
|
starting at POS. When it is `objects', return the list of object
|
|
|
|
|
types along with their beginning position within that element.
|
|
|
|
|
Otherwise, return the full data. In any case, return nil if no
|
|
|
|
|
data is found, or if caching is not allowed."
|
|
|
|
|
(when (and org-element-use-cache org-element--cache)
|
|
|
|
|
;; If there are pending changes, first sync them.
|
|
|
|
|
(when (org-element--cache-pending-changes-p)
|
|
|
|
|
(org-element--cache-sync (current-buffer)))
|
|
|
|
|
(let ((data (gethash pos org-element--cache)))
|
|
|
|
|
(case type
|
|
|
|
|
(element (car data))
|
|
|
|
|
(objects (cdr data))
|
|
|
|
|
(otherwise data)))))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element-cache-put (pos data)
|
|
|
|
|
"Store data in current buffer's cache, if allowed.
|
|
|
|
|
POS is a buffer position, which will be used as a key. DATA is
|
|
|
|
|
the value to store. Nothing will be stored if
|
|
|
|
|
`org-element-use-cache' is nil. Return DATA in any case."
|
|
|
|
|
(if (not org-element-use-cache) data
|
|
|
|
|
(unless org-element--cache (org-element-cache-reset))
|
|
|
|
|
(puthash pos data org-element--cache)))
|
|
|
|
|
|
|
|
|
|
(defsubst org-element--shift-positions (element offset)
|
|
|
|
|
"Shift ELEMENT properties relative to buffer positions by OFFSET.
|
|
|
|
|
Properties containing buffer positions are `:begin', `:end',
|
|
|
|
|
`:contents-begin', `:contents-end' and `:structure'. They are
|
|
|
|
|
modified by side-effect. Return modified element."
|
|
|
|
|
(let ((properties (nth 1 element)))
|
|
|
|
|
;; Shift :structure property for the first plain list only: it is
|
|
|
|
|
;; the only one that really matters and it prevents from shifting
|
|
|
|
|
;; it more than once.
|
2013-11-15 17:07:48 -05:00
|
|
|
|
(when (and (eq (org-element-type element) 'plain-list)
|
|
|
|
|
(not (eq (org-element-type (plist-get properties :parent))
|
|
|
|
|
'item)))
|
|
|
|
|
(dolist (item (plist-get properties :structure))
|
|
|
|
|
(incf (car item) offset)
|
|
|
|
|
(incf (nth 6 item) offset)))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
(plist-put properties :begin (+ (plist-get properties :begin) offset))
|
|
|
|
|
(plist-put properties :end (+ (plist-get properties :end) offset))
|
|
|
|
|
(dolist (key '(:contents-begin :contents-end :post-affiliated))
|
|
|
|
|
(let ((value (plist-get properties key)))
|
|
|
|
|
(and value (plist-put properties key (+ offset value))))))
|
|
|
|
|
element)
|
|
|
|
|
|
|
|
|
|
(defconst org-element--cache-opening-line
|
|
|
|
|
(concat "^[ \t]*\\(?:"
|
|
|
|
|
"#\\+BEGIN[:_]" "\\|"
|
|
|
|
|
"\\\\begin{[A-Za-z0-9]+\\*?}" "\\|"
|
|
|
|
|
":\\S-+:[ \t]*$"
|
|
|
|
|
"\\)")
|
|
|
|
|
"Regexp matching an element opening line.
|
|
|
|
|
When such a line is modified, modifications may propagate after
|
|
|
|
|
modified area. In that situation, every element between that
|
|
|
|
|
area and next section is removed from cache.")
|
|
|
|
|
|
|
|
|
|
(defconst org-element--cache-closing-line
|
|
|
|
|
(concat "^[ \t]*\\(?:"
|
|
|
|
|
"#\\+END\\(?:_\\|:?[ \t]*$\\)" "\\|"
|
|
|
|
|
"\\\\end{[A-Za-z0-9]+\\*?}[ \t]*$" "\\|"
|
|
|
|
|
":END:[ \t]*$"
|
|
|
|
|
"\\)")
|
|
|
|
|
"Regexp matching an element closing line.
|
|
|
|
|
When such a line is modified, modifications may propagate before
|
|
|
|
|
modified area. In that situation, every element between that
|
|
|
|
|
area and previous section is removed from cache.")
|
|
|
|
|
|
|
|
|
|
(defun org-element--cache-before-change (beg end)
|
|
|
|
|
"Request extension of area going to be modified if needed.
|
|
|
|
|
BEG and END are the beginning and end of the range of changed
|
|
|
|
|
text. See `before-change-functions' for more information."
|
|
|
|
|
(let ((inhibit-quit t))
|
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((top (point))
|
|
|
|
|
(bottom (save-excursion (goto-char end) (line-end-position)))
|
|
|
|
|
(sensitive-re
|
|
|
|
|
;; A sensitive line is a headline or a block (or drawer,
|
|
|
|
|
;; or latex-environment) boundary. Inserting one can
|
|
|
|
|
;; modify buffer drastically both above and below that
|
|
|
|
|
;; line, possibly making cache invalid. Therefore, we
|
|
|
|
|
;; need to pay special attention to changes happening to
|
|
|
|
|
;; them.
|
|
|
|
|
(concat
|
|
|
|
|
"\\(" (org-with-limited-levels org-outline-regexp-bol) "\\)" "\\|"
|
|
|
|
|
org-element--cache-closing-line "\\|"
|
|
|
|
|
org-element--cache-opening-line)))
|
|
|
|
|
(save-match-data
|
|
|
|
|
(aset org-element--cache-status 5
|
|
|
|
|
(cond ((not (re-search-forward sensitive-re bottom t)) nil)
|
|
|
|
|
((and (match-beginning 1)
|
|
|
|
|
(progn (goto-char bottom)
|
|
|
|
|
(or (not (re-search-backward sensitive-re
|
|
|
|
|
(match-end 1) t))
|
|
|
|
|
(match-beginning 1))))
|
|
|
|
|
'headline)
|
|
|
|
|
(t 'other))))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element--cache-record-change (beg end pre)
|
|
|
|
|
"Update buffer modifications for current buffer.
|
|
|
|
|
|
|
|
|
|
BEG and END are the beginning and end of the range of changed
|
|
|
|
|
text, and the length in bytes of the pre-change text replaced by
|
|
|
|
|
that range. See `after-change-functions' for more information.
|
|
|
|
|
|
|
|
|
|
If there are already pending changes, try to merge them into
|
|
|
|
|
a bigger change record. If that's not possible, the function
|
|
|
|
|
will first synchronize cache with previous change and store the
|
|
|
|
|
new one."
|
|
|
|
|
(let ((inhibit-quit t))
|
|
|
|
|
(when (and org-element-use-cache org-element--cache)
|
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((top (point))
|
|
|
|
|
(bottom (save-excursion (goto-char end) (line-end-position))))
|
|
|
|
|
(org-with-limited-levels
|
|
|
|
|
(save-match-data
|
|
|
|
|
;; Determine if modified area needs to be extended,
|
|
|
|
|
;; according to both previous and current state. We make
|
|
|
|
|
;; a special case for headline editing: if a headline is
|
|
|
|
|
;; modified but not removed, do not extend.
|
|
|
|
|
(when (let ((previous-state (aref org-element--cache-status 5))
|
|
|
|
|
(sensitive-re
|
|
|
|
|
(concat "\\(" org-outline-regexp-bol "\\)" "\\|"
|
|
|
|
|
org-element--cache-closing-line "\\|"
|
|
|
|
|
org-element--cache-opening-line)))
|
|
|
|
|
(cond ((eq previous-state 'other))
|
|
|
|
|
((not (re-search-forward sensitive-re bottom t))
|
|
|
|
|
(eq previous-state 'headline))
|
|
|
|
|
((match-beginning 1)
|
|
|
|
|
(or (not (eq previous-state 'headline))
|
|
|
|
|
(and (progn (goto-char bottom)
|
|
|
|
|
(re-search-backward
|
|
|
|
|
sensitive-re (match-end 1) t))
|
|
|
|
|
(not (match-beginning 1)))))
|
|
|
|
|
(t)))
|
|
|
|
|
;; Effectively extend modified area.
|
|
|
|
|
(setq top (progn (goto-char top)
|
|
|
|
|
(outline-previous-heading)
|
|
|
|
|
;; Headline above is inclusive.
|
|
|
|
|
(point)))
|
|
|
|
|
(setq bottom (progn (goto-char bottom)
|
|
|
|
|
(outline-next-heading)
|
|
|
|
|
;; Headline below is exclusive.
|
|
|
|
|
(if (eobp) (point) (1- (point))))))))
|
|
|
|
|
;; Store changes.
|
|
|
|
|
(let ((offset (- end beg pre)))
|
|
|
|
|
(if (not (org-element--cache-pending-changes-p))
|
|
|
|
|
;; No pending changes. Store the new ones.
|
|
|
|
|
(org-element--cache-push-change top (- bottom offset) offset)
|
|
|
|
|
(let* ((current-start (aref org-element--cache-status 1))
|
|
|
|
|
(current-end (+ (aref org-element--cache-status 2)
|
|
|
|
|
(aref org-element--cache-status 3)))
|
|
|
|
|
(gap (max (- beg current-end) (- current-start end))))
|
|
|
|
|
(if (> gap org-element--cache-merge-changes-threshold)
|
|
|
|
|
;; If we cannot merge two change sets (i.e. they
|
|
|
|
|
;; modify distinct buffer parts) first apply current
|
|
|
|
|
;; change set and store new one. This way, there is
|
|
|
|
|
;; never more than one pending change set, which
|
|
|
|
|
;; avoids handling costly merges.
|
|
|
|
|
(progn (org-element--cache-sync (current-buffer))
|
|
|
|
|
(org-element--cache-push-change
|
|
|
|
|
top (- bottom offset) offset))
|
|
|
|
|
;; Change sets can be merged. We can expand the area
|
|
|
|
|
;; that requires an update, and postpone the sync.
|
|
|
|
|
(timer-activate-when-idle (aref org-element--cache-status 4) t)
|
|
|
|
|
(aset org-element--cache-status 0 t)
|
|
|
|
|
(aset org-element--cache-status 1 (min top current-start))
|
|
|
|
|
(aset org-element--cache-status 2
|
|
|
|
|
(- (max current-end bottom) offset))
|
|
|
|
|
(incf (aref org-element--cache-status 3) offset))))))))))
|
|
|
|
|
|
|
|
|
|
(defun org-element--cache-sync (buffer)
|
|
|
|
|
"Synchronize cache with recent modification in BUFFER.
|
|
|
|
|
Elements ending before modification area are kept in cache.
|
|
|
|
|
Elements starting after modification area have their position
|
|
|
|
|
shifted by the size of the modification. Every other element is
|
|
|
|
|
removed from the cache."
|
|
|
|
|
(when (buffer-live-p buffer)
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(when (org-element--cache-pending-changes-p)
|
|
|
|
|
(let ((inhibit-quit t)
|
|
|
|
|
(beg (aref org-element--cache-status 1))
|
|
|
|
|
(end (aref org-element--cache-status 2))
|
|
|
|
|
(offset (aref org-element--cache-status 3))
|
|
|
|
|
new-keys)
|
|
|
|
|
(maphash
|
|
|
|
|
#'(lambda (key value)
|
|
|
|
|
(cond
|
|
|
|
|
((memq key new-keys))
|
|
|
|
|
((> key end)
|
|
|
|
|
;; Shift every element starting after END by OFFSET.
|
|
|
|
|
;; We also need to shift keys, since they refer to
|
|
|
|
|
;; buffer positions.
|
|
|
|
|
;;
|
|
|
|
|
;; Upon shifting a key a conflict can occur if the
|
|
|
|
|
;; shifted key also refers to some element in the
|
|
|
|
|
;; cache. In this case, we temporarily associate
|
|
|
|
|
;; both elements, as a cons cell, to the shifted key,
|
|
|
|
|
;; following the pattern (SHIFTED . CURRENT).
|
|
|
|
|
;;
|
|
|
|
|
;; Such a conflict can only occur if shifted key hash
|
|
|
|
|
;; hasn't been processed by `maphash' yet.
|
|
|
|
|
(unless (zerop offset)
|
|
|
|
|
(let* ((conflictp (consp (caar value)))
|
|
|
|
|
(value-to-shift (if conflictp (cdr value) value)))
|
|
|
|
|
;; Shift element part.
|
|
|
|
|
(org-element--shift-positions (car value-to-shift) offset)
|
|
|
|
|
;; Shift objects part.
|
|
|
|
|
(dolist (object-data (cdr value-to-shift))
|
|
|
|
|
(incf (car object-data) offset)
|
|
|
|
|
(dolist (successor (nth 1 object-data))
|
|
|
|
|
(incf (cdr successor) offset))
|
|
|
|
|
(dolist (object (cddr object-data))
|
|
|
|
|
(org-element--shift-positions object offset)))
|
|
|
|
|
;; Shift key-value pair.
|
|
|
|
|
(let* ((new-key (+ key offset))
|
|
|
|
|
(new-value (gethash new-key org-element--cache)))
|
|
|
|
|
;; Put new value to shifted key.
|
|
|
|
|
;;
|
|
|
|
|
;; If one already exists, do not overwrite it:
|
|
|
|
|
;; store it as the car of a cons cell instead,
|
|
|
|
|
;; and handle it when `maphash' reaches
|
|
|
|
|
;; NEW-KEY.
|
|
|
|
|
;;
|
|
|
|
|
;; If there is no element stored at NEW-KEY or
|
|
|
|
|
;; if NEW-KEY is going to be removed anyway
|
|
|
|
|
;; (i.e., it is before END), just store new
|
|
|
|
|
;; value there and make sure it will not be
|
|
|
|
|
;; processed again by storing NEW-KEY in
|
|
|
|
|
;; NEW-KEYS.
|
|
|
|
|
(puthash new-key
|
|
|
|
|
(if (and new-value (> new-key end))
|
|
|
|
|
(cons value-to-shift new-value)
|
|
|
|
|
(push new-key new-keys)
|
|
|
|
|
value-to-shift)
|
|
|
|
|
org-element--cache)
|
|
|
|
|
;; If current value contains two elements, car
|
|
|
|
|
;; should be the new value, since cdr has been
|
|
|
|
|
;; shifted already.
|
|
|
|
|
(if conflictp
|
|
|
|
|
(puthash key (car value) org-element--cache)
|
|
|
|
|
(remhash key org-element--cache))))))
|
|
|
|
|
;; Remove every element between BEG and END, since
|
|
|
|
|
;; this is where changes happened.
|
|
|
|
|
((>= key beg) (remhash key org-element--cache))
|
|
|
|
|
;; Preserve any element ending before BEG. If it
|
|
|
|
|
;; overlaps the BEG-END area, remove it.
|
2013-11-04 13:28:07 -05:00
|
|
|
|
(t
|
2013-11-15 17:46:45 -05:00
|
|
|
|
(let ((element (car value)))
|
|
|
|
|
(if (>= (org-element-property :end element) beg)
|
|
|
|
|
(remhash key org-element--cache)
|
|
|
|
|
;; Special case: footnote definitions and plain
|
|
|
|
|
;; lists can end with blank lines. Modifying
|
|
|
|
|
;; those can also alter last element inside. We
|
|
|
|
|
;; must therefore remove them from cache.
|
|
|
|
|
(let ((parent (org-element-property :parent element)))
|
|
|
|
|
(when (and parent (eq (org-element-type parent) 'item))
|
|
|
|
|
(setq parent (org-element-property :parent parent)))
|
|
|
|
|
(when (and parent
|
|
|
|
|
(>= (org-element-property :end parent) beg)
|
|
|
|
|
(= (org-element-property :contents-end parent)
|
|
|
|
|
(org-element-property :end element)))
|
|
|
|
|
(remhash key org-element--cache))))))))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
org-element--cache)
|
|
|
|
|
;; Signal cache as up-to-date.
|
|
|
|
|
(org-element--cache-cancel-changes))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
2012-08-06 13:13:43 -04:00
|
|
|
|
;;;###autoload
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(defun org-element-at-point (&optional keep-trail)
|
|
|
|
|
"Determine closest element around point.
|
|
|
|
|
|
|
|
|
|
Return value is a list like (TYPE PROPS) where TYPE is the type
|
|
|
|
|
of the element and PROPS a plist of properties associated to the
|
2012-07-29 18:40:21 -04:00
|
|
|
|
element.
|
|
|
|
|
|
|
|
|
|
Possible types are defined in `org-element-all-elements'.
|
2013-01-20 03:43:58 -05:00
|
|
|
|
Properties depend on element or object type, but always include
|
|
|
|
|
`:begin', `:end', `:parent' and `:post-blank' properties.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
As a special case, if point is at the very beginning of a list or
|
|
|
|
|
sub-list, returned element will be that list instead of the first
|
|
|
|
|
item. In the same way, if point is at the beginning of the first
|
|
|
|
|
row of a table, returned element will be the table instead of the
|
2013-01-21 15:06:34 -05:00
|
|
|
|
first row.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
If optional argument KEEP-TRAIL is non-nil, the function returns
|
2013-01-23 06:58:09 -05:00
|
|
|
|
a list of elements leading to element at point. The list's CAR
|
|
|
|
|
is always the element at point. The following positions contain
|
2012-07-28 01:02:21 -04:00
|
|
|
|
element's siblings, then parents, siblings of parents, until the
|
|
|
|
|
first element of current section."
|
|
|
|
|
(org-with-wide-buffer
|
2013-02-23 07:47:44 -05:00
|
|
|
|
;; If at a headline, parse it. It is the sole element that
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;; doesn't require to know about context. Be sure to disallow
|
|
|
|
|
;; secondary string parsing, though.
|
|
|
|
|
(if (org-with-limited-levels (org-at-heading-p))
|
|
|
|
|
(progn
|
|
|
|
|
(beginning-of-line)
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
(let ((headline
|
|
|
|
|
(or (org-element-cache-get (point) 'element)
|
|
|
|
|
(car (org-element-cache-put
|
|
|
|
|
(point)
|
|
|
|
|
(list (org-element-headline-parser
|
|
|
|
|
(point-max) t)))))))
|
|
|
|
|
(if keep-trail (list headline) headline)))
|
2013-01-21 15:06:34 -05:00
|
|
|
|
;; Otherwise move at the beginning of the section containing
|
|
|
|
|
;; point.
|
2013-02-15 10:00:16 -05:00
|
|
|
|
(catch 'exit
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
(let ((origin (point)))
|
|
|
|
|
(if (not (org-with-limited-levels (outline-previous-heading)))
|
|
|
|
|
;; In empty lines at buffer's beginning, return nil.
|
|
|
|
|
(progn (goto-char (point-min))
|
|
|
|
|
(org-skip-whitespace)
|
|
|
|
|
(when (or (eobp) (> (line-beginning-position) origin))
|
|
|
|
|
(throw 'exit nil)))
|
|
|
|
|
(forward-line)
|
|
|
|
|
(org-skip-whitespace)
|
|
|
|
|
(when (or (eobp) (> (line-beginning-position) origin))
|
|
|
|
|
;; In blank lines just after the headline, point still
|
|
|
|
|
;; belongs to the headline.
|
|
|
|
|
(throw 'exit
|
|
|
|
|
(progn
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((headline
|
|
|
|
|
(or (org-element-cache-get (point) 'element)
|
|
|
|
|
(car (org-element-cache-put
|
|
|
|
|
(point)
|
|
|
|
|
(list (org-element-headline-parser
|
|
|
|
|
(point-max) t)))))))
|
|
|
|
|
(if keep-trail (list headline) headline))))))
|
2013-02-15 10:00:16 -05:00
|
|
|
|
(beginning-of-line)
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
(let ((end (save-excursion
|
|
|
|
|
(org-with-limited-levels (outline-next-heading)) (point)))
|
|
|
|
|
element type special-flag trail struct parent)
|
|
|
|
|
;; Parse successively each element, skipping those ending
|
|
|
|
|
;; before original position.
|
|
|
|
|
(while t
|
|
|
|
|
(setq element
|
|
|
|
|
(let* ((pos (if (and (memq special-flag '(item table-row))
|
|
|
|
|
(memq type '(plain-list table)))
|
|
|
|
|
;; First item (resp. row) in plain
|
|
|
|
|
;; list (resp. table) gets
|
|
|
|
|
;; a special key in cache.
|
|
|
|
|
(1+ (point))
|
|
|
|
|
(point)))
|
|
|
|
|
(cached (org-element-cache-get pos 'element)))
|
|
|
|
|
(cond
|
|
|
|
|
((not cached)
|
|
|
|
|
(let ((element (org-element--current-element
|
|
|
|
|
end 'element special-flag struct)))
|
|
|
|
|
(when (derived-mode-p 'org-mode)
|
|
|
|
|
(org-element-cache-put pos (cons element nil)))
|
|
|
|
|
element))
|
|
|
|
|
;; When changes happened in the middle of a list,
|
|
|
|
|
;; its structure ends up being invalid.
|
|
|
|
|
;; Therefore, we make sure to use a valid one.
|
|
|
|
|
((and struct (memq (car cached) '(item plain-list)))
|
|
|
|
|
(org-element-put-property cached :structure struct))
|
|
|
|
|
(t cached))))
|
|
|
|
|
(setq type (org-element-type element))
|
|
|
|
|
(org-element-put-property element :parent parent)
|
|
|
|
|
(when keep-trail (push element trail))
|
|
|
|
|
(cond
|
|
|
|
|
;; 1. Skip any element ending before point. Also skip
|
|
|
|
|
;; element ending at point when we're sure that
|
|
|
|
|
;; another element has started.
|
|
|
|
|
((let ((elem-end (org-element-property :end element)))
|
|
|
|
|
(when (or (< elem-end origin)
|
|
|
|
|
(and (= elem-end origin) (/= elem-end end)))
|
|
|
|
|
(goto-char elem-end))))
|
|
|
|
|
;; 2. An element containing point is always the element at
|
|
|
|
|
;; point.
|
|
|
|
|
((not (memq type org-element-greater-elements))
|
|
|
|
|
(throw 'exit (if keep-trail trail element)))
|
|
|
|
|
;; 3. At any other greater element type, if point is
|
|
|
|
|
;; within contents, move into it.
|
|
|
|
|
(t
|
|
|
|
|
(let ((cbeg (org-element-property :contents-begin element))
|
|
|
|
|
(cend (org-element-property :contents-end element)))
|
|
|
|
|
(if (or (not cbeg) (not cend) (> cbeg origin) (< cend origin)
|
|
|
|
|
;; Create an anchor for tables and plain
|
|
|
|
|
;; lists: when point is at the very beginning
|
|
|
|
|
;; of these elements, ignoring affiliated
|
|
|
|
|
;; keywords, target them instead of their
|
|
|
|
|
;; contents.
|
|
|
|
|
(and (= cbeg origin) (memq type '(plain-list table)))
|
|
|
|
|
;; When point is at contents end, do not move
|
|
|
|
|
;; into elements with an explicit ending, but
|
|
|
|
|
;; return that element instead.
|
|
|
|
|
(and (= cend origin)
|
|
|
|
|
(or (memq type
|
|
|
|
|
'(center-block
|
|
|
|
|
drawer dynamic-block inlinetask
|
|
|
|
|
property-drawer quote-block
|
|
|
|
|
special-block))
|
|
|
|
|
;; Corner case: if a list ends at
|
|
|
|
|
;; the end of a buffer without
|
|
|
|
|
;; a final new line, return last
|
|
|
|
|
;; element in last item instead.
|
|
|
|
|
(and (memq type '(item plain-list))
|
|
|
|
|
(progn (goto-char cend)
|
|
|
|
|
(or (bolp) (not (eobp))))))))
|
|
|
|
|
(throw 'exit (if keep-trail trail element))
|
|
|
|
|
(setq parent element)
|
|
|
|
|
(case type
|
|
|
|
|
(plain-list
|
|
|
|
|
(setq special-flag 'item
|
|
|
|
|
struct (org-element-property :structure element)))
|
|
|
|
|
(item (setq special-flag nil))
|
|
|
|
|
(property-drawer
|
|
|
|
|
(setq special-flag 'node-property struct nil))
|
|
|
|
|
(table (setq special-flag 'table-row struct nil))
|
|
|
|
|
(otherwise (setq special-flag nil struct nil)))
|
|
|
|
|
(setq end cend)
|
|
|
|
|
(goto-char cbeg))))))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
2012-08-20 04:16:21 -04:00
|
|
|
|
;;;###autoload
|
2013-01-09 09:33:29 -05:00
|
|
|
|
(defun org-element-context (&optional element)
|
2012-07-29 18:40:21 -04:00
|
|
|
|
"Return closest element or object around point.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
|
|
|
|
Return value is a list like (TYPE PROPS) where TYPE is the type
|
|
|
|
|
of the element or object and PROPS a plist of properties
|
2013-01-21 15:06:34 -05:00
|
|
|
|
associated to it.
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
2012-07-29 18:40:21 -04:00
|
|
|
|
Possible types are defined in `org-element-all-elements' and
|
|
|
|
|
`org-element-all-objects'. Properties depend on element or
|
2013-01-19 09:29:39 -05:00
|
|
|
|
object type, but always include `:begin', `:end', `:parent' and
|
2013-01-20 03:50:32 -05:00
|
|
|
|
`:post-blank'.
|
2013-01-09 09:33:29 -05:00
|
|
|
|
|
|
|
|
|
Optional argument ELEMENT, when non-nil, is the closest element
|
|
|
|
|
containing point, as returned by `org-element-at-point'.
|
|
|
|
|
Providing it allows for quicker computation."
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(catch 'objects-forbidden
|
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(let* ((origin (point))
|
|
|
|
|
(element (or element (org-element-at-point)))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
(type (org-element-type element)))
|
|
|
|
|
;; If point is inside an element containing objects or
|
|
|
|
|
;; a secondary string, narrow buffer to the container and
|
|
|
|
|
;; proceed with parsing. Otherwise, return ELEMENT.
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(cond
|
|
|
|
|
;; At a parsed affiliated keyword, check if we're inside main
|
2013-08-30 08:37:16 -04:00
|
|
|
|
;; or dual value.
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
((let ((post (org-element-property :post-affiliated element)))
|
|
|
|
|
(and post (< origin post)))
|
|
|
|
|
(beginning-of-line)
|
2013-11-03 11:47:55 -05:00
|
|
|
|
(let ((case-fold-search t)) (looking-at org-element--affiliated-re))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(cond
|
2013-11-03 11:47:55 -05:00
|
|
|
|
((not (member-ignore-case (match-string 1)
|
|
|
|
|
org-element-parsed-keywords))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(throw 'objects-forbidden element))
|
|
|
|
|
((< (match-end 0) origin)
|
|
|
|
|
(narrow-to-region (match-end 0) (line-end-position)))
|
|
|
|
|
((and (match-beginning 2)
|
|
|
|
|
(>= origin (match-beginning 2))
|
|
|
|
|
(< origin (match-end 2)))
|
|
|
|
|
(narrow-to-region (match-beginning 2) (match-end 2)))
|
|
|
|
|
(t (throw 'objects-forbidden element)))
|
|
|
|
|
;; Also change type to retrieve correct restrictions.
|
|
|
|
|
(setq type 'keyword))
|
|
|
|
|
;; At an item, objects can only be located within tag, if any.
|
|
|
|
|
((eq type 'item)
|
|
|
|
|
(let ((tag (org-element-property :tag element)))
|
|
|
|
|
(if (not tag) (throw 'objects-forbidden element)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(search-forward tag (line-end-position))
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(if (and (>= origin (point)) (< origin (match-end 0)))
|
|
|
|
|
(narrow-to-region (point) (match-end 0))
|
|
|
|
|
(throw 'objects-forbidden element)))))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
;; At an headline or inlinetask, objects are in title.
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
((memq type '(headline inlinetask))
|
|
|
|
|
(goto-char (org-element-property :begin element))
|
|
|
|
|
(skip-chars-forward "* ")
|
|
|
|
|
(if (and (>= origin (point)) (< origin (line-end-position)))
|
|
|
|
|
(narrow-to-region (point) (line-end-position))
|
|
|
|
|
(throw 'objects-forbidden element)))
|
|
|
|
|
;; At a paragraph, a table-row or a verse block, objects are
|
|
|
|
|
;; located within their contents.
|
|
|
|
|
((memq type '(paragraph table-row verse-block))
|
|
|
|
|
(let ((cbeg (org-element-property :contents-begin element))
|
|
|
|
|
(cend (org-element-property :contents-end element)))
|
|
|
|
|
;; CBEG is nil for table rules.
|
|
|
|
|
(if (and cbeg cend (>= origin cbeg) (< origin cend))
|
|
|
|
|
(narrow-to-region cbeg cend)
|
|
|
|
|
(throw 'objects-forbidden element))))
|
|
|
|
|
;; At a parsed keyword, objects are located within value.
|
|
|
|
|
((eq type 'keyword)
|
|
|
|
|
(if (not (member (org-element-property :key element)
|
|
|
|
|
org-element-document-properties))
|
|
|
|
|
(throw 'objects-forbidden element)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(search-forward ":")
|
|
|
|
|
(if (and (>= origin (point)) (< origin (line-end-position)))
|
|
|
|
|
(narrow-to-region (point) (line-end-position))
|
|
|
|
|
(throw 'objects-forbidden element))))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
;; All other locations cannot contain objects: bail out.
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 07:29:51 -04:00
|
|
|
|
(t (throw 'objects-forbidden element)))
|
|
|
|
|
(goto-char (point-min))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 06:09:17 -04:00
|
|
|
|
(let* ((restriction (org-element-restriction type))
|
|
|
|
|
(parent element)
|
|
|
|
|
(candidates 'initial)
|
|
|
|
|
(cache-key (org-element--cache-get-key element))
|
|
|
|
|
(cache (org-element-cache-get cache-key 'objects))
|
|
|
|
|
objects-data next update-cache-flag)
|
|
|
|
|
(prog1
|
|
|
|
|
(catch 'exit
|
|
|
|
|
(while t
|
|
|
|
|
;; Get list of next object candidates in CANDIDATES.
|
|
|
|
|
;; When entering for the first time PARENT, grab it
|
|
|
|
|
;; from cache, if available, or compute it. Then,
|
|
|
|
|
;; for each subsequent iteration in PARENT, always
|
|
|
|
|
;; compute it since we're beyond cache anyway.
|
|
|
|
|
(when (and (not next) org-element-use-cache)
|
|
|
|
|
(let ((data (assq (point) cache)))
|
|
|
|
|
(if data (setq candidates (nth 1 (setq objects-data data)))
|
|
|
|
|
(push (setq objects-data (list (point) 'initial))
|
|
|
|
|
cache))))
|
|
|
|
|
(when (or next (eq 'initial candidates))
|
|
|
|
|
(setq candidates
|
|
|
|
|
(org-element--get-next-object-candidates
|
|
|
|
|
restriction candidates))
|
|
|
|
|
(when org-element-use-cache
|
|
|
|
|
(setcar (cdr objects-data) candidates)
|
|
|
|
|
(or update-cache-flag (setq update-cache-flag t))))
|
|
|
|
|
;; Compare ORIGIN with next object starting position,
|
|
|
|
|
;; if any.
|
|
|
|
|
;;
|
|
|
|
|
;; If ORIGIN is lesser or if there is no object
|
|
|
|
|
;; following, look for a previous object that might
|
|
|
|
|
;; contain it in cache. If there is no cache, we
|
|
|
|
|
;; didn't miss any object so simply return PARENT.
|
|
|
|
|
;;
|
|
|
|
|
;; If ORIGIN is greater or equal, parse next
|
|
|
|
|
;; candidate for further processing.
|
|
|
|
|
(let ((closest
|
|
|
|
|
(and candidates
|
|
|
|
|
(rassq (apply #'min (mapcar #'cdr candidates))
|
|
|
|
|
candidates))))
|
|
|
|
|
(if (or (not closest) (> (cdr closest) origin))
|
|
|
|
|
(catch 'found
|
|
|
|
|
(dolist (obj (cddr objects-data) (throw 'exit parent))
|
|
|
|
|
(when (<= (org-element-property :begin obj) origin)
|
|
|
|
|
(if (<= (org-element-property :end obj) origin)
|
|
|
|
|
;; Object ends before ORIGIN and we
|
|
|
|
|
;; know next one in cache starts
|
|
|
|
|
;; after it: bail out.
|
|
|
|
|
(throw 'exit parent)
|
|
|
|
|
(throw 'found (setq next obj))))))
|
|
|
|
|
(goto-char (cdr closest))
|
|
|
|
|
(setq next
|
|
|
|
|
(funcall (intern (format "org-element-%s-parser"
|
|
|
|
|
(car closest)))))
|
|
|
|
|
(when org-element-use-cache
|
|
|
|
|
(push next (cddr objects-data))
|
|
|
|
|
(or update-cache-flag (setq update-cache-flag t)))))
|
|
|
|
|
;; Process NEXT to know if we need to skip it, return
|
|
|
|
|
;; it or move into it.
|
|
|
|
|
(let ((cbeg (org-element-property :contents-begin next))
|
|
|
|
|
(cend (org-element-property :contents-end next))
|
|
|
|
|
(obj-end (org-element-property :end next)))
|
|
|
|
|
(cond
|
|
|
|
|
;; ORIGIN is after NEXT, so skip it.
|
|
|
|
|
((<= obj-end origin) (goto-char obj-end))
|
|
|
|
|
;; ORIGIN is within a non-recursive next or
|
|
|
|
|
;; at an object boundaries: Return that object.
|
|
|
|
|
((or (not cbeg) (< origin cbeg) (>= origin cend))
|
|
|
|
|
(throw 'exit
|
|
|
|
|
(org-element-put-property next :parent parent)))
|
|
|
|
|
;; Otherwise, move into NEXT and reset flags as we
|
|
|
|
|
;; shift parent.
|
|
|
|
|
(t (goto-char cbeg)
|
|
|
|
|
(narrow-to-region (point) cend)
|
|
|
|
|
(org-element-put-property next :parent parent)
|
|
|
|
|
(setq parent next
|
|
|
|
|
restriction (org-element-restriction next)
|
|
|
|
|
next nil
|
|
|
|
|
objects-data nil
|
|
|
|
|
candidates 'initial))))))
|
|
|
|
|
;; Update cache if required.
|
|
|
|
|
(when (and update-cache-flag (derived-mode-p 'org-mode))
|
|
|
|
|
(org-element-cache-put cache-key (cons element cache)))))))))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
|
2013-02-10 08:47:57 -05:00
|
|
|
|
(defun org-element-nested-p (elem-A elem-B)
|
2012-07-28 01:02:21 -04:00
|
|
|
|
"Non-nil when elements ELEM-A and ELEM-B are nested."
|
|
|
|
|
(let ((beg-A (org-element-property :begin elem-A))
|
|
|
|
|
(beg-B (org-element-property :begin elem-B))
|
|
|
|
|
(end-A (org-element-property :end elem-A))
|
|
|
|
|
(end-B (org-element-property :end elem-B)))
|
|
|
|
|
(or (and (>= beg-A beg-B) (<= end-A end-B))
|
|
|
|
|
(and (>= beg-B beg-A) (<= end-B end-A)))))
|
|
|
|
|
|
|
|
|
|
(defun org-element-swap-A-B (elem-A elem-B)
|
|
|
|
|
"Swap elements ELEM-A and ELEM-B.
|
|
|
|
|
Assume ELEM-B is after ELEM-A in the buffer. Leave point at the
|
|
|
|
|
end of ELEM-A."
|
|
|
|
|
(goto-char (org-element-property :begin elem-A))
|
|
|
|
|
;; There are two special cases when an element doesn't start at bol:
|
|
|
|
|
;; the first paragraph in an item or in a footnote definition.
|
|
|
|
|
(let ((specialp (not (bolp))))
|
|
|
|
|
;; Only a paragraph without any affiliated keyword can be moved at
|
|
|
|
|
;; ELEM-A position in such a situation. Note that the case of
|
|
|
|
|
;; a footnote definition is impossible: it cannot contain two
|
|
|
|
|
;; paragraphs in a row because it cannot contain a blank line.
|
|
|
|
|
(if (and specialp
|
|
|
|
|
(or (not (eq (org-element-type elem-B) 'paragraph))
|
|
|
|
|
(/= (org-element-property :begin elem-B)
|
|
|
|
|
(org-element-property :contents-begin elem-B))))
|
|
|
|
|
(error "Cannot swap elements"))
|
|
|
|
|
;; In a special situation, ELEM-A will have no indentation. We'll
|
|
|
|
|
;; give it ELEM-B's (which will in, in turn, have no indentation).
|
|
|
|
|
(let* ((ind-B (when specialp
|
|
|
|
|
(goto-char (org-element-property :begin elem-B))
|
|
|
|
|
(org-get-indentation)))
|
|
|
|
|
(beg-A (org-element-property :begin elem-A))
|
|
|
|
|
(end-A (save-excursion
|
|
|
|
|
(goto-char (org-element-property :end elem-A))
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(point-at-eol)))
|
|
|
|
|
(beg-B (org-element-property :begin elem-B))
|
|
|
|
|
(end-B (save-excursion
|
|
|
|
|
(goto-char (org-element-property :end elem-B))
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(point-at-eol)))
|
|
|
|
|
;; Store overlays responsible for visibility status. We
|
|
|
|
|
;; also need to store their boundaries as they will be
|
|
|
|
|
;; removed from buffer.
|
|
|
|
|
(overlays
|
|
|
|
|
(cons
|
|
|
|
|
(mapcar (lambda (ov) (list ov (overlay-start ov) (overlay-end ov)))
|
|
|
|
|
(overlays-in beg-A end-A))
|
|
|
|
|
(mapcar (lambda (ov) (list ov (overlay-start ov) (overlay-end ov)))
|
|
|
|
|
(overlays-in beg-B end-B))))
|
|
|
|
|
;; Get contents.
|
|
|
|
|
(body-A (buffer-substring beg-A end-A))
|
|
|
|
|
(body-B (delete-and-extract-region beg-B end-B)))
|
|
|
|
|
(goto-char beg-B)
|
|
|
|
|
(when specialp
|
|
|
|
|
(setq body-B (replace-regexp-in-string "\\`[ \t]*" "" body-B))
|
|
|
|
|
(org-indent-to-column ind-B))
|
|
|
|
|
(insert body-A)
|
|
|
|
|
;; Restore ex ELEM-A overlays.
|
2012-08-14 04:18:42 -04:00
|
|
|
|
(let ((offset (- beg-B beg-A)))
|
|
|
|
|
(mapc (lambda (ov)
|
|
|
|
|
(move-overlay
|
|
|
|
|
(car ov) (+ (nth 1 ov) offset) (+ (nth 2 ov) offset)))
|
|
|
|
|
(car overlays))
|
|
|
|
|
(goto-char beg-A)
|
|
|
|
|
(delete-region beg-A end-A)
|
|
|
|
|
(insert body-B)
|
|
|
|
|
;; Restore ex ELEM-B overlays.
|
|
|
|
|
(mapc (lambda (ov)
|
|
|
|
|
(move-overlay
|
|
|
|
|
(car ov) (- (nth 1 ov) offset) (- (nth 2 ov) offset)))
|
|
|
|
|
(cdr overlays)))
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(goto-char (org-element-property :end elem-B)))))
|
|
|
|
|
|
2013-10-27 06:03:05 -04:00
|
|
|
|
(defun org-element-remove-indentation (s &optional n)
|
|
|
|
|
"Remove maximum common indentation in string S and return it.
|
|
|
|
|
When optional argument N is a positive integer, remove exactly
|
|
|
|
|
that much characters from indentation, if possible, or return
|
|
|
|
|
S as-is otherwise. Unlike to `org-remove-indentation', this
|
|
|
|
|
function doesn't call `untabify' on S."
|
|
|
|
|
(catch 'exit
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert s)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
;; Find maximum common indentation, if not specified.
|
|
|
|
|
(setq n (or n
|
|
|
|
|
(let ((min-ind (point-max)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (re-search-forward "^[ \t]*\\S-" nil t)
|
|
|
|
|
(let ((ind (1- (current-column))))
|
|
|
|
|
(if (zerop ind) (throw 'exit s)
|
|
|
|
|
(setq min-ind (min min-ind ind))))))
|
|
|
|
|
min-ind)))
|
|
|
|
|
(if (zerop n) s
|
|
|
|
|
;; Remove exactly N indentation, but give up if not possible.
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
|
|
|
|
(cond ((eolp) (delete-region (line-beginning-position) (point)))
|
|
|
|
|
((< ind n) (throw 'exit s))
|
|
|
|
|
(t (org-indent-line-to (- ind n))))
|
|
|
|
|
(forward-line)))
|
|
|
|
|
(buffer-string)))))
|
|
|
|
|
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
(provide 'org-element)
|
2012-10-02 02:50:46 -04:00
|
|
|
|
|
|
|
|
|
;; Local variables:
|
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
|
;; End:
|
|
|
|
|
|
2012-07-28 01:02:21 -04:00
|
|
|
|
;;; org-element.el ends here
|