Function: org-element-org-data-parser

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

Signature

(org-element-org-data-parser &optional _)

Documentation

Parse org-data.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defun org-element-org-data-parser (&optional _)
  "Parse org-data."
  (org-with-wide-buffer
   (let* ((begin 1)
          (contents-begin (progn
                            (goto-char 1)
                            (org-skip-whitespace)
                            (beginning-of-line)
                            (point)))
	  (end (point-max))
	  (pos-before-blank (progn (goto-char (point-max))
                                   (skip-chars-backward " \r\t\n")
                                   (line-beginning-position 2)))
          (robust-end (when (> (- pos-before-blank 2) contents-begin)
                        (- pos-before-blank 2)))
          (robust-begin (when (and robust-end
                                   (< (+ 2 contents-begin) pos-before-blank))
                          (or
                           (org-with-wide-buffer
                            (goto-char (point-min))
                            (while (and (org-at-comment-p) (bolp)) (forward-line))
                            (when (looking-at org-property-drawer-re)
                              (goto-char (match-end 0))
                              (skip-chars-backward " \t")
                              (min robust-end (point))))
                           (+ 2 contents-begin))))
          (category (cond ((null org-category)
                           (when (org-with-base-buffer nil
                                   buffer-file-name)
                             (file-name-sans-extension
                              (file-name-nondirectory
                               (org-with-base-buffer nil
                                 buffer-file-name)))))
                          ((symbolp org-category) (symbol-name org-category))
                          (t org-category)))
          (category (catch 'buffer-category
                      (unless org-element-org-data-parser--recurse
                        (org-with-point-at end
                          ;; Avoid recursive calls from
                          ;; `org-element-at-point-no-context'.
                          (let ((org-element-org-data-parser--recurse t))
                            (while (re-search-backward "^[ \t]*#\\+CATEGORY:" (point-min) t)
                              (org-element-with-disabled-cache
                                (let ((element (org-element-at-point-no-context)))
                                  (when (eq (org-element-type element) 'keyword)
                                    (throw 'buffer-category
                                           (org-element-property :value element)))))))))
                      category))
          (properties (org-element--get-global-node-properties)))
     (unless (plist-get properties :CATEGORY)
       (setq properties (plist-put properties :CATEGORY category)))
     (list 'org-data
           (nconc
            (list :begin begin
                  :contents-begin contents-begin
                  :contents-end pos-before-blank
                  :end end
                  :robust-begin robust-begin
                  :robust-end robust-end
                  :post-blank (count-lines pos-before-blank end)
                  :post-affiliated begin
                  :path (buffer-file-name)
                  :mode 'org-data)
            properties)))))