Author Topic: Beautify code in SE2008  (Read 14941 times)

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Beautify code in SE2008
« Reply #15 on: April 08, 2008, 06:46:17 pm »
Hm, I opened your beautify.cpp file and ran Tools->Beautify on it.
All the lines seem to get properly indented.

You might want to carefully inspect all of the configuration options in the Beautify dialog, and make sure they are all set the way you intend.

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Beautify code in SE2008
« Reply #16 on: April 08, 2008, 07:08:00 pm »
Hm, I opened your beautify.cpp file and ran Tools->Beautify on it.
All the lines seem to get properly indented.

You might want to carefully inspect all of the configuration options in the Beautify dialog, and make sure they are all set the way you intend.

Perhaps a step by step of the settings you have?  Because that's my problem....  I've looked through all the settings, made various changes to each but it never really solves the issue.

thnx,
Christoph

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Beautify code in SE2008
« Reply #17 on: April 08, 2008, 08:56:40 pm »
If I post my settings, it will take me a while to compile them (and unfortunately I have a lot of day job stuff I need to get done and I don't know when I'll have time to compile a list of all my settings), but no one else can offer any insight -- you're the only one who can try to diagnose it.  On the other hand, if you post all your settings then it enables other knowledgeable people to take a look at your settings and offer insight.  That's probably the best next step.

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Beautify code in SE2008
« Reply #18 on: April 09, 2008, 12:04:24 pm »
If I post my settings, it will take me a while to compile them (and unfortunately I have a lot of day job stuff I need to get done and I don't know when I'll have time to compile a list of all my settings), but no one else can offer any insight -- you're the only one who can try to diagnose it.  On the other hand, if you post all your settings then it enables other knowledgeable people to take a look at your settings and offer insight.  That's probably the best next step.

As I stated before, I've tried a number of mix-n-match options to try to address the issue.  Nothing I've tried seemed to work. 

The following are the settings I currently have that were used in the attached file.  The results here are not that dissimilar to those that I posted previously.  The settings that I indicate for each tab of the beautifier gui are for those that are checked.  If the item isn't listed here, it is unchecked.

Begin/end style tab:
* Style 2
* Apply to function braces

Indenting tab:
* Continuation indent: 2
* Indent for each level: 2
* Tab size: 2
* Original tab size: 2

Comments tab:
* Indent stand alone comments
* Indent column 1 comments
* Original relative indent

Other tab:
* Remove padding

thnx,
Christoph

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Beautify code in SE2008
« Reply #19 on: April 09, 2008, 06:16:44 pm »
With those settings, here is what I get when I run Beautify on the beautify.cpp file you posted:

Code: [Select]
<?php
  
class BeforeBeautify
{
public function 
_construct()
  {
    if (
TRUE)
    {
      switch (
$var)
      {
      case 
1:
        foreach( 
$array as $key => $val )
        {
          echo 
"$key => $val";

        }
        break;
      case 
2:
        break;
      }
    }
  }
}

class 
AfterBeautify
{
public function 
_construct()
  {
    if (
TRUE)
    {
      switch (
$var)
      {
      case 
1:
        foreach( 
$array as $key => $val )
        {
          echo 
"$key => $val";

        }
        break;
      case 
2:
        break;
      }
    }
  }
}

?>


The lines appear indented properly to me.
You're going to need to try running the beautifer on the beautify.cpp file in a stock config.
Try running "vs -sc c:\tmpdir" (may need to create the tmpdir first, not sure) to have SE rebuild a new stock config in tmpdir, then load beautify.cpp and use the beautifier in the stock config.  That should work, and if it does then it means something about your custom config is interfering with the beautifier.  For example it could be that you have a custom macro with a function name that conflicts with a stock function name and replaces the stock function, and ends up interfering with beautify in a roundabout way.

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Beautify code in SE2008
« Reply #20 on: April 10, 2008, 12:14:39 pm »
With those settings, here is what I get when I run Beautify on the beautify.cpp file you posted:

Code: [Select]
<?php
class BeforeBeautify
{
  public function 
_construct()
  {
    if (
TRUE)
    {
      switch (
$var)
      {
        case 
1:
          foreach( 
$array as $key => $val )
          {
            echo 
"$key => $val";

          }
          break;
        case 
2:
          break;
      }
    }
  }
}

class 
AfterBeautify
{
public function 
_construct()
  {
    if (
TRUE)
    {
      switch (
$var)
      {
      case 
1:
        foreach( 
$array as $key => $val )
        {
          echo 
"$key => $val";

        }
        break;
      case 
2:
        break;
      }
    }
  }
}

?>


The lines appear indented properly to me.

The lines appear properly indented to you?  It's proper for the function definition to appear on the same indent level as the class definition?  The "case" statements to appear on the same indent level as the switch() statement?  That may seem proper to you but it does not seem proper to me and I'm trying to change the settings so that in my examples above, the before and after look the same.

You're going to need to try running the beautifer on the beautify.cpp file in a stock config.
Try running "vs -sc c:\tmpdir" (may need to create the tmpdir first, not sure) to have SE rebuild a new stock config in tmpdir, then load beautify.cpp and use the beautifier in the stock config.  That should work, and if it does then it means something about your custom config is interfering with the beautifier.  For example it could be that you have a custom macro with a function name that conflicts with a stock function name and replaces the stock function, and ends up interfering with beautify in a roundabout way.

