[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: auto-insert-mode: define-auto-insert condition problem
From: |
Michael Heerdegen |
Subject: |
Re: auto-insert-mode: define-auto-insert condition problem |
Date: |
Fri, 15 Feb 2013 21:19:48 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Zhiming Wang <zmwang@stanford.edu> writes:
> To use the auto insert mode, I have the following lines in my .emacs file:
>
> (require 'autoinsert)
> (auto-insert-mode)
> (setq auto-insert-directory "~/.mytemplates")
> (setq auto-insert-query nil)
> (define-auto-insert "\.c" "c.c")
> (define-auto-insert "\.tex" "latex.tex")
> ;;; other templates...
>
> This works fine when I create .c file, .tex file, etc. However, when I
> create files with extensions beginning with .c, .tex, etc. templates
> are also loaded. For instance, when creating foo.cpp, the c.c template
> is automatically loaded, which is not expected. Noticing this behavior
> I tried .text, and latex.tex template is loaded.
>
> So, is there any way to strengthen the define-auto-insert CONDITION so
> that auto insert is activated only upon the exact extensions?
I don't use "auto-insert", but I think I can help.
What you need is (from elisp manual: Regexp Backslash):
`\''
matches the empty string, but only at the end of the buffer or
string being matched against.
You would use it like that:
(define-auto-insert "\.c\\'" "c.c")
(define-auto-insert "\.tex\\'" "latex.tex")
Note that the backslash in `\'' must be quoted inside the string
delimiters - otherwise it would act as a quoting character on the
following character.
See (elisp) Regular Expressions for reference. Please also have a look
at the definition of `auto-insert-alist' (this is the list that
`define-auto-insert' manipulates) for more examples. Note that you can
also "match" the major mode instead of the file name. I.e., something
like that should work as well:
(define-auto-insert 'latex-mode "latex.tex")
Regards,
Michael.