Function: sh-set-shell
sh-set-shell is an interactive and byte-compiled function defined in
sh-script.el.gz.
Signature
(sh-set-shell SHELL &optional NO-QUERY-FLAG INSERT-FLAG)
Documentation
Set this buffer's shell to SHELL (a string).
When used interactively, insert the proper starting #!-line,
and make the visited file executable via executable-set-magic,
perhaps querying depending on the value of executable-query.
(If given a prefix (i.e., C-u (universal-argument)) don't insert any starting #!
line.)
When this function is called noninteractively, INSERT-FLAG (the third argument) controls whether to insert a #!-line and think about making the visited file executable, and NO-QUERY-FLAG (the second argument) controls whether to query about making the visited file executable.
Calls the value of sh-set-shell-hook if set.
Shell script files can cause this function be called automatically
when the file is visited by having a sh-shell file-local variable
whose value is the shell name (don't quote it).
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/sh-script.el.gz
(defun sh-set-shell (shell &optional no-query-flag insert-flag)
"Set this buffer's shell to SHELL (a string).
When used interactively, insert the proper starting #!-line,
and make the visited file executable via `executable-set-magic',
perhaps querying depending on the value of `executable-query'.
(If given a prefix (i.e., \\[universal-argument]) don't insert any starting #!
line.)
When this function is called noninteractively, INSERT-FLAG (the third
argument) controls whether to insert a #!-line and think about making
the visited file executable, and NO-QUERY-FLAG (the second argument)
controls whether to query about making the visited file executable.
Calls the value of `sh-set-shell-hook' if set.
Shell script files can cause this function be called automatically
when the file is visited by having a `sh-shell' file-local variable
whose value is the shell name (don't quote it)."
(interactive (list (completing-read
(format-prompt "Shell" sh-shell-file)
;; This used to use interpreter-mode-alist, but that is
;; no longer appropriate now that uses regexps.
;; Maybe there could be a separate variable that lists
;; the shells, used here and to construct i-mode-alist.
;; But the following is probably good enough:
(append (mapcar (lambda (e) (symbol-name (car e)))
sh-ancestor-alist)
'("csh" "rc" "sh"))
nil nil nil nil sh-shell-file)
(eq executable-query 'function)
(not current-prefix-arg)))
(if (string-match "\\.exe\\'" shell)
(setq shell (substring shell 0 (match-beginning 0))))
(setq sh-shell (sh-canonicalize-shell shell))
(if insert-flag
(setq sh-shell-file
(executable-set-magic shell (sh-feature sh-shell-arg)
no-query-flag insert-flag)))
(setq mode-line-process (format "[%s]" sh-shell))
(setq-local sh-shell-variables nil)
(setq-local sh-shell-variables-initialized nil)
(setq-local imenu-generic-expression
(sh-feature sh-imenu-generic-expression))
(let ((tem (sh-feature sh-mode-syntax-table-input)))
(when tem
(setq-local sh-mode-syntax-table
(apply 'sh-mode-syntax-table tem))
(set-syntax-table sh-mode-syntax-table)))
(dolist (var (sh-feature sh-variables))
(sh-remember-variable var))
(if (setq-local sh-indent-supported-here
(sh-feature sh-indent-supported))
(progn
(message "Setting up indent for shell type %s" sh-shell)
(let ((mksym (lambda (name)
(intern (format "sh-smie-%s-%s"
sh-indent-supported-here name)))))
(add-function :around (local 'smie--hanging-eolp-function)
(lambda (orig)
(if (looking-at "[ \t]*\\\\\n")
(goto-char (match-end 0))
(funcall orig))))
(add-hook 'smie-indent-functions #'sh-smie--indent-continuation nil t)
(smie-setup (symbol-value (funcall mksym "grammar"))
(funcall mksym "rules")
:forward-token (funcall mksym "forward-token")
:backward-token (funcall mksym "backward-token")))
(if sh-make-vars-local
(sh-make-vars-local))
(message "Indentation setup for shell type %s" sh-shell))
(message "No indentation for this shell type.")
(setq-local indent-line-function #'sh-basic-indent-line))
(when font-lock-mode
(setq font-lock-set-defaults nil)
(font-lock-set-defaults)
(font-lock-flush))
(setq sh-shell-process nil)
(run-hooks 'sh-set-shell-hook))