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

nerd-icons fail because treesit-auto makes (nil . glsl-ts-mode) entry in auto mode alist

Open Schievel1 opened this issue 1 year ago • 2 comments

Doom emacs uses nerd icons for it's mode-line. When using treesit-auto it changes the auto-mode-alist so that one entry of it is (nil . glsl-ts-mode). This causes problems when opening a file, because the function that searches for a fitting icon for that file in the modeline can not handle the nil it seems:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match(nil "/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/...")
  #f(compiled-function (it) #<bytecode -0x631c5a76de119ba>)((nil . glsl-ts-mode))
  cl--position(nil (("\\.conf$" . bitbake-mode) ("\\.bbclass$" . bitbake-mode) ("\\.bbappend$" . bitbake-mode) ("\\.inc$" . bitbake-mode) ("\\.bb$" . bitbake-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) (nil . glsl-ts-mode) ("[/\\]\\(?:Containerfile\\|Dockerfile\\)\\(?:\\.[^/\\]*\\)?..." . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.[pP][dD][fF]\\'" . pdf-view-mode) ("Procfile\\'" . yaml-mode) ("/bspwmrc\\'" . sh-mode) ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode) ("\\.bats\\'" . sh-mode) ("\\.rs\\'" . rustic-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.tsx\\'" . typescript-mode) ("\\.pac\\'" . rjsx-mode) ("\\.es6\\'" . rjsx-mode) ("\\.[mc]?js\\'" . rjsx-mode) ("\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" . json-mode) ("\\.Cask\\'" . emacs-lisp-mode) ("\\.rss\\'" . nxml-mode) ("\\.xs\\(?:d\\|lt\\)\\'" . nxml-mode) ("\\.p\\(?:list\\|om\\)\\'" . nxml-mode) ("\\.h\\'" . +cc-c-c++-objc-mode) ("\\.mm\\'" . objc-mode) ("\\.pdf\\'" . pdf-view-mode) ("/\\.doomrc\\'" . emacs-lisp-mode) ("/\\.doom\\(?:project\\|module\\|profile\\)?\\'" . lisp-data-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.tsx?\\'" . typescript-mode) ("\\.jsx\\'" . rjsx-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ...) 0 nil nil)
  cl-position(nil (("\\.conf$" . bitbake-mode) ("\\.bbclass$" . bitbake-mode) ("\\.bbappend$" . bitbake-mode) ("\\.inc$" . bitbake-mode) ("\\.bb$" . bitbake-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) (nil . glsl-ts-mode) ("[/\\]\\(?:Containerfile\\|Dockerfile\\)\\(?:\\.[^/\\]*\\)?..." . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.[pP][dD][fF]\\'" . pdf-view-mode) ("Procfile\\'" . yaml-mode) ("/bspwmrc\\'" . sh-mode) ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode) ("\\.bats\\'" . sh-mode) ("\\.rs\\'" . rustic-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.tsx\\'" . typescript-mode) ("\\.pac\\'" . rjsx-mode) ("\\.es6\\'" . rjsx-mode) ("\\.[mc]?js\\'" . rjsx-mode) ("\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" . json-mode) ("\\.Cask\\'" . emacs-lisp-mode) ("\\.rss\\'" . nxml-mode) ("\\.xs\\(?:d\\|lt\\)\\'" . nxml-mode) ("\\.p\\(?:list\\|om\\)\\'" . nxml-mode) ("\\.h\\'" . +cc-c-c++-objc-mode) ("\\.mm\\'" . objc-mode) ("\\.pdf\\'" . pdf-view-mode) ("/\\.doomrc\\'" . emacs-lisp-mode) ("/\\.doom\\(?:project\\|module\\|profile\\)?\\'" . lisp-data-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.tsx?\\'" . typescript-mode) ("\\.jsx\\'" . rjsx-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ...) :if #f(compiled-function (it) #<bytecode -0x631c5a76de119ba>))
  cl-find(nil (("\\.conf$" . bitbake-mode) ("\\.bbclass$" . bitbake-mode) ("\\.bbappend$" . bitbake-mode) ("\\.inc$" . bitbake-mode) ("\\.bb$" . bitbake-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) (nil . glsl-ts-mode) ("[/\\]\\(?:Containerfile\\|Dockerfile\\)\\(?:\\.[^/\\]*\\)?..." . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.[pP][dD][fF]\\'" . pdf-view-mode) ("Procfile\\'" . yaml-mode) ("/bspwmrc\\'" . sh-mode) ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode) ("\\.bats\\'" . sh-mode) ("\\.rs\\'" . rustic-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.tsx\\'" . typescript-mode) ("\\.pac\\'" . rjsx-mode) ("\\.es6\\'" . rjsx-mode) ("\\.[mc]?js\\'" . rjsx-mode) ("\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" . json-mode) ("\\.Cask\\'" . emacs-lisp-mode) ("\\.rss\\'" . nxml-mode) ("\\.xs\\(?:d\\|lt\\)\\'" . nxml-mode) ("\\.p\\(?:list\\|om\\)\\'" . nxml-mode) ("\\.h\\'" . +cc-c-c++-objc-mode) ("\\.mm\\'" . objc-mode) ("\\.pdf\\'" . pdf-view-mode) ("/\\.doomrc\\'" . emacs-lisp-mode) ("/\\.doom\\(?:project\\|module\\|profile\\)?\\'" . lisp-data-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.tsx?\\'" . typescript-mode) ("\\.jsx\\'" . rjsx-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ...) :if #f(compiled-function (it) #<bytecode -0x631c5a76de119ba>))
  cl-find-if(#f(compiled-function (it) #<bytecode -0x631c5a76de119ba>) (("\\.conf$" . bitbake-mode) ("\\.bbclass$" . bitbake-mode) ("\\.bbappend$" . bitbake-mode) ("\\.inc$" . bitbake-mode) ("\\.bb$" . bitbake-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) (nil . glsl-ts-mode) ("[/\\]\\(?:Containerfile\\|Dockerfile\\)\\(?:\\.[^/\\]*\\)?..." . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.[pP][dD][fF]\\'" . pdf-view-mode) ("Procfile\\'" . yaml-mode) ("/bspwmrc\\'" . sh-mode) ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode) ("\\.bats\\'" . sh-mode) ("\\.rs\\'" . rustic-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.tsx\\'" . typescript-mode) ("\\.pac\\'" . rjsx-mode) ("\\.es6\\'" . rjsx-mode) ("\\.[mc]?js\\'" . rjsx-mode) ("\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" . json-mode) ("\\.Cask\\'" . emacs-lisp-mode) ("\\.rss\\'" . nxml-mode) ("\\.xs\\(?:d\\|lt\\)\\'" . nxml-mode) ("\\.p\\(?:list\\|om\\)\\'" . nxml-mode) ("\\.h\\'" . +cc-c-c++-objc-mode) ("\\.mm\\'" . objc-mode) ("\\.pdf\\'" . pdf-view-mode) ("/\\.doomrc\\'" . emacs-lisp-mode) ("/\\.doom\\(?:project\\|module\\|profile\\)?\\'" . lisp-data-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.tsx?\\'" . typescript-mode) ("\\.jsx\\'" . rjsx-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ...))
  nerd-icons-match-to-alist("/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." (("\\.conf$" . bitbake-mode) ("\\.bbclass$" . bitbake-mode) ("\\.bbappend$" . bitbake-mode) ("\\.inc$" . bitbake-mode) ("\\.bb$" . bitbake-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) (nil . glsl-ts-mode) ("[/\\]\\(?:Containerfile\\|Dockerfile\\)\\(?:\\.[^/\\]*\\)?..." . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.[pP][dD][fF]\\'" . pdf-view-mode) ("Procfile\\'" . yaml-mode) ("/bspwmrc\\'" . sh-mode) ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode) ("\\.bats\\'" . sh-mode) ("\\.rs\\'" . rustic-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.tsx\\'" . typescript-mode) ("\\.pac\\'" . rjsx-mode) ("\\.es6\\'" . rjsx-mode) ("\\.[mc]?js\\'" . rjsx-mode) ("\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" . json-mode) ("\\.Cask\\'" . emacs-lisp-mode) ("\\.rss\\'" . nxml-mode) ("\\.xs\\(?:d\\|lt\\)\\'" . nxml-mode) ("\\.p\\(?:list\\|om\\)\\'" . nxml-mode) ("\\.h\\'" . +cc-c-c++-objc-mode) ("\\.mm\\'" . objc-mode) ("\\.pdf\\'" . pdf-view-mode) ("/\\.doomrc\\'" . emacs-lisp-mode) ("/\\.doom\\(?:project\\|module\\|profile\\)?\\'" . lisp-data-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.tsx?\\'" . typescript-mode) ("\\.jsx\\'" . rjsx-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ...))
  nerd-icons-auto-mode-match?()
  nerd-icons--icon-info-for-buffer()
  nerd-icons-icon-for-buffer()
  doom-modeline-icon-for-buffer()
  doom-modeline-update-buffer-file-icon()
  run-hooks(change-major-mode-after-body-hook after-change-major-mode-hook)
  normal-mode(t)
  #<subr after-find-file>(nil t nil nil nil)
  apply(#<subr after-find-file> (nil t))
  (progn (fset #'sit-for #'ignore) (apply fn args))
  (unwind-protect (progn (fset #'sit-for #'ignore) (apply fn args)) (fset #'sit-for old))
  (let* ((old (symbol-function #'sit-for))) (unwind-protect (progn (fset #'sit-for #'ignore) (apply fn args)) (fset #'sit-for old)))
  doom--shut-up-autosave-a(#<subr after-find-file> nil t)
  apply(doom--shut-up-autosave-a #<subr after-find-file> (nil t))
  #f(advice doom--shut-up-autosave-a :around #<subr after-find-file>)(nil t)
  apply(#f(advice doom--shut-up-autosave-a :around #<subr after-find-file>) (nil t))
  #f(advice chain-doom-first-buffer-hook-to-find-file-hook-h :before #f(advice doom--shut-up-autosave-a :around #<subr after-find-file>) ((depth . -101)))(nil t)
  apply(#f(advice chain-doom-first-buffer-hook-to-find-file-hook-h :before #f(advice doom--shut-up-autosave-a :around #<subr after-find-file>) ((depth . -101))) (nil t))
  after-find-file(nil t)
  find-file-noselect-1(#<buffer ./Stadler/FLIRT/Slowenien/trunk/src/main/c/Project/Project.c> "/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." nil nil "/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." (13792273858903848 82))
  #<subr find-file-noselect>("/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." nil nil nil)
  apply(#<subr find-file-noselect> "/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." (nil nil nil))
  editorconfig--advice-find-file-noselect(#<subr find-file-noselect> "/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." nil nil nil)
  apply(editorconfig--advice-find-file-noselect #<subr find-file-noselect> ("/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." nil nil nil))
  find-file-noselect("/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/..." nil nil nil)
  find-file("/mnt/c/svn/MTB4/Stadler/FLIRT/Slowenien/trunk/src/...")
  #<subr consult-recent-file>()
  apply(#<subr consult-recent-file> nil)
  consult-recent-file()
  funcall-interactively(consult-recent-file)
  command-execute(consult-recent-file)

Without treesit-auto the entry in auto-mode-alist looks like this: ("\.glsl\'" . glsl-mode)

My treesit-auto config looks like this:

(use-package treesit-auto
:custom
  (treesit-auto-install 'prompt)
:config
  (treesit-auto-add-to-auto-mode-alist 'all)
  (global-treesit-auto-mode))

Doing a simple (delete 'glsl treesit-auto-langs) makes nerdicons work again. I don't know what glsl is so I don't care that much for it's ts mode. But something off in treesit-autos generating of auto-mode-alist it seems.

Schievel1 avatar Nov 22 '24 11:11 Schievel1

I also hit this problem, when using (treesit-auto-add-to-auto-mode-alist 'all). The problem is, as far as I understand, that the recipe for the glsl-ts-mode does not declare an extension. I don't know, if there is a default extension, which could be set for this particular mode. But to avoid this in general, it would be easy to check, if the extension is set in treesit-auto-add-to-auto-mode-alist, before adding it to auto-mode-alist:

My proposed change would look like this:

624,625c624,627
<       (add-to-list 'auto-mode-alist
<                    (cons (treesit-auto-recipe-ext r) (treesit-auto-recipe-ts-mode r))))))
---
>       (let ((ext (treesit-auto-recipe-ext r)))
>         (unless (null ext)
>           (add-to-list 'auto-mode-alist
>                        (cons ext (treesit-auto-recipe-ts-mode r))))))))

I'm also happy to create a pull request if this fix would be accepted.

fbrosda avatar Mar 02 '25 18:03 fbrosda