Why doesn't my Emacs regex with ^ match the line start?

I am trying to configure .emacsso that any file starting with letters makefilesets it to makefile mode. For instance. makefile-somethingmust be in makefile mode.

This does not work:

(setq auto-mode-alist (cons '("^makefile" . makefile-mode) auto-mode-alist))

But it does:

(setq auto-mode-alist (cons '("makefile" . makefile-mode) auto-mode-alist))

Can someone explain why?

+5
source share
3 answers

This is because there is a path component in front of the file name, try:

"/makefile[^/]*$"

see http://www.gnu.org/s/emacs/manual/html_node/elisp/Auto-Major-Mode.html (bottom of page)

EDI: fixed regex according to Sean's comment

+7
source

, , , auto-mode-alist, , ^, /. :

("/\\.?\\(?:gnokiirc\\|kde.*rc\\|mime\\.types\\|wgetrc\\)\\'" . conf-mode)

( Emacs 23.2.1) , , , regexp , .

(setq auto-mode-alist (cons '("/makefile" . makefile-mode) auto-mode-alist))

.

+1

Just try for convenience.

 (add-to-list 'auto-mode-alist ...
0
source

All Articles