如何让 Emacs 中的 shell-script-mode 将 #PBS -S /bin/bash 解释为 bash shell 代码?

如何让 Emacs 中的 shell-script-mode 将 #PBS -S /bin/bash 解释为 bash shell 代码?

我在 LINUX 系统上使用 Emacs,该系统使用便携式批处理系统 (PBS) 来控制资源的使用。PBS 脚本需要“#PBS -S /bin/...”作为脚本的第一行,以向 PBS 声明脚本的 shell。当我将脚本加载到 Emacs 中时,没有 #!/bin/... 来提醒 Emacs 正在编写哪个 shell。那么,我如何才能让 Emacs 中的 shell-script-mode 将 #PBS -S /bin/bash 解释为 bash shell 代码?

答案1

将其添加到您的.emacs

(setq auto-mode-interpreter-regexp 
    "#\\(?:!\\|PBS -S \\)[ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")

这使得 Emacs 将其视为#PBS -S前缀的替代方案#!

答案2

在文件末尾添加如下内容:

# Local Variables:
# mode: shell-script
# End: 

当然,还有其他方法,例如用于设置变量 auto-mode-alist 的独特命名模式。

相关内容