notifications for erc.

This commit is contained in:
Ivan Malison 2014-11-21 10:43:09 -08:00
parent a432b94330
commit 702b0319a4
3 changed files with 103 additions and 40 deletions

View File

@ -16,6 +16,7 @@
keyboard-quit
kill-region
org-self-insert-command
phi-search
python-indent-electric-colon
sgml-slash
skeleton-pair-insert-maybe

77
init.el
View File

@ -152,14 +152,6 @@ buffer is not visiting a file."
(ido-read-file-name "Find file (as root): ")))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
(defun get-buffer-name ()
(interactive)
(file-relative-name (buffer-file-name)))
(defun message-buffer-name ()
(interactive)
(message (get-buffer-name)))
(defun frame-exists ()
(cl-find-if
(lambda (frame)
@ -348,6 +340,26 @@ buffer is not visiting a file."
:config (setq expand-region-contract-fast-key "j")
:bind (("C-c k" . er/expand-region)))
(use-package multiple-cursors
:bind
(("C-c m a" . mc/mark-all-like-this)
("C-c m m" . mc/mark-all-like-this-dwim)
("C-c m l" . mc/edit-lines)
("C-c m n" . mc/mark-next-like-this)
("C-c m p" . mc/mark-previous-like-this)
("C-c m s" . mc/mark-sgml-tag-pair)
("C-c m d" . mc/mark-all-like-this-in-defun)))
(use-package phi-search-mc
:ensure t
:config
(phi-search-mc/setup-keys))
(use-package mc-extras
:ensure t
:config
(define-key mc/keymap (kbd "C-. =") 'mc/compare-chars))
(use-package undo-tree
:ensure t
:bind ("C-c u" . undo-tree-visualize)
@ -377,6 +389,10 @@ buffer is not visiting a file."
:commands string-inflection-toggle
:bind ("C-c l" . string-inflection-toggle))
;; =============================================================================
;; Non-Programming Stuff
;; =============================================================================
(use-package org
:ensure t
:defer t
@ -397,7 +413,13 @@ buffer is not visiting a file."
:config
(epa-file-enable))
(use-package erc :ensure t :commands erc)
(use-package erc
:ensure t :commands erc
:config (use-package erc-colorize :ensure t) (erc-colorize-mode 1)))
(use-package gnus
:ensure t
:commands
;; =============================================================================
;; Programming Mode Hooks
@ -461,15 +483,15 @@ buffer is not visiting a file."
:commands (helm-projectile-on)
:defer t)))
(use-package smex
:ensure t
:bind ("M-x" . smex))
(ido-mode t)
(ido-ubiquitous-mode)
(ido-everywhere 1)
(setq ido-enable-flex-matching t)
(use-package smex
:ensure t
:bind ("M-x" . smex))
;; =============================================================================
;; elisp
;; =============================================================================
@ -606,8 +628,7 @@ buffer is not visiting a file."
:ensure t
:commands (js-mode)
:bind
(("C-c b" . web-beautify-js)
("C-c b" . web-beautify-js))
(("C-c b" . web-beautify-js))
:init
(progn
(use-package skewer-mode
@ -637,11 +658,6 @@ buffer is not visiting a file."
(add-hook 'css-mode-hook #'skewer-css-mode)
(add-hook 'html-mode-hook #'skewer-html-mode)
(add-hook 'css-mode-hook
(lambda ()
(define-key css-mode-map "\M-\C-x" 'slime-js-refresh-css)
(define-key css-mode-map "\C-c\C-r" 'slime-js-embed-css)))
(eval-after-load 'sgml-mode
'(define-key html-mode-map (kbd "C-c b") 'web-beautify-html))
(eval-after-load 'css-mode
@ -653,6 +669,7 @@ buffer is not visiting a file."
(use-package robe
:ensure t
:commands robe-mode
:init
(progn (add-hook 'ruby-mode-hook 'robe-mode)
(add-hook 'robe-mode-hook 'ac-robe-setup)
@ -715,31 +732,11 @@ buffer is not visiting a file."
;; =============================================================================
;; Custom Key Bindings
;; =============================================================================
(use-package multiple-cursors
:bind
(("C-c m a" . mc/mark-all-like-this)
("C-c m m" . mc/mark-all-like-this-dwim)
("C-c m l" . mc/edit-lines)
("C-c m n" . mc/mark-next-like-this)
("C-c m p" . mc/mark-previous-like-this)
("C-c m s" . mc/mark-sgml-tag-pair)
("C-c m d" . mc/mark-all-like-this-in-defun)))
(use-package phi-search-mc
:ensure t
:config
(phi-search-mc/setup-keys))
(use-package mc-extras
:ensure t
:config
(define-key mc/keymap (kbd "C-. =") 'mc/compare-chars))
;; Miscellaneous
(global-unset-key (kbd "C-o")) ;; Avoid collision with tmux binding.
(bind-key "M-q" 'fill-or-unfill-paragraph)
(bind-key "C--" 'undo)
(bind-key "C-c +" 'message-buffer-name)
(bind-key "C-c C-s" 'sudo-edit)
(bind-key "C-c SPC"
(lambda () (interactive)

65
lisp/erc-notify.el Normal file
View File

@ -0,0 +1,65 @@
;;; Notify me when a keyword is matched (someone wants to reach me)
(defvar my-erc-page-message "%s is calling your name."
"Format of message to display in dialog box")
(defvar my-erc-page-nick-alist nil
"Alist of nicks and the last time they tried to trigger a
notification")
(defvar my-erc-page-timeout 30
"Number of seconds that must elapse between notifications from
the same person.")
(defun my-erc-page-popup-notification (nick msg)
(notification-center-command (format "%s says:" nick) msg))
(defun my-erc-page-allowed (nick &optional delay)
"Return non-nil if a notification should be made for NICK.
If DELAY is specified, it will be the minimum time in seconds
that can occur between two notifications. The default is
`my-erc-page-timeout'."
(unless delay (setq delay my-erc-page-timeout))
(let ((cur-time (time-to-seconds (current-time)))
(cur-assoc (assoc nick my-erc-page-nick-alist))
(last-time))
(if cur-assoc
(progn
(setq last-time (cdr cur-assoc))
(setcdr cur-assoc cur-time)
(> (abs (- cur-time last-time)) delay))
(push (cons nick cur-time) my-erc-page-nick-alist)
t)))
(defun my-erc-page-me (match-type nick message)
"Notify the current user when someone sends a message that
matches a regexp in `erc-keywords'."
(interactive)
(when (and (eq match-type 'keyword)
;; I don't want to see anything from the erc server
(null (string-match "\\`\\([sS]erver\\|localhost\\)" nick))
;; or bots
(null (string-match "\\(bot\\|serv\\)!" nick))
;; or from those who abuse the system
(my-erc-page-allowed nick))
(my-erc-page-popup-notification nick)))
(defun my-erc-page-me-PRIVMSG (proc parsed)
(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 (erc-is-message-ctcp-and-not-action-p msg))
(my-erc-page-allowed nick))
(my-erc-page-popup-notification nick msg)
nil)))
(add-hook 'erc-text-matched-hook 'my-erc-page-me)
(add-hook 'erc-server-PRIVMSG-functions 'my-erc-page-me-PRIVMSG)
(defvar notify-function #'notification-center)
(defun notification-center-command (title message)
(flet ((encfn (s) (encode-coding-string s (keyboard-coding-system))))
(shell-command (format "osascript -e 'display notification \"%s\" with title \"%s\"'"
(encfn message) (encfn title)))))