Function: erc-open
erc-open is a byte-compiled function defined in erc.el.gz.
Signature
(erc-open &optional SERVER PORT NICK FULL-NAME CONNECT PASSWD TGT-LIST CHANNEL PROCESS CLIENT-CERTIFICATE USER ID)
Documentation
Return a new or reinitialized server or target buffer.
If CONNECT is non-nil, connect to SERVER and return its new or
reassociated buffer. Otherwise, assume PROCESS is non-nil and belongs
to an active session, and return a new or refurbished target buffer for
CHANNEL, which may also be a query target (the parameter name remains
for historical reasons). Pass SERVER, PORT, NICK, USER, FULL-NAME, and
PASSWD to erc-determine-parameters for preserving as session-local
variables. Do something similar for CLIENT-CERTIFICATE and ID, which
should be as described by erc-tls.
Note that ERC ignores TGT-LIST and initializes erc-default-recipients
with CHANNEL as its only member. Note also that this function has the
side effect of setting the current buffer to the one it returns. Use
with-current-buffer or save-excursion to nullify this effect.
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc-open (&optional server port nick full-name
connect passwd _tgt-list channel process
client-certificate user id)
"Return a new or reinitialized server or target buffer.
If CONNECT is non-nil, connect to SERVER and return its new or
reassociated buffer. Otherwise, assume PROCESS is non-nil and belongs
to an active session, and return a new or refurbished target buffer for
CHANNEL, which may also be a query target (the parameter name remains
for historical reasons). Pass SERVER, PORT, NICK, USER, FULL-NAME, and
PASSWD to `erc-determine-parameters' for preserving as session-local
variables. Do something similar for CLIENT-CERTIFICATE and ID, which
should be as described by `erc-tls'.
Note that ERC ignores TGT-LIST and initializes `erc-default-recipients'
with CHANNEL as its only member. Note also that this function has the
side effect of setting the current buffer to the one it returns. Use
`with-current-buffer' or `save-excursion' to nullify this effect."
(let* ((target (and channel (erc--target-from-string channel)))
(buffer (erc-get-buffer-create server port nil target id))
(old-buffer (current-buffer))
(erc--target-priors (and target ; buf from prior session
(buffer-local-value 'erc--target buffer)
(buffer-local-variables buffer)))
(old-recon-count erc-server-reconnect-count)
(old-point nil)
(delayed-modules nil)
(continued-session (or erc--server-reconnecting
erc--target-priors
(and-let* (((not target))
(m (buffer-local-value
'erc-input-marker buffer))
((marker-position m)))
(buffer-local-variables buffer)))))
(when connect (run-hook-with-args 'erc-before-connect server port nick))
(set-buffer buffer)
(setq old-point (point))
(setq delayed-modules
(erc--merge-local-modes (let ((erc--updating-modules-p t))
(erc--update-modules
(erc--sort-modules erc-modules)))
(or erc--server-reconnecting
erc--target-priors)))
(delay-mode-hooks (erc-mode))
(setq erc-server-reconnect-count old-recon-count)
(when (setq erc-server-connected (not connect))
(setq erc-server-announced-name
(buffer-local-value 'erc-server-announced-name old-buffer)))
;; connection parameters
(setq erc-server-process process)
;; stack of default recipients
(when channel (setq erc-default-recipients (list channel)))
(when target
(setq erc--target target
erc-network (erc-network)))
(setq erc-server-current-nick nil)
;; Initialize erc-server-users and erc-channel-users
(if connect
(progn ;; server buffer
(setq erc-server-users
(make-hash-table :test 'equal))
(setq erc-channel-users nil))
(progn ;; target buffer
(setq erc-server-users nil)
(setq erc-channel-users
(make-hash-table :test 'equal))))
(setq erc-channel-topic "")
;; limit on the number of users on the channel (mode +l)
(setq erc-channel-user-limit nil)
(setq erc-channel-key nil)
;; last active buffer, defaults to this one
(erc-set-active-buffer buffer)
;; last invitation channel
(setq erc-invitation nil)
;; Server channel list
(setq erc-channel-list ())
;; login-time 'nick in use' error
(setq erc-bad-nick nil)
;; whether we have logged in
(setq erc-logged-in nil)
;; The local copy of `erc-nick' - the list of nicks to choose
(setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
;; client certificate (only useful if connecting over TLS)
(setq erc-session-client-certificate client-certificate)
(setq erc-networks--id
(if connect
(or (and erc--server-reconnecting
(alist-get 'erc-networks--id erc--server-reconnecting))
(and id (erc-networks--id-create id)))
(buffer-local-value 'erc-networks--id old-buffer)))
;; debug output buffer
(setq erc-dbuf
(when erc-log-p
(get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
(erc--initialize-markers old-point continued-session)
(erc-determine-parameters server port nick full-name user passwd)
(save-excursion (run-mode-hooks)
(dolist (mod (car delayed-modules))
(unless (and (boundp mod) (symbol-value mod))
(funcall mod +1)))
(dolist (var (cdr delayed-modules)) (set var nil)))
;; Saving log file on exit
(run-hook-with-args 'erc-connect-pre-hook buffer)
(if connect
(erc-server-connect erc-session-server
(erc-string-to-port erc-session-port)
buffer
erc-session-client-certificate)
(erc-update-mode-line))
;; Now display the buffer in a window as per user wishes.
(when (eq buffer old-buffer) (cl-assert (and connect (not target))))
(unless (and (not erc-reconnect-display-server-buffers)
(eq buffer old-buffer))
(when erc-log-p
;; we can't log to debug buffer, it may not exist yet
(message "erc: old buffer %s, switching to %s"
old-buffer buffer))
(let ((display-buffer-overriding-action
(or erc--display-buffer-overriding-action
display-buffer-overriding-action)))
(erc-setup-buffer buffer)
(run-hooks 'erc--setup-buffer-hook)))
buffer))