Is it possible to comment out blocks of code that contain comments?
Asked Answered
C

8

15

Say I have code like this

some_line_of_code
some_line_of_code
/* some comment about code */
some_line_of_code
some_line_of_code

and i would like to comment out a whole block like this

/*
    some_line_of_code
    some_line_of_code
    /* some comment about code */
    some_line_of_code
    some_line_of_code
*/

As you can see even SO code parser will not consider last 2 lines of code comments. Is it possible to comment out blocks of code that contain comments?

edit : To clarify, I need this to be able to comment out large sections of code to check if a function I changed can compile in a package that otherwise can't be compiled until all changes have been done.

Cyd answered 21/5, 2015 at 13:45 Comment(4)
Not sure what IDE you are using, but there are some with great shortcuts. For instance - I highlight every line no matter the comments in between and once I hit Cntrl+/ .... Bam! All lines have been commented. Like I said though, this is an IDE specificCasework
I am so used to having such functionality in Visual studio, but i'm new to Oracle SQL Developer which im using atm. Which ide were u refering to that allows this ctrl+/?Physicist
JetBrains has the best IDE in my opinion. There are many versions for different types of work. I work with PHP mostly so I use PHPStorm which works nicely with SQL, JS, HTML. Check out products here - jetbrains.com/products.html?fromMenuCasework
Since you focus on SQL this blog may pertain to you blog.jetbrains.com/blog/2014/06/09/…Casework
K
31

In SQL Developer, I highlight all lines of PL/SQL that I want commented and use Ctrl + /.

Obviously, you would like a way to comment and uncomment multiple lines quickly. This will put -- in front of each line you have highlighted. Do the same command to uncomment.

Kluge answered 8/9, 2016 at 16:17 Comment(0)
A
6

you can assign a function key through Tools > Preferences > Key Configuration (Edit / Selection / Comment Lines).

Aprilette answered 31/3, 2020 at 8:48 Comment(1)
Exactly what I was needed. Thanks a lot.Reggiereggis
T
4

Shortcut to comment a line: Command + Option + / (in Mac)

Tortoni answered 4/10, 2019 at 19:7 Comment(0)
A
3

As was stated by @Acroneos, there is no way. This is common behaviour of most programming languages. Comments as well as oher tokens are recognized by lexers. And lexers work with context-free grammars. i.e. lexes usually can recognize only reqular expressions.

You can still use C/C++ approach (#if 0/#endif). See Conditional compilation. But it does not look "so nice".

begin
 something1;
 $if false $then
  something2;
 $endif;
endl;
Aldine answered 21/5, 2015 at 14:2 Comment(0)
D
1

you can use --

so this code :

some_line_of_code some_line_of_code -- some comment about code some_line_of_code some_line_of_code

will be :

--some_line_of_code --some_line_of_code ---- some comment about code --some_line_of_code --some_line_of_code

Dotation answered 21/5, 2015 at 13:53 Comment(4)
Regardless of it working or not, it is far from fast and elegant way to comment out large sections of code to check if your function can compile.Physicist
This approach work perfectly with Emacs. By executing uncomment-region on selected region, only one level comments is removed. And of course comment-region will add one level of single line comments to every selected line.Aldine
I always use VS / SublimeText, and both of these editors have this feature of adding comments, on vb it's a (quote), on C++ it's //Dotation
You tagged* your question as "oracle/plsql", what code are you trying to comment out ? isn't it a plsql ?Dotation
T
0

No, because everything between first delimiter until the next last delimiter will be recognized as comment (=not processed by compiler). Thats how multiline-comments work: If first delimiter (/ * ) is recognized, compiler will ignore anything until the very next last delimiter ( * /) is recognized. Now as you know this, you should be able to understand, why your second / * will never be recognized as a comment-delimiter by the compiler.

However, you can mark comments with special characters or concatenations within the multiline-comment-sector to line out comments into different sections.

Transitory answered 21/5, 2015 at 13:48 Comment(0)
C
0

in sql developer ; default shortcut is : ctrl + shift + c

Congressional answered 3/8, 2022 at 11:34 Comment(0)
P
0

In Sql Developer,You can use the following commands...

  1. For Commenting Sql Statements... ctl and / keys

  2. For un-commenting Sql Statements... ctl and / keys again

  3. Additionally, to format sql statement ctl and F7

Peonage answered 7/8, 2022 at 2:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.