emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] What is the best way to set #+DATE to today's date?


From: Kaushal
Subject: [O] What is the best way to set #+DATE to today's date?
Date: Thu, 6 Aug 2015 12:33:13 -0400

Hi all,

There are quite few documents in which I want to update the date stamp to the last update time.

I like that #+DATE keyword value is used aptly in latex/pdf and html exports.

But I couldn't find an elegant way for that date to be updated to today's (last updated) date.

I came up with the below. But please let me know if there's an inbuilt way to do the same.


PART 1: Config in init.el

    ;; Update TODAY macro with current date
    (defun modi/org-update-TODAY-macro (&rest ignore)
      "Update TODAY macro to hold string with current date."
      (interactive)
      (when (derived-mode-p 'org-mode)
        (save-excursion
          (goto-char (point-min))
          (while (re-search-forward
                  "^\\s-*#\\+MACRO:\\s-+TODAY"
                  nil 'noerror)
            (forward-line 0)
            (when (looking-at ".*TODAY\\(.*\\)")
              (replace-match
               (concat " "
                       (format-time-string "%b %d %Y, %a" (current-time)))
               :fixedcase :literal nil 1))))))
    (add-hook 'org-export-before-processing-hook #'modi/org-update-TODAY-macro)


PART 2: org document where I want the #+DATE to auto update

    #+MACRO: TODAY [current date is auto-inserted when exporting]
    #+DATE: {{{TODAY}}}


--
Kaushal Modi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]