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