unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Surrounding statements with conditionals in C mode.
@ 2003-09-05  8:38 Saurabh Kapoor
  0 siblings, 0 replies; 4+ messages in thread
From: Saurabh Kapoor @ 2003-09-05  8:38 UTC (permalink / raw)


I've got several statements in my c code that i wish to surround by 
#ifdefs and #endif.

Eg. The following code :

	printf("This is debugging info: %d\n",i);
	printf("This is some more debugging info: \n");

should become

#ifdef MACRO_NAME
	printf("This is debugging info: %d\n",i);
	printf("This is some more debugging info: \n");
#endif

So, all that i have to do is to write the macro name.
Is there a way to do this. 

Thanks,
Saurabh Kapoor

III Semester,
Department of Computer Science,
University of Pune.
India.


-- 
"...BACKWARDS understood be only can but,
    forwards lived be must Life"
			      -- Kierkegaard Soren

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

* Re: Surrounding statements with conditionals in C mode.
       [not found] <mailman.206.1062751223.18171.help-gnu-emacs@gnu.org>
@ 2003-09-05 12:36 ` Joakim Hove
  2003-09-08 14:24 ` Sandip Chitale
  2003-09-08 14:34 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Joakim Hove @ 2003-09-05 12:36 UTC (permalink / raw)



Saurabh Kapoor <u02137@cs.unipune.ernet.in> writes:


> So, all that i have to do is to write the macro name.
> Is there a way to do this. 

There might be proper included functionality for this already, but the
following solution seems to work reasonably well:


(defun ifdef-region (p1 p2)
  (interactive "r")
  (let* ((macro (read-from-minibuffer "Macro: "))
	 (ifdef (concat "#ifdef " macro "\n")))
    (goto-char p1)
    (beginning-of-line)
    
    (insert ifdef)
    (goto-char (+ p2 (length ifdef)))
    (end-of-line)
    (newline 1)
    (insert "#endif"))) 


Joakim 


-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/

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

* Re: Surrounding statements with conditionals in C mode.
       [not found] <mailman.206.1062751223.18171.help-gnu-emacs@gnu.org>
  2003-09-05 12:36 ` Surrounding statements with conditionals in C mode Joakim Hove
@ 2003-09-08 14:24 ` Sandip Chitale
  2003-09-08 14:34 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Sandip Chitale @ 2003-09-08 14:24 UTC (permalink / raw)


Look into <youremacsdir>/lisp/tempo.el file for how to set up such a template.

"Saurabh Kapoor" <u02137@cs.unipune.ernet.in> wrote in message news:mailman.206.1062751223.18171.help-gnu-emacs@gnu.org...
> I've got several statements in my c code that i wish to surround by
> #ifdefs and #endif.
>
> Eg. The following code :
>
> printf("This is debugging info: %d\n",i);
> printf("This is some more debugging info: \n");
>
> should become
>
> #ifdef MACRO_NAME
> printf("This is debugging info: %d\n",i);
> printf("This is some more debugging info: \n");
> #endif
>
> So, all that i have to do is to write the macro name.
> Is there a way to do this.
>
> Thanks,
> Saurabh Kapoor
>
> III Semester,
> Department of Computer Science,
> University of Pune.
> India.
>
>
> --
> "...BACKWARDS understood be only can but,
>     forwards lived be must Life"
>       -- Kierkegaard Soren
>
>
>

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

* Re: Surrounding statements with conditionals in C mode.
       [not found] <mailman.206.1062751223.18171.help-gnu-emacs@gnu.org>
  2003-09-05 12:36 ` Surrounding statements with conditionals in C mode Joakim Hove
  2003-09-08 14:24 ` Sandip Chitale
@ 2003-09-08 14:34 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2003-09-08 14:34 UTC (permalink / raw)


> Eg. The following code :

> 	printf("This is debugging info: %d\n",i);
> 	printf("This is some more debugging info: \n");

> should become

> #ifdef MACRO_NAME
> 	printf("This is debugging info: %d\n",i);
> 	printf("This is some more debugging info: \n");
> #endif

(define-skeleton my-c-conditionalize
  "Conditionalize a piece of code with cpp stuff."
  "CPP var to use: "
  \n "#ifdef " str
  \n _
  \n "#endif /* " str " */" \n)

And then (using transient-mark-mode) select the region of code you want
to conditionalize and do M-x my-c-conditionalize RET MACRO_NAME RET


        Stefan

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

end of thread, other threads:[~2003-09-08 14:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.206.1062751223.18171.help-gnu-emacs@gnu.org>
2003-09-05 12:36 ` Surrounding statements with conditionals in C mode Joakim Hove
2003-09-08 14:24 ` Sandip Chitale
2003-09-08 14:34 ` Stefan Monnier
2003-09-05  8:38 Saurabh Kapoor

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