Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Fabrizio Chiarello <fabrizio.chiarello <at> ieee.org>
Subject: Re: View inherited DEADLINEs in agenda
Newsgroups: gmane.emacs.orgmode
Date: Monday 14th November 2011 13:38:27 UTC (over 5 years ago)
On Wed, Nov 09, 2011 at 09:10:57AM +0100, Carsten Dominik wrote:
> 
> On 8.11.2011, at 23:35, Brian van den Broek wrote:
> 
> > On 7 November 2011 16:29, Carsten Dominik 
wrote:
> >> 
> >> On Nov 7, 2011, at 1:19 PM, Giovanni Ridolfi wrote:
> >> 
> >>> Fabrizio Chiarello  writes:
> >>> 
> >>> 
> >>>> I have many tasks with a DEADLINE, and I wish to have their subtasks
to
> >>>> inherit such DEADLINE. To this aim, I set:
> >>>> 
> >>>>  (setq org-use-property-inheritance (quote ("DEADLINE")))
> >>>> 
> >>> 
> >>>> The problem is that the agenda only shows deadlines for the tasks
that
> >>>> define them
> >>> 
> >>> is DEADLINE  a property that can be inherited?
> >> 
> >> Deadlines can currently *not* be inherited.  I would probably advice
> >> against implementing this because of performance issues that would
> >> result for the construction of the agenda.
> >> 
> >> - Carsten
> > 
> > 
> > Hi all,
> > 
> > Here's a thought: what about a function which scans a subtree of an
> > item that has a deadline and adds that same deadline to any
> > descendants that lack a deadline? It seems to me that this would, via
> > a one time user intervention, meet the OP's need, without the constant
> > overhead  about which Carsten is concerned.
> 
> This is a good idea and very easy to do.
> The only disadvantage is that any new entries you make
> would not get the deadline.  Though, I think, one
> could put a function into org-insert-heading-hook
> to check for a deadline higher up in the tree and copy it.
> 
> - Carsten
> 
> > 
> > It further occurred to me that invoked without arguments, it would
> > prompt the user for each item without deadline, with a prefix
> > argument, apply all the deadlines automatically, and, with a numeric
> > prefix n, automatically apply the alterations n-levels down.
> > 
> > Best,
> > 
> > Brian vdB
> 


I solved by adding the following block in the agenda:

;;;
(setq org-agenda-custom-commands
      '( ...
	(" " "Agenda"
	 ( ...
	  (todo "TODO|CANCELLED|NEXT|STARTED|WAITING|HOLD"
		((org-agenda-overriding-header "Inheritable DEADLINEs")
		 (org-agenda-skip-function 'fc/skip-non-inheritable-deadlines)))
))))
;;;

which shows the tasks without deadline that can inherit a deadline from
one of the parents. Then with the following keys I can set the deadline
of a task to that of the parent directly in the agenda.

;;;
(add-hook 'org-agenda-mode-hook
          (lambda ()
	    (org-defkey org-agenda-mode-map "D" 'fc/org-agenda-inherit-deadline))
          'append)

;;;

The rest of the functions are below

;;;
(defun fc/has-inheritable-deadline-p ()
  "Any task (without DEADLINE) that can inherit a DEADLINE"
  (let ((deadline (org-entry-get nil "DEADLINE"))
	(inheritable-deadline (org-entry-get-with-inheritance "DEADLINE")))

    (if (org-not-nil deadline)
	nil
      (if (org-not-nil inheritable-deadline)
	  t
	nil))))

(defun fc/skip-non-inheritable-deadlines ()
  "Skip tasks that cannot inherit a DEADLINE"
  (let* ((next-headline (save-excursion (or (outline-next-heading)
(point-max)))))
    (if (fc/has-inheritable-deadline-p)
	nil
      next-headline)))

(defun fc/org-inherit-deadline ()
  "Inherit a DEADLINE."
  (interactive)
  (let* ((deadline (org-entry-get-with-inheritance "DEADLINE")))
    (if (and (org-not-nil deadline)
	     (y-or-n-p (format "Inherit DEADLINE: <%s>? " deadline)))
	(org-deadline nil (org-time-string-to-time deadline)))))

(defun fc/org-agenda-inherit-deadline (&optional arg)
  "Inherit a DEADLINE in agenda."
  (interactive "P")
  (let* ((marker (or (org-get-at-bol 'org-marker)
		     (org-agenda-error)))
	 (hdmarker (or (org-get-at-bol 'org-hd-marker)
		       marker))
	 (pos (marker-position marker))
	 newhead)
    (org-with-remote-undo (marker-buffer marker)
      (with-current-buffer (marker-buffer marker)
	(widen)
	(goto-char pos)
	(org-show-context 'agenda)
	(org-show-entry)
	(org-cycle-hide-drawers 'children)
	(fc/org-inherit-deadline)
	(setq newhead (org-get-heading)))
      (org-agenda-change-all-lines newhead hdmarker))))

;;;

-- 
Fabrizio Chiarello 
Photonics and Electromagnetics Group
Department of Information Engineering
University of Padova, Italy

Wisdom alone is true ambition's aim, wisdom is the source of virtue and
of fame; obtained with labour, for mankind employed, and then, when most
you share it, best enjoyed.
  -- Alfred North Whitehead
 
CD: 3ms