I want to write a mode for ledger. The first thing I want to do is to be able to insert date stamps. There is a very nice mode in Emacs called calendar. I want to be able to select a date within it.

How do I register a call-back or something that will be executed when the user has select a date (by pressing enter or any other way that calendar mode already uses).

  • Check out the function org-read-date -- user selects date on calendar and the date is automatically inserted and the calendar buffer closes.
    – lawlist
    Aug 27, 2015 at 2:02
  • yea but I'll have to enable org-mode. I prefer to do it using the basic elisp functionality like calendar and some other function that will allow me to simply read the user's selection. Aug 27, 2015 at 12:16
  • It is not always necessary to enable a major mode in the working buffer to use a function from a particular library. In particular, you can evaluate (require 'org) (org-read-date) in your *Scratch* buffer and it works no matter what major-mode that buffer is in. It is only necessary to require a library one time per session, and can be placed at the top of the library you are building.
    – lawlist
    Aug 27, 2015 at 15:04
  • 4
    Possible duplicate of How do I pick a date in my new major mode?
    – lawlist
    Nov 7, 2015 at 22:08
  • 1
    See here: inserting a calendar date at point
    – RichieHH
    Feb 9, 2020 at 22:26

1 Answer 1


My solution is

(defvar *calendar-entry-buffer* nil)

(defun select-date ()
  (destructuring-bind (month day year) (calendar-cursor-to-date)
    (if *calendar-entry-buffer*
            (set-buffer *calendar-entry-buffer*)
            (insert (format "%d-%02d-%02d\n" year month day)))
          (setf *calendar-entry-buffer* nil)

(define-key calendar-mode-map (kbd "RET") 'select-date)

(defun insert-date-at-point ()
  (setf *calendar-entry-buffer* (current-buffer))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.