From 7aa9a0c647faff04c33c4934b290a2d6f7c6d64e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 14 Oct 2021 20:40:44 -0500 Subject: Move most of acdw-irc to acdw-circe --- lisp/acdw-circe.el | 60 +++++++++++++++++++++++++++++ lisp/acdw-irc.el | 108 ----------------------------------------------------- 2 files changed, 60 insertions(+), 108 deletions(-) (limited to 'lisp') 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 @@ ;;; Code: (require 'circe) +(require 'el-patch) ;;; Functions +(defun irc () + "Connect to all IRC networks in `circe-network-options'." + (interactive) + (dolist (network (mapcar #'car circe-network-options)) + (unless (member network circe-network-inhibit-autoconnect) + (circe-maybe-connect network)))) + +(defun circe-network-connected-p (network) + "Return whether circe is connected to NETWORK." + (catch 'return + (dolist (buffer (circe-server-buffers)) + (with-current-buffer buffer + (if (string= network circe-server-network) + (throw 'return t)))))) + +(defun circe-maybe-connect (network) + "Connect to NETWORK, asking for confirmation to reconnect." + (interactive "sNetwork: ") + (if (or (not (circe-network-connected-p network)) + (y-or-n-p (format "Already connected to %s, reconnect? " network))) + (circe network))) + (defun circe-current-topic (&optional message) "Return the topic of the current channel. When called with MESSAGE set to non-nil (or interactively), also @@ -93,6 +116,43 @@ message the current topic." (message "%s: %s" buf circe-server-killed-confirmation) (kill-buffer))))) +;;; Patches + +(el-patch-feature circe) +(with-eval-after-load 'circe + (defvar circe-server-buffer-action 'pop-to-buffer-same-window + "What to do with `circe-server' buffers when created.") + + (el-patch-defun circe (network-or-server &rest server-options) + "Connect to IRC. + +Connect to the given network specified by NETWORK-OR-SERVER. + +When this function is called, it collects options from the +SERVER-OPTIONS argument, the user variable +`circe-network-options', and the defaults found in +`circe-network-defaults', in this order. + +If NETWORK-OR-SERVER is not found in any of these variables, the +argument is assumed to be the host name for the server, and all +relevant settings must be passed via SERVER-OPTIONS. + +All SERVER-OPTIONS are treated as variables by getting the string +\"circe-\" prepended to their name. This variable is then set +locally in the server buffer. + +See `circe-network-options' for a list of common options." + (interactive (circe--read-network-and-options)) + (let* ((options (circe--server-get-network-options network-or-server + server-options)) + (buffer (circe--server-generate-buffer options))) + (with-current-buffer buffer + (circe-server-mode) + (circe--server-set-variables options) + (circe-reconnect)) + (el-patch-swap (pop-to-buffer-same-window buffer) + (funcall circe-server-buffer-action buffer))))) + ;;; Dumb modes (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." (if alignment "" (repeat-string left-over " ")) after))) -(defun irc () - "Connect to all IRC networks in `circe-network-options'." - (interactive) - (dolist (network (mapcar #'car circe-network-options)) - (unless (member network circe-network-inhibit-autoconnect) - (circe-maybe-connect network)))) - -(el-patch-feature circe) -(with-eval-after-load 'circe - (defvar circe-server-buffer-action 'pop-to-buffer-same-window - "What to do with `circe-server' buffers when created.") - - (el-patch-defun circe (network-or-server &rest server-options) - "Connect to IRC. - -Connect to the given network specified by NETWORK-OR-SERVER. - -When this function is called, it collects options from the -SERVER-OPTIONS argument, the user variable -`circe-network-options', and the defaults found in -`circe-network-defaults', in this order. - -If NETWORK-OR-SERVER is not found in any of these variables, the -argument is assumed to be the host name for the server, and all -relevant settings must be passed via SERVER-OPTIONS. - -All SERVER-OPTIONS are treated as variables by getting the string -\"circe-\" prepended to their name. This variable is then set -locally in the server buffer. - -See `circe-network-options' for a list of common options." - (interactive (circe--read-network-and-options)) - (let* ((options (circe--server-get-network-options network-or-server - server-options)) - (buffer (circe--server-generate-buffer options))) - (with-current-buffer buffer - (circe-server-mode) - (circe--server-set-variables options) - (circe-reconnect)) - (el-patch-swap (pop-to-buffer-same-window buffer) - (funcall circe-server-buffer-action buffer))))) - -(defun circe-network-connected-p (network) - "Return non-nil if there's any Circe server-buffer whose -`circe-server-netwok' is NETWORK." - (catch 'return - (dolist (buffer (circe-server-buffers)) - (with-current-buffer buffer - (if (string= network circe-server-network) - (throw 'return t)))))) - -(defun circe-maybe-connect (network) - "Connect to NETWORK, but ask user for confirmation if it's -already been connected to." - (interactive "sNetwork: ") - (if (or (not (circe-network-connected-p network)) - (y-or-n-p (format "Already connected to %s, reconnect?" network))) - (circe network))) - -;; the most important command ever. -(defun circe-command-SLAP (nick) - "Slap NICK around with a large trout." - (interactive "sNick: ") - (if (not circe-chat-target) - (circe-display-server-message "No target for current buffer") - (let ((line (concat "slaps " nick " around a bit with a large trout"))) - (circe-display 'circe-format-self-action - :body line - :nick (circe-nick)) - (irc-send-ctcp (circe-server-process) - circe-chat-target - "ACTION" line)))) - -(defun circe-command-SHORTEN (url) - "Shorten URL using `0x0-shorten-uri'." - (interactive "sURL to shorten: ") - ;; TODO: enable /shorten URL comment syntax - (let ((short-url (0x0-shorten-uri (0x0--choose-server) url))) - (circe-command-SAY short-url))) - -(defun circe-part@kill-buffer (&rest _) - (let ((circe-channel-killed-confirmation nil)) - (kill-buffer))) - -(defun circe-quit@kill-buffer (&rest _) - ;; `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 _) - ;; `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))) - (message "%s: %s" buf circe-server-killed-confirmation) - (kill-buffer))))) - (provide 'acdw-irc) ;;; acdw-irc.el ends here -- cgit 1.4.1-21-gabe81