alphapapa / topsy.el

Simple sticky header showing definition beyond top of window
GNU General Public License v3.0
100 stars 6 forks source link

Change: (topsy-mode) Match topsy-mode-functions by derived-mode-p #10

Open josephmturner opened 1 year ago

alphapapa commented 1 year ago

Hi Joseph,

This seems like a good idea, but this patch would seem to not select the default function in unrecognized major modes. I think the code should be more like this:

(or (cl-find-if #'derived-mode-p topsy-mode-functions :key #'car)
    (alist-get nil topsy-mode-functions))

What do you think? Thanks.

josephmturner commented 1 year ago

Good catch - (cl-find-if (lambda (cell) (derived-mode-p (car cell))) topsy-mode-functions) should be replaced with (cl-find-if #'derived-mode-p topsy-mode-functions :key #'car).

this patch would seem to not select the default function in unrecognized major modes

FWIW, the following does work since mode will be bound to nil when there's no match

 (let ((mode (car (cl-find-if #'derived-mode-p topsy-mode-functions :key #'car))))
          (setf topsy-fn (alist-get mode topsy-mode-functions)
                header-line-format 'topsy-header-line-format))

But... it's obviously not as easy to read. Hope this last commit looks good. Thank you!