확장자가 없는 파일에 major-mode를 허하라

trailing whitespace 제거 스크립트를 emacs로 열면 python-mode 활성화가 안 된다.

When you visit a file, Emacs chooses a major mode automatically. Normally, it makes the choice based on the file name-for example, files whose names end in ‘.c’ are normally edited in C mode—but sometimes it chooses the major mode based on special text in the file. This special text can also be used to enable buffer-local minor modes.

- Choosing File Modes

이유는 바로 확장자. 파일 이름이 remove-trailing-whitespace 이기 때문. 확장자가 없다. 이럴 때, emacs가 차려준 special text를 사용하면 된다.

# -*- mode: Python;-*-

파일 첫 라인에 추가하면 Emacs가 읽고 python-mode를 선택한다.

#!/usr/bin/env python

그런데 shebang을 써서 첫 라인은 양보할 수 없다. 어떻게 해야 하나?

When the first line starts with ‘#!’, you usually cannot use the ‘-*-’ feature on the first line, because the system would get confused when running the interpreter. So Emacs looks for ‘-*-’ on the second line in such files as well as on the first line.

- Choosing File Modes

shebang에 내가 양보할게. 착한 Emacs.

#!/usr/bin/env python
# -*- mode: Python;-*-

이렇게 사용하면 된다.

C-x C-s C-x C-c


크리에이티브 커먼즈 라이선스


Published: October 07 2015


Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com