From mboxrd@z Thu Jan 1 00:00:00 1970 From: Charles Cave Subject: My Python solution to generating unique Ids in headlines Date: Thu, 05 Mar 2009 10:20:13 +1100 Message-ID: <200903042320.n24NKDmD007471@mail11.syd.optusnet.com.au> Reply-To: charles_cave@optusnet.com.au Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: binary Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lf0Nz-00066v-PM for emacs-orgmode@gnu.org; Wed, 04 Mar 2009 18:20:23 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lf0Nx-00064Z-GA for emacs-orgmode@gnu.org; Wed, 04 Mar 2009 18:20:22 -0500 Received: from [199.232.76.173] (port=38122 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lf0Nx-00064P-9Y for emacs-orgmode@gnu.org; Wed, 04 Mar 2009 18:20:21 -0500 Received: from mail11.syd.optusnet.com.au ([211.29.132.192]:34233) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lf0Nw-0004bF-Gi for emacs-orgmode@gnu.org; Wed, 04 Mar 2009 18:20:21 -0500 Received: from localhost.localdomain (webmail01.syd.optusnet.com.au [211.29.132.235]) by mail11.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id n24NKDmD007471 for ; Thu, 5 Mar 2009 10:20:13 +1100 Content-Disposition: inline List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Recently I asked about a method of inserting a unique number in a headline. My requirement is to be able to uniquely identify a particular headline when exporting data to another system (ListPro on Palm/Windows). I settled on using a small Python script, since I am not a Lisp programmer. 1. I created a text file todononum.txt which contains the next number to use. 2. I created the following script to read this file, return the next available number formatted in a unique, easy to find string, for example [#310]. # script next_todo.py import sys nextnum_file = "C:/charles/gtd/todonum.txt" try: f = open(nextnum_file, 'r') except IOError: print "Unable to open %s. Program terminating." % nextnum_file sys.exit(1) val = int(f.readline()) + 1 f.close() of = open(nextnum_file, 'w') of.write("%d\n" % val) of.close() print "[#%s]" % val 3. I created a one line batch file nextnum.bat (I'm on Windows!) containing: python c:/charles/gtd/next_todo.py 4. In org-mode I insert the unique id by positioning the cursor at the end of the headline text, then entering the command ESC-1 ESC-! nextnum RET Ctl-D The Ctrl D is needed to remove a carriage return (not sure why it is there. Can someone give me Lisp code equivalent of the command sequene above? I know it is something to do with (shell command .... ) The end result now looks like *** Post to org-mode list about next sequential [#315] :COMPUTER: Once I have Lisp code to implement the command sequence I will have a satisfactory solution to generating the unique id when I need it. ------------------------------------------- Charles Cave Sydney, NSW, Australia Email: charles_cave@optusnet.com.au Follow me on Twitter: www.twitter.com/ozcaveman -------------------------------------------