I've been playing with customising jEdit a little bit, and decided to have a go at writing some simple date insertion macros. These perform the same work as some old elisp functions I wrote years ago in Emacs, to insert date/time stamps in various formats. In my .emacs file, I bind these functions to short-cut keys, and then use them for updating Changelogs in code and in offline journal entries.

These are fairly simple, the only obfuscated part is the way that the output list now has been created from the (decode-time) built-in, which then has to be picked appart to get the different date elements for formatting.

Compare this with the jEdit equivalents, which are written in BeanShell. Each macro is in it's own .bsh file, rather than all together in a single file like the elisp functions, and the documentation is done in XML, rather than as a doc-comment in elisp:

The comments are lot more verbose, but you can see the Insert_Date_ISO-MJL macro at work in the script comments above. Also, the Java SimpleDateFormat class makes formatting much simpler to read, I feel, but even with BeanShell's ability to use untyped variables (for example, in BeanShell you can say “dateFormatter = new SimpleDateFormat…”, instead of Java's “DateFormat dateFormatter=new SimpleDateFormat…”), the code is still not as elegant as the elisp version.

However, I think I'm starting to like jEdit over Emacs (blasphemy!). Mind you it's slow: it makes Emacs seem zippy, and traditionaly Emacs stood for “EMACS Makes A Computer Slow”!

On a side-note, there is a nice plugin for jEdit, called Code2HTML, which renders your code in HTML, with syntax highlighting to match that done by jEdit (and jEdit knows a lot of languages!). Unfortunately when I pasted the generated HTML into this WordPress post and then saved it, all the highlighting got removed… I wonder if it has something to do with the plugin's use of <SPAN>s and CSS Styles? But even if I paste the <STYLE> block into this post as well, the formatting gets eaten up by WordPress :( Something to look into.

2006-06-07T15:36+1000 - Update: I should make a point about the copyright on these scripts: they're copyleft, GNU GPL2.0. I just snipped out the boilerplate to make this post shorter. Feel free to copy/use as you like, subject to the GPL, and you should of course cite the author (me) and include the boilerplate disclamers on any copy you distribute to others. The missing boilerplate is below:

(defun mjl-insert-date-iso ()
"Inserts the current local date and time (to the minute) into
the current buffer before Point. The date is formatted per ISO
8601 specification. This is useful for prefixing entries in a log
book."
(interactive)
(insert (format-time-string "%Y-%m-%dT%R%z")))
(defun mjl-insert-date-stamp ()
"Inserts the current local date into the current buffer before
Point. The date is formatted per ISO 8601 short specification and
prefixed with my initials 'MJL'. This is useful for inserting mod
comments into code files."
(interactive)
(setq now (decode-time))
(insert (format-time-string "MJL%Y%m%d")))
(defun mjl-insert-date-dow ()
"Inserts the current local date and the day of the week into
the current buffer before Point. The date is formatted per ISO
8601 specification. The DOW is expanded to the full name. This is
useful for prefixing day entries in a log book."
(interactive)
(insert (format-time-string "%Y-%m-%d %A")))

(defun mjl-insert-log-entry-org ()
"Inserts the current local date and time into
the current buffer before Point. The date is formatted to suit
Org mode's agenda and highlighting functions. The date is also
formatted as a level 3 headline for inclusion in an org
file."
(interactive)
(insert (format-time-string "*** <%Y-%m-%d %A %R> ")))

I should add that my flirtation with jEdit is over, by the way. Back to emacs for me, and I'm repenting for my blasphemous ways…