Author Topic: SmartIndent after CodeCompletion  (Read 7523 times)

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
SmartIndent after CodeCompletion
« on: July 23, 2014, 10:17:39 pm »
I'd like to improve the SmartIndentHDL plugin.

The following case:
Code
process begin
    ...
    end pro|
After typing "pro" CC pops up and I choose "process".
Normally the SmartIndent plugin chatches the wxEVT_SCI_CHARADDED event.
I tried additional with wxEVT_SCI_AUTOCOMP_SELECTION but at this time the completion is not done yet so the
line only contains "end pro" and the plugin can't decide how to unindent.

Any ideas?

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: SmartIndent after CodeCompletion
« Reply #1 on: July 24, 2014, 03:46:47 am »
Hooking into the modified event should notify you at the right time (but it will also give many other notifications, so watch out for double handling events).
Code
if (evtType == wxEVT_SCI_MODIFIED && (event.GetModificationType() & wxSCI_MOD_INSERTTEXT))
{
    // handle changes...
    if (!didJustAutocomplete()) // might need to try a filter or something (wxSCI_PERFORMED_USER might help)
        return;  // ignore
}

Alternatively, you could add an API call into sdk/ccmanager.cpp line 742, so SmartIndent plugins get called at when necessary.

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: SmartIndent after CodeCompletion
« Reply #2 on: July 25, 2014, 02:59:33 pm »
I tried alphas suggestion without success:
From Scintilla documentation:
"No modifications may be performed while in a SCN_MODIFIED event...".

I have a possible solution where i "take" the first wxEVT_SCI_UPDATEUI event after the wxEVT_SCI_AUTOCOMP_SELECTION event (Patch is attached).
Any better proposals?


regards danselmi

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: SmartIndent after CodeCompletion
« Reply #3 on: July 29, 2014, 03:46:09 am »
Oops, sorry about that.  I guess I did not read the docs closely enough.

Reading through your patch, it seems like it relies too much on a specific order of events (which *might* be interrupted/altered someday in the future).  I think a cleaner way is to:
[...] add an API call into sdk/ccmanager.cpp line 742, so SmartIndent plugins get called at when necessary.
Have CCManager either broadcast a CC_Done event (which SmartIndent plugins could pick up), or iterate through all SmartIndent plugins and execute plugin->OnCCDone(ed).

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: SmartIndent after CodeCompletion
« Reply #4 on: July 30, 2014, 09:13:05 am »
just commited rev9853

It implements the approach where CCManager calls SmartIndentPlugin->OnCCDone(ed).
Kudos to alpha for support and reviewing!

regards danselmi