Function: org-element-special-block-parser

org-element-special-block-parser is a byte-compiled function defined in org-element.el.gz.

Signature

(org-element-special-block-parser LIMIT AFFILIATED)

Documentation

Parse a special 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 new syntax node of special-block type containing :type,
:parameters, :begin, :end, :contents-begin, :contents-end,
:post-blank and :post-affiliated properties.

Assume point is at the beginning of the block.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
;;;; Special Block

(defun org-element-special-block-parser (limit affiliated)
  "Parse a special 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 new syntax node of `special-block' type containing `:type',
`:parameters', `:begin', `:end', `:contents-begin', `:contents-end',
`:post-blank' and `:post-affiliated' properties.

Assume point is at the beginning of the block."
  (let* ((case-fold-search t)
	 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)[ \t]*\\(.*\\)[ \t]*$")
		      (org-element--get-cached-string
                       (match-string-no-properties 1))))
	 (parameters (match-string-no-properties 2)))
    (if (not (save-excursion
	     (re-search-forward
	      (format "^[ \t]*#\\+END_%s[ \t]*$" (regexp-quote type))
	      limit t)))
	;; Incomplete block: parse it as a paragraph.
	(org-element-paragraph-parser limit affiliated)
      (let ((block-end-line (match-beginning 0)))
	(save-excursion
	  (let* ((begin (car affiliated))
		 (post-affiliated (point))
		 ;; 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)))
		 (end (progn (skip-chars-forward " \r\t\n" limit)
			     (if (eobp) (point) (line-beginning-position)))))
	    (org-element-create
             'special-block
	     (nconc
	      (list :type type
		    :parameters (and (org-string-nw-p parameters)
				     (org-trim parameters))
		    :begin begin
		    :end end
		    :contents-begin contents-begin
		    :contents-end contents-end
		    :post-blank (count-lines pos-before-blank end)
		    :post-affiliated post-affiliated)
	      (cdr affiliated)))))))))