Function: erc--warn-once-before-connect

erc--warn-once-before-connect is a byte-compiled function defined in erc.el.gz.

Signature

(erc--warn-once-before-connect MODE-VAR &rest ARGS)

Documentation

Display an "error notice" once per session (logical connection).

Defer to erc--warn-once-before-connect-function to do the displaying. If the current buffer is associated with a live server buffer and a non-nil erc-server-process, even if no longer live, display the notice. Do so soon rather than immediately if called by erc-display-message indirectly. If in a server buffer that's yet to dial, arrange to try again on erc-connect-pre-hook. Otherwise, in non-ERC buffers, if MODE-VAR belongs to a global module, try again at most once the next time erc-mode-hook runs anywhere. If a message is displayed, inhibit duplicates by adding a hash of MODE-VAR and ARGS to erc--warn-once-before-connect-calls.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc--warn-once-before-connect (mode-var &rest args)
  "Display an \"error notice\" once per session (logical connection).
Defer to `erc--warn-once-before-connect-function' to do the displaying.
If the current buffer is associated with a live server buffer and a
non-nil `erc-server-process', even if no longer live, display the
notice.  Do so soon rather than immediately if called by
`erc-display-message' indirectly.  If in a server buffer that's yet to
dial, arrange to try again on `erc-connect-pre-hook'.  Otherwise, in
non-ERC buffers, if MODE-VAR belongs to a global module, try again at
most once the next time `erc-mode-hook' runs anywhere.  If a message is
displayed, inhibit duplicates by adding a hash of MODE-VAR and ARGS to
`erc--warn-once-before-connect-calls'."
  (declare (indent 1))
  (cl-assert (stringp (car args)))
  (letrec ((warn-fn erc--warn-once-before-connect-function)
           (hook-name nil)
           (hook-fn
            (lambda (&rest _)
              (when hook-name
                (remove-hook hook-name hook-fn (local-variable-p hook-name)))
              (let ((erc--warn-once-before-connect-function warn-fn))
                (apply #'erc--warn-once-before-connect 'erc-fake args)))))
    (cond
     ((not (derived-mode-p 'erc-mode))
      (when (custom-variable-p mode-var)
        (add-hook (setq hook-name 'erc-mode-hook) hook-fn)))
     ;; Has a live server buffer with a non-nil `erc-server-process'.
     ((erc-with-server-buffer
        (let ((do-fn (lambda ()
                       (with-memoization
                           ;; Use `sxhash' to avoid weak references.
                           (alist-get (sxhash-equal (cons mode-var args))
                                      erc--warn-once-before-connect-calls)
                         (apply warn-fn args)
                         t)))) ; for side-effects only
          (if erc--msg-props ; escape `erc-display-message' call stack
              (run-at-time nil nil (lambda (buffer)
                                     (erc-with-buffer (buffer)
                                       (funcall do-fn)))
                           (current-buffer))
            (funcall do-fn)))))
     ;; A server buffer with a null `erc-server-process'.
     ((null erc--target)
      (add-hook (setq hook-name 'erc-connect-pre-hook) hook-fn 0 t)))))