block commenting-out

N

newyorkdolluk

hi,

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

thanks
 
R

Robert Klemme

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
 
F

Francis Cianfrocca

hi,

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

thanks


=begin

your code

=end

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

Farrel Lifson

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
 
K

Ken Bloom

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.

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
 
G

Gene Tani

newyorkdolluk said:
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.
 
C

Chad Perrin

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

Matt Todd

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.

;)

M.T.
 
A

Alex Young

Huw said:
With Ruby In Steel you just mark a block and click a button to comment or
uncomment ;-)
But... but... that requires taking your hand off the keyboard!

Heresy!

:)
 
C

Charles M. Gerungan

With Ruby In Steel you just mark a block and click a button to
comment or
uncomment ;-)

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

Daniel Harple

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

-- Daniel
 
H

Huw Collingbourne

Alex Young said:
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. :)

best wishes
Huw Collingbourne

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

Chad Perrin

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?

How many modes are there to emacs?
 
C

Chad Perrin

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

. . 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?
 
C

Chad Perrin

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.

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

Holy crap.
 
P

Piers Harding

--tjCHc7DPkfUGtrlw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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.


=20

=20
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.
=20

--=20
Home - http://www.piersharding.com
xmpp:p[email protected]


--tjCHc7DPkfUGtrlw
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFE4sADGETamPT/o4ARAv/FAJ0S3SAUbVBNNr7+Yq59ucWI7B+oSwCfSv59
c2z7WMAcQdB8S27QHNb0UjY=
=cBsC
-----END PGP SIGNATURE-----

--tjCHc7DPkfUGtrlw--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,089
Members
47,687
Latest member
IngridXxj

Latest Threads

Top