Author Topic: Problems beautifying code  (Read 5771 times)

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Problems beautifying code
« on: April 08, 2009, 08:27:18 pm »
I'm running a trial version of SE on the mac.  Here is what the "About" has to say:

SlickEdit Version 14.0.0.7

Serial number: VMX_TRIAL
License type: Trial
License expiration: 22-apr-2009
License file: /Applications/SlickEdit2009.app/Contents/slickedit/bin/slickedit.lic

Build Date: March 25, 2009
Emulation: Visual C++ 6

OS: Darwin
Kernel Level: 9.6.0
Build Version: Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008
X Server Vendor: The X.Org Foundation

Installation Directory: /Applications/SlickEdit2009.app/Contents/slickedit/
Configuration Directory: /Users/jcboget/.slickedit/14.0.0/
Spill File: /tmp/$slk.jcboget.11880

I'm having a problem when I try to beautify a PHP file.  I've tried using my SE install on Linux and am having no problem there; it's happening just on my mac install.  When I run "gui-beautify", I'm getting a dialog with the following error message:

"Can't find form: _phpscript_beautify_form"

I've tried to see if that is perhaps a missing file but it doesn't appear to exist on my linux box so I'm not sure that it is.  I've gone through the options but found nothing that might pertain to my problem.  I've tried searching for "beautify" in the options but found nothing on that, either.

So what's going on?  And is there something I can do to fix it?

thnx,
Christoph

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: Problems beautifying code
« Reply #1 on: April 09, 2009, 02:39:56 pm »
The gui-beautify command runs the language-specific beautifier for the current file. Unfortunately, we don't have a PHP beautifier, so this function can't find the associated dialog to run. We do have plans to create a PHP beautifier for a future release. In the meantime, you might want to see if you can find a 3rd party beautifier. You can run that from withing SlickEdit by adding it to the Build menu via Project > Project Propeties. Select the Tools tab and click the Add button. You can then configure the command line to launch the tool.

Rodney

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 742
  • Hero Points: 47
Re: Problems beautifying code
« Reply #2 on: April 09, 2009, 03:00:34 pm »
We beautify HTML, but not embedded phpscript. In other words, when we beautify a .php file, we format the surrounding HTML and leave the phpscript alone.

Some possible causes:

* We have to switch in and out of embedded phpscript mode for some operations, so maybe that file got "stuck" in embedded phpscript mode. Simply closing and reopening the file should fix this.

* You have remapped your .php extension away from 'HTML' to 'phpscript'. You can check this from Options>Languages>File Extension Manager. The 'php' extension should be set to 'HTML' for the "Associate with language" setting.

