Function: icalendar-make-uid

icalendar-make-uid is a byte-compiled function defined in icalendar.el.gz.

Signature

(icalendar-make-uid &optional CONTENTS _)

Documentation

Construct a unique ID from icalendar-uid-format.

CONTENTS can be any object which represents the contents of the iCalendar component for which the UID is generated. If CONTENTS is a string with the text property 'uid, that property's value will be used as the returned UID.

Otherwise, CONTENTS will be used to create the hash substituted for
'%h' in icalendar-uid-format. If CONTENTS is not given, the hash
will be based on an internal counter, the system name, and the current time in nanoseconds.

The second optional argument is for backward compatibility and is ignored.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar.el.gz
(defun ical:make-uid (&optional contents _)
  "Construct a unique ID from `icalendar-uid-format'.

CONTENTS can be any object which represents the contents of the
iCalendar component for which the UID is generated.  If CONTENTS is a
string with the text property \\='uid, that property's value will be
used as the returned UID.

Otherwise, CONTENTS will be used to create the hash substituted for
\\='%h' in `icalendar-uid-format'.  If CONTENTS is not given, the hash
will be based on an internal counter, the system name, and the current
time in nanoseconds.

The second optional argument is for backward compatibility and is ignored."
  (cl-incf icalendar--uid-count)
  (let* ((uid icalendar-uid-format)
         (timestamp (format-time-string "%s%N"))
         (tohash (or contents
                     (format "%d%s%s" ical:-uid-count (system-name) timestamp))))
    (if (and (stringp contents) (get-text-property 0 'uid contents))
        ;; "Allow other apps (such as org-mode) to create its own uid"
        ;; FIXME: is this necessary?  If caller already has a UID, why
        ;; call this function at all?
	(setq uid (get-text-property 0 'uid contents))
      (progn
        (setq uid (replace-regexp-in-string
                   "%c" (format "%d" icalendar--uid-count) uid t t))
        (setq uid (replace-regexp-in-string
                   "%t" timestamp uid t t))
        (setq uid (replace-regexp-in-string
                   "%h" (format "%d" (abs (sxhash tohash))) uid t t))
        (setq uid (replace-regexp-in-string
                   "%u" (or user-login-name "UNKNOWN_USER") uid t t))
        ;; `%s' no longer used, but allowed for backward compatibility:
        (setq uid (replace-regexp-in-string "%s" "" uid t t))))
    uid))