Function: org-element-headline-parser
org-element-headline-parser is a byte-compiled function defined in
org-element.el.gz.
Signature
(org-element-headline-parser &optional _ RAW-SECONDARY-P)
Documentation
Parse a headline.
Return a list whose CAR is headline and CDR is a plist
containing :raw-value, :title, :begin, :end,
:pre-blank, :contents-begin and :contents-end, :level,
:priority, :tags, :todo-keyword, :todo-type, :scheduled,
:deadline, :closed, :archivedp, :commentedp
:footnote-section-p, :post-blank and :post-affiliated
keywords.
The plist also contains any property set in the property drawer, with its name in upper cases and colons added at the beginning (e.g., :CUSTOM_ID).
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.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defun org-element-headline-parser (&optional _ raw-secondary-p)
"Parse a headline.
Return a list whose CAR is `headline' and CDR is a plist
containing `:raw-value', `:title', `:begin', `:end',
`:pre-blank', `:contents-begin' and `:contents-end', `:level',
`:priority', `:tags', `:todo-keyword', `:todo-type', `:scheduled',
`:deadline', `:closed', `:archivedp', `:commentedp'
`:footnote-section-p', `:post-blank' and `:post-affiliated'
keywords.
The plist also contains any property set in the property drawer,
with its name in upper cases and colons added at the
beginning (e.g., `:CUSTOM_ID').
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* ((begin (point))
(true-level (prog1 (skip-chars-forward "*")
(skip-chars-forward " \t")))
(level (org-reduced-level true-level))
(todo (and org-todo-regexp
(let (case-fold-search) (looking-at (concat org-todo-regexp " ")))
(progn (goto-char (match-end 0))
(skip-chars-forward " \t")
(match-string 1))))
(todo-type
(and todo (if (member todo org-done-keywords) 'done 'todo)))
(priority (and (looking-at "\\[#.\\][ \t]*")
(progn (goto-char (match-end 0))
(aref (match-string 0) 2))))
(commentedp
(and (let ((case-fold-search nil))
(looking-at org-element-comment-string))
(goto-char (match-end 0))
(when (looking-at-p "\\(?:[ \t]\\|$\\)")
(point))))
(title-start (prog1 (point)
(unless (or todo priority commentedp)
;; Headline like "* :tag:"
(skip-chars-backward " \t"))))
(tags (when (re-search-forward
"[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
(line-end-position)
'move)
(goto-char (match-beginning 0))
(org-split-string (match-string 1) ":")))
(title-end (point))
(raw-value (org-trim
(buffer-substring-no-properties title-start title-end)))
(archivedp (member org-element-archive-tag tags))
(footnote-section-p (and org-footnote-section
(string= org-footnote-section raw-value)))
(standard-props (org-element--get-node-properties))
(time-props (org-element--get-time-properties))
(end
(save-excursion
(let ((re (rx-to-string
`(seq line-start (** 1 ,true-level "*") " "))))
(if (re-search-forward re nil t)
(line-beginning-position)
(point-max)))))
(contents-begin (save-excursion
(forward-line)
(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")
(line-beginning-position 2))))
(robust-begin (and contents-begin
(progn (goto-char contents-begin)
(when (looking-at-p org-element-planning-line-re)
(forward-line))
(when (looking-at org-property-drawer-re)
(goto-char (match-end 0)))
;; If there is :pre-blank, we
;; need to be careful about
;; robust beginning.
(max (if (< (+ 2 contents-begin) contents-end)
(+ 2 contents-begin)
0)
(point)))))
(robust-end (and robust-begin
(when (> (- contents-end 2) robust-begin)
(- contents-end 2)))))
(unless robust-end (setq robust-begin nil))
(let ((headline
(list 'headline
(nconc
(list :raw-value raw-value
:begin begin
:end end
:pre-blank
(if (not contents-begin) 0
(1- (count-lines begin contents-begin)))
:contents-begin contents-begin
:contents-end contents-end
:robust-begin robust-begin
:robust-end robust-end
:level level
:priority priority
:tags tags
:todo-keyword todo
:todo-type todo-type
:post-blank
(if contents-end
(count-lines contents-end end)
(1- (count-lines begin end)))
:footnote-section-p footnote-section-p
:archivedp archivedp
:commentedp commentedp
:post-affiliated begin)
time-props
standard-props))))
(org-element-put-property
headline :title
(if raw-secondary-p raw-value
(org-element--parse-objects
(progn (goto-char title-start)
(skip-chars-forward " \t")
(point))
(progn (goto-char title-end)
(skip-chars-backward " \t")
(point))
nil
(org-element-restriction 'headline)
headline)))))))