diff options
Diffstat (limited to 'lisp/acdw-circe.el')
-rw-r--r-- | lisp/acdw-circe.el | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/lisp/acdw-circe.el b/lisp/acdw-circe.el deleted file mode 100644 index 73b1cdf..0000000 --- a/lisp/acdw-circe.el +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
1 | ;;; acdw-circe.el --- bespoke circe customizations -*- lexical-binding: t -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; Besoke Circe customizations. | ||
6 | |||
7 | ;;; Code: | ||
8 | |||
9 | (require 'circe) | ||
10 | (require 'el-patch) | ||
11 | |||
12 | ;;; Functions | ||
13 | |||
14 | (defun irc () | ||
15 | "Connect to all IRC networks in `circe-network-options'." | ||
16 | (interactive) | ||
17 | (dolist (network (mapcar #'car circe-network-options)) | ||
18 | (unless (member network circe-network-inhibit-autoconnect) | ||
19 | (circe-maybe-connect network)))) | ||
20 | |||
21 | (defun circe-network-connected-p (network) | ||
22 | "Return whether circe is connected to NETWORK." | ||
23 | (catch 'return | ||
24 | (dolist (buffer (circe-server-buffers)) | ||
25 | (with-current-buffer buffer | ||
26 | (if (string= network circe-server-network) | ||
27 | (throw 'return t)))))) | ||
28 | |||
29 | (defun circe-maybe-connect (network) | ||
30 | "Connect to NETWORK, asking for confirmation to reconnect." | ||
31 | (interactive "sNetwork: ") | ||
32 | (if (or (not (circe-network-connected-p network)) | ||
33 | (y-or-n-p (format "Already connected to %s, reconnect? " network))) | ||
34 | (circe network))) | ||
35 | |||
36 | (defun circe-current-topic (&optional message) | ||
37 | "Return the topic of the current channel. | ||
38 | When called with MESSAGE set to non-nil (or interactively), also | ||
39 | message the current topic." | ||
40 | (interactive "p") | ||
41 | (let ((topic | ||
42 | (save-excursion | ||
43 | (goto-char (point-max)) | ||
44 | (or (re-search-backward | ||
45 | (rx (group "*** Topic" (+ (not ":")) ": ") | ||
46 | (group (+ nonl))))) | ||
47 | (buffer-substring-no-properties | ||
48 | (match-beginning 2) (match-end 2))))) | ||
49 | (when message | ||
50 | (message "%s" topic)) | ||
51 | topic)) | ||
52 | |||
53 | ;;; Chat commands | ||
54 | |||
55 | (defun circe-command-SHORTEN (url) | ||
56 | "Shorten URL using `0x0-shorten-uri'." | ||
57 | (interactive "sURL to shorten: ") | ||
58 | (require '0x0) | ||
59 | ;; TODO: enable /shorten URL comment syntax | ||
60 | (let ((short-url (0x0-shorten-uri (0x0--choose-server) url))) | ||
61 | (circe-command-SAY short-url))) | ||
62 | |||
63 | (defun circe-command-SLAP (nick) | ||
64 | "Slap NICK around a bit with a large trout." | ||
65 | (interactive "sWho we slappin' today, boss? ") | ||
66 | (circe-command-ME (concat "slaps " | ||
67 | (string-trim nick) | ||
68 | " around a bit with a large trout"))) | ||
69 | |||
70 | ;;; Hooks | ||
71 | |||
72 | (defun circe-chat@set-prompt () | ||
73 | "Set the prompt to the buffer name, shortening it." | ||
74 | (interactive) ; set interactive to unfuck the prompt when need be | ||
75 | (lui-set-prompt | ||
76 | (propertize | ||
77 | (concat | ||
78 | (acdw-irc/margin-format (buffer-name) "" ">") | ||
79 | " ") | ||
80 | 'face 'circe-prompt-face | ||
81 | 'read-only t | ||
82 | 'intangible t | ||
83 | 'cursor-intangible t))) | ||
84 | |||
85 | ;;; Advices | ||
86 | |||
87 | (defun circe-part@kill-buffer (&rest _) | ||
88 | "Advice to kill the channel buffer after PART." | ||
89 | (let ((circe-channel-killed-confirmation nil)) | ||
90 | (kill-buffer))) | ||
91 | |||
92 | (defun circe-quit@kill-buffer (&rest _) | ||
93 | "Advice to kill all buffers of a server after QUIT." | ||
94 | ;; `circe-server-killed-confirmation' set to nil, and manually | ||
95 | ;; deleting all chat buffers, pending Github issue #402 | ||
96 | ;; (https://github.com/emacs-circe/circe/issues/402) | ||
97 | (let ((circe-server-killed-confirmation nil)) | ||
98 | (with-circe-server-buffer | ||
99 | (dolist (buf (circe-server-chat-buffers)) | ||
100 | (let ((circe-channel-killed-confirmation nil)) | ||
101 | (run-with-timer 0.1 nil #'kill-buffer buf))) | ||
102 | (run-with-timer 0.1 nil #'kill-buffer)))) | ||
103 | |||
104 | (defun circe-gquit@kill-buffer (&rest _) | ||
105 | "Advice to kill all Circe related buffers after GQUIT." | ||
106 | ;; `circe-server-killed-confirmation' set to nil, and manually | ||
107 | ;; deleting all chat buffers, pending Github issue #402 | ||
108 | ;; (https://github.com/emacs-circe/circe/issues/402) | ||
109 | (let ((circe-server-killed-confirmation nil)) | ||
110 | (dolist (buf (circe-server-buffers)) | ||
111 | (with-current-buffer buf | ||
112 | (dolist (buf (circe-server-chat-buffers)) | ||
113 | (let ((circe-channel-killed-confirmation nil)) | ||
114 | (run-with-timer 0.1 nil #'kill-buffer buf))) | ||
115 | (run-with-timer 0.1 nil #'kill-buffer))))) | ||
116 | |||
117 | ;;; Patches | ||
118 | |||
119 | (el-patch-feature circe) | ||
120 | (with-eval-after-load 'circe | ||
121 | (defvar circe-server-buffer-action 'pop-to-buffer-same-window | ||
122 | "What to do with `circe-server' buffers when created.") | ||
123 | |||
124 | (el-patch-defun circe (network-or-server &rest server-options) | ||
125 | "Connect to IRC. | ||
126 | |||
127 | Connect to the given network specified by NETWORK-OR-SERVER. | ||
128 | |||
129 | When this function is called, it collects options from the | ||
130 | SERVER-OPTIONS argument, the user variable | ||
131 | `circe-network-options', and the defaults found in | ||
132 | `circe-network-defaults', in this order. | ||
133 | |||
134 | If NETWORK-OR-SERVER is not found in any of these variables, the | ||
135 | argument is assumed to be the host name for the server, and all | ||
136 | relevant settings must be passed via SERVER-OPTIONS. | ||
137 | |||
138 | All SERVER-OPTIONS are treated as variables by getting the string | ||
139 | \"circe-\" prepended to their name. This variable is then set | ||
140 | locally in the server buffer. | ||
141 | |||
142 | See `circe-network-options' for a list of common options." | ||
143 | (interactive (circe--read-network-and-options)) | ||
144 | (let* ((options (circe--server-get-network-options network-or-server | ||
145 | server-options)) | ||
146 | (buffer (circe--server-generate-buffer options))) | ||
147 | (with-current-buffer buffer | ||
148 | (circe-server-mode) | ||
149 | (circe--server-set-variables options) | ||
150 | (circe-reconnect)) | ||
151 | (el-patch-swap (pop-to-buffer-same-window buffer) | ||
152 | (funcall circe-server-buffer-action buffer))))) | ||
153 | |||
154 | ;;; Dumb modes | ||
155 | |||
156 | (define-minor-mode circe-cappy-hour-mode | ||
157 | "ENABLE CAPPY HOUR IN CIRCE!" | ||
158 | :lighter "CAPPY HOUR" | ||
159 | (when (derived-mode-p 'circe-chat-mode) | ||
160 | (if circe-cappy-hour-mode | ||
161 | (setq-local lui-input-function | ||
162 | (lambda (input) (circe--input (upcase input)))) | ||
163 | ;; XXX: It'd be better if this were more general, but whatever. | ||
164 | (setq-local lui-input-function #'circe--input)))) | ||
165 | |||
166 | (provide 'acdw-circe) | ||
167 | ;;; acdw-circe.el ends here | ||