Author Topic: Pretty(and easy) Syntax Expansion  (Read 17401 times)

bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Pretty(and easy) Syntax Expansion
« on: May 01, 2008, 11:12:36 PM »
Ryan,

     I have been looking to the fortran.e and modula.e files for examples related to syntax expansion and i have found a couple of different ways syntax highlighting is being performed. The easiest(but ugliest) way seems to be to add certain definitions to the <extension>.als file and creating aliases for common language features. I say ugliest, because whenever there is a clash for similar types, you get the somewhat annoying modal pop-up window with the alias_names rather than a description of what will be inserted. In contrast to this solution, there is the much prettier solution where a hashmap of type, SYNTAX_EXPANSION_INFO, is used to create a list to be displayed to the user next to the lightbulb, very similar to how eclipse displays Syntax Expansion options. However, when i dig into the code further it looks like all of these entries are handled via an large nested if-else structure and hand-coded for each scenario. Since I would prefer not to custom code all of the 200+ syntax assist entries i have to implement, is there someway to combine these two strategies?

Thanks,
Rob
« Last Edit: May 01, 2008, 11:21:36 PM by bercikr »

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: Pretty(and easy) Syntax Expansion
« Reply #1 on: May 02, 2008, 03:10:19 PM »
First, you need to understand some things about the architecture.

The "light bulb" is auto-complete.  Though most people regard it as a completion or syntax expansion mechanism, auto-complete is really a suggestion mechanism.  It will suggest a variety of completions for you based on the word prefix under the cursor.  That is all auto-complete does.  It suggests a completion and provides you a mechanism to easily invoke that completion.  It works with aliases, keywords, words, symbols, and the syntax expansion callbacks.  Before auto-complete, those completions were all separate keystrokes and commands.  Auto-complete brought them under a common umbrella with the intention of teaching users what SlickEdit is capable of.  Now, many people just let auto-complete do everything and don't even know how to explicitly complete an alias, for example.

Syntax expansion is the workhorse.  Auto-complete uses the display strings in the language specific SYNTAX_EXPANSION_INFO tables just for display, nothing else.  Most of those display strings are just approximations of what syntax expansion will generate, because they don't know anything about your brace style, your indentation preferences, etc. etc.  The code you found that does the expansion does know about your options and the context where the code is being inserted and does a lot of work to get that right for you.  There is no substitute for the flexibility of being able to write code to implement syntax expansion and being able to get things right that a rule base could never get right (for example, completing an if-else statement in C/C++).

Alias expansion is a sort of rule based approach that is user-configurable.  If you have an alias that matches a syntax expansion keyword, the alias will override the default, hard coded syntax expansion.  Aliases have tons of escape sequences for handling indentation and querying some data, such as the current function name or current class name.

So, now, advice for you on what strategies to choose.  First, you get back what you invest time in.  I would, of course, start with aliases, because they are the easiest.  A useful tip to know that if you select text in the editor, you can right click for the context menu and select "Create Alias..." to create a language specific alias from that text.  Auto-complete will suggest whatever aliases you create if the prefix matches the word under the cursor, so that's nearly automatic.

You may eventually find that you have items that the alias mechanism can not handle, then you can write up your own mylang_space() and mylang_expand_space() functions to implement syntax expansion for those items.

bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Re: Pretty(and easy) Syntax Expansion
« Reply #2 on: May 06, 2008, 12:10:18 AM »
Dennis,

    Thanks for the response regarding syntax highlighting, I'm starting to understand the differences between these different code-assistance tools and I've managed to at least display a large number of code-assist possibilities using the SYNTAX_EXPANSION_INFO and i've started to clean up an alias file that is helping with the syntax expansion, etc.

One thing i've noticed is that that my editor seems to lose track of its alias file quite frequently and i need to type alias -e in order to re-associate the alias file with the language. Also, i have not found a way to associate an alias file when creating the language definition...is there a way to do this?

Another feature I would like to implement is better navigation within alias definitions or auto-complete. I would like to emulate the function/method information that you see when you type '(' for java or slickedit style code. Is this pretty difficult to implement? Eclipse has a really nice facility where the edited line stays highlighted while you tab between fields in FOR loops, etc. Is there anything equivalent to that in SlickEdit?

Thanks,
Rob


« Last Edit: May 07, 2008, 03:38:20 PM by bercikr »

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Pretty(and easy) Syntax Expansion
« Reply #3 on: May 06, 2008, 02:32:27 PM »
Quote
Also, i have not found a way to associate an alias file when creating the language definition...is there a way to do this?

I believe that if you have an extension for your language, let's call it .abc, if you have an abc.als file, then abc.als is automatically associated with all .abc files.  Is this not the behavior you are seeing?

Quote
Eclipse has a really nice facility where the edited line stays highlighted while you tab between fields in FOR loops, etc. Is there anything equivalent to that in SlickEdit?

We have "hotspots" for jumping between fields in statements...the command is next-hotspot, and it probably isn't bound by default in your emulation, so you will have to bind it to something to make it useful.  If you do where-is next-hotspot this will tell you if you have a key defined.  You can use it to jump back and forth between the body of a while loop and the conditional statement, for example.

