summary refs log tree commit diff stats
path: root/lisp/acdw-erc.el
blob: 937505fc4441611c3e8bc260eb7f6a45a609329f (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
;;; acdw-erc.el -*- lexical-binding: t; coding: utf-8-unix -*-

;; Author: Case Duckworth <acdw@acdw.net>
;; Created: 24 May 2021
;; Keywords: configuration
;; URL: https://tildegit.org/acdw/emacs

;; This file is NOT part of GNU Emacs.

;;; License:
;; Everyone is permitted to do whatever with this software, without
;; limitation.  This software comes without any warranty whatsoever,
;; but with two pieces of advice:
;; - Don't hurt yourself.
;; - Make good choices.

;;; Commentary:
;; `acdw-erc' is a dumping ground for functions and stuff for ERC, so they
;; don't clutter up `init.el'.

;;; Code:

(defgroup acdw-erc nil
  "Customizations for ERC."
  :group 'erc)


;;; Show a different header-line face when ERC is disconnected.
;; https://www.emacswiki.org/emacs/ErcModeline#h5o-1

(defface erc/header-line-disconnected
  '((t (:foreground "black" :background "indianred")))
  "Face to use when ERC has been disconnected.")

(defun erc/update-header-line-show-disconnected ()
  "Use a different face in the header-line when disconnected."
  (erc-with-server-buffer
    (cond ((erc-server-process-alive) 'erc-header-line)
          (t 'erc/header-line-disconnected))))


;;; Convenience functions
;; from Prelude:
;; https://github.com/bbatsov/prelude/blob/master/modules/prelude-erc.el#L114

(defcustom erc/servers nil
  "The list of IRC servers to connect to with `erc/connect'."
  :type '(list string))

(defcustom erc/bye-message "See You Space Cowpokes."
  "Quit message sent when calling `erc/disconnect'."
  :type 'string)

(defun connect-to-erc (server &optional use-tls port nick)
  "Connects to IRC SERVER at PORT with NICK.
If USE-TLS is non-nil, use TLS."
  (let* ((use-tls (or use-tls t))
         (erc-fn (if use-tls #'erc-tls #'erc))
         (port (or port (if use-tls 6697 6667)))
         (nick (or nick erc-nick)))
    (funcall erc-fn
             :server server
             :port port
             :nick nick)))

(defun erc/connect ()
  "Connect to all the servers in `erc/servers'."
  (interactive)
  (mapcar #'connect-to-erc erc/servers))

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

(defun erc/disconnect ()
  "Disconnect from all IRC servers."
  (interactive)
  (dolist (buffer (filter-server-buffers))
    (with-message (format "Killing server buffer: %s" (buffer-name buffer))
      (with-current-buffer buffer
        (erc-quit-server acdw-erc/bye-message)))))

(provide 'acdw-erc)
;;; acdw-erc.el ends here