summaryrefslogtreecommitdiff
path: root/dotfiles/.emacs.d/erc.el
blob: 1b365802ea8133d36286f7f74275d704f56dba4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(require 'erc)
(require 'erc-log)
(require 'erc-notify)
(require 'erc-spelling)
(require 'erc-autoaway)
(require 'erc-services)
(require 'notifications)

;; Notify the user of private messages
(defun erc-private-message-notify (proc parsed)
  (let ((nick (car (erc-parse-user (erc-response.sender parsed))))
        (target (car (erc-response.command-args parsed)))
        (msg (erc-response.contents parsed)))
    (notifications-notify :title nick :body msg)))

;; (add-hook 'erc-server-PRIVMSG-functions 'erc-private-message-notify)

;; Notify the user when their nick is mentioned
(defun erc-nick-mentioned-notify (match-type nick message)
  "Shows a notification when user's nick is mentioned."
  (when (and (not (posix-string-match "^\\** *Users on #" message))
             (eq math-type 'current-nick))
    (notifications-notify
     :title nick
     :body message
     :app-icon "/usr/share/notify-osd/icons/gnome/scalable/status/notification-message-im.svg"
     :urgency 'low)))

;; (add-hook 'erc-text-matched-hook 'erc-nick-mentioned-notify)

;; Nickname
(setq erc-nick "davexunit")

;; Interpret mIRC-style color commands in IRC chats
(setq erc-interpret-mirc-color t)

;; The following are commented out by default, but users of other
;; non-Emacs IRC clients might find them useful.
;; Kill buffers for channels after /part
(setq erc-kill-buffer-on-part t)
;; Kill buffers for private queries after quitting the server
(setq erc-kill-queries-on-quit t)
;; Kill buffers for server messages after quitting the server
(setq erc-kill-server-buffer-on-quit t)

;; open query buffers in the current window
(setq erc-query-display 'buffer)

;; exclude boring stuff from tracking
(erc-track-mode t)
(setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
                                "324" "329" "332" "333" "353" "477"))

;; logging
(setq erc-log-channels-directory "~/.erc/logs/")

(if (not (file-exists-p erc-log-channels-directory))
    (mkdir erc-log-channels-directory t))

(setq erc-save-buffer-on-part t)

;; truncate long irc buffers
(erc-truncate-mode 1)

;; enable spell checking
(erc-spelling-mode 0)

;; utf-8 always and forever
(setq erc-server-coding-system '(utf-8 . utf-8))

;; Auto-join channels
(erc-autojoin-mode t)
(setq erc-autojoin-channels-alist
      '(("freenode.net" "#libre.fm" "#guile" "#guix" "#gnu"
         "#gnu-webmasters" "#emacs" "#scheme" "#lispgames" "#fsf"
         "#libreplanet" "##wizards" "#tox" "#tox-dev" "#sly")))
;; Don't open channel buffers in place of the current buffer because
;; that drives me fucking crazy.
(setq erc-join-buffer 'bury)

;; Secret password file
(load "~/.emacs.d/.ercpasswords")

;; Stuff to make authenticating with Rizon work
(erc-services-mode t)
(setq erc-prompt-for-nickserv-password nil)
(setq erc-nickserv-identify-mode 'autodetect)

;; Start and stop erc
(defun start-irc ()
  "Connect to IRC."
  (interactive)
  (erc :server "irc.freenode.net"
       :port 6667
       :nick erc-nick
       :password freenode-password))

(defun filter-erc-server-buffers ()
  (delq nil
        (mapcar
         (lambda (x) (and (erc-server-buffer-p x) x))
         (buffer-list))))

(defun stop-irc ()
  "Disconnects from all irc servers"
  (interactive)
  (dolist (buffer (filter-erc-server-buffers))
    (message "Server buffer: %s" (buffer-name buffer))
    (with-current-buffer buffer
      (erc-quit-server "Later"))))