Function: org-element-example-block-parser
org-element-example-block-parser is a byte-compiled function defined
in org-element.el.gz.
Signature
(org-element-example-block-parser LIMIT AFFILIATED)
Documentation
Parse an example block.
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 example-block and CDR is a plist
containing :begin, :end, :number-lines, :preserve-indent,
:retain-labels, :use-labels, :label-fmt, :switches,
:value, :post-blank and :post-affiliated keywords.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
;;;; Example Block
(defun org-element-example-block-parser (limit affiliated)
"Parse an example block.
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 `example-block' and CDR is a plist
containing `:begin', `:end', `:number-lines', `:preserve-indent',
`:retain-labels', `:use-labels', `:label-fmt', `:switches',
`:value', `:post-blank' and `:post-affiliated' keywords."
(let ((case-fold-search t))
(if (not (save-excursion
(re-search-forward "^[ \t]*#\\+END_EXAMPLE[ \t]*$" limit t)))
;; Incomplete block: parse it as a paragraph.
(org-element-paragraph-parser limit affiliated)
(let ((contents-end (match-beginning 0)))
(save-excursion
(let* ((switches
(progn
(looking-at "^[ \t]*#\\+BEGIN_EXAMPLE\\(?: +\\(.*\\)\\)?")
(match-string-no-properties 1)))
;; Switches analysis.
(number-lines
(and switches
(string-match "\\([-+]\\)n\\(?: *\\([0-9]+\\)\\)?\\>"
switches)
(cons
(if (equal (match-string 1 switches) "-")
'new
'continued)
(if (not (match-end 2)) 0
;; Subtract 1 to give number of lines before
;; first line.
(1- (string-to-number (match-string 2 switches)))))))
(preserve-indent
(and switches (string-match "-i\\>" switches)))
;; 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)
(and retain-labels
(not (string-match "-k\\>" switches)))))
(label-fmt
(and switches
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
(match-string 1 switches)))
;; Standard block parsing.
(begin (car affiliated))
(post-affiliated (point))
(contents-begin (line-beginning-position 2))
(value (org-unescape-code-in-string
(buffer-substring-no-properties
contents-begin contents-end)))
(pos-before-blank (progn (goto-char contents-end)
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
(if (eobp) (point) (line-beginning-position)))))
(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
:post-blank (count-lines pos-before-blank end)
:post-affiliated post-affiliated)
(cdr affiliated)))))))))