Function: erc-cmd-BANLIST

erc-cmd-BANLIST is a byte-compiled function defined in erc.el.gz.

Signature

(erc-cmd-BANLIST)

Documentation

Pretty-print the contents of erc-channel-banlist.

The ban list is fetched from the server if necessary.

Aliases

erc-cmd-BL

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc-cmd-BANLIST ()
  "Pretty-print the contents of `erc-channel-banlist'.

The ban list is fetched from the server if necessary."
  (let ((chnl (erc-default-target))
        (chnl-name (buffer-name)))

    (cond
     ((not (erc-channel-p chnl))
      (erc-display-line (erc-make-notice "You're not on a channel\n")
                        'active))

     ((not (get 'erc-channel-banlist 'received-from-server))
      (let ((old-367-hook erc-server-367-functions))
        (setq erc-server-367-functions 'erc-banlist-store
              erc-channel-banlist nil)
        ;; fetch the ban list then callback
        (erc-with-server-buffer
          (erc-once-with-server-event
           368
           (lambda (_proc _parsed)
             (with-current-buffer chnl-name
               (put 'erc-channel-banlist 'received-from-server t)
               (setq erc-server-367-functions old-367-hook)
               (erc-cmd-BANLIST)
               t)))
          (erc-server-send (format "MODE %s b" chnl)))))

     ((null erc-channel-banlist)
      (erc-display-line (erc-make-notice
                         (format "No bans for channel: %s\n" chnl))
                        'active)
      (put 'erc-channel-banlist 'received-from-server nil))

     (t
      (let* ((erc-fill-column (or (and (boundp 'erc-fill-column)
                                       erc-fill-column)
                                  (and (boundp 'fill-column)
                                       fill-column)
                                  (1- (window-width))))
             (separator (make-string erc-fill-column ?=))
             (fmt (concat
                   "%-" (number-to-string (/ erc-fill-column 2)) "s"
                   "%" (number-to-string (/ erc-fill-column 2)) "s")))

        (erc-display-line
         (erc-make-notice (format "Ban list for channel: %s\n"
                                  (erc-default-target)))
         'active)

        (erc-display-line separator 'active)
        (erc-display-line (format fmt "Ban Mask" "Banned By") 'active)
        (erc-display-line separator 'active)

        (mapc
         (lambda (x)
           (erc-display-line
            (format fmt
                    (truncate-string-to-width (cdr x) (/ erc-fill-column 2))
                    (if (car x)
                        (truncate-string-to-width (car x) (/ erc-fill-column 2))
                      ""))
            'active))
         erc-channel-banlist)

        (erc-display-line (erc-make-notice "End of Ban list")
                          'active)
        (put 'erc-channel-banlist 'received-from-server nil)))))
  t)