From 5a52ee57d4a04334ce39162119fa271e6d579d9a Mon Sep 17 00:00:00 2001 From: Matthew Trzcinski Date: Wed, 22 Mar 2023 14:08:08 -0400 Subject: [PATCH] org-macs.el: Move UUID related code * org-id.el (org-id-uuid): Move to org-macs.el. * org.el (org-uuidgen-p): Move to org-macs.el. Expose regexp used to match UUID. * org-macs.el (org-uuid-regexp): Refactor `org-uuidgen-p' to expose regexp used to match UUID. --- lisp/org-id.el | 24 ------------------------ lisp/org-macs.el | 32 ++++++++++++++++++++++++++++++++ lisp/org.el | 4 ---- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lisp/org-id.el b/lisp/org-id.el index 490e4ddee..aa9610f16 100644 --- a/lisp/org-id.el +++ b/lisp/org-id.el @@ -399,30 +399,6 @@ So a typical ID could look like \"Org:4nd91V40HI\"." (t (error "Invalid `org-id-method'"))) (concat prefix unique))) -(defun org-id-uuid () - "Return string with random (version 4) UUID." - (let ((rnd (md5 (format "%s%s%s%s%s%s%s" - (random) - (org-time-convert-to-list nil) - (user-uid) - (emacs-pid) - (user-full-name) - user-mail-address - (recent-keys))))) - (format "%s-%s-4%s-%s%s-%s" - (substring rnd 0 8) - (substring rnd 8 12) - (substring rnd 13 16) - (format "%x" - (logior - #b10000000 - (logand - #b10111111 - (string-to-number - (substring rnd 16 18) 16)))) - (substring rnd 18 20) - (substring rnd 20 32)))) - (defun org-id-int-to-b36-one-digit (integer) "Convert INTEGER between 0 and 61 into a single character 0..9, A..Z, a..z." (cond diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 946e19e04..00979c2ed 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -829,6 +829,29 @@ When NEXT is non-nil, check the next line instead." When NEXT is non-nil, check the next line instead." (org--line-empty-p 2)) +(defun org-id-uuid () + "Return string with random (version 4) UUID." + (let ((rnd (md5 (format "%s%s%s%s%s%s%s" + (random) + (org-time-convert-to-list nil) + (user-uid) + (emacs-pid) + (user-full-name) + user-mail-address + (recent-keys))))) + (format "%s-%s-4%s-%s%s-%s" + (substring rnd 0 8) + (substring rnd 8 12) + (substring rnd 13 16) + (format "%x" + (logior + #b10000000 + (logand + #b10111111 + (string-to-number + (substring rnd 16 18) 16)))) + (substring rnd 18 20) + (substring rnd 20 32)))) ;;; Motion @@ -948,6 +971,15 @@ return nil." (require 'ffap) (and ffap-url-regexp (string-match-p ffap-url-regexp s))) +(defconst org-uuid-regexp + "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" + "Regular expression matching a universal unique identifier (UUID).") + +(defun org-uuidgen-p (s) + "Is S an ID created by UUIDGEN?" + (string-match org-uuid-regexp (downcase s))) + + ;;; String manipulation diff --git a/lisp/org.el b/lisp/org.el index c5ea3ebb7..23cb6012d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -18457,10 +18457,6 @@ With prefix arg UNCOMPILED, load the uncompiled versions." (setq s (replace-match "\\vert" t t s))) s) -(defun org-uuidgen-p (s) - "Is S an ID created by UUIDGEN?" - (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s))) - (defun org-in-src-block-p (&optional inside element) "Whether point is in a code source block. When INSIDE is non-nil, don't consider we are within a source