Function: org-element-paragraph-parser

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

Signature

(org-element-paragraph-parser LIMIT AFFILIATED)

Documentation

Parse a paragraph.

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 paragraph type containing :begin,
:end, :contents-begin and :contents-end, :post-blank and
:post-affiliated properties.

Assume point is at the beginning of the paragraph.

Source Code

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

(defun org-element-paragraph-parser (limit affiliated)
  "Parse a paragraph.

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 `paragraph' type containing `:begin',
`:end', `:contents-begin' and `:contents-end', `:post-blank' and
`:post-affiliated' properties.

Assume point is at the beginning of the paragraph."
  (save-excursion
    (let* ((begin (car affiliated))
	   (contents-begin (point))
	   (before-blank
	    (let ((case-fold-search t))
	      (end-of-line)
	      ;; A matching `org-element-paragraph-separate' is not
	      ;; necessarily the end of the paragraph.  In particular,
	      ;; drawers, blocks or LaTeX environments opening lines
	      ;; must be closed.  Moreover keywords with a secondary
	      ;; value must belong to "dual keywords".
	      (while (not
		      (cond
		       ((not (and (re-search-forward
				 org-element-paragraph-separate limit 'move)
				(progn (forward-line 0) t))))
		       ((looking-at-p org-element-drawer-re)
			(save-excursion
                          (forward-line 1)
			  (re-search-forward "^[ \t]*:END:[ \t]*$" limit t)))
		       ((looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
			(save-excursion
			  (re-search-forward
			   (format "^[ \t]*#\\+END_%s[ \t]*$"
				   (regexp-quote (match-string 1)))
			   limit t)))
		       ((looking-at org-element--latex-begin-environment)
			(save-excursion
			  (re-search-forward
			   (format org-element--latex-end-environment
				   (regexp-quote (match-string 1)))
			   limit t)))
		       ((looking-at "[ \t]*#\\+\\(\\S-+\\)\\[.*\\]:")
			(member-ignore-case (match-string 1)
					    org-element-dual-keywords))
		       ;; Everything else is unambiguous.
		       (t)))
		(end-of-line))
	      (if (= (point) limit) limit
		(goto-char (line-beginning-position)))))
	   (contents-end (save-excursion
			   (skip-chars-backward " \r\t\n" contents-begin)
			   (line-beginning-position 2)))
	   (end (progn (skip-chars-forward " \r\t\n" limit)
		       (if (eobp) (point) (line-beginning-position)))))
      (org-element-create
       'paragraph
       (nconc
	(list :begin begin
	      :end end
	      :contents-begin contents-begin
	      :contents-end contents-end
	      :post-blank (count-lines before-blank end)
	      :post-affiliated contents-begin)
	(cdr affiliated))))))