'("\\(\\.ii\\|\\.\\(CC?\\|HH?\\)\\|\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\|\\.\\(cc\\|hh\\)\\)\\'"
. c++-ts-mode)))
-(if (treesit-ready-p 'c)
- (add-to-list 'auto-mode-alist
- '("\\(\\.[chi]\\|\\.lex\\|\\.y\\(acc\\)?\\|\\.x[bp]m\\)\\'"
- . c-ts-mode)))
+(when (treesit-ready-p 'c)
+ (add-to-list 'auto-mode-alist
+ '("\\(\\.[chi]\\|\\.lex\\|\\.y\\(acc\\)?\\)\\'" . c-ts-mode))
+ (add-to-list 'auto-mode-alist '("\\.x[pb]m\\'" . c-ts-mode))
+ ;; image-mode's association must be before the C mode, otherwise XPM
+ ;; images will be initially visited as C files. Also note that the
+ ;; regexp must be different from what files.el does, or else
+ ;; add-to-list will not add the association where we want it.
+ (add-to-list 'auto-mode-alist '("\\.x[pb]m\\'" . image-mode)))
(if (and (treesit-ready-p 'cpp)
(treesit-ready-p 'c))