Function: org--insert-structure-template-unique-keys
org--insert-structure-template-unique-keys is a byte-compiled function
defined in org.el.gz.
Signature
(org--insert-structure-template-unique-keys KEYS)
Documentation
Make a list of unique, two characters long elements from KEYS.
Elements of length one have a tab appended. Elements of length two are kept as is. Longer elements are truncated to length two.
If an element cannot be made unique, an error is raised.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org--insert-structure-template-unique-keys (keys)
"Make a list of unique, two characters long elements from KEYS.
Elements of length one have a tab appended. Elements of length
two are kept as is. Longer elements are truncated to length two.
If an element cannot be made unique, an error is raised."
(let ((ordered-keys (cl-sort (copy-sequence keys) #'< :key #'length))
menu-keys)
(dolist (key ordered-keys)
(let ((potential-key
(cl-case (length key)
(1 (concat key "\t"))
(2 key)
(otherwise
(cl-find-if-not (lambda (k) (assoc k menu-keys))
(mapcar (apply-partially #'concat (substring key 0 1))
(split-string (substring key 1) "" t)))))))
(if (or (not potential-key) (assoc potential-key menu-keys))
(user-error "Could not make unique key for `%s'" key)
(push (cons potential-key key) menu-keys))))
(mapcar #'car
(cl-sort menu-keys #'<
:key (lambda (elm) (cl-position (cdr elm) keys))))))