title: Emacs auto-minor-mode based on extension
body: <p>I found <a href="https://stackoverflow.com/questions/1299193/in-emacs-how-to-automatically-enable-a-minor-mode-based-on-buffer-name">this question</a> somewhat on the topic, but is there a way [in emacs] to set a minor mode (or a list thereof) based on <em>extension</em>? For example, it's pretty easy to find out that major modes can be manipulated like so</p>
  
  <pre><code>(add-to-list 'auto-mode-alist '("\\.notes\\'" . text-mode))
  </code></pre>
  
  <p>and what I'd ideally like to be able to do is</p>
  
  <pre><code>(add-to-list 'auto-minor-mode-alist '("\\.notes\\'" . auto-fill-mode))
  </code></pre>
  
  <p>The accept answer of the linked question mentions hooks, specifically <a href="http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/elisp/Temporary-Displays.html#Temporary-Displays" rel="noreferrer"><code>temp-buffer-setup-hook</code></a>. To use this, you have to add a function to the hook like so</p>
  
  <pre><code>(add-hook 'temp-buffer-setup-hook #'my-func-to-set-minor-mode)
  </code></pre>
  
  <p>My question is two-fold:</p>
  
  <ol>
  <li>Is there an easier way to do this, similar to major modes?</li>
  <li>If not, how would one write the function for the hook?
  
  <ol>
  <li>It needs to check the file path against a regular expression.</li>
  <li>If it matches, activate the desired mode (e.g. <code>auto-fill-mode</code>).</li>
  </ol></li>
  </ol>
  
  <hr>
  
  <p>Feeble and buggy attempt at a solution:</p>
  
  <pre><code>;; Enables the given minor mode for the current buffer it it matches regex
  ;; my-pair is a cons cell (regular-expression . minor-mode)
  (defun enable-minor-mode (my-pair)
    (if buffer-file-name ; If we are visiting a file,
        ;; and the filename matches our regular expression,
        (if (string-match (car my-pair) buffer-file-name) 
        (funcall (cdr my-pair))))) ; enable the minor mode
  
  ; used as
  (add-hook 'temp-buffer-setup-hook
            (lambda ()
              (enable-minor-mode '("\\.notes\\'" . auto-fill-mode))))
  </code></pre>