emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* My Python solution to generating unique Ids in headlines
@ 2009-03-04 23:20 Charles Cave
  2009-03-04 23:59 ` Nick Dokos
  2009-03-05  8:39 ` Ian Barton
  0 siblings, 2 replies; 6+ messages in thread
From: Charles Cave @ 2009-03-04 23:20 UTC (permalink / raw)
  To: emacs-orgmode

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
-------------------------------------------

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-03-06  2:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2009-03-06  2:13       ` Samuel Wales
2009-03-05  8:39 ` Ian Barton

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).