kiwanami / emacs-calfw

A calendar framework for Emacs
1.17k stars 100 forks source link

Another function for calfw-org.el #52

Open jwiegley opened 9 years ago

jwiegley commented 9 years ago

The following makes a good option for cfw:read-date-command, as it makes the date selection prompt for calfw works exactly like org-mode.

(defun cfw:org-goto-date ()
  (interactive)
  (let ((xs (decode-time (org-time-string-to-time
                          (org-read-date)))))
    (list (nth 4 xs) (nth 3 xs) (nth 5 xs))))
kiwanami commented 9 years ago

Thank you for your advice!

cfw:org-read-date-command uses org-read-date. I think this code is intended.

(defun cfw:org-goto-date ()
  "Move the cursor to the specified date."
  (interactive)
  (cfw:navi-goto-date 
   (cfw:org-read-date-command)))

Is it nice for org users?

@takaxp How about this code? Can I add navigation code in cfw:org-read-date-command?

takaxp commented 9 years ago

The code provided by kiwanami-san works fine and good for me. I recommend a keymap, j, may assigned to the function so that org-agenda user can easily understand the operation because it is assigned to org-agenda-goto-date in org-agenda. I know j is already used for moving between weeks in Vi style so we should add some description for org users in docstring.

Kiwanami-san, could you explain the detail of "add navigation" means, I couldn't get point :-/

kiwanami commented 9 years ago

@takaxp Thank you for your key-binding advice. It is difficult to change the original calfw key-binding, we would provide another key-binding set for org users.

I'm sorry for my not clear word "add navigation". The original code for cfw:org-read-date-command just returns a calendar-date value. The interactive command is expected to do some side-effect, not just return values, because almost users can hardly use the value via interactive command. So, I meant we can rewrite cfw:org-read-date-command function as following:

(defun cfw:org-read-date-command ()
  "Move the cursor to the specified date."
  (interactive)
  (cfw:navi-goto-date 
   (cfw:emacs-to-calendar (org-read-date nil 'to-time))))

We can also rename this function to cfw:org-goto-date, if no one use cfw:org-read-date-command.

takaxp commented 9 years ago

I'm little confused because the last code cfw:org-read-date-command actually reflects my expectation.

Let me explain. When I tested the proposed code in this thread,

I just put the following code into my `.emacs'.

(defun cfw:org-goto-date ()
  "Move the cursor to the specified date."
  (interactive)
  (cfw:navi-goto-date 
   (cfw:org-read-date-command)))

At the same time, the cfw:org-read-data-command was defined in my local code like

(defun cfw:org-read-date-command ()
  "Move the cursor to the specified date."
  (interactive)
  (cfw:emacs-to-calendar (org-read-date nil 'to-time)))

So, as you can see, if we combine these two codes, then it is exactly the same your revised code including navigation. I support merging cfw:org-read-date-command into cfw:org-goto-date and therefore the code will be revised as follows:

(defun cfw:org-goto-date ()
  "Move the cursor to the specified date."
  (interactive)
  (cfw:navi-goto-date 
   (cfw:emacs-to-calendar (org-read-date nil 'to-time))))