2

Is there a way to retrieve the date under the cursor in emacs calendar as the format day.month.year like 05.07.2018 as a clipboard content?

3

The following code augments the key sequence M-w such that it copies the date below point with the format "%d.%m.%Y when region is not active ( %d: zero padded day, %m: zero-padded month, %Y: year).

You can change the format with the customization option calendar-copy-as-kill-format.

(defcustom calendar-copy-as-kill-format "%d.%m.%Y"
  "Format string for formatting calendar dates with `format-time-string'."
  :type 'string
  :group 'calendar)

(defun calendar-copy-as-kill ()
  "Copy date at point as kill if region is not active.
Delegate to `kill-ring-save' otherwise."
  (interactive)
  (if (use-region-p)
      (call-interactively #'kill-ring-save)
    (let ((date (calendar-cursor-to-date)))
      (when date
        (setq date (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))
        (kill-new (format-time-string calendar-copy-as-kill-format date))))))

(defun my-calendar-mode-hook-fun ()
  "Let \[kill-ring-save] copy the date at point if region is not active."
  (local-set-key [remap kill-ring-save] #'calendar-copy-as-kill))

(add-hook 'calendar-mode-hook #'my-calendar-mode-hook-fun)
  • Wonderful, thank you for this great answer. Let me wait for a while for possible alternative solutions before accepting yours. – Name Jun 12 '18 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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