blob: 076bbc6bbb9c196269f5f2729273df80f121521b (
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
|
;;; acdw-circe.el --- bespoke circe customizations -*- lexical-binding: t -*-
;;; Commentary:
;; Besoke Circe customizations.
;;; Code:
(require 'circe)
;;; Functions
(defun circe-current-topic (&optional message)
"Return the topic of the current channel.
When called with MESSAGE set to non-nil (or interactively), also
message the current topic."
(interactive "p")
(let ((topic
(save-excursion
(goto-char (point-max))
(or (re-search-backward
(rx (group "*** Topic" (+ (not ":")) ": ")
(group (+ nonl)))))
(buffer-substring-no-properties
(match-beginning 2) (match-end 2)))))
(when message
(message "%s" topic))
topic))
;;; Chat commands
(defun circe-command-SHORTEN (url)
"Shorten URL using `0x0-shorten-uri'."
(interactive "sURL to shorten: ")
(require '0x0)
;; TODO: enable /shorten URL comment syntax
(let ((short-url (0x0-shorten-uri (0x0--choose-server) url)))
(circe-command-SAY short-url)))
(defun circe-command-SLAP (nick)
"Slap NICK around a bit with a large trout."
(interactive "sWho we slappin' today, boss? ")
(circe-command-ME (concat "slaps "
(string-trim nick)
" around a bit with a large trout")))
;;; Hooks
(defun circe-chat@set-prompt ()
"Set the prompt to the buffer name, shortening it."
(interactive) ; set interactive to unfuck the prompt when need be
(lui-set-prompt
(propertize
(concat
(acdw-irc/margin-format (buffer-name) "" ">")
" ")
'face 'circe-prompt-face
'read-only t
'intangible t
'cursor-intangible t)))
;;; Advices
(defun circe-part@kill-buffer (&rest _)
"Advice to kill the channel buffer after PART."
(let ((circe-channel-killed-confirmation nil))
(kill-buffer)))
(defun circe-quit@kill-buffer (&rest _)
"Advice to kill all buffers of a server after QUIT."
;; `circe-server-killed-confirmation' set to nil, and manually
;; deleting all chat buffers, pending Github issue #402
;; (https://github.com/emacs-circe/circe/issues/402)
(let ((circe-server-killed-confirmation nil))
(with-circe-server-buffer
(dolist (buf (circe-server-chat-buffers))
(let ((circe-channel-killed-confirmation nil))
(kill-buffer buf)))
(kill-buffer))))
(defun circe-gquit@kill-buffer (&rest _)
"Advice to kill all Circe related buffers after GQUIT."
;; `circe-server-killed-confirmation' set to nil, and manually
;; deleting all chat buffers, pending Github issue #402
;; (https://github.com/emacs-circe/circe/issues/402)
(let ((circe-server-killed-confirmation nil))
(dolist (buf (circe-server-buffers))
(with-current-buffer buf
(dolist (buf (circe-server-chat-buffers))
(let ((circe-channel-killed-confirmation nil))
(kill-buffer buf))
(cancel-timer 'irc-send--queue))
(message "%s: %s" buf circe-server-killed-confirmation)
(kill-buffer)))))
;;; Dumb modes
(define-minor-mode circe-cappy-hour-mode
"ENABLE CAPPY HOUR IN CIRCE!"
:lighter "CAPPY HOUR"
(when (derived-mode-p 'circe-chat-mode)
(if circe-cappy-hour-mode
(setq-local lui-input-function
(lambda (input) (circe--input (upcase input))))
;; XXX: It'd be better if this were more general, but whatever.
(setq-local lui-input-function #'circe--input))))
(provide 'acdw-circe)
;;; acdw-circe.el ends here
|