1

I'm looking for a way to tell auto-insert-mode to use different templates regarding on the file path (not only on the file extension).

I want all .org files created under a directory */meetings to have a defined template.

The following setting does not work :

(auto-insert-mode)  
(setq auto-insert-directory "~/org/template/") ;;; *NOTE* Trailing slash important
(setq auto-insert-query nil) ;;; If you don't want to be prompted before insertion
(define-auto-insert "\/meetings/\.org" ".meetings_template.org")
(define-auto-insert "\.org" ".template.org")

Do you have an idea ?

skizo
  • 267
  • 1
  • 3
  • 15
  • Your version of emacs seems to be outdated. In recent version of autoinsert, there is no 'auto-insert-search-current-dir'. Nicolas' answer should be working on a recent emacs. – thisirs Aug 09 '12 at 09:53
  • @thisirs : as a matter of fact, it's the autoinsert documentation I've read which is outdated. My emacs is 2.24.10 – skizo Aug 09 '12 at 11:37

1 Answers1

1

The names are matched with a regular expression. The one you gave for meetings is not doing what you want. Try this one instead: "/meeting/.*\\.org"

Nicolas Dudebout
  • 9,172
  • 2
  • 34
  • 43
  • Good point. But it doesn't work. I tried also the `(setq auto-insert-search-current-dir t)` and placed a template file in the **meeting** directory but it did not work either. – skizo Aug 09 '12 at 08:01
  • More information on this : If I comment out `(define-auto-insert "\.org" ".template.org")` then it acts as expected (the template is inserted on each org file under the meetings directory). But somehow, when the two lines are set, emacs seems to act as if only the second line were valid (ie. it adds the `.template.org` on each new .org file – skizo Aug 09 '12 at 11:40
  • The first regular expression matches also the second regular expression. Therefore emacs only copies the content of one template file. To fix your problem you need to make the condition of the second line more restrictive so that it does not capture the first line. – Nicolas Dudebout Aug 09 '12 at 12:28