help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: writing ledger mode, date picker


From: jenia.ivlev
Subject: Re: writing ledger mode, date picker
Date: Sun, 08 Nov 2015 23:35:44 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> Yuri Khan <yuri.v.khan@gmail.com> writes:
>
>> You want to ask a user to select a date on the
>> calendar and then insert that date into a buffer.
>
> Aha, that is what the OP wants to do!
>
> Then what I provided should be modified somewhat - see
> the code below.
>
> The problem is, `calendar-cursor-to-date' only gives
> me dates in February 1970... So what is that, Diane
> Keaton and Mariel Hemingway?
>
> Maybe the OP has better luck (?) with that!
>
Yes I did. I'll copy paste the answer. 

(defun insert-new-entry ()
   (interactive)
   (save-excursion
      (goto-char (point-max))
      (print "Asti")
      (define-key calendar-mode-map (kbd "RET") 'get-date)
      (calendar)
          (let* ((x (calendar-cursor-to-date))
                (time (encode-time 0 0 0 (nth 1 x) (nth 0 x) (nth 2 x))))
            (select-window (get-buffer-window "asti" t))
            (insert (format-time-string "%Y-%m-%d" time)))))

I didn't yet use the `calendar-mode-map`. Too tired. But I'm confident
that it'll work. 
So now I have all the pieces ;))))

Thanks you so much Emanuel, Yuri and Drew!!

P.S. I got this from org-read-date ;)
> (require 'calendar)
>
> (defun calendar-cursor-date-into-asti ()
>   (interactive)
>   (let*((date (calendar-cursor-to-date))
>         (date-string (format-time-string "%Y-%m-%d\n" date))
>         (buffer (get-buffer-create "asti")) )
>     (with-current-buffer
>         buffer (insert date-string) )))
>
> (define-key calendar-mode-map "\r" 'calendar-cursor-date-into-asti)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]