From 6fb1d3ec1dafed6389447dc7acef5c237457d263 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Wed, 27 Jul 2011 17:20:18 +0200 Subject: [PATCH 3/3] New implementation for `org-loop-over-headlines-in-active-region'. `org-schedule' and `org-deadline' don't use a macro anymore. * org.el (org-schedule-do): Rename from `org-schedule'. (org-schedule): Add a loop. (org-deadline-do): Rename from `org-deadline'. (org-deadline): Add a loop. (org-map-entries): Use org-end-of-subtree to make sure the active region contains the whole subtree. (org-loop-over-headlines-in-active-region): New variable. --- lisp/org.el | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 45 insertions(+), 1 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 36b290a..aa1b206 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -396,6 +396,25 @@ is Emacs 23 only." (const :tag "When outside special context" t) (const :tag "Everywhere except timestamps" always))) +(defcustom org-loop-over-headlines-in-active-region nil + "Shall some commands act upon headlines in the active region? + +When set to `t', some commands will be performed in all headlines +within the active region. + +When set to a string, those commands will be performed on the +matching headlines within the active region. Such string must be +a tags/property/todo match as it is used in the agenda tags view. + +The list of commands is: +- `org-schedule' +- `org-deadline'" + :type '(choice (const :tag "Don't loop" nil) + (const :tag "All headlines in active region" t) + (string :tag "Tags/Property/Todo matcher")) + :group 'org-todo + :group 'org-archive) + (defgroup org-startup nil "Options concerning startup of Org-mode." :tag "Org Startup" @@ -11694,6 +11713,18 @@ of `org-todo-keywords-1'." (org-occur (concat "^" org-outline-regexp " *" kwd-re ))))) (defun org-deadline (&optional remove time) + "Insert the DEADLINE: string with a timestamp to schedule a TODO item. +See `org-deadline-do' for details." + (interactive "P") + (if (or (not (org-region-active-p)) + (not org-loop-over-headlines-in-active-region)) + (org-deadline-do remove time) + (org-map-entries + `(org-deadline-do ,remove ,time) + org-loop-over-headlines-in-active-region + 'region))) + +(defun org-deadline-do (&optional remove time) "Insert the \"DEADLINE:\" string with a timestamp to make a deadline. With argument REMOVE, remove any deadline from the item. With argument TIME, set the deadline at the corresponding date. TIME @@ -11735,6 +11766,18 @@ can either be an Org date like \"2011-07-24\" or a delta like \"+2d\"." (defun org-schedule (&optional remove time) "Insert the SCHEDULED: string with a timestamp to schedule a TODO item. +See `org-schedule-do' for details." + (interactive "P") + (if (or (not (org-region-active-p)) + (not org-loop-over-headlines-in-active-region)) + (org-schedule-do remove time) + (org-map-entries + `(org-schedule-do ,remove ,time) + org-loop-over-headlines-in-active-region + 'region))) + +(defun org-schedule-do (&optional remove time) + "Insert the SCHEDULED: string with a timestamp to schedule a TODO item. With argument REMOVE, remove any scheduling date from the item. With argument TIME, scheduled at the corresponding date. TIME can either be an Org date like \"2011-07-24\" or a delta like \"+2d\"." @@ -13518,7 +13561,8 @@ a *different* entry, you cannot use these techniques." (org-narrow-to-subtree) (setq scope nil)) ((and (eq scope 'region) (org-region-active-p)) - (narrow-to-region (region-beginning) (region-end)) + (narrow-to-region (region-beginning) + (org-end-of-subtree t)) (setq scope nil))) (if (not scope) -- 1.7.5.2