The "Add/Remove Comment" command should use indention

Discuss syntax highlighting or submit new syntax files.
Post Reply
dustwalker
Posts: 28
Joined: 08 Jun 2011 17:14

The "Add/Remove Comment" command should use indention

Post by dustwalker »

Hi,
This is a minor issue. The "Add/Remove Comment" or "Block Comments" command (CTRL+') puts or removes a "comment out" character at the very beginning of the selected lines. However, many source code lines have "comment out" characters preceded by spaces. The "Add/Remove Comment" command fails in those lines. Also, when "Add/Remove Comment" adds a "comment out" character, it breaks the indention pattern. Python relies on indention, so RJ TextEd's "code folding" feature stops working in Python source files.

I think that the "Add/Remove Comment" command should put or remove the "comment out" character after the initial spaces or tabs.

Best regards
User avatar
pjj
Posts: 2108
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: The "Add/Remove Comment" command should use indention

Post by pjj »

I don't quite understand. Say, I have this piece of code:

Code: Select all

  if (isset($osSearchPresets['minlength']))
  {
    // $minlength = $osSearchPresets['minlength'];
    $minlength = 5;
  }
When I highlight it all and comment out, I get this:

Code: Select all

//  if (isset($osSearchPresets['minlength']))
//  {
//    // $minlength = $osSearchPresets['minlength'];
//    $minlength = 5;
//  }
This is handy, I have visual clue of the commented block, as comment chars are nicely lined up. Do you want it to look like this:

Code: Select all

  // if (isset($osSearchPresets['minlength']))
  // {
    // // $minlength = $osSearchPresets['minlength'];
    // $minlength = 5;
  //}
? That would be ugly and IMHO unproductive.
dustwalker wrote:However, many source code lines have "comment out" characters preceded by spaces. The "Add/Remove Comment" command fails in those lines.

?? I would say it works as expected: adds comment chars.
dustwalker wrote:Also, when "Add/Remove Comment" adds a "comment out" character, it breaks the indention pattern.
I have never seen broken indentation due to "add comment" command. Perhaps it is due to your specific settings (or highlighter you use)?
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
dustwalker
Posts: 28
Joined: 08 Jun 2011 17:14

Re: The "Add/Remove Comment" command should use indention

Post by dustwalker »

I misunderstood the "Add/Remove Comment" command. I noticed that if I used it several times, it alternated between adding and removing the "comment character". Also, it used the "comment line character", instead of "begin comment block" and "end comment block" characters. So, I assumed that its purpose was to switch individual lines from code to comment, or from comment to code. Thus, in your example, I expected:

Code: Select all

  // if (isset($osSearchPresets['minlength']))
  // {
     $minlength = $osSearchPresets['minlength'];
     // $minlength = 5;
  // }
I have done a couple of tests and now I realize that it modifies a selection of contiguous lines, depending on the first character of the first line. The command's other name "Block Comment" should have been a pretty big clue.

The style guide for Python code recommends indenting block comments. I, too, prefer comments indented at the level of the code; they seem less disrupting.

My problem with "Add Comment" and "code folding" happens with languages that use indentation to define blocks of code, like Python. For example:

Code: Select all

def internet_on(x):
    try:
        response=urllib.urlopen(x)
        #response=urllib2.urlopen(x,timeout=y)
        return True
    except IOError as err: pass
    return False
    
def other(x,y):
If I click the little square before the function internet_on(), the code folds to:

Code: Select all

def internet_on(x)  (...)
def other(x,y):
Which is fine. However, If I put Python's comment character (#) with "Add/Remove Comment", the code is

Code: Select all

def internet_on(x):
    try:
        response=urllib.urlopen(x)
#        response=urllib2.urlopen(x,timeout=y)
        return True
    except IOError as err: pass
    return False
    
def other(x,y):
which folds to:

Code: Select all

def internet_on(x):
#        response=urllib2.urlopen(x,timeout=y)
        return True
    except IOError as err: pass
    return False
    
def other(x,y):
which is wrong. "return True" and the next two lines belong to the function internet_on(). I tried editing the syntax file for Python, but I could not find an option to correct this problem.

Best Regards
User avatar
pjj
Posts: 2108
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: The "Add/Remove Comment" command should use indention

Post by pjj »

dustwalker wrote: However, If I put Python's comment character (#) with "Add/Remove Comment", the code is

Code: Select all

def internet_on(x):
    try:
        response=urllib.urlopen(x)
#        response=urllib2.urlopen(x,timeout=y)
        return True
    except IOError as err: pass
    return False
    
def other(x,y):
Got it, thank you! So it seems that the "offending factor" (so to say) is Python's highlighter folding scheme.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Post Reply