unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* emacs function for writing C++ iterator loop
@ 2007-06-29  0:56 Mohitz
  2007-06-29  3:22 ` weber
  2007-06-29  7:09 ` Pascal Bourguignon
  0 siblings, 2 replies; 5+ messages in thread
From: Mohitz @ 2007-06-29  0:56 UTC (permalink / raw)
  To: help-gnu-emacs

I program in C++ using emacs. And i tend to use the C++ iterator a
lot. Now, whenever I want to iterate I always write almost the same
kinda code. So, i want to write a emacs function so that emacs does
that for me.

For example

If i tell emacs that i am iterating on a "deque<ClassName> " variable
with variable name "var" pointing to
"someThing", Emacs should potentially be able to generate the
following

deque<CLassName> var = someThing;
deque<ClassName>::iterator varIterate;
varIterate = var.begin();
while (varIterate != var.end())
{
      ClassName tempClassName;
      tempClassName = *varIterate;

      //Do something with tempClassName

      varIterate++;
}

Any kind of help or pointers to help material would be greatly
appreciated

Thanks
Mohit

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

* Re: emacs function for writing C++ iterator loop
  2007-06-29  0:56 emacs function for writing C++ iterator loop Mohitz
@ 2007-06-29  3:22 ` weber
  2007-06-29  6:35   ` Mohitz
  2007-06-29  7:09 ` Pascal Bourguignon
  1 sibling, 1 reply; 5+ messages in thread
From: weber @ 2007-06-29  3:22 UTC (permalink / raw)
  To: help-gnu-emacs

On 28 jun, 21:56, Mohitz <coolmoh...@gmail.com> wrote:
> I program in C++ using emacs. And i tend to use the C++ iterator a
> lot. Now, whenever I want to iterate I always write almost the same
> kinda code. So, i want to write a emacs function so that emacs does
> that for me.
>
> For example
>
> If i tell emacs that i am iterating on a "deque<ClassName> " variable
> with variable name "var" pointing to
> "someThing", Emacs should potentially be able to generate the
> following
>
> deque<CLassName> var = someThing;
> deque<ClassName>::iterator varIterate;
> varIterate = var.begin();
> while (varIterate != var.end())
> {
>       ClassName tempClassName;
>       tempClassName = *varIterate;
>
>       //Do something with tempClassName
>
>       varIterate++;
>
> }
>
> Any kind of help or pointers to help material would be greatly
> appreciated
>
> Thanks
> Mohit

Hi
This is probably a good starting point:
http://www.emacswiki.org/cgi-bin/wiki/SkeletonMode
Cheers,
weber

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

* Re: emacs function for writing C++ iterator loop
  2007-06-29  3:22 ` weber
@ 2007-06-29  6:35   ` Mohitz
  2007-06-29  7:31     ` Pascal Bourguignon
  0 siblings, 1 reply; 5+ messages in thread
From: Mohitz @ 2007-06-29  6:35 UTC (permalink / raw)
  To: help-gnu-emacs

> Hi
> This is probably a good starting point:http://www.emacswiki.org/cgi-bin/wiki/SkeletonMode
> Cheers,

Thank you so much... Got it working :)

I would post the solution in case it benefits someone else..

(define-skeleton generate-iterator-loop
      "Generate Iterator Loop"
      ""
      > (setq v1 (skeleton-read "Iterate on? ")) "<"
      > (setq v4 (skeleton-read "Class Name? ")) "> "
      > (setq v2 (skeleton-read "Var Name? ")) " = "
      > (setq v3 (skeleton-read "Points to? ")) ";" \n
      > v1 "<" v4 ">::iterator " v2 "Iterate;" \n
      > v2 "Iterate = " v2 ".begin();" \n
      > "while (" v2 "Iterate != " v2  ".end())" \n
      > "{" \n
      > v4 " temp" v4 ";" \n
      > "temp" v4 " = *" v2 "Iterate;" \n
      > "//Do something with temp" v4 \n
      > v2 "Iterate++;" \n
      > "}" \n)

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

