Support `C-1' prefix for `org-agenda-capture' and `org-capture'.

* org.el (org-get-cursor-date): New optional argument
WITH-TIME to add the time of the day.

* org-capture.el (org-capture): When capturing from the agenda
and with a non-nil value for `org-capture-use-agenda-date', a
`C-1' prefix will set the capture time to the HH:MM of the
current line or the current HH:MM.

* org-agenda.el (org-agenda-capture): New optional argument
WITH-TIME: when set to 1, the capture time will be set to the
HH:MM time of the current line, or the current HH:MM time.

From an agenda buffer, C-1 k (i.e. org-agenda-capture) and
C-1 M-x org-capture RET will use the time of the day of the
current line, or the current time of the day.  The date is
not changed by using this prefix.

Thanks to Rene for triggering this change.
This commit is contained in:
Bastien Guerry 2012-12-12 15:21:10 +01:00
parent 275f07c16a
commit 1bfea39fd4
3 changed files with 28 additions and 14 deletions

View File

@ -9349,13 +9349,15 @@ The prefix arg is passed through to the command if possible."
(if (not org-agenda-persistent-marks)
"" " (kept marked)"))))))
(defun org-agenda-capture ()
"Call `org-capture' with the date at point."
(interactive)
(defun org-agenda-capture (&optional with-time)
"Call `org-capture' with the date at point.
With a `C-1' prefix, use the HH:MM value at point (if any) or the
current HH:MM time."
(interactive "P")
(if (not (eq major-mode 'org-agenda-mode))
(error "You cannot do this outside of agenda buffers")
(user-error "You cannot do this outside of agenda buffers")
(let ((org-overriding-default-time
(org-get-cursor-date)))
(org-get-cursor-date (equal with-time 1))))
(call-interactively 'org-capture))))
;;; Flagging notes

View File

@ -516,17 +516,19 @@ stored.
When called with a `C-0' (zero) prefix, insert a template at point.
Lisp programs can set KEYS to a string associated with a template
ELisp programs can set KEYS to a string associated with a template
in `org-capture-templates'. In this case, interactive selection
will be bypassed.
If `org-capture-use-agenda-date' is non-nil, capturing from the
agenda will use the date at point as the default date."
agenda will use the date at point as the default date. Then, a
`C-1' prefix will tell the capture process to use the HH:MM time
of the day at point (if any) or the current HH:MM time."
(interactive "P")
(when (and org-capture-use-agenda-date
(eq major-mode 'org-agenda-mode))
(setq org-overriding-default-time
(org-get-cursor-date)))
(org-get-cursor-date (equal goto 1))))
(cond
((equal goto '(4)) (org-capture-goto-target))
((equal goto '(16)) (org-capture-goto-last-stored))

View File

@ -21021,21 +21021,31 @@ If EXTENSIONS is given, only match these."
(save-match-data
(string-match (org-image-file-name-regexp extensions) file)))
(defun org-get-cursor-date ()
(defun org-get-cursor-date (&optional with-time)
"Return the date at cursor in as a time.
This works in the calendar and in the agenda, anywhere else it just
returns the current time."
(let (date day defd)
returns the current time.
If WITH-TIME is non-nil, returns the time of the event at point (in
the agenda) or the current time of the day."
(let (date day defd tp tm hod mod)
(when with-time
(setq tp (get-text-property (point) 'time))
(when (and tp (string-match "\\([0-9][0-9]\\):\\([0-9][0-9]\\)" tp))
(setq hod (string-to-number (match-string 1 tp))
mod (string-to-number (match-string 2 tp))))
(or tp (setq hod (nth 2 (decode-time (current-time)))
mod (nth 1 (decode-time (current-time))))))
(cond
((eq major-mode 'calendar-mode)
(setq date (calendar-cursor-to-date)
defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
defd (encode-time 0 (or mod 0) (or hod 0)
(nth 1 date) (nth 0 date) (nth 2 date))))
((eq major-mode 'org-agenda-mode)
(setq day (get-text-property (point) 'day))
(if day
(setq date (calendar-gregorian-from-absolute day)
defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
(nth 2 date))))))
defd (encode-time 0 (or mod 0) (or hod 0)
(nth 1 date) (nth 0 date) (nth 2 date))))))
(or defd (current-time))))
(defun org-mark-subtree (&optional up)