From f011496cebc63b002464fb07785068db16951d3a Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Sun, 2 Sep 2012 12:52:38 +0200 Subject: [PATCH] `k' now calls org-agenda-capture from agenda. Also add `org-capture-use-agenda-date' option. * org-capture.el (org-capture-use-agenda-date): New option. (org-capture): Use it. * org-agenda.el (org-agenda-capture): New command. (org-agenda-mode-map): Bind it to `k'. (org-agenda-menu): Add it to the menu. * org.texi (Agenda commands): Document the new command and the new option. Thanks to Eric Abrahamsen who suggested this change, along with other merging about bulk actions. --- doc/org.texi | 7 +++++++ lisp/org-agenda.el | 12 ++++++++++++ lisp/org-capture.el | 24 ++++++++++++++++-------- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 68c3ada7e..c8823f6cc 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -8459,6 +8459,13 @@ Cancel the currently running clock. @c @orgcmd{J,org-agenda-clock-goto} Jump to the running clock in another window. +@c +@orgcmd{k,org-agenda-capture} +Like @code{org-capture}, but use the date at point as the default date for +the capture template. See @var{org-capture-use-agenda-date} to make this +the default behavior of @code{org-capture}. +@cindex capturing, from agenda +@vindex org-capture-use-agenda-date @tsubheading{Bulk remote editing selected entries} @cindex remote editing, bulk, from agenda diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 621c2151e..b7a848757 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -83,6 +83,7 @@ (&optional buffer-or-name norecord label)) (declare-function org-agenda-columns "org-colview" ()) (declare-function org-add-archive-files "org-archive" (files)) +(declare-function org-capture "org-capture" (&optional goto keys)) (defvar calendar-mode-map) ; defined in calendar.el (defvar org-clock-current-task nil) ; defined in org-clock.el @@ -2007,6 +2008,7 @@ The following commands are available: (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark) (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all) (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action) +(org-defkey org-agenda-mode-map "k" 'org-agenda-capture) (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda) (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload) (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default) @@ -2190,6 +2192,7 @@ The following commands are available: ["Show original entry" org-agenda-show t] ["Go To (other window)" org-agenda-goto t] ["Go To (this window)" org-agenda-switch-to t] + ["Capture with cursor date" org-agenda-capture t] ["Follow Mode" org-agenda-follow-mode :style toggle :selected org-agenda-follow-mode :active t] ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t] @@ -9048,6 +9051,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) + (if (not (eq major-mode 'org-agenda-mode)) + (error "You cannot do this outside of agenda buffers") + (let ((org-overriding-default-time + (org-get-cursor-date))) + (call-interactively 'org-capture)))) + ;;; Flagging notes (defun org-agenda-show-the-flagging-note () diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 10bfcf44a..a932ce74f 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -483,6 +483,13 @@ to avoid duplicates.)" (regexp)) (function :tag "Custom function")))))) +(defcustom org-capture-use-agenda-date nil + "Non-nil means use the date at point when capturing from agendas. +When nil, you can still capturing using the date at point with \\[org-agenda-capture]]." + :group 'org-capture + ;; :version "24.3" + :type 'boolean) + ;;;###autoload (defun org-capture (&optional goto keys) "Capture something. @@ -501,16 +508,17 @@ stored. When called with a `C-0' (zero) prefix, insert a template at point. -When called from an agenda buffer, use the date of the cursor at point -as the default date for the capture template. +Lisp programs can set KEYS to a string associated with a template +in `org-capture-templates'. In this case, interactive selection +will be bypassed. -Lisp 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." (interactive "P") - (if (eq major-mode 'org-agenda-mode) - (setq org-overriding-default-time - (org-get-cursor-date))) + (when (and org-capture-use-agenda-date + (eq major-mode 'org-agenda-mode)) + (setq org-overriding-default-time + (org-get-cursor-date))) (cond ((equal goto '(4)) (org-capture-goto-target)) ((equal goto '(16)) (org-capture-goto-last-stored))