renzmann / treesit-auto

Automatic installation, usage, and fallback for tree-sitter major modes in Emacs 29
GNU General Public License v3.0
407 stars 31 forks source link

(global-treesit-auto-mode t) causes sh-mode not loaded first for bash files #96

Open IceAsteroid opened 7 months ago

IceAsteroid commented 7 months ago

If the (global-treesit-auto-mode t) is set, opening a bash script would not enable the sh-mode.

The reason for sh-mode to be enabled is its useful keybindings for various features it provides.

If I was to set the following, the *message* buffer would complaint:

File mode specification error: (excessive-lisp-nesting 1601)

For example:

    (add-hook 'sh-base-mode-hook (lambda ()
                   (sh-mode)
                   (eglot-ensure)))

After toggle-debug-on-error is toggled, and to reopen a bash script, the debugger would output:

Debugger entered--Lisp error: (excessive-lisp-nesting 1601)
  sh-feature(((bash sh-append bourne "bye" "logout" "select") (bourne sh-append sh "function") (csh sh-append shell "breaksw" "default" "end" "endif" "endsw" "foreach" "goto" "if" "logout" "onintr" "repeat" "switch" "then" "while") (es "break" "catch" "exec" "exit" "fn" "for" "forever" "fork" "if" "return" "throw" "while") (ksh88 sh-append bourne "select") (rc "break" "case" "exec" "exit" "fn" "for" "if" "in" "return" "switch" "while") (sh sh-append shell "done" "esac" "fi" "for" "in" "return") (shell "break" "case" "continue" "exec" "exit") (zsh sh-append bash "select" "foreach")))
  sh-feature(((bash sh-append bourne "bye" "logout" "select") (bourne sh-append sh "function") (csh sh-append shell "breaksw" "default" "end" "endif" "endsw" "foreach" "goto" "if" "logout" "onintr" "repeat" "switch" "then" "while") (es "break" "catch" "exec" "exit" "fn" "for" "forever" "fork" "if" "return" "throw" "while") (ksh88 sh-append bourne "select") (rc "break" "case" "exec" "exit" "fn" "for" "if" "in" "return" "switch" "while") (sh sh-append shell "done" "esac" "fi" "for" "in" "return") (shell "break" "case" "continue" "exec" "exit") (zsh sh-append bash "select" "foreach")))
  sh-feature(((bash sh-append bourne "bye" "logout" "select") (bourne sh-append sh "function") (csh sh-append shell "breaksw" "default" "end" "endif" "endsw" "foreach" "goto" "if" "logout" "onintr" "repeat" "switch" "then" "while") (es "break" "catch" "exec" "exit" "fn" "for" "forever" "fork" "if" "return" "throw" "while") (ksh88 sh-append bourne "select") (rc "break" "case" "exec" "exit" "fn" "for" "if" "in" "return" "switch" "while") (sh sh-append shell "done" "esac" "fi" "for" "in" "return") (shell "break" "case" "continue" "exec" "exit") (zsh sh-append bash "select" "foreach")))
  sh-font-lock-keywords-1(t)
  sh-font-lock-keywords-2()
  font-lock-eval-keywords(sh-font-lock-keywords-2)
  font-lock-set-defaults()
  font-lock-remove-keywords(nil (rainbow-delimiters--propertize))
  rainbow-delimiters-mode()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()
  (lambda nil (sh-mode) (eglot-ensure))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook sh-base-mode-hook sh-mode-hook))
  run-mode-hooks(sh-mode-hook)
  sh-mode()

;;; Omitted excessive lines of the output

;;; It seems to be too long and in endless looping

The problem is, how could I also have sh-mode enabled when (global-treesit-auto-mode t) is set?

Other programming modes like for python work fine, for example, I've set to enable eglot for python files

    (add-hook 'python-base-mode-hook 'eglot-ensure)

Nice and simple, and it works, the python-mode's keybindings and features are loaded unlike sh-mode

IceAsteroid commented 7 months ago

Adding sh-mode to the bash-ts-mode-hook solved the problem. Like follows

(add-hook 'bash-ts-mode-hook 'sh-mode)

I wonder why other modes work fine, but this mode does not

renzmann commented 7 months ago

sh-mode is a bit special, and honestly kind of a pain to program around

Since you have a workaround, I'm not sure if we should keep this issue open?