6

Q: How can I make org-mode understand alternate day/month abbreviations?

org-mode uses the function org-read-date when entering timestamps, scheduling dates, and creating deadlines. One may enter three-letter day or month abbreviations (e.g., "sun" for Sunday, "oct" for October), and org-read-date recognizes them.

But: a few common abbreviations are longer than three letters -- e.g., I almost always write "tues" (rather than "tue") for Tuesday, "thurs" (rather than "thu") for Thursday, "sept" (rather than "sep") for September, and so on. The problem is that, the instant one gets past the third letter, org-read-date no longer recognizes the abbreviation.

So the question is: how can I tell org-read-date to accept these longer abbreviations in addition to the three-letter versions?

NB: I realize, of course, that I could just stop typing at the third letter, but the muscle memory is strongly-ingrained and I often don't realize I've used the longer abbreviation until much later when the item does not show up on the correct date in the agenda.

Dan
  • 32,584
  • 6
  • 98
  • 168

1 Answers1

8

You have to change parse-time-weekdays and parse-time-months. For example, something like this will do:

(defvar parse-time-weekdays-longer
  '(("sund" . 0) ("tues" . 2) ("thurs" . 4))

(defvar parse-time-months-longer
  '(("janu" . 1) ("dece" . 12)))

(eval-after-load 'parse-time
  '(progn
    (setq parse-time-weekdays (nconc parse-time-weekdays
                                     parse-time-weekdays-longer))
    (setq parse-time-months (nconc parse-time-months
                                   parse-time-months-longer))))

In weekdays, 0 is Sunday, 1 is Monday... 6 is Saturday, in months it is the obvious number of the month.

I'm using eval-after-load to add my abbreviations to the default one: one need to wait for parse-time to be loaded for parse-time-weekdays and parse-time-months to have their default value.

Note that this is not only for abbreviations, I use translation of the weekday name for example.

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
Rémi
  • 1,607
  • 11
  • 13