I’m having some problems with my setup/teardown for a mode. It looks like enable
is called three times…? And my failsafe to avoid running more than once doesn’t work?
The code tries to add an extra hint-selector, , div[role='link']
when starting, and tries to remove it when stopping. It only adds if it doesn’t find it already, and only removes a single instance if it added it.
But somehow three instances are added, and none removed. I don’t know how to correctly debug this. sly-db-break-on-signal
gives too much noise as there’s a lot of signals. Tried using sly stickers, but couldn’t get it to break.
;; TODO: This probably exist somewhere already
(defun find-mode (mode &optional (buffer (current-buffer)))
(find mode (modes buffer) :test #'equal :key #'name))
(define-mode gmail-mode ()
((extra-hints ", div[role='link']")
(extra-hints-added nil)))
(defmethod enable ((mode gmail-mode) &key)
(let* ((hint-mode (find-mode 'nyxt/mode/hint:hint-mode (buffer mode)))
(hints-selector (nyxt/mode/hint:hints-selector hint-mode)))
(unless (find (extra-hints mode) hints-selector :test #'equal)
(setf (extra-hints-added mode) (extra-hints mode)
(nyxt/mode/hint:hints-selector hint-mode) (str:concat hints-selector (extra-hints mode))))))
(defmethod disable ((mode gmail-mode) &key)
(when (extra-hints-added mode)
(let* ((hint-mode (find-mode 'nyxt/mode/hint:hint-mode (buffer mode)))
(new-selector (cl-ppcre:regex-replace (extra-hints-added mode) (nyxt/mode/hint:hints-selector hint-mode) "")))
(setf (nyxt/mode/hint:hints-selector hint-mode) new-selector
(extra-hints-added mode) nil))))
(define-auto-rule '(match-host "mail.google.com")
:included '(gmail-mode))