Better hint-selectiors for gmail

I’ve created a small mode which fixes the hints-selector in gmail buffers. It adds a selector for div[role='link'] when visiting a gmail buffer, and removes it when the mode is disabled.

Without gmail-mode:

With gmail-mode:

;; 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 (str:replace-first (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 "")
  :included '(gmail-mode))
1 Like

That is really cool man! I am always inspired to see people doing cool things with Lisp, and especially Nyxt, of course :slight_smile: