Block commenting-out

hi,

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

thanks

hi,

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

thanks

15:56:48 [~]: ruby <<XXX
> puts 1
> =begin
> foo
> adha sdjas dha dad +asdp+adp+ad+
> =end
> puts 2
> XXX
1
2

In short, use "=begin" and "=end".

Kind regards

  robert

···

On 14.08.2006 15:51, newyorkdolluk wrote:

=begin

your code

=end

I have to know, how does a New York Doll end up in the UK?

···

On 8/14/06, newyorkdolluk <all@itgiant.co.uk> wrote:

hi,

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

thanks

=begin
This is a comment
on multiple lines
=end

Farrel

···

On 14/08/06, newyorkdolluk <all@itgiant.co.uk> wrote:

hi,

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

thanks

If you're going to take this approach (and =begin =end is probably better)
then there's no need to define a method. simply use a heredoc that won't
get used:

<<end_comment
The comment started with the previous line

and ends when the heredoc ends
end_comment

Of course, this won't work correctly as the last line in a method, so use
(=begin...=end) as other posters have described.

--Ken

···

On Mon, 14 Aug 2006 14:05:11 +0000, Jeffrey Schwab wrote:

newyorkdolluk wrote:

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

I don't think there's a multi-line comment character, although I'm sure
someone on this list will come up with a neat hack. At the very least,
you could embed the code in a string:

def begin_comment(s)
     # Ignore it. It's a comment.
end

begin_comment <<end_comment # Comment until end of comment.
     This is a string that's actually serving
     as a multi-line comment.
end_comment

If you're using vim, though:

Go to the beginning of the first line to be commented.
Hit ^V to begin block selection.
Use j to get down to the last line to be commented.
Enter capital I to begin inserting.
Enter #, since it's the Ruby comment character.
Hit Esc.

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

newyorkdolluk wrote:

hi,

can anyone tell me how to bulk comment-out lines of code rather than
#'ing each line?

thanks

Komodo can do block commenting out, prepending "#". Scite prepends
"##" so you know that is was done in bulk fashion. Your editor must
hvae something of the sort to block comment and uncomment.

Vim could, of course, do it via a substitution iterating over a number
of lines indicated by a prepended number. I'm sure EMACS (Esc Meta Alt
Ctrl Shift) could do something similar, but with four times as many keys
involved.

What, me biased? Never.

···

On Tue, Aug 15, 2006 at 03:42:20PM +0900, Gene Tani wrote:

newyorkdolluk wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks

Komodo can do block commenting out, prepending "#". Scite prepends
"##" so you know that is was done in bulk fashion. Your editor must
hvae something of the sort to block comment and uncomment.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"There comes a time in the history of any project when it becomes necessary
to shoot the engineers and begin production." - MacUser, November 1990

In vim you could put this in your .vimrc file:
map ,# :s/^/#/<CR>

mark the block you want to comment and then hit ,# (or whatever else you
want to map it to), and its done.

Cheers.

···

On Tue, Aug 15, 2006 at 03:42:20PM +0900, Gene Tani wrote:

newyorkdolluk wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks

Komodo can do block commenting out, prepending "#". Scite prepends
"##" so you know that is was done in bulk fashion. Your editor must
hvae something of the sort to block comment and uncomment.

--
Home - http://www.piersharding.com
xmpp:piers@ompka.net

If you highlight the lines you want commented out in Textmate, then
press Command + /, it will prepend # to every line. It works quite
well. Plus, if you highlight and Command + / again, it'll remove the
#s.

:wink:

M.T.

Chad Perrin <perrin@apotheon.com> writes:

···

On Tue, Aug 15, 2006 at 03:42:20PM +0900, Gene Tani wrote:

newyorkdolluk wrote:
> hi,
>
> can anyone tell me how to bulk comment-out lines of code rather than
> #'ing each line?
>
> thanks

Komodo can do block commenting out, prepending "#". Scite prepends
"##" so you know that is was done in bulk fashion. Your editor must
hvae something of the sort to block comment and uncomment.

Vim could, of course, do it via a substitution iterating over a number
of lines indicated by a prepended number. I'm sure EMACS (Esc Meta Alt
Ctrl Shift) could do something similar, but with four times as many keys
involved.

What, me biased? Never.

M-x comment-region

Bind to every key you like (I don't use it often).

C-u M-x comment-region (or M-x uncomment-region) will uncomment.

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

With Ruby In Steel you just mark a block and click a button to comment or
uncomment :wink:

best wishes
Huw Collingbourne

http://www.sapphiresteel.com
Ruby Programming In Visual Studio 2005

Try M-; (comment-dwim).

-- Daniel

···

On Aug 15, 2006, at 6:42 AM, Christian Neukirchen wrote:

Chad Perrin <perrin@apotheon.com> writes:

Vim could, of course, do it via a substitution iterating over a number
of lines indicated by a prepended number. I'm sure EMACS (Esc Meta Alt
Ctrl Shift) could do something similar, but with four times as many keys
involved.

What, me biased? Never.

M-x comment-region

Bind to every key you like (I don't use it often).

C-u M-x comment-region (or M-x uncomment-region) will uncomment.

Huw Collingbourne wrote:

With Ruby In Steel you just mark a block and click a button to comment or uncomment :wink:

But... but... that requires taking your hand off the keyboard!

Heresy!

:slight_smile:

···

--
Alex

Click a button? Isn't that what most people try to avoid when editing files? :slight_smile:

···

On 15-aug-2006, at 11:35, Huw Collingbourne wrote:

With Ruby In Steel you just mark a block and click a button to comment or
uncomment :wink:

--
Regards, Charles.

Daniel Harple <dharple@generalconsumption.org> writes:

Chad Perrin <perrin@apotheon.com> writes:

Vim could, of course, do it via a substitution iterating over a
number
of lines indicated by a prepended number. I'm sure EMACS (Esc
Meta Alt
Ctrl Shift) could do something similar, but with four times as
many keys
involved.

What, me biased? Never.

M-x comment-region

