Skip to content

Commit

Permalink
Check if network is already connected before connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaodan committed Jun 25, 2024
1 parent 9d703f4 commit be04811
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions circe.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

;;; Code:

(eval-when-compile
(require 'cl-lib))
(defvar circe-version "2.13"
"Circe version string.")

Expand Down Expand Up @@ -1107,6 +1109,13 @@ joined channels.")
(substring (shell-command-to-string "git rev-parse --short HEAD")
0 -1))))))

(defun circe-network-server-buffer (network)
"Return the server buffer of if existing NETWORK or nil if none."
(dolist (buffer (circe-server-buffers))
(with-current-buffer buffer
(when (string= network circe-network)
(cl-return buffer)))))

;;;###autoload
(defun circe (network-or-server &rest server-options)
"Connect to IRC.
Expand All @@ -1130,12 +1139,16 @@ 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))
(pop-to-buffer-same-window buffer)))
(buffer (or (circe-network-server-buffer network-or-server)
(circe--server-generate-buffer options))))
(if (or (not (circe-network-server-buffer network-or-server))
(y-or-n-p (format "Already connected to %s, reconnect?" network-or-server)))
(progn (with-current-buffer buffer
(if (not (eq major-mode 'circe-server-mode))
(circe-server-mode))
(circe--server-set-variables options)
(circe-reconnect))
(pop-to-buffer-same-window buffer)))))

(defun circe--read-network-and-options ()
"Read a host or network name with completion.
Expand Down

0 comments on commit be04811

Please sign in to comment.