Fix visiting RPM files

We cannot call 'sh-set-shell' inside 'sh-base-mode', since various
settings of 'sh-mode', in particular the syntax table, is not yet
set.  Likewise with various hooks: since 'sh-base-mode' is not a
mode any file should be visited with, it makes no sense to set up
stuff like 'hack-local-variables-hook' in 'sh-base-mode'; it
should be set in the descendant modes instead.
* lisp/progmodes/sh-script.el (sh-base-mode): Move the call to
'sh-set-shell' from here...
(sh-mode): ...to here...
(bash-ts-mode): ...with a copy here.  (Bug#62748)
This commit is contained in:
Eli Zaretskii 2023-04-10 16:09:58 +03:00
parent b4afee0319
commit 338b3718b6

View file

@ -1537,13 +1537,7 @@ implementations. Currently there are two: `sh-mode' and
(lambda (terminator) (lambda (terminator)
(if (eq terminator ?') (if (eq terminator ?')
"'\\'" "'\\'"
"\\"))) "\\"))))
;; Parse or insert magic number for exec, and set all variables depending
;; on the shell thus determined.
(sh-set-shell (sh--guess-shell) nil nil)
(add-hook 'flymake-diagnostic-functions #'sh-shellcheck-flymake nil t)
(add-hook 'hack-local-variables-hook
#'sh-after-hack-local-variables nil t))
;;;###autoload ;;;###autoload
(define-derived-mode sh-mode sh-base-mode "Shell-script" (define-derived-mode sh-mode sh-base-mode "Shell-script"
@ -1603,7 +1597,13 @@ with your script for an edit-interpret-debug cycle."
nil nil nil nil
((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil
(font-lock-syntactic-face-function (font-lock-syntactic-face-function
. ,#'sh-font-lock-syntactic-face-function)))) . ,#'sh-font-lock-syntactic-face-function)))
;; Parse or insert magic number for exec, and set all variables depending
;; on the shell thus determined.
(sh-set-shell (sh--guess-shell) nil nil)
(add-hook 'flymake-diagnostic-functions #'sh-shellcheck-flymake nil t)
(add-hook 'hack-local-variables-hook
#'sh-after-hack-local-variables nil t))
;;;###autoload ;;;###autoload
(defalias 'shell-script-mode 'sh-mode) (defalias 'shell-script-mode 'sh-mode)
@ -1615,6 +1615,10 @@ This mode automatically falls back to `sh-mode' if the buffer is
not written in Bash or sh." not written in Bash or sh."
:syntax-table sh-mode-syntax-table :syntax-table sh-mode-syntax-table
(when (treesit-ready-p 'bash) (when (treesit-ready-p 'bash)
(sh-set-shell "bash" nil nil)
(add-hook 'flymake-diagnostic-functions #'sh-shellcheck-flymake nil t)
(add-hook 'hack-local-variables-hook
#'sh-after-hack-local-variables nil t)
(treesit-parser-create 'bash) (treesit-parser-create 'bash)
(setq-local treesit-font-lock-feature-list (setq-local treesit-font-lock-feature-list
'(( comment function) '(( comment function)