瀏覽代碼

org-id: Additional id method; ISO8601 timestamp

* New choice in org-id-method

Timestamps can be chosen as org-id-method.  This id-method has the
benefit of being human-readable and has synergies with org-attach if
one likes to organize attachment directories by timestamp instead of
by random names.
Gustav Wikström 5 年之前
父節點
當前提交
b082de626d
共有 2 個文件被更改,包括 18 次插入3 次删除
  1. 4 0
      etc/ORG-NEWS
  2. 14 3
      lisp/org-id.el

+ 4 - 0
etc/ORG-NEWS

@@ -387,6 +387,10 @@ separator using ~org-agenda-breadcrumbs-separator~.
 This variable makes it possible to customize the list of commands for
 the attachment dispatcher.
 
+*** New ID method based on timestamp
+If one chooses, it is now possible to create ID's based on timestamp
+(ISO8601) instead of UUID by changing org-id-method to ts.
+
 *** New customization: ~org-id-locations-relative~
 New customization to make the persisting of org-id-locations between
 sessions to store links to files as relative instead of absolute.  The

+ 14 - 3
lisp/org-id.el

@@ -142,11 +142,15 @@ org        Org's own internal method, using an encoding of the current time to
 
 uuid       Create random (version 4) UUIDs.  If the program defined in
            `org-id-uuid-program' is available it is used to create the ID.
-           Otherwise an internal functions is used."
+           Otherwise an internal functions is used.
+
+ts         Create ID's based on ISO8601 timestamps (without separators
+           and without timezone, local time).  Precision down to seconds."
   :group 'org-id
   :type '(choice
 	  (const :tag "Org's internal method" org)
-	  (const :tag "external: uuidgen" uuid)))
+	  (const :tag "external: uuidgen" uuid)
+	  (const :tag "ISO8601 timestamp" ts)))
 
 (defcustom org-id-prefix nil
   "The prefix for IDs.
@@ -163,7 +167,7 @@ to have no space characters in them."
   "Non-nil means add the domain name to new IDs.
 This ensures global uniqueness of IDs, and is also suggested by
 the relevant RFCs.  This is relevant only if `org-id-method' is
-`org'.  When uuidgen is used, the domain will never be added.
+`org' or `ts'.  When uuidgen is used, the domain will never be added.
 
 The default is to not use this because we have no really good way to get
 the true domain, and Org entries will normally not be shared with enough
@@ -368,6 +372,13 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
 			    (require 'message)
 			    (concat "@" (message-make-fqdn))))))
 	(setq unique (concat etime postfix))))
+     ((eq org-id-method 'ts)
+      (let ((ts (format-time-string "%Y%m%dT%H%M%S"))
+	    (postfix (if org-id-include-domain
+			 (progn
+			   (require 'message)
+			   (concat "@" (message-make-fqdn))))))
+	(setq unique (concat ts postfix))))
      (t (error "Invalid `org-id-method'")))
     (concat prefix unique)))