unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Replacing ocurrences of a string...
@ 2005-05-13 13:15 luca.spinacci
  0 siblings, 0 replies; 3+ messages in thread
From: luca.spinacci @ 2005-05-13 13:15 UTC (permalink / raw)



I generate a C function template in a buffer running a command.
I would like to replace every occurence of the <name> string
on direct request.
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
call SHIFT-e to be requested for "Edit replacement string: "  and
SHIFT-1 to replace every occurence of <name> with the new string "my-name".
Is there a smarter way (I'm sure there is) to be requested for the
replacement
string ("Edit replacement string: ") automatically as the template is
inserted
in the buffer without using SHIFT-e?
The function query-replace is not mandatory...

Thanks in advance,
Luca.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Replacing ocurrences of a string...
       [not found] <mailman.5053.1115990680.2819.help-gnu-emacs@gnu.org>
@ 2005-05-13 14:35 ` Pascal Bourguignon
  2005-05-13 15:04 ` Greg Rowe
  1 sibling, 0 replies; 3+ messages in thread
From: Pascal Bourguignon @ 2005-05-13 14:35 UTC (permalink / raw)


luca.spinacci@seleniacomms.com writes:

> I generate a C function template in a buffer running a command.
> I would like to replace every occurence of the <name> string
> on direct request.
> 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
> call SHIFT-e to be requested for "Edit replacement string: "  and
> SHIFT-1 to replace every occurence of <name> with the new string "my-name".
> Is there a smarter way (I'm sure there is) to be requested for the
> replacement
> string ("Edit replacement string: ") automatically as the template is
> inserted
> in the buffer without using SHIFT-e?
> The function query-replace is not mandatory...

Usually, this is done by programming correctly my-template-generator:

(defun my-template-generator (funame)
   (interactive "sFunction name: ")
   (insert "/*\n"
           "********************\n"
           "* "funame"\n"
           "********************\n"
           "*/\n"
           "void "funame"()\n"
           "{\n"
           "    \n"
           "}//"funame"\n\n"))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Replacing ocurrences of a string...
       [not found] <mailman.5053.1115990680.2819.help-gnu-emacs@gnu.org>
  2005-05-13 14:35 ` Replacing ocurrences of a string Pascal Bourguignon
@ 2005-05-13 15:04 ` Greg Rowe
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Rowe @ 2005-05-13 15:04 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-05-13 15:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.5053.1115990680.2819.help-gnu-emacs@gnu.org>
2005-05-13 14:35 ` Replacing ocurrences of a string Pascal Bourguignon
2005-05-13 15:04 ` Greg Rowe
2005-05-13 13:15 luca.spinacci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).