I know that emacs can recognize a file by the extension, a -*- mode -*- first line, and even by the shebang line, but what do I do if I want to override the shebang?

For example, a script that starts with

#!/usr/bin/env python2.7
...

won't be recognized by the shebang line alone. I also can't add in a -*-python-*- line, because then the shell tries to parse it. How do I deal with this?

有帮助吗?

解决方案

You put the -*- mode: python -*- in the second line (special exception, added specifically for the shebang thingies).

其他提示

You can try putting something like

(add-to-list 'interpreter-mode-alist '("python2.7" . python-mode))

in your .emacs. See “Choosing File Modes” for more info.

Like this:

#!/usr/bin/env python2.7

print "test"

# Local Variables:
# mode: python
# End:

This information comes from Specifying File Variables node of info.

  1. Use f1 i to enter info.
  2. Use g (emacs) to jump to emacs info.
  3. Use g Specifying File Variables to jump to the page. You can use tab to complete node names.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top