[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacing ocurrences of a string...
From: |
Greg Rowe |
Subject: |
Re: Replacing ocurrences of a string... |
Date: |
Fri, 13 May 2005 11:04:02 -0400 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
luca.spinacci@seleniacomms.com wrote:
Let's say:
M-x my-template-generator
generates in my - C - buffer
a template like
/*
**********************
* <name>
**********************
void <name>()
{
} // <name>
I would like to be prompted for the function name to be replaced with.
Using (query-replace "<name>" "") in "my-template-generator" I have to
What I think you are looking for is skeletons. Here's an example from
my emacs skeletons that I use a lot when writing C code.
(define-skeleton skel-struct-c
"struct"
"Struct Name:"
> "typedef struct " str \n
"{" > \n
_ > \n
"} " str "_t;" > )
That defines a skeleton that asks me for the name of the struct and then
inserts that name everywhere "str" appears. So if I used the skeleton
above and entered "schmoo" when prompted I'd get:
typedef struct schmoo
{
} schmoo_t;
In addition the cursor ends up inside the struct braces because of the
'_' character in the skeleton.
To run this skeleton I have the following in my .emacs:
(define-abbrev c-mode-abbrev-table "st" "" 'skel-struct-c)
Then, when editing code I can type stC-x a e to use the skeleton. C-x a
e runs expand-abbrev and the "define-abbrev" tells emacs to use
skel-struct-c as an abbreviation expansion for the strings "st".
For more information check out
http://www.emacswiki.org/cgi-bin/wiki/SkeletonMode
Greg
--
Home is where the .bashrc is.