1

I've created a generic mode for emacs, but I have trouble matching the file names I want the generic mode to be on, right now I'm using proguard-* but I would like to match only file names with proguard-*.txt and proguard-*.pro. How can I do this?

  • 1
    Show your code for how you're currently matching filenames, please. – phils Apr 6 '16 at 5:50
1

The rules for selecting a major mode are a bit complex, the manual says this about choosing based on the file name :

Fourth—if Emacs still hasn’t found a suitable major mode—it looks at the file’s name. The correspondence between file names and major modes is controlled by the variable ‘auto-mode-alist’. Its value is a list in which each element has this form,

(REGEXP . MODE-FUNCTION)

or this form,

(REGEXP MODE-FUNCTION FLAG)

What it doesn't say explicitely (nor the docstring for auto-mode-alist) is that what is matched against the regexp is the full pathname of the file.

The syntax of regexps is also decribed in the manual.

1

I expect that something like this should do what you want?

(add-to-list 'auto-mode-alist '("^proguard-.*\\.txt$" . generic-mode))
(add-to-list 'auto-mode-alist '("^proguard-.*\\.pro$" . generic-mode))

Replace generic-mode by the actual name of your mode, of course.

The strings are regular expressions, or regexps for short. You may read about them in the elisp manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.