Function: org-datetree-comparefun-from-regex

org-datetree-comparefun-from-regex is a byte-compiled function defined in org-datetree.el.gz.

Signature

(org-datetree-comparefun-from-regex SIBLING-REGEX)

Documentation

Construct comparison function based on regular expression.

The generated comparison function can be used with org-datetree-find-create-hierarchy. SIBLING-REGEX should be a regex that matches the headline and its siblings, with 1 match group. Headlines are compared by the lexicographic ordering of match group 1. The generated function returns -1 if the first argument is earlier, 1 if later, 0 if equal, or nil if either argument doesn't match.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-datetree.el.gz
(defun org-datetree-comparefun-from-regex (sibling-regex)
  "Construct comparison function based on regular expression.
The generated comparison function can be used with
`org-datetree-find-create-hierarchy'.  SIBLING-REGEX should be a
regex that matches the headline and its siblings, with 1 match
group.  Headlines are compared by the lexicographic ordering of
match group 1.  The generated function returns -1 if the first
argument is earlier, 1 if later, 0 if equal, or nil if either
argument doesn't match."
  (lambda (sibling-title new-title)
    (let ((target-match (and (string-match sibling-regex new-title)
                             (match-string 1 new-title)))
          (sibling-match (and (string-match sibling-regex sibling-title)
                              (match-string 1 sibling-title))))
      (cond
       ((not (and target-match sibling-match)) nil)
       ((string< sibling-match target-match) -1)
       ((string> sibling-match target-match) 1)
       (t 0)))))