summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2012-12-12 15:21:10 +0100
committerBastien Guerry <bzg@altern.org>2012-12-12 15:21:10 +0100
commit1bfea39fd497c24f3b2ca01b3438b2bcc7cdfce4 (patch)
tree26ed686fb9f5b33ce1498f611c48b0fa135c8064
parent275f07c16aa67b334eb0b86a0ac131f2091bb1c8 (diff)
downloadorg-mode-1bfea39fd497c24f3b2ca01b3438b2bcc7cdfce4.tar.gz
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.
-rw-r--r--lisp/org-agenda.el12
-rw-r--r--lisp/org-capture.el8
-rw-r--r--lisp/org.el22
3 files changed, 28 insertions, 14 deletions
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 9fabba9..5343887 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -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
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 5d483d7..405d897 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -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))
diff --git a/lisp/org.el b/lisp/org.el
index 72046dc..ce605f4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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)