* Something else. Try running SE with a clean config (search this forum if you don't know what I mean) and see if the problem goes away.

--rodney

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Problems beautifying code
« Reply #3 on: April 09, 2009, 04:44:43 pm »
The gui-beautify command runs the language-specific beautifier for the current file. Unfortunately, we don't have a PHP beautifier, so this function can't find the associated dialog to run. We do have plans to create a PHP beautifier for a future release. In the meantime, you might want to see if you can find a 3rd party beautifier.

Well, I don't really need a 3rd party beautifier.  PHP is close enough to C/C++ to where I should be able to use that (SE internal) beautifier.  But I'm not at all sure how to set SE2k9 up to use it.  I don't recall having to do this for SE2k8 and I was beautifying PHP code just fine there...

thnx,
Christoph

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Problems beautifying code
« Reply #4 on: April 10, 2009, 02:07:44 pm »
Is there a way I can tell one language to use another language's beautifier?  I've been looking but haven't found that setting. :(

thnx,
Christoph

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Problems beautifying code
« Reply #5 on: April 10, 2009, 06:59:15 pm »
This topic rang a bell for me.  So I used the forum Search to look for "beautify php".
I found this topic started by you which eventually contained a solution.
It appears that you probably patched your stock SE macros, and upgrading of course overwrites them.

@SlickTeam:  It might be worth picking up the fix, if it's a reasonable fix.

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Problems beautifying code
« Reply #6 on: April 10, 2009, 07:06:52 pm »
This topic rang a bell for me.  So I used the forum Search to look for "beautify php".
I found this topic started by you which eventually contained a solution.
It appears that you probably patched your stock SE macros, and upgrading of course overwrites them.
@SlickTeam:  It might be worth picking up the fix, if it's a reasonable fix.

Wow, I totally forgot about that!  Thanks for the reminder. :P

thnx,
Christoph

Christoph

  • Senior Community Member
  • Posts: 114
  • Hero Points: 6
Re: Problems beautifying code
« Reply #7 on: April 24, 2009, 01:02:52 pm »
This topic rang a bell for me.  So I used the forum Search to look for "beautify php".
I found this topic started by you which eventually contained a solution.
It appears that you probably patched your stock SE macros, and upgrading of course overwrites them.

@SlickTeam:  It might be worth picking up the fix, if it's a reasonable fix.

Ok, I tried everything listed in that thread, up to an including altering my cformat.e file (and reloading the module so that SE compiled the new .ex file).  However, I'm still getting the errors

"Can't find form: _phpscript_beautify_form"

and

"Cannot find command: phpscript_beautify_selection"

depending on what/how I am trying to beautify.  So there must be something (significantly?) different between SE2k8 and SE2k9.  So what am I missing now?  Is there something else I can try to beautify my PHP code?

thnx,
Christoph

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Problems beautifying code
« Reply #8 on: April 24, 2009, 06:55:37 pm »
I'd like to try to help.  Can you be more specific about the details?  The devil really is in the details.

For example:
What file extensions are associated with the "PHP" language node in the Tools|Options dialog?
What is the file name you are trying to beautify?
For the file name you are trying to beautify, what language is its extension associated with in Tools|Options?



My psychic powers tell me that if you comment out the following lines, in addition to making the changes you already did from the other topic (if they're applied correctly) then the beautify dialog will work again for you.  At least, when I recreate your configuration based on the information you've provided then it works for me.
Code: [Select]
int BeautifyCheckSupport(_str &lang)
{
//HACK: comment out these lines
//   if (lang == 'phpscript')
//      return(0);
   lang=eq_name2value(lang,DEFAULT_BEAUTIFIER_EXT);

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Problems beautifying code
« Reply #9 on: April 24, 2009, 07:13:12 pm »
I think these two tweaks in cformat.e are the only ones you need:

Find the BeautifyCheckSupport function, and insert the two #if1/#endif chunks:
Code: [Select]
#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 docbook=xml ant=xml as=c d=c"   /* Valid beautifier languages */
#if 1
#define DEFAULT_BEAUTIFIER_EXT2 "php=c phpscript=c" /* Invalid beautifier languages that we're hacking */
#endif
int BeautifyCheckSupport(_str &lang)
{
#if 1
   _str tmp=eq_name2value(lang,DEFAULT_BEAUTIFIER_EXT2);
   if ( tmp!='' ) {
      lang=tmp;
      return(0);
   }
#endif
   lang=eq_name2value(lang,DEFAULT_BEAUTIFIER_EXT);

Find the onCreateIndenting function, scroll to the end of the function, and insert the part in the #if1/endif:
Code: [Select]
   _ctl_indent_access_specifier.p_visible = (_orig_lang == 'c');
#if 1
   if ( _orig_lang == 'php' || _orig_lang == 'phpscript' ) {
      _ctl_indent_access_specifier.p_visible = true;
   }
#endif
   _ctl_indent_access_specifier.p_value=p:["indent_access_specifier"];

Assuming the PHP files you want to beautify using the C beautifier are associated with the PHP language in Tools|Options, those two changes should be all you need.  The first change tells PHP to use the C beautifier.  The second change enables the "Indent access specifier" checkbox (in the first topic you said you wanted that to be available).

But to avoid this hassle every time you upgrade, you're going to need to follow up with Support about this.  Or learn the SE macro sources and modify them yourself to suit your needs -- but even if you want to modify the sources yourself, I'd still recommend following up on this with Support.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Problems beautifying code
« Reply #10 on: April 24, 2009, 07:21:10 pm »
Oh!  I must be slow.

I just realized that the SlickTeam already tried to make your scenario work.
But there is a slight issue in how it was hooked up:

Code: [Select]
int BeautifyCheckSupport(_str &lang)
{
   if (lang == 'phpscript')
      return(0);
   lang=eq_name2value(lang,DEFAULT_BEAUTIFIER_EXT);

If lang is 'phpscript' it returns (0) to indicate that Beautify is supported.
But it doesn't set lang='c', so lang is still 'phpscript', but there is no _phpscript_beautify_form, so it doesn't actually work.

It seems like the code should probably set lang='c' before returning.
That would be a smaller fix that the one I posted above, though perhaps less generalized.