Emacs auto-minor-mode based on extension

Posted by vermiculus on Stack Overflow See other posts from Stack Overflow or by vermiculus
Published on 2012-12-19T04:57:17Z Indexed on 2012/12/19 5:03 UTC
Read the original article Hit count: 158

Filed under:
|
|

I found this question somewhat on the topic, but is there a way [in emacs] to set a minor mode (or a list thereof) based on extension? For example, it's pretty easy to find out that major modes can be manipulated like so

(setq auto-mode-alist
  (cons '("\\.notes$" . text-mode)
        auto-mode-alist))

and what I'd ideally like to be able to do is

(setq auto-minor-mode-alist
  (cons '("\\.notes$" . auto-fill-mode)
        auto-minor-mode-alist))

The accept answer of the linked question mentions hooks, specifically temp-buffer-setup-hook. To use this, you have to add a function to the hook like so

(add-hook 'temp-buffer-setup-hook 'my-func-to-set-minor-mode)

My question is two-fold:

  1. Is there an easier way to do this, similar to major modes?
  2. If not, how would one write the function for the hook?
    1. It needs to check the file path against a regular expression.
    2. If it matches, activate the desired mode (e.g. auto-fill-mode).

© Stack Overflow or respective owner

Related posts about emacs

Related posts about elisp