Function: org-element--cache-key

org-element--cache-key is a byte-compiled function defined in org-element.el.gz.

Signature

(org-element--cache-key ELEMENT)

Documentation

Return a unique key for ELEMENT in cache tree.

Keys are used to keep a total order among elements in the cache. Comparison is done with org-element--cache-key-less-p.

When no synchronization is taking place, a key is simply the beginning position of the element, or that position plus one in the case of an first item (respectively row) in a list (respectively a table). They key of a section is its beginning position minus one.

During a synchronization, the key is the one the element had when the cache was synchronized for the last time. Elements added to cache during the synchronization get a new key generated with org-element--cache-generate-key.

Such keys are stored inside the element property
:org-element--cache-sync-key. The property is a cons containing
current org-element--cache-sync-keys-value and the element key.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defsubst org-element--cache-key (element)
  "Return a unique key for ELEMENT in cache tree.

Keys are used to keep a total order among elements in the cache.
Comparison is done with `org-element--cache-key-less-p'.

When no synchronization is taking place, a key is simply the
beginning position of the element, or that position plus one in
the case of an first item (respectively row) in
a list (respectively a table).  They key of a section is its beginning
position minus one.

During a synchronization, the key is the one the element had when
the cache was synchronized for the last time.  Elements added to
cache during the synchronization get a new key generated with
`org-element--cache-generate-key'.

Such keys are stored inside the element property
`:org-element--cache-sync-key'.  The property is a cons containing
current `org-element--cache-sync-keys-value' and the element key."
  (or (when (eq org-element--cache-sync-keys-value (car (org-element-property :org-element--cache-sync-key element)))
        (cdr (org-element-property :org-element--cache-sync-key element)))
      (let* ((begin (org-element-property :begin element))
	     ;; Increase beginning position of items (respectively
	     ;; table rows) by one, so the first item can get
	     ;; a different key from its parent list (respectively
	     ;; table).
	     (key (if (memq (org-element-type element) '(item table-row))
		      (1+ begin)
                    ;; Decrease beginning position of sections by one,
                    ;; so that the first element of the section get
                    ;; different key from the parent section.
                    (if (eq (org-element-type element) 'section)
                        (1- begin)
                      (if (eq (org-element-type element) 'org-data)
                          (- begin 2)
                        begin)))))
        (when org-element--cache-sync-requests
	  (org-element-put-property
           element
           :org-element--cache-sync-key
           (cons org-element--cache-sync-keys-value key)))
        key)))