Skip to content

Instantly share code, notes, and snippets.

@doitian
Created May 25, 2009 03:47
Show Gist options
  • Save doitian/117372 to your computer and use it in GitHub Desktop.
Save doitian/117372 to your computer and use it in GitHub Desktop.
(defvar iy/calendar-copy-date-format-history '("%Y-%m-%d"))
(defun iy/calendar-copy-date (arg)
"Copy date under the cursor. Read format from minibuffer if ARG,
use recently used format if no ARG. See the function `format-time-string'
for the document of time format string"
(interactive "P")
(let ((date (calendar-cursor-to-date t))
(format (if arg
(completing-read
"Date Format:"
iy/calendar-copy-date-format-history nil nil nil
'iy/calendar-copy-date-format-history nil nil)
(car iy/calendar-copy-date-format-history)))
string)
(setq date (encode-time 0 0 0 (cadr date) (car date) (nth 2 date)))
(setq string (format-time-string format date))
(if (eq last-command 'kill-region)
(kill-append string nil)
(kill-new string))))
(defun iy/calendar-mode-init ()
(local-set-key (kbd "w") 'iy/calendar-copy-date))
(add-hook 'calendar-mode-hook 'iy/calendar-mode-init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment