dot/ercrc.el: Hack `mdw-pushnew-replace' for newer Emacsen.
[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 '(("irc.ssdis.loc" "#devel" "#jukebox" "#nextgen")
34 ("cam.irc.devel.ncipher.com"
35 "#devel" "#jukebox" "#nextgen" "#sec-team")
36 ("chiark.greenend.org.uk" "#chiark")
37 ("irc.distorted.org.uk" "#distorted" "#jukebox")
38 ("irc.hstg.corp.good.com" "#hstg")))
39
40 (defvar mdw-erc-auto-greet-bots-alist nil
41 "*Alist of (SERVER-REGEXP BOT-NICK MESSAGE-FORM).
42 Evaluate MESSAGE-FORM and sent to BOT-NICK when connected to a server which
43 matches SERVER-REGEXP.")
44
45 (defvar mdw-erc-ircop-alist nil
46 "*Alist of (SERVER-REGEXP ACCT PASSWD).
47 Login details for claiming server admin rights.")
48
49 (defun mdw-remprop-nondestructive (indic plist)
50 "Return a plist like PLIST, only without the first entry for INDIC.
51 The PLIST is not itself modified."
52 (if (getf plist indic)
53 (let* ((head (cons nil nil))
54 (tail head))
55 (while (and plist (not (eq (car plist) indic)))
56 (let* ((i (pop plist)) (v (pop plist))
57 (vv (cons v nil)) (ii (cons i vv)))
58 (rplacd tail ii)
59 (setq tail vv)))
60 (rplacd tail (cddr plist))
61 (cdr head))
62 plist))
63
64 (defun* mdw-cons-replace
65 (item list &rest keys &key (key '#'identity) &allow-other-keys)
66 "Return LIST, with ITEM at the start, replacing any existing matching item.
67 Specifically, any item in the list satisfying the test are removed
68 \(nondestructively), and then the new ITEM is added to the front."
69 (cons item (apply #'remove* (funcall key item) list :key key
70 (mdw-remprop-nondestructive :key keys))))
71
72 (defmacro* mdw-pushnew-replace (item place &rest keys)
73 "Add ITEM to the list PLACE, replacing any existing matching item.
74 Specifically, any item in the list satisfying the test are removed
75 \(nondestructively), and then the new ITEM is added to the front.
76
77 Evaluation order for the keywords is a bit screwy: don't rely on it."
78 (cond ((fboundp 'cl-callf2)
79 `(cl-callf2 mdw-cons-replace ,item ,place ,@keys))
80 ((fboundp 'cl-setf-do-modify)
81 ;; `cl-setf-do-modify' returns a list (LETS STORE FETCH).
82 (let ((setf-things (cl-setf-do-modify place (cons 'list keys))))
83 `(let (,@(car setf-things))
84 ,(cl-setf-do-store (cadr setf-things)
85 `(mdw-cons-replace ,item ,place
86 ,@keys)))))
87 (t (error "Don't know how to hack places on this Emacs."))))
88
89 (defun mdw-define-bot-greeting (server bot greeting)
90 "Define a new bot greeting."
91 (mdw-pushnew-replace (list server bot greeting)
92 mdw-erc-auto-greet-bots-alist
93 :test #'string= :key #'car))
94 (defun mdw-add-ircop-credentials (server acct passwd)
95 "Define a new set of `ircop' credentials."
96 (mdw-pushnew-replace (list server acct passwd)
97 mdw-erc-ircop-alist
98 :test #'string= :key #'car))
99 (load "~/.erc-auth.el")
100
101 (defun mdw-assoc-regexp (regexp alist)
102 "Return the association in ALIST whose car matches REGEXP."
103 (let ((answer nil))
104 (dolist (l alist)
105 (when (string-match (car l) regexp)
106 (setq answer l)))
107 answer))
108
109 (defun mdw-erc-auto-greet-bots (server nick)
110 "Send greeting message to bots."
111 (let ((a (mdw-assoc-regexp server mdw-erc-auto-greet-bots-alist)))
112 (when a
113 (let ((bot (cadr a))
114 (message (caddr a)))
115 (erc-server-send (concat "PRIVMSG " bot " :" message))))))
116 (add-hook 'erc-after-connect 'mdw-erc-auto-greet-bots)
117
118 (defun erc-cmd-GREET ()
119 "Send greeting messages, according to `mdw-erc-auto-greet-bots-alist'."
120 (mdw-erc-auto-greet-bots erc-session-server (erc-current-nick)))
121
122 (defun erc-cmd-IRCOP ()
123 "Claim `ircop' privileges."
124 (let ((a (mdw-assoc-regexp erc-session-server mdw-erc-ircop-alist)))
125 (when a
126 (let ((acct (cadr a))
127 (passwd (caddr a)))
128 (erc-server-send (concat "OPER " acct " " passwd))))))