[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date)
From: |
Deus Max |
Subject: |
bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date) |
Date: |
Sun, 11 Aug 2019 14:13:25 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
On Sat, Aug 10 2019, Tomas Nordin wrote:
>
> I can add my sympathy for the desire of functionality to add date under
> point to the kill ring. I was searching for such a feature at some point
> (didn't find it) and wrote this function which I bound to RET in
> calendar-mode-map:
>
> (defun tn-calendar-kill-date (&optional arg)
> "Kill new a string based on point in calendar buffer in iso format
>
> With no prefix ARG, kill the date as an iso date.
> With one prefix arg ('C-u'), kill the date as an iso week.
> with two prefix arg ('C-u C-u'), kill as both the iso week and date."
> (interactive "p")
> (let* ((date (calendar-cursor-to-date))
> (encoded-time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2
> date)))
> (date-string (format-time-string "%Y-%m-%d" encoded-time))
> (iso-week-string (format-time-string "%gW%V" encoded-time))
> kill-string)
>
> (cond
> ((= arg 4)
> (setq kill-string iso-week-string))
> ((= arg 16)
> (setq kill-string (format "%s %s" iso-week-string date-string)))
> (t
> (setq kill-string date-string)))
>
> (kill-new kill-string)
> (message "Put %s to kill-ring" kill-string)))
>
> Best regards
> --
> Tomas
Hi Tomas,
Great function for it can be very useful thank you.
I slightly modified it, so it doesn't blow up when the cursor is not on
a date and provides an informative message.
;; Copied from bug#36979 by Tomas Nordin, emacs-bugs maillist.
(defun tn-calendar-kill-date (&optional arg)
"Kill new a string based on point in calendar buffer in iso format
With no prefix ARG, kill the date as an iso date.
With one prefix arg ('C-u'), kill the date as an iso week.
with two prefix arg ('C-u C-u'), kill as both the iso week and date."
(interactive "p")
(let ((date (calendar-cursor-to-date t)))
(if date
;; date is valid
(let* ((encoded-time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth
2 date)))
(date-string (format-time-string "%Y-%m-%d" encoded-time))
(iso-week-string (format-time-string "%gW%V" encoded-time))
kill-string)
(cond
((= arg 4)
(setq kill-string iso-week-string))
((= arg 16)
(setq kill-string (format "%s %s" iso-week-string date-string)))
(t
(setq kill-string date-string)))
;; add to kill ring
(kill-new kill-string)
(message "Put %s to kill-ring" kill-string))
;; date is not valid - cursor is not on a date.
(message "Not on a date."))))
- bug#36979: Calendar: mention how to copy date, 積丹尼 Dan Jacobson, 2019/08/08
- bug#36979: Calendar: mention how to copy date, Glenn Morris, 2019/08/08
- Message not available
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), 積丹尼 Dan Jacobson, 2019/08/08
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Richard Stallman, 2019/08/09
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), 積丹尼 Dan Jacobson, 2019/08/10
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Tomas Nordin, 2019/08/10
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), 積丹尼 Dan Jacobson, 2019/08/10
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date),
Deus Max <=
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Deus Max, 2019/08/11
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Richard Stallman, 2019/08/10
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), 積丹尼 Dan Jacobson, 2019/08/10
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Richard Stallman, 2019/08/11
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), 積丹尼 Dan Jacobson, 2019/08/12
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Richard Stallman, 2019/08/12
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), 積丹尼 Dan Jacobson, 2019/08/16
- bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date), Richard Stallman, 2019/08/17