all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Deus Max <deusmax@gmx.com>
To: Tomas Nordin <tomasn@posteo.net>
Cc: 36979@debbugs.gnu.org
Subject: bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date)
Date: Sun, 11 Aug 2019 14:13:25 +0300	[thread overview]
Message-ID: <87a7cgosyy.fsf@aia00054aia.gr> (raw)
In-Reply-To: <8736i86ea8.fsf@fliptop.i-did-not-set--mail-host-address--so-tickle-me> (Tomas Nordin's message of "Sat, 10 Aug 2019 20:55:43 +0200")

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."))))






  parent reply	other threads:[~2019-08-11 11:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 18:56 bug#36979: Calendar: mention how to copy date 積丹尼 Dan Jacobson
2019-08-08 23:07 ` Glenn Morris
     [not found] ` <handler.36979.D36979.156530565717008.notifdone@debbugs.gnu.org>
2019-08-09  1:31   ` bug#36979: closed (Re: bug#36979: Calendar: mention how to copy date) 積丹尼 Dan Jacobson
2019-08-10  2:30     ` Richard Stallman
2019-08-10 18:25       ` 積丹尼 Dan Jacobson
2019-08-10 18:55         ` Tomas Nordin
2019-08-10 19:05           ` 積丹尼 Dan Jacobson
2019-08-11 11:13           ` Deus Max [this message]
2019-08-11 12:37             ` Deus Max
2019-08-11  2:39         ` Richard Stallman
2019-08-11  2:50           ` 積丹尼 Dan Jacobson
2019-08-12  1:36             ` Richard Stallman
2019-08-12 21:55               ` 積丹尼 Dan Jacobson
2019-08-13  2:14                 ` Richard Stallman
2019-08-17  1:15                   ` 積丹尼 Dan Jacobson
2019-08-17 22:20                     ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a7cgosyy.fsf@aia00054aia.gr \
    --to=deusmax@gmx.com \
    --cc=36979@debbugs.gnu.org \
    --cc=tomasn@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.