emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Fabrizio Chiarello <fabrizio.chiarello@ieee.org>
To: emacs-orgmode@gnu.org
Cc: Brian van den Broek <brian.van.den.broek@gmail.com>,
	Carsten Dominik <carsten.dominik@gmail.com>
Subject: Re: View inherited DEADLINEs in agenda
Date: Mon, 14 Nov 2011 14:38:27 +0100	[thread overview]
Message-ID: <20111114133827.GA7282@hydrogen.black.hole> (raw)
In-Reply-To: <A341EB4D-21F5-4B04-A3DE-75FFE43CE56D@gmail.com>

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 <carsten.dominik@gmail.com> wrote:
> >> 
> >> On Nov 7, 2011, at 1:19 PM, Giovanni Ridolfi wrote:
> >> 
> >>> Fabrizio Chiarello <fabrizio.chiarello@ieee.org> 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 <fabrizio.chiarello@ieee.org>
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

  reply	other threads:[~2011-11-14 13:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-07 12:03 View inherited DEADLINEs in agenda Fabrizio Chiarello
2011-11-07 12:19 ` Giovanni Ridolfi
2011-11-07 12:22   ` suvayu ali
2011-11-07 13:16     ` Fabrizio Chiarello
2011-11-07 13:23       ` Gustav Wikström
2011-11-07 14:29   ` Carsten Dominik
2011-11-07 19:46     ` Fabrizio Chiarello
2011-11-08 22:35     ` Brian van den Broek
2011-11-09  8:10       ` Carsten Dominik
2011-11-14 13:38         ` Fabrizio Chiarello [this message]
2012-04-03  7:16           ` Bastien
2012-04-11 13:38             ` Vedang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111114133827.GA7282@hydrogen.black.hole \
    --to=fabrizio.chiarello@ieee.org \
    --cc=brian.van.den.broek@gmail.com \
    --cc=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).