0

I would like to be able to run M-x calendar, navigate to a date, press some keystroke which would do one of the following:

  1. place the selected date onto the kill ring

or

  1. close the calendar and insert the selected date into my current buffer.

Is there any built-in functionality for this?

Drew
  • 75,699
  • 9
  • 109
  • 225
killdash9
  • 179
  • 8

1 Answers1

0

org-read-date uses the function calendar from the calendar.el library. It is not necessary to be in an org-mode buffer to use org-read-date; i.e, the function org-insert-copy-date should work in just about any buffer that is read-write. The nifty thing about org-read-date is that you can use the mouse to select a date and exit, or use the minibuffer to select a date (which has some pretty overlays).

(defun org-insert-copy-date ()
"Insert a date at point using `org-read-date' with its optional argument
of TO-TIME so that the user can customize the date format more easily.
Also, copy the time-string to the `kill-ring'."
(interactive)
  (require 'org)
  (let* ((time (org-read-date nil 'to-time nil "Date:  "))
         (time-string (format-time-string "%Y-%m-%d" time)))
    (kill-new time-string)
    (insert time-string)))
lawlist
  • 18,826
  • 5
  • 37
  • 118