* Re: auto-insert-mode: define-auto-insert condition problem
[not found] <mailman.19989.1360916586.855.help-gnu-emacs@gnu.org>
@ 2013-02-15 20:19 ` Michael Heerdegen
0 siblings, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2013-02-15 20:19 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* auto-insert-mode: define-auto-insert condition problem
@ 2013-02-15 8:08 Zhiming Wang
2013-02-19 15:35 ` Kevin Rodgers
0 siblings, 1 reply; 3+ messages in thread
From: Zhiming Wang @ 2013-02-15 8:08 UTC (permalink / raw)
To: help-gnu-emacs
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?
Thanks,
Kevin
P.S. Here is the documentation of define-auto-insert in 23.4.1:
define-auto-insert is a compiled Lisp function in `autoinsert.el'.
(define-auto-insert CONDITION ACTION &optional AFTER)
Associate CONDITION with (additional) ACTION in `auto-insert-alist'.
Optional AFTER means to insert action after all existing actions for CONDITION,
or if CONDITION had no actions, after all other CONDITIONs.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: auto-insert-mode: define-auto-insert condition problem
2013-02-15 8:08 Zhiming Wang
@ 2013-02-19 15:35 ` Kevin Rodgers
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2013-02-19 15:35 UTC (permalink / raw)
To: help-gnu-emacs
On 2/15/13 1:08 AM, Zhiming Wang wrote:
> 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?
"\.c" should be "\\.c\\'" and "\.tex" should be "\\.tex\\'"
> Thanks,
> Kevin
>
> P.S. Here is the documentation of define-auto-insert in 23.4.1:
>
> define-auto-insert is a compiled Lisp function in `autoinsert.el'.
>
> (define-auto-insert CONDITION ACTION&optional AFTER)
>
> Associate CONDITION with (additional) ACTION in `auto-insert-alist'.
> Optional AFTER means to insert action after all existing actions for CONDITION,
> or if CONDITION had no actions, after all other CONDITIONs.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-19 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.19989.1360916586.855.help-gnu-emacs@gnu.org>
2013-02-15 20:19 ` auto-insert-mode: define-auto-insert condition problem Michael Heerdegen
2013-02-15 8:08 Zhiming Wang
2013-02-19 15:35 ` Kevin Rodgers
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.