I just tried that in trying to track down another issue I'm having with comment blocks.  I was finally able to get SE2k8 started using

vs.exe -sc c:\temp\seconfig

after having removed my VSE9.x directory from the path and replacing vslick.sta with rescue.sta.  The comment issue seemed to be fixed (but that's another thread) but when attempting to beautify the code, SE did so in exactly the same way it did with my other settings.

thnx,
Christoph

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Beautify code in SE2008
« Reply #21 on: April 10, 2008, 05:50:27 pm »
Ahhhh.

1.  I did not look closely at the class names, and you did not mention that only the second half of the file was the repro case.  I misunderstood what you expected to happen.  Furthermore, the indentation appeared inconsistent to me in the "Before" chunk, and I naturally assumed you had shifted lines as a means of testing whether Beautify was touching them.  It turns out that you are using spaces to indent in some places, and using tabs to indent in other places, and my tab settings are 4, but your tab settings are 2.
2.  In your original statement, you showed that the lines within an "if" did not get indented.  So I ran Beautify, and verified that the lines within the "if" DO get indented.  That was as far as I went.

You need to be more specific about your expectations and observations.

Responding to your most recent questions:

Quote
It's proper for the function definition to appear on the same indent level as the class definition?
In C/C++ the "public" keyword does not work the way you've used it in your sample code.  I assume that is a PHP-specific difference.  In C/C++, the "public:" keyword needs a colon after it, and generally goes on its own line (technically newlines are never needed in C/C++, but I've never seen anything but comments on the same line after a "public:").
So, keep in mind that you are using the C/C++ beautifier to beautify a different language that is merely similar to C/C++.  Now, with that in mind, you said that you do not have "Indent access specifier" checked.  The "public" keyword is an access specifier.  You explicitly told it not to indent access specifiers.  So due to a syntax difference between C/C++ and PHP, that is why your functions aren't being indented.

Quote
The "case" statements to appear on the same indent level as the switch() statement?
Well, yes.  Reread the settings you posted.  You said you do not have "Indent CASE from SWITCH" checked.  You explicitly told Beautify not to indent the "case" statements, so naturally it shouldn't indent them.  (None of the Style 2 projects I've ever worked in indented the case, so from my perspective, I would that yes, from a stylistic perspective as well it appears correct to me for the case not to be indented.  ;))

It seems that if you check the "Indent access specifier", and "Indent CASE from SWITCH" checkboxes, then the things you complained about work properly.

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Beautify code in SE2008
« Reply #22 on: April 10, 2008, 06:01:53 pm »
It seems that if you check the "Indent access specifier", and "Indent CASE from SWITCH" checkboxes, then the things you complained about work properly.

Re: the CASE checkbox, fair enough.  I did have that checked before and it didn't seem to change anything w/r/t to the behavior but having now just tried it, it seems I wasn't paying enough attention before.  However, w/r/t the "Indent access specifier", I don't see that checkbox anywhere on my (PHP) beautifier dialog.  I don't see it on Indenting tab nor do I see it on the Other tab.  I do see it on the Indenting tab of the C++ Beautifier, however.  I'm curious why the two different dialogs?  Before I altered the cformat.e, I couldn't even get it to beautify my PHP file.  When I altered the cformat.e, I made it (or so I thought) so that the file extensions I'm working with would use the c beautifier.  Around approx line 2929, I changed the existing line to:

#define DEFAULT_BEAUTIFIER_EXT  "ada=ada c=c java=c js=c cs=c e=c html=html cfml=html xml=html xsd=html vpj=xml as=c phpscript=c php=c inc=c tpl=html"   /* Valid beautifier languages */

So why isn't it using the c beautifier?

thnx,
Christoph

Phil Barila

  • Senior Community Member
  • Posts: 742
  • Hero Points: 61
Re: Beautify code in SE2008
« Reply #23 on: April 10, 2008, 06:48:10 pm »
If you want SE to use the c settings, including the beautifier, did you consider just changing the .php extension to refer to .c, instead of hacking at code?

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Beautify code in SE2008
« Reply #24 on: April 10, 2008, 06:55:00 pm »
If you want SE to use the c settings, including the beautifier, did you consider just changing the .php extension to refer to .c, instead of hacking at code?

Yep, I sure did.  However, in doing that, my color coding went completely out the window.  The IDE no longer color coded PHP's internal functions and, instead of going in and entering all several hundred into the C settings, I figured it'd be much easier just to get the beautifier turned on for the PHP extensions.

thnx,
Christoph

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Beautify code in SE2008
« Reply #25 on: April 11, 2008, 12:23:43 am »
You said the checkbox wasn't visible in the beautifier when the file extension is php.
So presumably something hid the checkbox.
I searched the "*.e" files in the "macros" directory for the text "access specifier", and sure enough:

In cformat.e, in onCreateIndenting, circa line 2149 is a line that says:
Code: [Select]
   _ctl_indent_access_specifier.p_visible = (_orig_lang == 'c');

Try adding ||_orig_lang == 'php' and see if that makes the checkbox show up.

I'd encourage you to poke around in the macro code.  It's not that hard to read, and the stuff that you've needed to tweak has been pretty easy to find.  Teach a man to fish, and all that.  ;D