anchor.diff:                           (and enable-p (last-active-modes auto-mode)))
                   :test #'mode-equal))))
   
  -(export-always 'url-infer-match)
   (declaim (ftype (function (string) list) url-infer-match))
   (defun url-infer-match (url)
     "Infer the best `test' for `auto-mode-rule', based on the form of URL.
  
positive.code: 
  (uiop:define-package :nyxt/auto-mode
    (:use :common-lisp :nyxt)
    (:import-from #:serapeum #:export-always)
    (:import-from #:class-star #:define-class)
    (:documentation "Mode for automatic URL-based mode toggling."))
  (in-package :nyxt/auto-mode)
  
  (export-always '*prompt-on-mode-toggle*)
  (defvar *prompt-on-mode-toggle* nil
    "Whether user will be asked about adding the mode to included/excluded modes
  in the auto-mode rules on mode activation/deactivation.")
  
  (export-always '*non-rememberable-modes*)
  (defvar *non-rememberable-modes*
    ;; base-mode conflicts with its Nyxt symbol if it's not prefixed
    '(help-mode web-mode auto-mode nyxt::base-mode)
    "Modes that `auto-mode' won't even try to save.
  Append names of modes you want to always control manually to this list.
  Be careful with deleting the defaults -- it can be harmful for your browsing.")
  
  (declaim (ftype (function ((or symbol root-mode)) (values symbol &optional)) maybe-mode-name))
  (defun maybe-mode-name (mode)
  
negative.code: 
  (declaim (ftype (function (quri:uri buffer)) enable-matching-modes))
  (defun enable-matching-modes (url buffer)
    (let ((rule (matching-auto-mode-rule url buffer))
          (auto-mode (find-mode buffer 'auto-mode)))
      (enable-modes (set-difference
                     (included rule)
                     (rememberable-of (mapcar #'mode-name (modes buffer)) auto-mode)
                     :test #'mode-equal)
                    buffer)
      (disable-modes (if (exact-p rule)
                         (set-difference
                          (rememberable-of (mapcar #'mode-name (modes buffer)) auto-mode)
                          (included rule) :test #'mode-equal)
                         (excluded rule))
                     buffer)))
  