Skip to content

leathekd/ercn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 

Repository files navigation

ercn - Flexible ERC notifications

Motivation

I was unhappy with the granularity at which I could control notifications in ERC and decided to roll my own. There is a fair chance that I simply failed to understand the tools that ERC-match already provides for this purpose, but I’m reasonably happy with ercn at this point so I decided to publish it anyway.

Installation

Via Emacs Packages (recommended)

On Emacs 24, add Melpa or Melpa Stable (I try to tag releases) as a package archive source in ~/.emacs.d/init.el:

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

Then you can install it:

M-x package-refresh-contents
M-x package-install RET ercn RET

Manually (via git)

Download the source or clone the repo and add the following to ~/.emacs.d/init.el:

(add-to-list 'load-path "path/to/ercn")
(require 'ercn)

Configuration

Two variables control whether or not ercn calls ercn-notify-hook:

  • ercn-notify-rules: Rules to determine if the hook should be called. It defaults to calling the hook whenever a pal speaks, a keyword is mentioned, your current-nick is mentioned, or a message is sent inside a query buffer.
  • ercn-suppress-rules: Rules to determine if the notification should be suppressed. Takes precedent over ercn-notify-rules. The default will suppress messages from fools, dangerous-hosts, and system messages.

Both vars are alists that contain the category of message as the keys and as the value either the symbol all, a list of buffer names in which to notify or suppress, or a function predicate.

The supported categories are:

  • message - category added to all messages
  • current-nick - messages that mention you
  • keyword - words in the erc-keywords list
  • pal - nicks in the erc-pals list
  • query-buffer - private messages
  • fool - nicks in the erc-fools list
  • dangerous-host - hosts in the erc-dangerous-hosts list
  • system - messages sent from the system (join, part, etc.)

An example configuration

(setq ercn-notify-rules
      '((current-nick . all)
        (keyword . all)
        (pal . ("#emacs"))
        (query-buffer . all)))

(defun do-notify (nickname message)
  ;; notification code goes here
  )

(add-hook 'ercn-notify-hook 'do-notify)

In this example, ercn-notify-hook will be called whenever anyone mentions my nick or a keyword or when sent from a query buffer, or if a pal speaks in #emacs.

To call the hook on all messages

(setq ercn-notify-rules '((message . all))
      ercn-suppress-rules nil)

(defun do-notify (nickname message)
  ;; notification code goes here
  )

(add-hook 'ercn-notify-hook 'do-notify)

I wouldn’t recommend it, but it’s your setup.

An example notify hook function

It’s helpful to know what the state of the world is when the hook function is invoked. The following is an example hook. Note, for instance, that the current buffer for the hook function is actually the buffer for the channel where the IRC message was sent.

(defun do-notify (nickname message)
  (let* ((channel (buffer-name))
         ;; using https://github.com/leathekd/erc-hl-nicks
         (nick (erc-hl-nicks-trim-irc-nick nickname))
         (title (if (string-match-p (concat "^" nickname) channel)
                    nick
                  (concat nick " (" channel ")")))
         ;; Using https://github.com/magnars/s.el
         (msg (s-trim (s-collapse-whitespace message))))
    ;; call the system notifier here
    ))

License

Source Copyright © 2012 David Leatherman. Distributed under the GNU General Public License version 3.

About

Flexible ERC notifications

Resources

Stars

Watchers

Forks

Packages

No packages published