]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix visiting XBM/XPM files when 'c-ts-mode' is active
authorEli Zaretskii <eliz@gnu.org>
Sun, 19 Mar 2023 20:19:52 +0000 (22:19 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sun, 19 Mar 2023 20:19:52 +0000 (22:19 +0200)
* lisp/progmodes/c-ts-mode.el (treesit-ready-p): Fix association
for XBM/XPM files in 'auto-mode-alist'.  (Bug#62276)

lisp/progmodes/c-ts-mode.el

index ff86b9e054468d8be7c47d13abf15545b9bdcd8d..659db46dc129793bd2e77cfa203c49c0dacb6913 100644 (file)
@@ -1061,10 +1061,15 @@ the code is C or C++ and based on that chooses whether to enable
                  '("\\(\\.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))