EOS: Notification Module

Table of Contents

(provide 'eos-notify)

A Word about Notifications and Alerting

Yep. I need to actually make this work for OSX, for Linux it's no problem though.

(use-package alert
  :ensure t
  :config
  (when (eq system-type 'darwin)
    (setq alert-default-style 'notifier))
  (when (eq system-type 'gnu/linux)
    (setq alert-default-style 'notifications)))

To use this, I just need to do (alert "this is a message").

The all-seeing eye of Sauron

(use-package sauron
  :ensure t
  :init
  (when (not (boundp 'dbus-compiled-version))
    ;; Remove dbus if it is not compiled
    (require 'sauron)
    (setq sauron-modules (remove 'sauron-dbus sauron-modules)))

  (setq sauron-max-line-length 120
        sauron-watch-patterns '("dakrone" "thnetos" "okenezak")
        sauron-watch-nicks '("dakrone" "thnetos")
        sauron-nick-insensitivity 20
        sauron-prio-twittering-new-tweets 2
        sauron-frame-geometry "120x36+0+0")
  ;; filter out IRC spam
  (defun tsp/hide-irc-user-spam (origin priority msg &optional properties)
    (or (string-match "^*** Users" msg)))
  (defun tsp/hide-tweet-counts (origin priority msg &optional properties)
    (or (string-match "^[0-9]+ new tweets" msg)))
  (add-hook 'sauron-event-block-functions #'tsp/hide-irc-user-spam)
  (add-hook 'sauron-event-block-functions #'tsp/hide-tweet-counts)

  (sauron-start-hidden)
  ;; Need to stop tracking notifications, because sauron will be sending
  ;; notifications!
  (sauron-notifications-stop)
  (add-hook 'sauron-event-added-functions 'sauron-alert-el-adapter)
  :commands (sauron-toggle-hide-show)
  :bind ("M-o" . sauron-toggle-hide-show)
  :config
  ;; Add the unread sauron notification count to the modeline
  ;;(add-to-list 'global-mode-string '(cdr (sauron-count-events)))

  (defun eos/compilation-finish (buffer msg)
    "Send a sauron notification for compilation completing"
    (interactive)
    (sauron-add-event 'compilation
                      3
                      (format "[%s]: %s" buffer msg)
                      (lambda () (switch-to-buffer-other-window "*compilation*"))
                      nil))
  (add-to-list 'compilation-finish-functions #'eos/compilation-finish)

  (defun finish ()
    "Generic function for signaling something is \"done\"."
    (interactive)
    (sauron-add-event major-mode
                      3
                      (concat "Finished command in " (buffer-name))
                      (lambda () (switch-to-buffer-other-window (buffer-name)))
                      nil)))

Notifications for running commands in Eshell

This is used to mimic zsh's REPORTTIME feature, but with sauron alerting!

(use-package eshell
  :config
  ;; Seconds a command must take before showing an alert
  (setq eos/eshell-time-before-alert 5.0)

  (defun eos/eshell-precommand ()
    (interactive)
    (setq-local eos/eshell-command-start-time (current-time)))

  (defun eos/eshell-command-finished ()
    (interactive)
    (when (and (boundp 'eos/eshell-command-start-time)
           (> (float-time (time-subtract (current-time)
                                          eos/eshell-command-start-time))
               eos/eshell-time-before-alert))
      (sauron-add-event major-mode
                        (if (zerop eshell-last-command-status)
                            3
                          4)
                        (format "EShell: command [%s] finished, status: %s"
                                eshell-last-command-name
                                eshell-last-command-status)
                        (lambda () (switch-to-buffer-other-window (buffer-name)))
                        nil)))
  (add-hook 'eshell-pre-command-hook #'eos/eshell-precommand)
  (add-hook 'eshell-post-command-hook #'eos/eshell-command-finished))

Author: Lee Hinman

Created: 2017-08-21 Mon 14:26