summary refs log tree commit diff stats
path: root/lisp/+circe.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+circe.el')
-rw-r--r--lisp/+circe.el148
1 files changed, 148 insertions, 0 deletions
diff --git a/lisp/+circe.el b/lisp/+circe.el new file mode 100644 index 0000000..1403af8 --- /dev/null +++ b/lisp/+circe.el
@@ -0,0 +1,148 @@
1;;; +circe.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(require '+util)
6(require 'circe)
7
8(defgroup +circe nil
9 "Extra customizations for Circe."
10 :group 'circe)
11
12(defcustom +circe-left-margin 16
13 "The size of the margin on the left."
14 :type 'integer)
15
16(defcustom +circe-network-inhibit-autoconnect nil
17 "Servers to inhibit autoconnecting from `circe-network-options'."
18 :type '(repeat string))
19
20;;; Connecting to IRC
21
22;;;###autoload
23(defun +irc ()
24 "Connect to all IRC networks in `circe-network-options'."
25 (interactive)
26 (dolist (network (mapcar 'car circe-network-options))
27 (unless (member network +circe-network-inhibit-autoconnect)
28 (+circe-maybe-connect network))))
29
30(defun +circe-network-connected-p (network)
31 "Return t if connected to NETWORK, nil otherwise."
32 (catch 'return
33 (dolist (buffer (circe-server-buffers))
34 (with-current-buffer buffer
35 (when (string= network circe-server-network)
36 (throw 'return t))))))
37
38(defun +circe-maybe-connect (network)
39 "Connect to NETWORK, asking for confirmation to reconnect."
40 (interactive ("sNetwork: "))
41 (when (or (not (+circe-network-connected-p network))
42 (yes-or-no-p (format "Already connected to %s, reconnect? "
43 network)))
44 (circe network)))
45
46;;; Channel information
47
48(defun +circe-current-topic (&optional message)
49 "Return the topic of the current channel.
50When called with optional MESSAGE non-nil, or interactively, also
51message the current topic.")
52
53;;; Formatting messages
54
55(defun +circe-format-meta (string)
56 "Return a format string for `lui-format' for metadata messages."
57 (format "{nick:%1$d.%1$ds} *** %s" (- +circe-left-margin 3) string))
58
59;;; Hooks & Advice
60
61(defun +circe-chat@set-prompt ()
62 "Set the prompt to the (shortened) buffer name."
63 (interactive)
64 (lui-set-prompt (propertize (+string-align (buffer-name) +circe-left-margin
65 :after " > "
66 :ellipsis "~"
67 :alignment 'right))))
68
69(defun +circe-kill-buffer (&rest _)
70 "Kill a circe buffer without confirmation, and after a delay."
71 (let ((circe-channel-killed-confirmation nil)
72 (circe-server-killed-confirmation nil))
73 (run-with-timer 0.25 nil 'kill-buffer)))
74
75(defun +circe-quit@kill-buffer (&rest _)
76 "ADVICE: kill all buffers of a server after `circe-command-QUIT'."
77 (with-circe-server-buffer
78 (dolist (buf (circe-server-buffers))
79 (with-current-buffer buf
80 (+circe-kill-buffer)))
81 (+circe-kill-buffer)))
82
83(defun +circe-gquit@kill-buffer (&rest _)
84 "ADVICE: kill all Circe buffers after `circe-command-GQUIT'."
85 (dolist (buf (circe-server-buffers))
86 (with-current-buffer buf
87 (+circe-quit@kill-buffer))))
88
89;;; Patches
90
91(require 'el-patch)
92
93(el-patch-feature circe)
94(defvar circe-server-buffer-action 'pop-to-buffer-same-window
95 "What to do with `circe-server' buffers when created.")
96
97(el-patch-defun circe (network-or-server &rest server-options)
98 "Connect to IRC.
99
100Connect to the given network specified by NETWORK-OR-SERVER.
101
102When this function is called, it collects options from the
103SERVER-OPTIONS argument, the user variable
104`circe-network-options', and the defaults found in
105`circe-network-defaults', in this order.
106
107If NETWORK-OR-SERVER is not found in any of these variables, the
108argument is assumed to be the host name for the server, and all
109relevant settings must be passed via SERVER-OPTIONS.
110
111All SERVER-OPTIONS are treated as variables by getting the string
112\"circe-\" prepended to their name. This variable is then set
113locally in the server buffer.
114
115See `circe-network-options' for a list of common options."
116 (interactive (circe--read-network-and-options))
117 (let* ((options (circe--server-get-network-options network-or-server
118 server-options))
119 (buffer (circe--server-generate-buffer options)))
120 (with-current-buffer buffer
121 (circe-server-mode)
122 (circe--server-set-variables options)
123 (circe-reconnect))
124 (el-patch-swap (pop-to-buffer-same-window buffer)
125 (funcall circe-server-buffer-action buffer))))
126
127;;; Chat commands
128
129(defun circe-command-SHORTEN (url)
130 "Shorten URL using `0x0-shorten-uri'.")
131
132(defun circe-command-SLAP (nick)
133 "Slap NICK around a bit with a large trout.")
134
135;;; Pure idiocy
136
137(define-minor-mode circe-cappy-hour-mode
138 "ENABLE CAPPY HOUR IN CIRCE!"
139 :lighter "CAPPY HOUR"
140 (when (derived-mode-p 'circe-chat-mode)
141 (if circe-cappy-hour-mode
142 (setq-local lui-input-function
143 (lambda (input) (circe--input (upcase input))))
144 ;; XXX: It'd be better if this were more general, but whatever.
145 (setq-local lui-input-function #'circe--input))))
146
147(provide '+circe)
148;;; +circe.el ends here