Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting auto-mode-alist in emacs

Tags:

emacs

elisp

I notice that the current auto-mode-alist entries all end with a single quote, for example

 ("\\.java\\'" . java-mode) 

What is the purpose of the single quote. I would have expected to see

 ("\\.java$" . java-mode) 

The reason I ask is that I am trying to get files with names matching regexp

^twiki\.corp.*  

to open in org-mode. I have tried the following without success:

(add-to-list 'auto-mode-alist '("^twiki\\.corp" . org-mode)) (add-to-list 'auto-mode-alist '("\\'twiki\\.corp" . org-mode)) 

The following works:

(add-to-list 'auto-mode-alist '("twiki\\.corp" . org-mode)) 

but is not quite what I want since file names with twiki.corp embedded in them will be opened in org-mode.

like image 741
chris Avatar asked Aug 16 '10 15:08

chris


People also ask

How do I change modes in Emacs?

To get a list of the all the available modes, both major and minor, on your system's version of Emacs, look up "mode" using Emacs' apropos command. Do this by pressing C-h a and entering the word mode .

What is the default mode of Emacs?

The standard default value is fundamental-mode . If the default value is nil , then whenever Emacs creates a new buffer via a command such as C-x b ( switch-to-buffer ), the new buffer is put in the major mode of the previously current buffer.


1 Answers

\\' matches the empty string at the end of the string/buffer:

http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html e l

$ will match the end of the line: If you have newlines in your filename (very uncommon) $ will match the newline and not the end of the string.

The regex is matched against the whole filename, so you need include "/" to match the directory seperator:

(add-to-list 'auto-mode-alist '("/twiki\\.corp" . org-mode)) 
like image 71
Jürgen Hötzel Avatar answered Sep 27 '22 20:09

Jürgen Hötzel