Bind to every key you like (I don't use it often).

C-u M-x comment-region (or M-x uncomment-region) will uncomment.

Try M-; (comment-dwim).

I knew there was an easier way, but M-; requires using transient-mark
mode (shudder). Well, not too bad in Emacs 22, C-SPC, C-SPC.

···

On Aug 15, 2006, at 6:42 AM, Christian Neukirchen wrote:

-- Daniel

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

"Alex Young" <alex@blackkettle.org> wrote in message
news:44E196AF.30301@blackkettle.org...

Huw Collingbourne wrote:

With Ruby In Steel you just mark a block and click a button to comment or
uncomment :wink:

But... but... that requires taking your hand off the keyboard!

Heresy!

Sorry, my mind must have been warped by doing too much Smalltalk programming
lately. You can, of course, use the keyboard: CTRL+E,C to comment, CTRL+E, U
to uncomment, or you can define your own favourite keystrokes. :slight_smile:

best wishes
Huw Collingbourne

http://www.sapphiresteel.com
Ruby Programming In Visual Studio 2005

What do "comment-region" and "comment-dwim" mean in practical terms in
this case?

How many modes are there to emacs?

···

On Wed, Aug 16, 2006 at 12:53:24AM +0900, Christian Neukirchen wrote:

Daniel Harple <dharple@generalconsumption.org> writes:

> On Aug 15, 2006, at 6:42 AM, Christian Neukirchen wrote:
>
>> Chad Perrin <perrin@apotheon.com> writes:
>>>
>>> Vim could, of course, do it via a substitution iterating over a
>>> number
>>> of lines indicated by a prepended number. I'm sure EMACS (Esc
>>> Meta Alt
>>> Ctrl Shift) could do something similar, but with four times as
>>> many keys
>>> involved.
>>>
>>> What, me biased? Never.
>>
>> M-x comment-region
>>
>> Bind to every key you like (I don't use it often).
>>
>> C-u M-x comment-region (or M-x uncomment-region) will uncomment.
>
> Try M-; (comment-dwim).

I knew there was an easier way, but M-; requires using transient-mark
mode (shudder). Well, not too bad in Emacs 22, C-SPC, C-SPC.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"There comes a time in the history of any project when it becomes necessary
to shoot the engineers and begin production." - MacUser, November 1990

. . . and to "mark a block" in preparation for this, I gather you have
to use arrow keys and the Shift key, or take a hand off the keyboard.
Yes?

···

On Tue, Aug 15, 2006 at 08:35:10PM +0900, Huw Collingbourne wrote:

"Alex Young" <alex@blackkettle.org> wrote in message
news:44E196AF.30301@blackkettle.org...
> Huw Collingbourne wrote:
>> With Ruby In Steel you just mark a block and click a button to comment or
>> uncomment :wink:
>>
> But... but... that requires taking your hand off the keyboard!
>
> Heresy!

Sorry, my mind must have been warped by doing too much Smalltalk programming
lately. You can, of course, use the keyboard: CTRL+E,C to comment, CTRL+E, U
to uncomment, or you can define your own favourite keystrokes. :slight_smile:

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts." - Paul Graham

Chad Perrin <perrin@apotheon.com> writes:

>> M-x comment-region
>>
>> Bind to every key you like (I don't use it often).
>>
>> C-u M-x comment-region (or M-x uncomment-region) will uncomment.
>
> Try M-; (comment-dwim).

I knew there was an easier way, but M-; requires using transient-mark
mode (shudder). Well, not too bad in Emacs 22, C-SPC, C-SPC.

What do "comment-region" and "comment-dwim" mean in practical terms in
this case?

comment-region:

  Comment or uncomment each line in the region.
  With just C-u prefix arg, uncomment each line in region beg .. end.
  Numeric prefix arg means use arg comment characters.
  If arg is negative, delete that many comment characters instead.
  By default, comments start at the left margin, are terminated on each line,
  even for syntax in which newline does not end the comment and blank lines
  do not get comments. This can be changed with `comment-style'.

comment-dwim:

  Call the comment command you want (Do What I Mean).
  If the region is active and `transient-mark-mode' is on, call
    `comment-region' (unless it only consists of comments, in which
    case it calls `uncomment-region').
  Else, if the current line is empty, insert a comment and indent it.
  Else if a prefix arg is specified, call `comment-kill'.
  Else, call `comment-indent'.
  You can configure `comment-style' to change the way regions are commented.

How many modes are there to emacs?

492 matches for "-mode$" in buffer: *Apropos*

:slight_smile:

···

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

Chad Perrin <perrin@apotheon.com> writes:
>
> What do "comment-region" and "comment-dwim" mean in practical terms in
> this case?

comment-region:

  Comment or uncomment each line in the region.
  With just C-u prefix arg, uncomment each line in region beg .. end.
  Numeric prefix arg means use arg comment characters.
  If arg is negative, delete that many comment characters instead.
  By default, comments start at the left margin, are terminated on each line,
  even for syntax in which newline does not end the comment and blank lines
  do not get comments. This can be changed with `comment-style'.

comment-dwim:

  Call the comment command you want (Do What I Mean).
  If the region is active and `transient-mark-mode' is on, call
    `comment-region' (unless it only consists of comments, in which
    case it calls `uncomment-region').
  Else, if the current line is empty, insert a comment and indent it.
  Else if a prefix arg is specified, call `comment-kill'.
  Else, call `comment-indent'.
  You can configure `comment-style' to change the way regions are commented.

Thanks. That satisfies my curiosity.

> How many modes are there to emacs?

492 matches for "-mode$" in buffer: *Apropos*

Holy crap.

···

On Wed, Aug 16, 2006 at 03:25:49AM +0900, Christian Neukirchen wrote:

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Brian K. Reid: "In computer science, we stand on each other's feet."