Author Topic: How do I modify Syntax Expansion for PHP ?  (Read 249 times)

jcelle

  • Senior Community Member
  • Posts: 102
  • Hero Points: 4
How do I modify Syntax Expansion for PHP ?
« on: May 08, 2020, 10:22:54 am »
Hello,
I am trying to understand how to modify Syntax Expansion for PHP.
I can successfully trigger Syntax Expansion for 'if' and 'for' keywords for instance but not for 'foreach'.
I read in some posts here that one way to modify Syntax Expansion is to create (update?) language specific aliases.
For C/C++ language many aliases are already predefined. For PHP there are none.
This puzzles me.
Where are the PHP aliases used for Syntax Epanxansion stored ?
I'd rather build on existing data rather than create a PHP alias from scratch for the missing foreach.
Besides I intend to use 'for' to trigger the foreach loop, so I also need to disable the original 'for' configuration.
Thanks for any advice.
« Last Edit: May 08, 2020, 10:26:03 am by jcelle »

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2455
  • Hero Points: 137
Re: How do I modify Syntax Expansion for PHP ?
« Reply #1 on: May 08, 2020, 12:49:35 pm »
The easiest way to do it i so go to Tools>Options, Languages>Web Authoring Languages>PHP>Aliases.  Give the name you want to expand (foreach) and the whole loop that you want to use.

jcelle

  • Senior Community Member
  • Posts: 102
  • Hero Points: 4
Re: How do I modify Syntax Expansion for PHP ?
« Reply #2 on: May 08, 2020, 02:08:27 pm »
Thanks for your answer Dan.
I would like to understand where PHP 'out of the box' Syntax Expansion comes from.
Do you know why 'local' aliases show for C/C++ and not for PHP ?

Besides, how can I use 'for' (and not 'foreach') and make sure my 'for' takes precedence on the 'out of the box' for ?
Regards.

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2455
  • Hero Points: 137
Re: How do I modify Syntax Expansion for PHP ?
« Reply #3 on: May 08, 2020, 08:45:54 pm »
There are some that we ship for C/C++, so that is why they show up.

You should be able to get those to work, you may need to define your own foreach.

jcelle

  • Senior Community Member
  • Posts: 102
  • Hero Points: 4
Re: How do I modify Syntax Expansion for PHP ?
« Reply #4 on: May 20, 2020, 12:52:04 pm »
Hello Dennis,
I think we have a problem here.
Out of the box if I type "if(" I get an automatic expansion for if.
I don't like it as such and wish I could change it.
I understood it was not possible so I created a PHP alias on this key "if', note I do not include the opening parenthesis.
I have now a perfect "if" + space alias.

However I still have an unwanted "if(" alias remaining: how do I get rid of it ?
There must be a way to update existing templates: I can't believe it is hard coded.

Ideally I wish that typing "if(" would trigger my template - note "if(" not if( + space or any other trigger key.

Thanks for helping me.
Regards.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5240
  • Hero Points: 432
Re: How do I modify Syntax Expansion for PHP ?
« Reply #5 on: May 20, 2020, 05:52:34 pm »
There isn't a way to configure SlickEdit to use your IF alias when '(' is typed unless you create your own "c_paren" macro.  SlickEdit doesn't try to predict what a user defined alias might do. That's why this isn't done.

You can disable 'if(' from doing some built-in syntax expansion. It requires disabling all syntax expansion. Turn off "Use Syntax Expansion on space" (Tools>Options>Languages>Web Authoring Languages>PHP>Auto-Complete).

Once you've disabled all built-in syntax expansions, you may want to add more of your own aliases.