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)

Documentation

Connect to SERVER on PORT as NICK with FULL-NAME.

If CONNECT is non-nil, connect to the server. Otherwise assume already connected and just create a separate buffer for the new target CHANNEL.

Use PASSWD as user password on the server. If TGT-LIST is non-nil, use it to initialize erc-default-recipients.

CLIENT-CERTIFICATE, if non-nil, should either be a list where the first element is the file name of the private key corresponding to a client certificate and the second element is the file name of the client certificate itself to use when connecting over TLS, or t, which means that auth-source will be queried for the private key and the certificate.

Returns the buffer for the given server or channel.

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)
  "Connect to SERVER on PORT as NICK with FULL-NAME.

If CONNECT is non-nil, connect to the server.  Otherwise assume
already connected and just create a separate buffer for the new
target CHANNEL.

Use PASSWD as user password on the server.  If TGT-LIST is
non-nil, use it to initialize `erc-default-recipients'.

CLIENT-CERTIFICATE, if non-nil, should either be a list where the
first element is the file name of the private key corresponding
to a client certificate and the second element is the file name
of the client certificate itself to use when connecting over TLS,
or t, which means that `auth-source' will be queried for the
private key and the certificate.

Returns the buffer for the given server or channel."
  (let ((server-announced-name (when (and (boundp 'erc-session-server)
                                          (string= server erc-session-server))
                                 erc-server-announced-name))
        (connected-p (unless connect erc-server-connected))
        (buffer (erc-get-buffer-create server port channel))
        (old-buffer (current-buffer))
        old-point
        continued-session)
    (when connect (run-hook-with-args 'erc-before-connect server port nick))
    (erc-update-modules)
    (set-buffer buffer)
    (setq old-point (point))
    (let ((old-recon-count erc-server-reconnect-count))
      (erc-mode)
      (setq erc-server-reconnect-count old-recon-count))
    (setq erc-server-announced-name server-announced-name)
    (setq erc-server-connected connected-p)
    ;; connection parameters
    (setq erc-server-process process)
    (setq erc-insert-marker (make-marker))
    (setq erc-input-marker (make-marker))
    ;; go to the end of the buffer and open a new line
    ;; (the buffer may have existed)
    (goto-char (point-max))
    (forward-line 0)
    (when (get-text-property (point) 'erc-prompt)
      (setq continued-session t)
      (set-marker erc-input-marker
                  (or (next-single-property-change (point) 'erc-prompt)
                      (point-max))))
    (unless continued-session
      (goto-char (point-max))
      (insert "\n"))
    (set-marker erc-insert-marker (point))
    ;; stack of default recipients
    (setq erc-default-recipients tgt-list)
    (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))))
    ;; clear last incomplete line read
    (setq erc-server-filter-data nil)
    (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)))
    ;; password stuff
    (setq erc-session-password
          (or passwd
              (let ((secret
                     (plist-get
                      (nth 0
                           (auth-source-search :host server
                                               :max 1
                                               :user nick
                                               ;; secrets.el wouldn’t accept a number
                                               :port (if (numberp port) (number-to-string port) port)
                                               :require '(:secret)))
                      :secret)))
                (if (functionp secret)
                    (funcall secret)
                  secret))))
    ;; client certificate (only useful if connecting over TLS)
    (setq erc-session-client-certificate client-certificate)
    ;; debug output buffer
    (setq erc-dbuf
          (when erc-log-p
            (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
    ;; set up prompt
    (unless continued-session
      (goto-char (point-max))
      (insert "\n"))
    (if continued-session
        (goto-char old-point)
      (set-marker erc-insert-marker (point))
      (erc-display-prompt)
      (goto-char (point-max)))

    (erc-determine-parameters server port nick full-name)

    ;; Saving log file on exit
    (run-hook-with-args 'erc-connect-pre-hook buffer)

    (when connect
      (erc-server-connect erc-session-server
                          erc-session-port
                          buffer
                          erc-session-client-certificate))
    (erc-update-mode-line)

    ;; Now display the buffer in a window as per user wishes.
    (unless (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))
      (erc-setup-buffer buffer))

    buffer))