emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-orgmode@gnu.org
Subject: Re: notify, when something to do
Date: Sun, 23 Oct 2011 18:20:07 +0200	[thread overview]
Message-ID: <87pqhnade0.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: 87vcrgqav9.fsf@micropit.couberia.bzh

pmlists@free.fr (Peter Münster) writes:

Hi Peter,

> I would like to be notified[1], when a todo item enters the warning
> period, scheduled time, or deadline.

I export my org entries as appt alarms, so that I get system
notifications 15 minutes before meetings (every 1 minute until I
discard them).  Here's the code:

--8<---------------cut here---------------start------------->8---
(defvar th-notify-title-to-id-map (make-hash-table :test 'string=)
  "Maps TITLE values of notifications to the last notification ID.
If ID is -1, then any further notifications with that body will
be skipped.")

(defun th-notify (&rest args)
  "Create a notification popup.
For ARGS, see `notifications-notify'.
There's some new default behavior over the function above:

  - Notifications with same :body replace each other.  :body,
    because my notifications are usually something like

      :title \"Meeting with Hugo\"
      :body \"In 15 Minutes\"

    where each minute a similar notification with decreasing
    minutes in the :body is triggered.

  - If a notification was dismissed, then don't show any
    notifications with that :title anymore (the next 15 minutes).

  - Use unlimited timeout."
  (require 'notifications)
  (let* ((title (plist-get args :body))
	 (body (plist-get args :body))
	 (replaces-id (or (plist-get args :replaces-id)
			  (gethash title th-notify-title-to-id-map)))
	 (on-close (or (plist-get args :on-close)
		       `(lambda (id reason)
			  (when (eq reason 'dismissed)
			    ;; Mark as "don't show again!"
			    (puthash ,title -1 th-notify-title-to-id-map)
			    ;; But clear that "dont-show-mark" after 15 minutes
			    (run-with-timer (* 15 60) nil
					    (lambda ()
					      (remhash ,title th-notify-title-to-id-map)))))))
	 ;; 0 means, it should not expire at all
	 (timeout (or (plist-get args :timeout) 0)))
    (unless (eql replaces-id -1)
      (puthash title (apply 'notifications-notify
			    (th-plist-put-many args
					       :timeout timeout
					       :replaces-id replaces-id
					       :on-close on-close))

(defun th-appt-alarm (mins time text)
  "Show a notification popup (or update the current one) for the
appt with TEXT in MINS minutes (a string)."
  (let ((body (substring-no-properties text)))
     :title text
     :body (concat "Appointment "
		   (if (string= mins "0")
		     (concat "in " mins " minutes:"))))))

(setq appt-display-format 'window
      appt-disp-window-function 'th-appt-alarm
      appt-display-interval 1
      appt-display-duration 60)

(defun th-org-agenda-to-appt ()
  (require 'org-agenda)
  (org-agenda-to-appt t)
  (appt-activate 1))

(add-hook 'org-finalize-agenda-hook 'th-org-agenda-to-appt)
--8<---------------cut here---------------end--------------->8---


  reply	other threads:[~2011-10-23 16:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-23 10:07 notify, when something to do Peter Münster
2011-10-23 16:20 ` Tassilo Horn [this message]
2011-10-23 16:30   ` Tassilo Horn
2011-10-23 18:17   ` Peter Münster
2011-10-23 19:09     ` Tassilo Horn
2011-10-23 21:23       ` Bastien
2011-10-24  5:14         ` Tassilo Horn
2011-10-23 21:29     ` Bastien
2011-10-24  9:29       ` Sebastien Vauban
2011-11-01 23:01       ` Peter Münster
2011-10-24 15:01 ` Christopher Allan Webber
2011-10-25 18:56   ` Marcelo de Moraes Serpa

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:

  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=87pqhnade0.fsf@thinkpad.tsdh.de \
    --to=tassilo@member.fsf.org \
    --cc=emacs-orgmode@gnu.org \


* 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


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).