emacs/lisp/erc/erc-desktop-notifications.el

112 lines
4.2 KiB
EmacsLisp
Raw Normal View History

;; erc-desktop-notifications.el -- Send notification on PRIVMSG or mentions -*- lexical-binding:t -*-
2012-07-21 13:08:32 +02:00
;; Copyright (C) 2012-2020 Free Software Foundation, Inc.
2012-07-21 13:08:32 +02:00
;; Author: Julien Danjou <julien@danjou.info>
;; Maintainer: Amin Bandali <mab@gnu.org>
2012-07-21 13:08:32 +02:00
;; Keywords: comm
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2012-07-21 13:08:32 +02:00
;;; Commentary:
;; This implements notifications using `notifications-notify' on
;; PRIVMSG received and on public nickname mentions.
;;; Code:
(require 'erc)
(require 'xml)
(require 'notifications)
(require 'erc-match)
(require 'dbus)
(defgroup erc-notifications nil
"Send notifications on PRIVMSG or mentions."
Add missing :version tags * profiler.el (profiler): Add missing group :version tag. * avoid.el (mouse-avoidance-banish-position): * proced.el (proced-renice-command): * calc/calc.el (calc-ensure-consistent-units): * calendar/icalendar.el (icalendar-import-format-uid): * net/tramp.el (tramp-save-ad-hoc-proxies): * progmodes/bug-reference.el (bug-reference-bug-regexp): * progmodes/flymake.el (flymake-error-bitmap) (flymake-warning-bitmap, flymake-fringe-indicator-position): * progmodes/sh-script.el (sh-indent-after-continuation): * progmodes/verilog-mode.el (verilog-auto-template-warn-unused) (verilog-before-save-font-hook, verilog-after-save-font-hook): * progmodes/vhdl-mode.el (vhdl-makefile-default-targets) (vhdl-array-index-record-field-in-sensitivity-list) (vhdl-indent-comment-like-next-code-line): * textmodes/reftex-vars.el (reftex-ref-style-alist) (reftex-ref-macro-prompt, reftex-ref-style-default-list) (reftex-cite-key-separator, reftex-create-bibtex-header) (reftex-create-bibtex-footer): * textmodes/rst.el (rst-new-adornment-down, rst-indent-field) (rst-indent-literal-normal, rst-indent-literal-minimized) (rst-indent-comment): Add missing custom :version tags. * cedet/semantic/complete.el (semantic-displayor-tooltip-mode) (semantic-displayor-tooltip-initial-max-tags) (semantic-displayor-tooltip-max-tags): Add missing custom :version tags. * cedet/ede/linux.el (project-linux): Add missing group :version tag. * cedet/semantic/complete.el (semantic-displayor-tooltip-max-tags): Doc fix. * erc/erc.el (erc-lurker): * erc/erc-desktop-notifications.el (erc-notifications): Add missing group :version tags. * gnus/gnus-notifications.el (gnus-notifications): Add missing group :version tag. * gnus/gnus-msg.el (gnus-gcc-pre-body-encode-hook) (gnus-gcc-post-body-encode-hook): * gnus/gnus-sync.el (gnus-sync-lesync-name) (gnus-sync-lesync-install-topics): Add missing custom :version tags.
2012-10-06 13:30:26 -07:00
:version "24.3"
2012-07-21 13:08:32 +02:00
:group 'erc)
(defvar erc-notifications-last-notification nil
"Last notification id.")
(defcustom erc-notifications-icon nil
"Icon to use for notification."
:group 'erc-notifications
Fix a bunch of custom types (thank you cus-test.el) * lisp/bookmark.el (bookmark-search-delay): * lisp/cus-start.el (vertical-centering-font-regexp): * lisp/ps-mule.el (ps-mule-font-info-database-default): * lisp/ps-print.el (ps-default-fg, ps-default-bg): * lisp/type-break.el (type-break-good-break-interval): * lisp/whitespace.el (whitespace-indentation-regexp) (whitespace-space-after-tab-regexp): * lisp/emacs-lisp/testcover.el (testcover-1value-functions) (testcover-noreturn-functions, testcover-progn-functions) (testcover-prog1-functions): * lisp/emulation/viper-init.el (viper-emacs-state-cursor-color): * lisp/erc/erc-desktop-notifications.el (erc-notifications-icon): * lisp/eshell/em-glob.el (eshell-glob-translate-alist): * lisp/gnus/gnus-art.el (gnus-article-date-headers, gnus-blocked-images): * lisp/gnus/gnus-async.el (gnus-async-post-fetch-function): * lisp/gnus/gnus-gravatar.el (gnus-gravatar-size, gnus-gravatar-properties): * lisp/gnus/gnus-html.el (gnus-html-image-cache-ttl): * lisp/gnus/gnus-notifications.el (gnus-notifications-timeout): * lisp/gnus/gnus-picon.el (gnus-picon-properties): * lisp/gnus/gnus-util.el (gnus-completion-styles): * lisp/gnus/gnus.el (gnus-other-frame-resume-function): * lisp/gnus/message.el (message-user-organization-file) (message-cite-reply-position): * lisp/gnus/nnir.el (nnir-summary-line-format) (nnir-retrieve-headers-override-function): * lisp/gnus/shr-color.el (shr-color-visible-luminance-min): * lisp/gnus/shr.el (shr-blocked-images): * lisp/gnus/spam-report.el (spam-report-resend-to): * lisp/gnus/spam.el (spam-summary-exit-behavior): * lisp/mh-e/mh-e.el (mh-sortm-args, mh-default-folder-for-message-function): * lisp/play/tetris.el (tetris-tty-colors): * lisp/progmodes/cpp.el (cpp-face-default-list): * lisp/progmodes/flymake.el (flymake-allowed-file-name-masks): * lisp/progmodes/idlw-help.el (idlwave-help-browser-generic-program) (idlwave-help-browser-generic-args): * lisp/progmodes/make-mode.el (makefile-special-targets-list): * lisp/progmodes/python.el (python-shell-virtualenv-path): * lisp/progmodes/verilog-mode.el (verilog-active-low-regexp) (verilog-auto-input-ignore-regexp, verilog-auto-inout-ignore-regexp) (verilog-auto-output-ignore-regexp, verilog-auto-tieoff-ignore-regexp) (verilog-auto-unused-ignore-regexp, verilog-typedef-regexp): * lisp/textmodes/reftex-vars.el (reftex-format-label-function): * lisp/textmodes/remember.el (remember-diary-file): Fix custom types. * lisp/cedet/semantic/db-find.el (semanticdb-find-throttle-custom-list): Fix value. * lisp/gnus/gnus-salt.el (gnus-selected-tree-face): Fix default.
2013-05-08 21:40:20 -04:00
:type '(choice (const :tag "No icon" nil) file))
2012-07-21 13:08:32 +02:00
(defcustom erc-notifications-bus :session
"D-Bus bus to use for notification."
:version "25.1"
:group 'erc-notifications
:type '(choice (const :tag "Session bus" :session) string))
(defvar dbus-debug) ; used in the macroexpansion of dbus-ignore-errors
2012-07-21 13:08:32 +02:00
(defun erc-notifications-notify (nick msg)
"Notify that NICK send some MSG.
This will replace the last notification sent with this function."
(dbus-ignore-errors
(setq erc-notifications-last-notification
(let ((channel (erc-get-buffer nick)))
(notifications-notify :bus erc-notifications-bus
:title (format "%s in %s"
(xml-escape-string nick)
channel)
:body (xml-escape-string msg)
:replaces-id erc-notifications-last-notification
:app-icon erc-notifications-icon
:actions '("default" "Switch to buffer")
:on-action (lambda (&rest _)
(pop-to-buffer channel)))))))
(defun erc-notifications-PRIVMSG (_proc parsed)
2012-07-21 13:08:32 +02:00
(let ((nick (car (erc-parse-user (erc-response.sender parsed))))
(target (car (erc-response.command-args parsed)))
(msg (erc-response.contents parsed)))
(when (and (erc-current-nick-p target)
(not (and (boundp 'erc-track-exclude)
(member nick erc-track-exclude)))
(not (erc-is-message-ctcp-and-not-action-p msg)))
(erc-notifications-notify nick msg)))
;; Return nil to continue processing by ERC
nil)
(defun erc-notifications-notify-on-match (match-type nickuserhost msg)
(when (eq match-type 'current-nick)
(let ((nick (nth 0 (erc-parse-user nickuserhost))))
(unless (or (string-match-p "^Server:" nick)
(when (boundp 'erc-track-exclude)
(member nick erc-track-exclude)))
(erc-notifications-notify nick msg)))))
;;;###autoload(autoload 'erc-notifications-mode "erc-desktop-notifications" "" t)
2012-07-21 13:08:32 +02:00
(define-erc-module notifications nil
"Send notifications on private message reception and mentions."
;; Enable
((add-hook 'erc-server-PRIVMSG-functions 'erc-notifications-PRIVMSG)
(add-hook 'erc-text-matched-hook 'erc-notifications-notify-on-match))
;; Disable
((remove-hook 'erc-server-PRIVMSG-functions 'erc-notifications-PRIVMSG)
(remove-hook 'erc-text-matched-hook 'erc-notifications-notify-on-match)))
(provide 'erc-desktop-notifications)
2012-07-21 13:08:32 +02:00
;;; erc-desktop-notifications.el ends here
;; Local Variables:
;; generated-autoload-file: "erc-loaddefs.el"
;; End: