all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: help-gnu-emacs@gnu.org
Subject: Re: use linux native notifications with tea-time
Date: Wed, 08 Jun 2011 08:51:34 +0200	[thread overview]
Message-ID: <877h8wg6ix.fsf@member.fsf.org> (raw)
In-Reply-To: BANLkTikbQPUmmEOEKvWOkDZS+_0vXC8ckQ@mail.gmail.com

Hi Benjamin,

in case you are using Emacs 24, that comes with notifications.el, which
allows sending off notifications via DBUS.  Just check the function
`notifications-notify'.

For my personal use, I've created some wrapper around it that changes
some defaults and allows for dismissing notifications.

--8<---------------cut here---------------start------------->8---
(defun th-plist-put-many (plist &rest args)
  "Put all prop-value pairs given in ARGS into PLIST.

Example:
  (th-plist-put-many '(:a 1 :b 2) :a 10 :c 30 :d 40)
  ==> (:a 10 :b 2 :c 30 :d 40)"
  (let ((rest args))
    (while rest
      (setq plist (plist-put plist (car rest) (cadr rest)))
      (setq rest (cddr rest)))
    plist))

(defvar th-notify-body-to-id-map (make-hash-table :test 'string=)
  "Maps BODY 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 \"In 15 Minutes\"
      :body \"Meeting with Hugo\"

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

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

  - Use unlimited timeout."
  (require 'notifications)
  (let* ((body (plist-get args :body))
	 (replaces-id (or (plist-get args :replaces-id)
			  (gethash body th-notify-body-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 ,body -1 th-notify-body-to-id-map)
			    ;; But clear that "dont-show-mark" after 15 minutes
			    (run-with-timer (* 15 60) nil
					    (lambda ()
					      (remhash ,body th-notify-body-to-id-map)))))))
	 (timeout (or (plist-get args :timeout)
		      ;; 0 means, it should not expire at all
		      0)))
    (unless (eql replaces-id -1)
      (puthash body (apply 'notifications-notify
			   (th-plist-put-many args
					      :timeout timeout
					      :replaces-id replaces-id
					      :on-close on-close))
	       th-notify-body-to-id-map))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




  reply	other threads:[~2011-06-08  6:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06 19:28 use linux native notifications with tea-time Benjamin Slade
2011-06-08  6:51 ` Tassilo Horn [this message]
2011-06-08 14:42 ` Dove Young
2011-06-08 15:37   ` Benjamin Slade
2011-06-10  5:33     ` Kevin Rodgers
2011-06-10  5:23   ` Kevin Rodgers

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

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

  git send-email \
    --in-reply-to=877h8wg6ix.fsf@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=help-gnu-emacs@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.