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.el130
1 files changed, 105 insertions, 25 deletions
diff --git a/lisp/+circe.el b/lisp/+circe.el index c29cea6..3d6ea60 100644 --- a/lisp/+circe.el +++ b/lisp/+circe.el
@@ -101,9 +101,11 @@ For entry into `lui-formatting-list'."
101 101
102(defun +circe-kill-buffer (&rest _) 102(defun +circe-kill-buffer (&rest _)
103 "Kill a circe buffer without confirmation, and after a delay." 103 "Kill a circe buffer without confirmation, and after a delay."
104 (let ((circe-channel-killed-confirmation nil) 104 (let ((circe-channel-killed-confirmation)
105 (circe-server-killed-confirmation nil)) 105 (circe-server-killed-confirmation))
106 (run-with-timer 0.25 nil 'kill-buffer))) 106 (when (derived-mode-p 'lui-mode) ; don't spuriously kill
107 (ignore-errors
108 (kill-buffer)))))
107 109
108(defun +circe-quit@kill-buffer (&rest _) 110(defun +circe-quit@kill-buffer (&rest _)
109 "ADVICE: kill all buffers of a server after `circe-command-QUIT'." 111 "ADVICE: kill all buffers of a server after `circe-command-QUIT'."
@@ -115,9 +117,11 @@ For entry into `lui-formatting-list'."
115 117
116(defun +circe-gquit@kill-buffer (&rest _) 118(defun +circe-gquit@kill-buffer (&rest _)
117 "ADVICE: kill all Circe buffers after `circe-command-GQUIT'." 119 "ADVICE: kill all Circe buffers after `circe-command-GQUIT'."
118 (dolist (buf (circe-server-buffers)) 120 (let ((circe-channel-killed-confirmation)
119 (with-current-buffer buf 121 (circe-server-killed-confirmation))
120 (+circe-quit@kill-buffer)))) 122 (dolist (buf (circe-server-buffers))
123 (with-current-buffer buf
124 (+circe-quit@kill-buffer)))))
121 125
122(defun +circe-quit-all@kill-emacs () 126(defun +circe-quit-all@kill-emacs ()
123 "Quit all circe buffers when killing Emacs." 127 "Quit all circe buffers when killing Emacs."
@@ -165,28 +169,104 @@ See `circe-network-options' for a list of common options."
165 (funcall +circe-server-buffer-action buffer)))) 169 (funcall +circe-server-buffer-action buffer))))
166 170
167;;; Chat commands 171;;; Chat commands
168;; TODO: Actually ... write these~!?!?!
169
170(defun circe-command-SHORTEN (url)
171 "Shorten URL using `0x0-shorten-uri'.")
172 172
173(defun circe-command-SLAP (nick) 173(defun circe-command-SLAP (nick)
174 "Slap NICK around a bit with a large trout.") 174 "Slap NICK around a bit with a large trout."
175 175 (interactive (list (completing-read "Nick to slap: "
176(defun circe-command-POKE (nick) 176 (circe-channel-nicks)
177 "Poke NICK like in the old Facebook days.") 177 nil t nil)))
178 178 (circe-command-ME (format "slaps %s about a bit with a large trout" nick)))
179;;; Pure idiocy 179
180 180;;; Filtering functions
181(define-minor-mode circe-cappy-hour-mode 181;; Set `lui-input-function' to `+lui-filter', then add the filters you want to
182;; `circe-channel-mode-hook'.
183
184(require 'dash)
185
186(defvar +lui-filters nil
187 "Stack of input functions to apply.
188This is an alist with cells of the structure (TAG . FN), so we
189can easily remove elements.")
190(make-variable-buffer-local '+lui-filters)
191
192(defun +lui-filter (text &optional fn-alist)
193 (let ((fs (nreverse (purecopy (or fn-alist +lui-filters)))))
194 (while fs
195 (setq text (funcall (cdr (pop fs)) text)))
196 (circe--input text)))
197
198(defmacro +circe-define-filter (name docstring &rest body)
199 "Define a filter for circe-inputted text."
200 (declare (doc-string 2)
201 (indent 1))
202 (let (plist)
203 (while (keywordp (car-safe body))
204 (push (pop body) plist)
205 (push (pop body) plist))
206 ;; Return value
207 `(define-minor-mode ,name
208 ,docstring
209 ,@(nreverse plist)
210 (when (derived-mode-p 'circe-chat-mode)
211 (if ,name
212 (push '(,name . (lambda (it) ,@body)) +lui-filters)
213 (setq +lui-filters
214 (assoc-delete-all ',name +lui-filters)))))))
215
216;; CAPPY HOUR! (Pure idiocy)
217
218(+circe-define-filter +circe-cappy-hour-mode
182 "ENABLE CAPPY HOUR IN CIRCE!" 219 "ENABLE CAPPY HOUR IN CIRCE!"
183 :lighter "CAPPY HOUR" 220 :lighter " CAPPY HOUR"
184 (when (derived-mode-p 'circe-chat-mode) 221 (upcase it))
185 (if circe-cappy-hour-mode 222
186 (setq-local lui-input-function 223;; URL Shortener
187 (lambda (input) (circe--input (upcase input)))) 224
188 ;; XXX: It'd be better if this were more general, but whatever. 225(+circe-define-filter +circe-shorten-url-mode
189 (setq-local lui-input-function #'circe--input)))) 226 "Shorten long urls when chatting."
227 :lighter " c0x0"
228 (+circe-0x0-shorten-urls it))
229
230(defvar +circe-0x0-max-length 20
231 "Maximum length of URLs before using a shortener.")
232
233(defun +circe-0x0-shorten-urls (text)
234 "Find urls in TEXT and shorten them using `0x0'."
235 (require '0x0)
236 (require 'browse-url)
237 (let ((case-fold-search t))
238 (replace-regexp-in-string
239 browse-url-button-regexp
240 (lambda (match)
241 (if (> (length match) +circe-0x0-max-length)
242 (+with-message (format "Shortening URL: %s" match)
243 (0x0-shorten-uri (0x0--choose-server)
244 (substring-no-properties match)))
245 match))
246 text)))
247
248;; Temperature conversion
249
250(+circe-define-filter +circe-F/C-mode
251 "Convert degF to degF/degC for international chats."
252 :lighter " F/C"
253 (str-F/C it))
254
255(defun fahrenheit-to-celsius (degf)
256 "Convert DEGF to Celsius."
257 (round (* (/ 5.0 9.0) (- degf 32))))
258
259(defun celsius-to-fahrenheit (degc)
260 "Convert DEGC to Fahrenheit."
261 (round (+ 32 (* (/ 9.0 5.0) degc))))
262
263(defun str-F/C (text)
264 (replace-regexp-in-string "[0-9.]+[Ff]"
265 (lambda (match)
266 (format "%s/%dC" match
267 (fahrenheit-to-celsius
268 (string-to-number match))))
269 text))
190 270
191(provide '+circe) 271(provide '+circe)
192;;; +circe.el ends here 272;;; +circe.el ends here