开发者

How do I associate a minor mode to a particular file or a set of files based on extension?

Currently, every time I open a text file in emacs, I have to M-x longlines-mode in order to开发者_如何学Python get my line-wrapping turned on. Likewise in clojure, I have to M-x paredit-mode (although it does automatically set the major modes to text and clojure, respectively).

I am hazy on the difference between major and minor modes, but I'm thinking the above-mentioned modes are minor. Is there a way to:

  1. configure emacs to open all clojure (*.clj) files with paredit-mode automatically?
  2. configure a particular file (say, notes.txt) to open with longlines-mode. I have tried adding -^- mode: longlines -^- or -^- mode: longlines-mode -^- as suggested in other threads, but it doesn't seem to work. I can't search for documentation on the -^- syntax because I don't know what it's called.


I have this in my .emacs file

(require 'clojure-mode)
(defun turn-on-paredit () (paredit-mode 1))
(add-hook 'clojure-mode-hook 'turn-on-paredit)


See the section on file associations in this tutorial.

Basically, what you want to do is this (untested, but should work):

(setq auto-mode-alist (cons '("\\.clj$" . paredit-mode) auto-mode-alist))

You can repeat the same procedure for text files and long-lines-mode.


An alternative code with the same effect could be (also untested, but should work):

(add-to-list 'auto-mode-alist '("\\.clj$\\'" . paredit-mode))


You can put mode name just in the first nonblank line, preceded and followed by ‘-*-’. Other text may appear on the line as well. For example,

; -*-longlines-*-

or

; -*- mode: longlines -*-

You can see detail in: http://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