treesit-auto icon indicating copy to clipboard operation
treesit-auto copied to clipboard

Guard against empty :ext on treesit-auto-add-to-auto-mode-alist

Open bvraghav opened this issue 7 months ago • 1 comments

An unguarded (add-to-list 'auto-mode-alist ...) introduces a bug in 'auto-mode-alist e.g. the following entry

'(nil . glsl-mode)

This miserably fails at every file visitation, because
(set-auto-mode) would eventually do
(assoc-default filename auto-mode-alist #'string-match) wherein
(string-match nil filename) raises the following error:

(wrong-type-argument stringp nil)

PS: In treesit-auto.el:

(add-to-list 'auto-mode-alist
             (cons (treesit-auto-recipe-ext r) (treesit-auto-recipe-ts-mode r)))

bvraghav avatar May 16 '25 00:05 bvraghav

Locally, I introduced this correction instead,

(when (treesit-auto-recipe-ext r)
  (add-to-list 'auto-mode-alist
               (cons (treesit-auto-recipe-ext r) (treesit-auto-recipe-ts-mode r))))

Hope this suggestion aligns with the intended design.

bvraghav avatar May 16 '25 00:05 bvraghav