EmEditor (text editor) Forum Index
   Questions and Answers about EmEditor Core
     Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
JohnQSmith
Posted on: 1/17/2013 12:11 pm
Not too shy to talk
Joined: 7/15/2011
From:
Posts: 30
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Quote:
Hmmm! IMHO, the most desirable functionality is a single, toggle command which can be assigned a keyboard shortcut, working on the current line if none is selected or on all selected lines is. If any of these are already commented out, uncomment it!

Toggle, because obviously if it is already commented out, why would you want to comment it out again?


Because the code I'm editing already has comments that I want to keep. For example,

... 
for(int i=0;i<10;i++) {
// the following line prints incremented variable
   printf("%d",i);
}
...


Using your idea, if I wanted to comment out that loop, I'd end up with

...
//for(int i=0;i<10;i++) {
 the following line prints incremented variable
//   printf("%d",i);
//}
...


which would be wrong.

If I comment out that block, it should add additional comments on previously commented lines like

...
//for(int i=0;i<10;i++) {
//// the following line prints incremented variable
//   printf("%d",i);
//}
...


that way when I later uncomment it, it will be back the way it was when I started.
ArthurZ
Posted on: 1/15/2013 7:47 am
Just can't stay away
Joined: 1/26/2012
From:
Posts: 78
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
My both thumbs are up for the proposed!

By the way your rephrase Meir: "Toggle" is the word and the way to go.
mguttman
Posted on: 1/15/2013 7:20 am
Just can't stay away
Joined: 11/14/2009
From: Ashdod, Israel
Posts: 76
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Thanks Arthur,

OK...

Hmmm! IMHO, the most desirable functionality is a single, toggle command which can be assigned a keyboard shortcut, working on the current line if none is selected or on all selected lines is. If any of these are already commented out, uncomment it!

Toggle, because obviously if it is already commented out, why would you want to comment it out again? Also in the opposite direction.

Yes I am sure Yutaka is listening. He always does, and that is not the least reason that I am using EE


----------------
Regards,
Meir

ArthurZ
Posted on: 1/15/2013 6:42 am
Just can't stay away
Joined: 1/26/2012
From:
Posts: 78
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Hello Meir,

Yes, the macro is designed to work on a single line of unselected text.
This is because in the rest of the situations we have the right-click -> Convert Selection > Comment/Uncomment functionality or you can pull these two buttons onto the toolbar.
Agin, the latter just does not work for a single un-highlighted line of code - hence the macro.

I must add, this creates some uncomfort for me - split, non-unified functionality .

Hope Yutaka is listening: I suggest a change to allow commenting code regardless of whether a line is highlighted/selected.
mguttman
Posted on: 1/15/2013 3:35 am
Just can't stay away
Joined: 11/14/2009
From: Ashdod, Israel
Posts: 76
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Dear Arthur,

I agree with you, but when one or more lines are SELECTED, nothing happens! No commenting-out!

Is this last behavior planned? If so, what should I add to have it comment out a bunch of selected lines?


----------------
Regards,
Meir

ArthurZ
Posted on: 1/14/2013 5:33 am
Just can't stay away
Joined: 1/26/2012
From:
Posts: 78
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Hello Meir,

It highlights and comments out a line of code (even if it was commented out already). You need to just position the cursor within the line.

While the cursor is still on the same (just commented) line it un-comments it.
mguttman
Posted on: 1/14/2013 12:27 am
Just can't stay away
Joined: 11/14/2009
From: Ashdod, Israel
Posts: 76
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Hi!

IMHO this macro just UN-comments an already commented-out text. It didn't comment out any un-commented one, or am I missing something?


----------------
Regards,
Meir

ArthurZ
Posted on: 1/13/2013 4:59 pm
Just can't stay away
Joined: 1/26/2012
From:
Posts: 78
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Not quite there, but the following variation is almost what I need, how to un-select a line?

if( document.selection.IsEmpty )
{ 	
// highlight select and comment 

editor.ExecuteCommandByID(4154); 	editor.ExecuteCommandByID(4371); 
} 
else
{     
// uncomment 	
editor.ExecuteCommandByID(4372); 
}
Yutaka
Posted on: 1/13/2013 8:49 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2401
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
You are right; the above code was to comment in all cases.

To toggle the comment, it will a little more complicated. To uncomment in all cases, here is the code:

if( document.selection.IsEmpty ){
	editor.ExecuteCommandByID(4154);
}
editor.ExecuteCommandByID(4372);


Thanks!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

ArthurZ
Posted on: 1/11/2013 9:27 am
Just can't stay away
Joined: 1/26/2012
From:
Posts: 78
Re: Why Comment/Uncomment Functionality Becomes Enabled Only When Line(s) Selected?
Probably you meant it will comment in either case. At least the code does this. And I think it would be nice to enhance the functionality so if the comment is already there - uncomment - thus toggling the comments on/off.
(1) 2 »
Threaded | Oldest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文