From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: auto-insert-mode: define-auto-insert condition problem Date: Fri, 15 Feb 2013 21:19:48 +0100 Message-ID: <871uchs523.fsf@web.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1360959514 3034 80.91.229.3 (15 Feb 2013 20:18:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Feb 2013 20:18:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 15 21:18:46 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U6Rk5-0000Ua-2C for geh-help-gnu-emacs@m.gmane.org; Fri, 15 Feb 2013 21:18:45 +0100 Original-Received: from localhost ([::1]:54697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6Rji-0000lx-3B for geh-help-gnu-emacs@m.gmane.org; Fri, 15 Feb 2013 15:18:22 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:60536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6Rja-0000lZ-G1 for help-gnu-emacs@gnu.org; Fri, 15 Feb 2013 15:18:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6RjW-0007zh-6l for help-gnu-emacs@gnu.org; Fri, 15 Feb 2013 15:18:13 -0500 Original-Received: from mout.web.de ([212.227.15.3]:63145) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6RjV-0007z3-TL for help-gnu-emacs@gnu.org; Fri, 15 Feb 2013 15:18:10 -0500 Original-Received: from drachen.dragon ([92.74.177.220]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0Mb8xf-1ULdzz3wQl-00KKoo; Fri, 15 Feb 2013 21:18:05 +0100 Mail-Followup-To: help-gnu-emacs@gnu.org In-Reply-To: (Zhiming Wang's message of "Fri, 15 Feb 2013 00:08:07 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Provags-ID: V02:K0:08a5d9LqO1Vy11eXA94bnzQFGbrosN90X4ISHIhhBzM U++A0rhSpuX8zPKVsyrdTiq/yHFXQi+Kn3/w2hWkYCKIirwq77 DRI5SSVb7DCLdgv5oh76DdbeYq19ydgUl8/ztNseY+3QwatgCt vC8LB3MKzEHUtaKVUpjU5JUSTCfwNpG2+yvJVC0tiyNuGASksX ojQ90GH8vVXn1wvNK5C5dsVunFwKmdHWncku4b/7M8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.15.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89118 Archived-At: Zhiming Wang 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.