Function: org-element--collect-affiliated-keywords

org-element--collect-affiliated-keywords is a byte-compiled function defined in org-element.el.gz.

Signature

(org-element--collect-affiliated-keywords LIMIT PARSE)

Documentation

Collect affiliated keywords from point down to LIMIT.

Return a list whose CAR is the position at the first of them and CDR a plist of keywords and values and move point to the beginning of the first line after them.

As a special case, if element doesn't start at the beginning of the line (e.g., a paragraph starting an item), CAR is current position of point and CDR is nil.

When PARSE is non-nil, values from keywords belonging to org-element-parsed-keywords are parsed as secondary strings.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
;; Most elements can have affiliated keywords.  When looking for an
;; element beginning, we want to move before them, as they belong to
;; that element, and, in the meantime, collect information they give
;; into appropriate properties.  Hence the following function.

(defun org-element--collect-affiliated-keywords (limit parse)
  "Collect affiliated keywords from point down to LIMIT.

Return a list whose CAR is the position at the first of them and
CDR a plist of keywords and values and move point to the
beginning of the first line after them.

As a special case, if element doesn't start at the beginning of
the line (e.g., a paragraph starting an item), CAR is current
position of point and CDR is nil.

When PARSE is non-nil, values from keywords belonging to
`org-element-parsed-keywords' are parsed as secondary strings."
  (if (not (bolp)) (list (point))
    (let ((case-fold-search t)
	  (origin (point))
	  ;; RESTRICT is the list of objects allowed in parsed
	  ;; keywords value.  If PARSE is nil, no object is allowed.
	  (restrict (and parse (org-element-restriction 'keyword)))
	  output)
      (while (and (< (point) limit) (looking-at org-element--affiliated-re))
	(let* ((raw-kwd (upcase (match-string 1)))
	       ;; Apply translation to RAW-KWD.  From there, KWD is
	       ;; the official keyword.
	       (kwd (or (cdr (assoc raw-kwd
				    org-element-keyword-translation-alist))
			raw-kwd))
	       ;; PARSED? is non-nil when keyword should have its
	       ;; value parsed.
	       (parsed? (member kwd org-element-parsed-keywords))
	       ;; Find main value for any keyword.
               (value-begin (match-end 0))
               (value-end
                (save-excursion
		  (end-of-line)
		  (skip-chars-backward " \t")
		  (point)))
	       value
	       ;; If KWD is a dual keyword, find its secondary value.
	       ;; Maybe parse it.
	       (dual? (member kwd org-element-dual-keywords))
	       (dual-value
		(and dual?
		     (let ((sec (match-string-no-properties 2)))
		       (cond
			((and sec parsed?)
			 (org-element--parse-objects
			  (match-beginning 2) (match-end 2) nil restrict))
			(sec sec)))))
	       ;; Attribute a property name to KWD.
	       (kwd-sym (and kwd (intern (concat ":" (downcase kwd))))))
          (setq value
                (if parsed?
                    (org-element--parse-objects
                     value-begin value-end nil restrict)
                  (org-trim (buffer-substring-no-properties
                             value-begin value-end))))
	  ;; Now set final shape for VALUE.
	  (when dual?
	    (setq value (and (or value dual-value) (cons value dual-value))))
	  (when (or (member kwd org-element-multiple-keywords)
		    ;; Attributes can always appear on multiple lines.
		    (string-match-p "^ATTR_" kwd))
	    (setq value (nconc (plist-get output kwd-sym) (list value))))
	  ;; Eventually store the new value in OUTPUT.
	  (setq output (plist-put output kwd-sym value))
	  ;; Move to next keyword.
	  (forward-line)))
      ;; If affiliated keywords are orphaned: move back to first one.
      ;; They will be parsed as a paragraph.
      (when (or (looking-at-p "[ \t]*$")
                ;; Affiliated keywords are not allowed before comments.
                (looking-at-p org-comment-regexp)
                ;; Clock lines are also not allowed.
                (looking-at-p org-clock-line-re)
                ;; Inlinetasks not allowed.
                (looking-at-p "^\\*+ "))
        (goto-char origin) (setq output nil))
      ;; Return value.
      (cons origin output))))