* Re: emacs function for writing C++ iterator loop
  2007-06-29  0:56 emacs function for writing C++ iterator loop Mohitz
  2007-06-29  3:22 ` weber
@ 2007-06-29  7:09 ` Pascal Bourguignon
  1 sibling, 0 replies; 5+ messages in thread
From: Pascal Bourguignon @ 2007-06-29  7:09 UTC (permalink / raw)
  To: help-gnu-emacs

Mohitz <coolmohitz@gmail.com> writes:

> I program in C++ using emacs. And i tend to use the C++ iterator a
> lot. Now, whenever I want to iterate I always write almost the same
> kinda code. So, i want to write a emacs function so that emacs does
> that for me.
>
> For example
>
> If i tell emacs that i am iterating on a "deque<ClassName> " variable
> with variable name "var" pointing to
> "someThing", Emacs should potentially be able to generate the
> following
>
> deque<CLassName> var = someThing;
> deque<ClassName>::iterator varIterate;
> varIterate = var.begin();
> while (varIterate != var.end())
> {
>       ClassName tempClassName;
>       tempClassName = *varIterate;
>
>       //Do something with tempClassName
>
>       varIterate++;
> }
>
> Any kind of help or pointers to help material would be greatly
> appreciated

Perhaps better than skeleton mode, use emacs as a C/C++ preprocessor:

http://www.xcf.berkeley.edu/~ali/elpp/elpp.el
http://www.xcf.berkeley.edu/~ali/elpp/elppc.el
http://www.xcf.berkeley.edu/~ali/elpp/cgen.el

Basically it allows you to insert elisp in your c code and to
autogenerate c code from elisp s-expressions.

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

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.

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

* Re: emacs function for writing C++ iterator loop
  2007-06-29  6:35   ` Mohitz
@ 2007-06-29  7:31     ` Pascal Bourguignon
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal Bourguignon @ 2007-06-29  7:31 UTC (permalink / raw)
  To: help-gnu-emacs

Mohitz <coolmohitz@gmail.com> writes:

>> Hi
>> This is probably a good starting point:http://www.emacswiki.org/cgi-bin/wiki/SkeletonMode
>> Cheers,
>
> Thank you so much... Got it working :)
>
> I would post the solution in case it benefits someone else..
>
> (define-skeleton generate-iterator-loop
>       "Generate Iterator Loop"
>       ""
>       > (setq v1 (skeleton-read "Iterate on? ")) "<"
>       > (setq v4 (skeleton-read "Class Name? ")) "> "
>       > (setq v2 (skeleton-read "Var Name? ")) " = "
>       > (setq v3 (skeleton-read "Points to? ")) ";" \n
>       > v1 "<" v4 ">::iterator " v2 "Iterate;" \n
>       > v2 "Iterate = " v2 ".begin();" \n
>       > "while (" v2 "Iterate != " v2  ".end())" \n
>       > "{" \n
>       > v4 " temp" v4 ";" \n
>       > "temp" v4 " = *" v2 "Iterate;" \n
>       > "//Do something with temp" v4 \n
>       > v2 "Iterate++;" \n
>       > "}" \n)

The problem with skeletons is that it inserts the results, and you or
your coworkers will edit it, so when the skeleton changes, the
generated parts cannot be updated automatically.

That's why macros (or preprocessors) are better: you edit only the
true source, the macro call or the macro definition, and the code
generated is updated everywhere.


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

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.

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

end of thread, other threads:[~2007-06-29  7:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-29  0:56 emacs function for writing C++ iterator loop Mohitz
2007-06-29  3:22 ` weber
2007-06-29  6:35   ` Mohitz
2007-06-29  7:31     ` Pascal Bourguignon
2007-06-29  7:09 ` Pascal Bourguignon

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).