emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <dominik@science.uva.nl>
To: Charles Cave <charles_cave@optusnet.com.au>
Cc: emacs-orgmode@gnu.org
Subject: Re: Re: My Python solution to generating unique Ids in	headlines
Date: Thu, 5 Mar 2009 10:37:47 +0100	[thread overview]
Message-ID: <5639E37F-D378-4C36-8DB9-CBE303CC36BC@uva.nl> (raw)
In-Reply-To: <loom.20090305T022823-529@post.gmane.org>

[-- Attachment #1.1: Type: text/plain, Size: 4506 bytes --]

Hi Charles,

if you want a pure Emacs solution for this, here is one

(defvar charles-num-file "C:/charles/gtd/todonum.txt")
(defun charles-add-id ()
   "Add ID number to headline."
     (org-back-to-heading t)
     (when (looking-at ".*\\[#[0-9]+\\]")
       (error "ID number already present"))
     (when (looking-at org-complex-heading-regexp)
       (goto-char (match-end 4))
       (insert (format " [#%s]" (charles-next-num)))
       (org-set-tags nil 'align))))

(defun charles-next-num ()
   "Get next number"
   (let (num)
       (if (file-exists-p charles-num-file)
	  (insert-file-contents-literally charles-num-file))
       (goto-char (point-min))
       (setq num (1+ (or (ignore-errors (read (current-buffer))) 0))))
     (with-temp-file charles-num-file
       (insert (number-to-string num)))


It really depends on how much you want to depend on these numbers.
In fact, my first implementation of IDs in org did use numbers just
like yours, but I moved away from them because they are simply not

1. If you ever sit on a different computer and would like
    to create a task, you will mess up the numbering.
2. If you forget to backup and restore the numbering file, you will
    run into trouble.
3. No good way to collaborate with others.

But if you are convinced that you alone will use this, with a
single computer, it might work OK.  The one advantage of numbers
as IDs is that they are better readable with the eye, and that you
can even remember "Oh yes, this was task 136".  However, if it is
a computer that is looking at the IDs, there are much better

1. Of course, as Nick proposes, the IDs created by uuidgen.
    Globally unique, they will never ever give you any trouble.
    They are long, though, if you want to store them in the
    headline - that's why Org has them in a property.

2. Instead of (charles-next-num), you could use


    This will give you an encoding of the current time, to
    microsecond accuracy, in just 12 characters, good enough
    for multiple computers and even for large collaborations.
    Even if 2 people are trying to make an ID at exactly the
    same time, chances are still 1 in 100000 or so that they
    would actually get the same ID.

3. If you are sure the you never make 2 IDs in the same second,
    you can nibble off the last digits, like

      (substring (org-id-time-to-b36) 0 -4)

    which is an 8 character encoding of the creation time,
    accurate to a second.  Quite safe for yourself, unless
    you use a program like org-map-entries to create these
    IDs for many entries in very short time.
    You could even nibble away the first digit which will
    not become significant for another 100 years or so.

      (substring (org-id-time-to-b36) 1 -4)

    7 characters, one second accuracy, hard to beat.


- Carsten

On Mar 5, 2009, at 3:40 AM, Charles Cave wrote:

> Nick Dokos <nicholas.dokos <at> hp.com> writes:
>> Try
>>      import sys
>>      sys.stdout.write("[%d]" % val)
> Thanks. That works fine.
>> (shell-command "nextnum" t)
> This worked fine.
>> It may be necessary to specify a complete path to the command.
> I diodnt need to because the .BAT file was in a directory which is
> part of the PAHT list.  By the way, I had to include a beginning
> line of @ECHO OFF in the bat file.
>> But I still don't understand why you need an external program: what  
>> is
>> wrong with (insert (format "[%s]" (org-id-new)))? Are the IDs too  
>> ugly
>> or is there some other problem?
> I'm struggling to find documentation or installing and using org-id.
> I added the line (require 'org-id) to my .eamcs file
> then discovered a variable to customise the method to internal
> or to use an external command uuidgen which doesnt exist on Windows.
> How do I change the name of the external command from uuidgent
> to nextnum
>> The trouble with unique IDs in files is that it's easy for them to  
>> get
>> out of sync (leading to non-uniqueness), e.g. if there are two  
>> processes
>> trying to get a unique id at the same time.
> This shouldnt be a problem as I am the only user.
> Thanks for your help,
> Charles
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

[-- Attachment #1.2: Type: text/html, Size: 6897 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.

  reply	other threads:[~2009-03-05  9:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-04 23:20 My Python solution to generating unique Ids in headlines Charles Cave
2009-03-04 23:59 ` Nick Dokos
2009-03-05  2:40   ` Charles Cave
2009-03-05  9:37     ` Carsten Dominik [this message]
2009-03-06  2:13       ` Samuel Wales
2009-03-05  8:39 ` Ian Barton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5639E37F-D378-4C36-8DB9-CBE303CC36BC@uva.nl \
    --to=dominik@science.uva.nl \
    --cc=charles_cave@optusnet.com.au \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).