dot/ercrc.el: Remove IRC servers I can't talk to any more.
[profile] / dot / ercrc.el
1 ;;; -*-emacs-lisp-*-
2 ;;;
3 ;;; ERC configuration
4
5 (setq erc-nick "mdw"
6 erc-user-full-name "Mark Wooding")
7
8 (if (not (memq 'truncate erc-modules))
9 (setq erc-modules (cons 'truncate erc-modules)))
10
11 (setq erc-fill-column 76
12 erc-timestamp-right-column 68
13 erc-fill-prefix " "
14 erc-max-buffer-size (* 60 3000))
15
16 (load "~/.erc-local.el")
17
18 (setq erc-track-exclude-types '("NICK" "JOIN" "PART"))
19
20 (setq erc-auto-query 'buffer)
21
22 (defun mdw-erc-turn-off-truncate-lines ()
23 (setq truncate-lines nil
24 truncate-partial-with-windows nil
25 word-wrap t
26 wrap-prefix (concat (propertize " " 'face 'erc-prompt-face)
27 " ")))
28 (add-hook 'erc-mode-hook 'mdw-erc-turn-off-truncate-lines)
29
30 (setq erc-autojoin t
31 erc-autojoin-domain-only nil
32 erc-autojoin-channels-alist
33 '(("chiark.greenend.org.uk" "#chiark")
34 ("irc.distorted.org.uk" "#distorted" "#jukebox")
35 ("irc.hstg.corp.good.com" "#hstg")))
36
37 (defvar mdw-erc-auto-greet-bots-alist nil
38 "*Alist of (SERVER-REGEXP BOT-NICK MESSAGE-FORM).
39 Evaluate MESSAGE-FORM and sent to BOT-NICK when connected to a server which
40 matches SERVER-REGEXP.")
41
42 (defvar mdw-erc-ircop-alist nil
43 "*Alist of (SERVER-REGEXP ACCT PASSWD).
44 Login details for claiming server admin rights.")
45
46 (defun mdw-remprop-nondestructive (indic plist)
47 "Return a plist like PLIST, only without the first entry for INDIC.
48 The PLIST is not itself modified."
49 (if (getf plist indic)
50 (let* ((head (cons nil nil))
51 (tail head))
52 (while (and plist (not (eq (car plist) indic)))
53 (let* ((i (pop plist)) (v (pop plist))
54 (vv (cons v nil)) (ii (cons i vv)))
55 (rplacd tail ii)
56 (setq tail vv)))
57 (rplacd tail (cddr plist))
58 (cdr head))
59 plist))
60
61 (defun* mdw-cons-replace
62 (item list &rest keys &key (key '#'identity) &allow-other-keys)
63 "Return LIST, with ITEM at the start, replacing any existing matching item.
64 Specifically, any item in the list satisfying the test are removed
65 \(nondestructively), and then the new ITEM is added to the front."
66 (cons item (apply #'remove* (funcall key item) list :key key
67 (mdw-remprop-nondestructive :key keys))))
68
69 (defmacro* mdw-pushnew-replace (item place &rest keys)
70 "Add ITEM to the list PLACE, replacing any existing matching item.
71 Specifically, any item in the list satisfying the test are removed
72 \(nondestructively), and then the new ITEM is added to the front.
73
74 Evaluation order for the keywords is a bit screwy: don't rely on it."
75 (cond ((fboundp 'cl-callf2)
76 `(cl-callf2 mdw-cons-replace ,item ,place ,@keys))
77 ((fboundp 'cl-setf-do-modify)
78 ;; `cl-setf-do-modify' returns a list (LETS STORE FETCH).
79 (let ((setf-things (cl-setf-do-modify place (cons 'list keys))))
80 `(let (,@(car setf-things))
81 ,(cl-setf-do-store (cadr setf-things)
82 `(mdw-cons-replace ,item ,place
83 ,@keys)))))
84 (t (error "Don't know how to hack places on this Emacs."))))
85
86 (defun mdw-define-bot-greeting (server bot greeting)
87 "Define a new bot greeting."
88 (mdw-pushnew-replace (list server bot greeting)
89 mdw-erc-auto-greet-bots-alist
90 :test #'string= :key #'car))
91 (defun mdw-add-ircop-credentials (server acct passwd)
92 "Define a new set of `ircop' credentials."
93 (mdw-pushnew-replace (list server acct passwd)
94 mdw-erc-ircop-alist
95 :test #'string= :key #'car))
96 (load "~/.erc-auth.el")
97
98 (defun mdw-assoc-regexp (regexp alist)
99 "Return the association in ALIST whose car matches REGEXP."
100 (let ((answer nil))
101 (dolist (l alist)
102 (when (string-match (car l) regexp)
103 (setq answer l)))
104 answer))
105
106 (defun mdw-erc-auto-greet-bots (server nick)
107 "Send greeting message to bots."
108 (let ((a (mdw-assoc-regexp server mdw-erc-auto-greet-bots-alist)))
109 (when a
110 (let ((bot (cadr a))
111 (message (caddr a)))
112 (erc-server-send (concat "PRIVMSG " bot " :" message))))))
113 (add-hook 'erc-after-connect 'mdw-erc-auto-greet-bots)
114
115 (defun erc-cmd-GREET ()
116 "Send greeting messages, according to `mdw-erc-auto-greet-bots-alist'."
117 (mdw-erc-auto-greet-bots erc-session-server (erc-current-nick)))
118
119 (defun erc-cmd-IRCOP ()
120 "Claim `ircop' privileges."
121 (let ((a (mdw-assoc-regexp erc-session-server mdw-erc-ircop-alist)))
122 (when a
123 (let ((acct (cadr a))
124 (passwd (caddr a)))
125 (erc-server-send (concat "OPER " acct " " passwd))))))