about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-circe.el60
-rw-r--r--lisp/acdw-irc.el108
2 files changed, 60 insertions, 108 deletions
diff --git a/lisp/acdw-circe.el b/lisp/acdw-circe.el index 076bbc6..4ff3fdf 100644 --- a/lisp/acdw-circe.el +++ b/lisp/acdw-circe.el
@@ -7,9 +7,32 @@
7;;; Code: 7;;; Code:
8 8
9(require 'circe) 9(require 'circe)
10(require 'el-patch)
10 11
11;;; Functions 12;;; Functions
12 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
13(defun circe-current-topic (&optional message) 36(defun circe-current-topic (&optional message)
14 "Return the topic of the current channel. 37 "Return the topic of the current channel.
15When called with MESSAGE set to non-nil (or interactively), also 38When called with MESSAGE set to non-nil (or interactively), also
@@ -93,6 +116,43 @@ message the current topic."
93 (message "%s: %s" buf circe-server-killed-confirmation) 116 (message "%s: %s" buf circe-server-killed-confirmation)
94 (kill-buffer))))) 117 (kill-buffer)))))
95 118
119;;; Patches
120
121(el-patch-feature circe)
122(with-eval-after-load 'circe
123 (defvar circe-server-buffer-action 'pop-to-buffer-same-window
124 "What to do with `circe-server' buffers when created.")
125
126 (el-patch-defun circe (network-or-server &rest server-options)
127 "Connect to IRC.
128
129Connect to the given network specified by NETWORK-OR-SERVER.
130
131When this function is called, it collects options from the
132SERVER-OPTIONS argument, the user variable
133`circe-network-options', and the defaults found in
134`circe-network-defaults', in this order.
135
136If NETWORK-OR-SERVER is not found in any of these variables, the
137argument is assumed to be the host name for the server, and all
138relevant settings must be passed via SERVER-OPTIONS.
139
140All SERVER-OPTIONS are treated as variables by getting the string
141\"circe-\" prepended to their name. This variable is then set
142locally in the server buffer.
143
144See `circe-network-options' for a list of common options."
145 (interactive (circe--read-network-and-options))
146 (let* ((options (circe--server-get-network-options network-or-server
147 server-options))
148 (buffer (circe--server-generate-buffer options)))
149 (with-current-buffer buffer
150 (circe-server-mode)
151 (circe--server-set-variables options)
152 (circe-reconnect))
153 (el-patch-swap (pop-to-buffer-same-window buffer)
154 (funcall circe-server-buffer-action buffer)))))
155
96;;; Dumb modes 156;;; Dumb modes
97 157
98(define-minor-mode circe-cappy-hour-mode 158(define-minor-mode circe-cappy-hour-mode
diff --git a/lisp/acdw-irc.el b/lisp/acdw-irc.el index 8ec5893..4427a4d 100644 --- a/lisp/acdw-irc.el +++ b/lisp/acdw-irc.el
@@ -67,114 +67,6 @@ and right on t."
67 (if alignment "" (repeat-string left-over " ")) 67 (if alignment "" (repeat-string left-over " "))
68 after))) 68 after)))
69 69
70(defun irc ()
71 "Connect to all IRC networks in `circe-network-options'."
72 (interactive)
73 (dolist (network (mapcar #'car circe-network-options))
74 (unless (member network circe-network-inhibit-autoconnect)
75 (circe-maybe-connect network))))
76
77(el-patch-feature circe)
78(with-eval-after-load 'circe
79 (defvar circe-server-buffer-action 'pop-to-buffer-same-window
80 "What to do with `circe-server' buffers when created.")
81
82 (el-patch-defun circe (network-or-server &rest server-options)
83 "Connect to IRC.
84
85Connect to the given network specified by NETWORK-OR-SERVER.
86
87When this function is called, it collects options from the
88SERVER-OPTIONS argument, the user variable
89`circe-network-options', and the defaults found in
90`circe-network-defaults', in this order.
91
92If NETWORK-OR-SERVER is not found in any of these variables, the
93argument is assumed to be the host name for the server, and all
94relevant settings must be passed via SERVER-OPTIONS.
95
96All SERVER-OPTIONS are treated as variables by getting the string
97\"circe-\" prepended to their name. This variable is then set
98locally in the server buffer.
99
100See `circe-network-options' for a list of common options."
101 (interactive (circe--read-network-and-options))
102 (let* ((options (circe--server-get-network-options network-or-server
103 server-options))
104 (buffer (circe--server-generate-buffer options)))
105 (with-current-buffer buffer
106 (circe-server-mode)
107 (circe--server-set-variables options)
108 (circe-reconnect))
109 (el-patch-swap (pop-to-buffer-same-window buffer)
110 (funcall circe-server-buffer-action buffer)))))
111
112(defun circe-network-connected-p (network)
113 "Return non-nil if there's any Circe server-buffer whose
114`circe-server-netwok' is NETWORK."
115 (catch 'return
116 (dolist (buffer (circe-server-buffers))
117 (with-current-buffer buffer
118 (if (string= network circe-server-network)
119 (throw 'return t))))))
120
121(defun circe-maybe-connect (network)
122 "Connect to NETWORK, but ask user for confirmation if it's
123already been connected to."
124 (interactive "sNetwork: ")
125 (if (or (not (circe-network-connected-p network))
126 (y-or-n-p (format "Already connected to %s, reconnect?" network)))
127 (circe network)))
128
129;; the most important command ever.
130(defun circe-command-SLAP (nick)
131 "Slap NICK around with a large trout."
132 (interactive "sNick: ")
133 (if (not circe-chat-target)
134 (circe-display-server-message "No target for current buffer")
135 (let ((line (concat "slaps " nick " around a bit with a large trout")))
136 (circe-display 'circe-format-self-action
137 :body line
138 :nick (circe-nick))
139 (irc-send-ctcp (circe-server-process)
140 circe-chat-target
141 "ACTION" line))))
142
143(defun circe-command-SHORTEN (url)
144 "Shorten URL using `0x0-shorten-uri'."
145 (interactive "sURL to shorten: ")
146 ;; TODO: enable /shorten URL comment syntax
147 (let ((short-url (0x0-shorten-uri (0x0--choose-server) url)))
148 (circe-command-SAY short-url)))
149
150(defun circe-part@kill-buffer (&rest _)
151 (let ((circe-channel-killed-confirmation nil))
152 (kill-buffer)))
153
154(defun circe-quit@kill-buffer (&rest _)
155 ;; `circe-server-killed-confirmation' set to nil, and manually
156 ;; deleting all chat buffers, pending Github issue #402
157 ;; (https://github.com/emacs-circe/circe/issues/402)
158 (let ((circe-server-killed-confirmation nil))
159 (with-circe-server-buffer
160 (dolist (buf (circe-server-chat-buffers))
161 (let ((circe-channel-killed-confirmation nil))
162 (kill-buffer buf)))
163 (kill-buffer))))
164
165(defun circe-gquit@kill-buffer (&rest _)
166 ;; `circe-server-killed-confirmation' set to nil, and manually
167 ;; deleting all chat buffers, pending Github issue #402
168 ;; (https://github.com/emacs-circe/circe/issues/402)
169 (let ((circe-server-killed-confirmation nil))
170 (dolist (buf (circe-server-buffers))
171 (with-current-buffer buf
172 (dolist (buf (circe-server-chat-buffers))
173 (let ((circe-channel-killed-confirmation nil))
174 (kill-buffer buf)))
175 (message "%s: %s" buf circe-server-killed-confirmation)
176 (kill-buffer)))))
177
178 70
179(provide 'acdw-irc) 71(provide 'acdw-irc)
180;;; acdw-irc.el ends here 72;;; acdw-irc.el ends here