diff options
| author | Julien Danjou | 2012-07-21 13:08:32 +0200 |
|---|---|---|
| committer | Julien Danjou | 2012-07-21 13:08:32 +0200 |
| commit | f1e8a7f1a52f13291bf8e45106233059add14e89 (patch) | |
| tree | ec234205f09afb4a30a2e0305a317cb2f6fb1657 | |
| parent | 0fb40182ca2991975bb419199fa48bfc7d322dad (diff) | |
| download | emacs-f1e8a7f1a52f13291bf8e45106233059add14e89.tar.gz emacs-f1e8a7f1a52f13291bf8e45106233059add14e89.zip | |
erc-notifications: new file
| -rw-r--r-- | lisp/erc/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/erc/erc-notifications.el | 90 |
2 files changed, 94 insertions, 0 deletions
diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog index f84df4c7b89..37758048258 100644 --- a/lisp/erc/ChangeLog +++ b/lisp/erc/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2012-07-21 Julien Danjou <julien@danjou.info> | ||
| 2 | |||
| 3 | * erc-notifications.el: New file. | ||
| 4 | |||
| 1 | 2012-06-15 Julien Danjou <julien@danjou.info> | 5 | 2012-06-15 Julien Danjou <julien@danjou.info> |
| 2 | 6 | ||
| 3 | * erc.el (erc-open): Use `auth-source' for password retrieval when | 7 | * erc.el (erc-open): Use `auth-source' for password retrieval when |
diff --git a/lisp/erc/erc-notifications.el b/lisp/erc/erc-notifications.el new file mode 100644 index 00000000000..4faffc913c5 --- /dev/null +++ b/lisp/erc/erc-notifications.el | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | ;; erc-notifications.el -- Send notification on PRIVMSG or mentions | ||
| 2 | |||
| 3 | ;; Copyright (C) 2012 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Julien Danjou <julien@danjou.info> | ||
| 6 | ;; Keywords: comm | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; This implements notifications using `notifications-notify' on | ||
| 26 | ;; PRIVMSG received and on public nickname mentions. | ||
| 27 | |||
| 28 | ;;; Code: | ||
| 29 | |||
| 30 | (require 'erc) | ||
| 31 | (require 'xml) | ||
| 32 | (require 'notifications) | ||
| 33 | (require 'erc-match) | ||
| 34 | (require 'dbus) | ||
| 35 | |||
| 36 | (defgroup erc-notifications nil | ||
| 37 | "Send notifications on PRIVMSG or mentions." | ||
| 38 | :group 'erc) | ||
| 39 | |||
| 40 | (defvar erc-notifications-last-notification nil | ||
| 41 | "Last notification id.") | ||
| 42 | |||
| 43 | (defcustom erc-notifications-icon nil | ||
| 44 | "Icon to use for notification." | ||
| 45 | :group 'erc-notifications | ||
| 46 | :type 'file) | ||
| 47 | |||
| 48 | (defun erc-notifications-notify (nick msg) | ||
| 49 | "Notify that NICK send some MSG. | ||
| 50 | This will replace the last notification sent with this function." | ||
| 51 | (dbus-ignore-errors | ||
| 52 | (setq erc-notifications-last-notification | ||
| 53 | (notifications-notify :title (xml-escape-string nick) | ||
| 54 | :body (xml-escape-string msg) | ||
| 55 | :replaces-id erc-notifications-last-notification | ||
| 56 | :app-icon erc-notifications-icon)))) | ||
| 57 | |||
| 58 | (defun erc-notifications-PRIVMSG (proc parsed) | ||
| 59 | (let ((nick (car (erc-parse-user (erc-response.sender parsed)))) | ||
| 60 | (target (car (erc-response.command-args parsed))) | ||
| 61 | (msg (erc-response.contents parsed))) | ||
| 62 | (when (and (erc-current-nick-p target) | ||
| 63 | (not (and (boundp 'erc-track-exclude) | ||
| 64 | (member nick erc-track-exclude))) | ||
| 65 | (not (erc-is-message-ctcp-and-not-action-p msg))) | ||
| 66 | (erc-notifications-notify nick msg))) | ||
| 67 | ;; Return nil to continue processing by ERC | ||
| 68 | nil) | ||
| 69 | |||
| 70 | (defun erc-notifications-notify-on-match (match-type nickuserhost msg) | ||
| 71 | (when (eq match-type 'current-nick) | ||
| 72 | (let ((nick (nth 0 (erc-parse-user nickuserhost)))) | ||
| 73 | (unless (or (string-match-p "^Server:" nick) | ||
| 74 | (when (boundp 'erc-track-exclude) | ||
| 75 | (member nick erc-track-exclude))) | ||
| 76 | (erc-notifications-notify nick msg))))) | ||
| 77 | |||
| 78 | ;;;###autoload(autoload 'erc-notifications-mode "erc-notifications" "" t) | ||
| 79 | (define-erc-module notifications nil | ||
| 80 | "Send notifications on private message reception and mentions." | ||
| 81 | ;; Enable | ||
| 82 | ((add-hook 'erc-server-PRIVMSG-functions 'erc-notifications-PRIVMSG) | ||
| 83 | (add-hook 'erc-text-matched-hook 'erc-notifications-notify-on-match)) | ||
| 84 | ;; Disable | ||
| 85 | ((remove-hook 'erc-server-PRIVMSG-functions 'erc-notifications-PRIVMSG) | ||
| 86 | (remove-hook 'erc-text-matched-hook 'erc-notifications-notify-on-match))) | ||
| 87 | |||
| 88 | (provide 'erc-notifications) | ||
| 89 | |||
| 90 | ;;; erc-notifications.el ends here | ||