Using Org Modes's Date Routines In Any Buffer

I really like Org Mode's method for inserting time/date stamps into an Org file. Org Mode has two types of dates, active and inactive, that differ in how Org Mode treats them but we needn't worry about that here. In either case when you ask to insert a date, Org Mode presents you with a three month window of calendars centered at the current month and a default of the current day's date. You can just press return to accept that, add a time or change the date to something else. You can enter an absolute date or you can say +5 to indicate 5 days from today or +1w for a week from today and so on. You can also click on the calendars to pick a date and, of course, you can scroll the calendar window. There are lots of options for entering the dates and times as described here in the Org Mode Manual.

Unless I'm writing code, I'm usually in Org Mode so the date routines are available most of the time. Sometimes I want to enter a date in a comment in a program or I am in some other sort of buffer where the Org Mode key bindings aren't available. Therefore, I wrote a quick piece of Emacs Lisp to call the Org function directly and bound it to 【F5】:

(defun jcs-insert-date (and-time)
  "Prompt for and insert date at point into the current buffer using the
org-read-date routines."
  (interactive "P")
  (org-time-stamp and-time t))

(global-set-key (kbd "<f5>") 'jcs-insert-date)

Now when I want to insert a date stamp I just type 【F5】 or 【Ctrl+u F5】 if I want the add the current time.

This entry was posted in General and tagged . Bookmark the permalink.