Prompter:object-attributes not called?

I’m trying to create a theme switcher prompt, but I don’t understand how prompter:active-attributes-keys is supposed to work. I list Name and Package, but only Name is visible. If I don’t include active-attribute-keys, Name, Visibility and Documentation is shown. So I guess my prompter:object-attributes isn’t called…?


My configuration:

(defun set-current-theme (theme)
  (setf (slot-value *browser* 'theme) theme))

(defun get-themes (&optional (package 'nyxt-user))
  (cl:remove-if-not (lambda (x) (theme:themep (symbol-value x)))
                    (nsymbols:package-variables package)))

(defun all-themes ()
  (mapcan #'get-themes (list-all-packages)))

(define-class theme-source (prompter:source)
  ((prompter:name "Themes")
   (prompter:constructor (all-themes))
   (prompter:filter-preprocessor #'prompter:filter-exact-matches)
   (prompter:active-attributes-keys '("Name" "Package"))
   (prompter:actions-on-return (list (lambda-command set-theme (themes)
                                       (set-current-theme (symbol-value (car themes))))))))

(defmethod prompter:object-attributes ((theme theme:theme) (source theme-source))
  (declare (ignore source))
  `(("Name" ,(symbol-name theme))
    ("Package" ,(package-name (symbol-package theme)))))

(define-command switch-theme ()
   :prompt "Set current theme"
   :sources (make-instance 'theme-source)))

@ambrevar is probably best equipped to understand what’s going on. But it’s real weird and I cannot guess what has gone wrong here :cold_sweat:

You’re specializing your prompter:object-attributes method against theme:theme, but all-themes returns theme symbols, not theme objects.

Either specialize against symbol, or change get-themes to return theme objects.

Thanks! I need the symbol as the theme doesn’t have a name, but specializing on symbol works great!

1 Like