summaryrefslogtreecommitdiff
path: root/lisp/org-element.el
diff options
context:
space:
mode:
authorS├ębastien Delafond <sdelafond@gmail.com>2014-07-13 13:35:31 +0200
committerS├ębastien Delafond <sdelafond@gmail.com>2014-07-13 13:35:31 +0200
commit52fbfeb04b10aa78f24f339a352fe1161c0b37e4 (patch)
treea3b147a3a2e4bb39c4ae36c0f442c6137ae506e2 /lisp/org-element.el
parent40ce6b75e6245659a3a14622356e32e7dd1125dd (diff)
Imported Upstream version 8.2.4
Diffstat (limited to 'lisp/org-element.el')
-rw-r--r--lisp/org-element.el172
1 files changed, 86 insertions, 86 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 807fdb4..6162383 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -143,10 +143,12 @@
"$" "\\|"
;; 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.
- "[#:]" "\\|"
+ ;; Blocks (any type), Babel calls and keywords. Note: this
+ ;; is only an indication and need some thorough check.
+ "#\\(?:[+ ]\\|$\\)" "\\|"
+ ;; Drawers (any type) and fixed-width areas. This is also
+ ;; only an indication.
+ ":" "\\|"
;; Horizontal rules.
"-\\{5,\\}[ \t]*$" "\\|"
;; LaTeX environments.
@@ -514,9 +516,9 @@ Assume point is at the beginning of the block."
(pos-before-blank (progn (goto-char block-end-line)
(forward-line)
(point)))
- (end (save-excursion (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (end (save-excursion
+ (skip-chars-forward " \r\t\n" limit)
+ (if (eobp) (point) (line-beginning-position)))))
(list 'center-block
(nconc
(list :begin begin
@@ -569,8 +571,7 @@ Assume point is at beginning of drawer."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'drawer
(nconc
(list :begin begin
@@ -629,8 +630,7 @@ Assume point is at beginning of dynamic block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'dynamic-block
(nconc
(list :begin begin
@@ -692,8 +692,7 @@ Assume point is at the beginning of the footnote definition."
(contents-end (and contents-begin ending))
(end (progn (goto-char ending)
(skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'footnote-definition
(nconc
(list :label label
@@ -868,7 +867,7 @@ CONTENTS is the contents of the element."
(commentedp (org-element-property :commentedp headline))
(quotedp (org-element-property :quotedp headline))
(pre-blank (or (org-element-property :pre-blank headline) 0))
- (heading (concat (make-string level ?*)
+ (heading (concat (make-string (org-reduced-level level) ?*)
(and todo (concat " " todo))
(and quotedp (concat " " org-quote-string))
(and commentedp (concat " " org-comment-string))
@@ -972,8 +971,7 @@ Assume point is at beginning of the inline task."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position))))
+ (if (eobp) (point) (line-beginning-position))))
(inlinetask
(list 'inlinetask
(nconc
@@ -1230,9 +1228,10 @@ CONTENTS is the contents of the element."
(throw 'exit (sort struct 'car-less-than-car))))))
;; Skip blocks (any type) and drawers contents.
(cond
- ((and (looking-at "#\\+BEGIN\\(:[ \t]*$\\|_\\S-\\)+")
+ ((and (looking-at "#\\+BEGIN\\(:\\|_\\S-+\\)")
(re-search-forward
- (format "^[ \t]*#\\+END%s[ \t]*$" (match-string 1))
+ (format "^[ \t]*#\\+END%s[ \t]*$"
+ (org-match-string-no-properties 1))
limit t)))
((and (looking-at drawers-re)
(re-search-forward "^[ \t]*:END:[ \t]*$" limit t))))
@@ -1322,8 +1321,7 @@ Assume point is at the beginning of the property drawer."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'property-drawer
(nconc
(list :begin begin
@@ -1375,8 +1373,7 @@ Assume point is at the beginning of the block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'quote-block
(nconc
(list :begin begin
@@ -1465,8 +1462,7 @@ Assume point is at the beginning of the block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'special-block
(nconc
(list :type type
@@ -1522,8 +1518,7 @@ containing `:begin', `:end', `:info', `:post-blank' and
(post-affiliated (point))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'babel-call
(nconc
(list :begin begin
@@ -1632,8 +1627,7 @@ Assume point is at comment beginning."
(point)))
(end (progn (goto-char com-end)
(skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'comment
(nconc
(list :begin begin
@@ -1679,8 +1673,7 @@ Assume point is at comment block beginning."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position))))
+ (if (eobp) (point) (line-beginning-position))))
(value (buffer-substring-no-properties
contents-begin contents-end)))
(list 'comment-block
@@ -1720,8 +1713,7 @@ containing `:begin', `:end', `:value', `:post-blank' and
(org-match-string-no-properties 1)))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'diary-sexp
(nconc
(list :value value
@@ -1831,8 +1823,7 @@ keywords."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'example-block
(nconc
(list :begin begin
@@ -1892,8 +1883,7 @@ Assume point is at export-block beginning."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position))))
+ (if (eobp) (point) (line-beginning-position))))
(value (buffer-substring-no-properties contents-begin
contents-end)))
(list 'export-block
@@ -1948,8 +1938,7 @@ Assume point is at the beginning of the fixed-width area."
(forward-line))
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'fixed-width
(nconc
(list :begin begin
@@ -1987,8 +1976,7 @@ keywords."
(post-affiliated (point))
(post-hr (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'horizontal-rule
(nconc
(list :begin begin
@@ -2025,8 +2013,7 @@ containing `:key', `:value', `:begin', `:end', `:post-blank' and
(match-end 0) (point-at-eol))))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'keyword
(nconc
(list :key key
@@ -2073,8 +2060,7 @@ Assume point is at the beginning of the latex environment."
(begin (car affiliated))
(value (buffer-substring-no-properties code-begin code-end))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'latex-environment
(nconc
(list :begin begin
@@ -2206,8 +2192,7 @@ Assume point is at the beginning of the paragraph."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'paragraph
(nconc
(list :begin begin
@@ -2391,8 +2376,7 @@ Assume point is at the beginning of the block."
(point)))
;; Get position after ending blank lines.
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'src-block
(nconc
(list :language language
@@ -2468,8 +2452,7 @@ Assume point is at the beginning of the table."
acc))
(pos-before-blank (point))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'table
(nconc
(list :begin begin
@@ -2570,8 +2553,7 @@ Assume point is at beginning of the block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (skip-chars-backward " \t")
- (if (bolp) (point) (line-end-position)))))
+ (if (eobp) (point) (line-beginning-position)))))
(list 'verse-block
(nconc
(list :begin begin
@@ -2744,16 +2726,12 @@ Return value is a cons cell whose CAR is `entity' or
`latex-fragment' and CDR is beginning position."
(save-excursion
(unless (bolp) (backward-char))
- (let ((matchers
- (remove "begin" (plist-get org-format-latex-options :matchers)))
+ (let ((matchers (cdr org-latex-regexps))
;; 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
- (concat (mapconcat (lambda (e) (nth 1 (assoc e org-latex-regexps)))
- matchers "\\|")
- "\\|" entity-re)
- nil t)
+ (concat (mapconcat #'cadr matchers "\\|") "\\|" entity-re) nil t)
(goto-char (match-beginning 0))
(if (looking-at entity-re)
;; Determine if it's a real entity or a LaTeX command.
@@ -2763,12 +2741,9 @@ Return value is a cons cell whose CAR is `entity' or
;; Determine its type to get the correct beginning position.
(cons 'latex-fragment
(catch 'return
- (mapc (lambda (e)
- (when (looking-at (nth 1 (assoc e org-latex-regexps)))
- (throw 'return
- (match-beginning
- (nth 2 (assoc e org-latex-regexps))))))
- matchers)
+ (dolist (e matchers)
+ (when (looking-at (nth 1 e))
+ (throw 'return (match-beginning (nth 2 e)))))
(point))))))))
@@ -3023,29 +2998,28 @@ CONTENTS is the contents of the object."
;;;; Latex Fragment
(defun org-element-latex-fragment-parser ()
- "Parse latex fragment at point.
+ "Parse LaTeX fragment at point.
Return a list whose CAR is `latex-fragment' and CDR a plist with
`:value', `:begin', `:end', and `:post-blank' as keywords.
-Assume point is at the beginning of the latex fragment."
+Assume point is at the beginning of the LaTeX fragment."
(save-excursion
(let* ((begin (point))
(substring-match
(catch 'exit
- (mapc (lambda (e)
- (let ((latex-regexp (nth 1 (assoc e org-latex-regexps))))
- (when (or (looking-at latex-regexp)
- (and (not (bobp))
- (save-excursion
- (backward-char)
- (looking-at latex-regexp))))
- (throw 'exit (nth 2 (assoc e org-latex-regexps))))))
- (plist-get org-format-latex-options :matchers))
+ (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)))))
;; None found: it's a macro.
(looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")
0))
- (value (match-string-no-properties substring-match))
+ (value (org-match-string-no-properties substring-match))
(post-blank (progn (goto-char (match-end substring-match))
(skip-chars-forward " \t")))
(end (point)))
@@ -3549,7 +3523,12 @@ beginning position."
"Parse time stamp at point.
Return a list whose CAR is `timestamp', and CDR a plist with
-`:type', `:begin', `:end', `:value' and `:post-blank' keywords.
+`: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.
Assume point is at the beginning of the timestamp."
(save-excursion
@@ -3579,7 +3558,7 @@ Assume point is at the beginning of the timestamp."
(t 'inactive)))
(repeater-props
(and (not diaryp)
- (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)>"
+ (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)"
raw-value)
(list
:repeater-type
@@ -3591,6 +3570,15 @@ Assume point is at the beginning of the timestamp."
:repeater-unit
(case (string-to-char (match-string 3 raw-value))
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (t 'year)))))
+ (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)))))
year-start month-start day-start hour-start minute-start year-end
month-end day-end hour-end minute-end)
;; Parse date-start.
@@ -3627,7 +3615,8 @@ Assume point is at the beginning of the timestamp."
:begin begin
:end end
:post-blank post-blank)
- repeater-props)))))
+ repeater-props
+ warning-props)))))
(defun org-element-timestamp-interpreter (timestamp contents)
"Interpret TIMESTAMP object as Org syntax.
@@ -3643,6 +3632,15 @@ CONTENTS is nil."
(and val (number-to-string val)))
(case (org-element-property :repeater-unit timestamp)
(hour "h") (day "d") (week "w") (month "m") (year "y"))))
+ (warning-string
+ (concat
+ (case (org-element-property :warning-type timestamp)
+ (first "--")
+ (all "-"))
+ (let ((val (org-element-property :warning-value timestamp)))
+ (and val (number-to-string val)))
+ (case (org-element-property :warning-unit timestamp)
+ (hour "h") (day "d") (week "w") (month "m") (year "y"))))
(build-ts-string
;; Build an Org timestamp string from TIME. ACTIVEP is
;; non-nil when time stamp is active. If WITH-TIME-P is
@@ -3661,11 +3659,12 @@ CONTENTS is nil."
(format "\\&-%02d:%02d" hour-end minute-end)
nil nil ts)))
(unless activep (setq ts (format "[%s]" (substring ts 1 -1))))
- (when (org-string-nw-p repeat-string)
- (setq ts (concat (substring ts 0 -1)
- " "
- repeat-string
- (substring ts -1))))
+ (dolist (s (list repeat-string warning-string))
+ (when (org-string-nw-p s)
+ (setq ts (concat (substring ts 0 -1)
+ " "
+ s
+ (substring ts -1)))))
;; Return value.
ts)))
(type (org-element-property :type timestamp)))
@@ -4838,9 +4837,10 @@ Providing it allows for quicker computation."
((let ((post (org-element-property :post-affiliated element)))
(and post (< origin post)))
(beginning-of-line)
- (looking-at org-element--affiliated-re)
+ (let ((case-fold-search t)) (looking-at org-element--affiliated-re))
(cond
- ((not (member (upcase (match-string 1)) org-element-parsed-keywords))
+ ((not (member-ignore-case (match-string 1)
+ org-element-parsed-keywords))
(throw 'objects-forbidden element))
((< (match-end 0) origin)
(narrow-to-region (match-end 0) (line-end-position)))