Quote
I would like to emulate the function/method information that you see when you type '(' for java or slickedit style code. Is this pretty difficult to implement?

I'm gonna try to coax Dennis into giving you some feedback on this one ;)...

- Ryan



bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Re: Pretty(and easy) Syntax Expansion
« Reply #4 on: June 11, 2008, 07:51:29 PM »
Ryan/Dennis,

Ok, I've done the homework and learned how autocomplete works in harmony with aliases etc. Here's some of the feedback I have so far both from my own experiences and from my users, etc.

From a functionality perspective the SE alias functionality is relatively powerful and is comparable to a lot of the code-complete features of eclipse. In some areas I would say the ability to add custom parameters, etc. might even be a little better/easier in SlickEdit. However, in a number of areas it is really lacking as far as usability and portability are concerned.

Let me first say as a caveat that I have read most of the documentation on this stuff and cut through a whole lot of lines of SlickEdit code but I could still be doing stuff a little bit differently than intended. I still don't have a great handle on the difference between  codehelp-complete and autocomplete but I think i have a decent grasp of the functionality overall. That being said, this is what we've had as a user experience with the syntax-completion and alias functionality in slickedit thus far.

Firstly, from a usability perspective we run into some pretty big roadblocks. People can add aliases quite easily which is great. However when they go to access them from our standard CTRL+SPACEBAR keystroke(mapped to the autocomplete command), they can don't see the name of the alias they added they see the first line of the alias competion text as listed in the alias file. So if the first line of the alias happens to be a big comment like this, /***********************/ they see something that doesn't really help them figure out what text is going to be expanded. In order for them to not see that I have to update the SYNTAX_EXPANSIONS_KEYWORD list with the proper text to display under the Syntax Expansion folder icon.  So this doesn't really mesh well with having the users have complete control of their aliases. Is there anyway to have the alias name show  up automatically under the Alias folder that pops up when the autocomplete command is run?

Secondly, from a portability perspective, its very hard to trade/combine alias files since they are not in a standard format like XML for instance. It would be great if the Alias files could be imported/exported via some standard facility where our users could create/add content as needed and I wouldn't have to keep pace with them by updating the SYNTAX_EXPANSION_KEYWORDS etc to match the alias files.

Ok, thats what we have so far. I'm not so much looking for a quick and easy answer to these questions, but rather I would like some more insight into how we can better use the functionality that exists. Also, I think some of these features could use a little modernization to better reflect the very appealing implementation in Eclipse(use the java for loop as an example).

-Rob





Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Pretty(and easy) Syntax Expansion
« Reply #5 on: June 12, 2008, 02:51:07 PM »
Thanks for the feedback Rob, we talked about this stuff for a while yesterday.

Quote
Is there anyway to have the alias name show  up automatically under the Alias folder that pops up when the autocomplete command is run?

We also thought this is an improvement...and I believe Dennis put in a change to this effect for our next SlickEdit release, but I can show you how to hotfix it really quickly.  I know you said you weren't looking for a quick and easy answer, but here is one anyway.  Open up alias.e and go to line 1463 (version 3.3.1).  Change:

Code: [Select]
AutoCompleteAddResult(words, 300, "Aliases", expanded_alias,
                               _autocomplete_expand_alias, comments,
                                null, true, _pic_alias, match_name);

to

Code: [Select]
AutoCompleteAddResult(words, 300, "Aliases", match_name ': 'expanded_alias,
                               _autocomplete_expand_alias, comments,
                                null, true, _pic_alias, match_name);

Does that help?

Quote
Secondly, from a portability perspective, its very hard to trade/combine alias files since they are not in a standard format like XML for instance.

Yea, that would be nice :).  Certainly we have taken steps in this direction with other facilities (our options in version 13 are stored in XML format).  I'll bring this up on your behalf when we start talking about features for the next release, I don't think it will be met with any opposition.

- Ryan


bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Re: Pretty(and easy) Syntax Expansion
« Reply #6 on: June 12, 2008, 03:21:42 PM »
I specifically said no quick and easy fixes!!!  :) Ok, this earned you a couple of hero points because It will make my job/life a lot easier. Moving forward I can just focus on creating the alias files and let SlickEdit do all the work.

I hate to be greedy but can you think of an easy way for us to strip out the replacement parameters from the beginning of the expanded_alias field. I was trying to throw together a regex, but I was hoping there might be an easier method to access the text itself...

thanks again!
-Rob

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Pretty(and easy) Syntax Expansion
« Reply #7 on: June 16, 2008, 01:36:08 PM »
Happy to help  :)

Quote
I hate to be greedy but can you think of an easy way for us to strip out the replacement parameters from the beginning of the expanded_alias field. I was trying to throw together a regex, but I was hoping there might be an easier method to access the text itself...

Without a regex?  Nothing comes to mind...I'll let you know if I have any brilliant or semi-brilliant ideas.

- Ryan