Author Topic: Dynamic surround with "if" need to press ESC 2 times  (Read 1287 times)

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Dynamic surround with "if" need to press ESC 2 times
« on: February 01, 2023, 03:40:00 PM »
I type in the following code:

Code: [Select]
  if (NULL != threadName)
  {
  }

When I'm done typing it in my cursor is to the right of 'threadName' and before the closing parenthesis.

I have to press ESC 2 times in order to get rid of the dynamic surround box. I think I should only have to press ESC one time?

Another slight annoyance, after I type "threadName" when I press the down arrow it is not expanding the dynamic surround box, instead I get the autocomplete box showing "Locals" with threadName as the only element and the down arrow moves in there. I'd rather use the down arrow to control the dynamic surround.

I'm using SE 27.0.1 on Linux x64. I have hotfix 2. I did not try with a clean config. If you can't repro with a clean config I can send my user.cfg.xml to support.

I also have horizontal dynamic surround disabled.

Dennis

  • Senior Community Member
  • Posts: 3941
  • Hero Points: 515
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #1 on: February 01, 2023, 06:15:41 PM »
I tried to reproduce this, but could not.  The extra ESC may be necessary to cancel Auto-Complete, which may have came up while you were typing threadName.  First ESC would cancel Auto-Complete, second one would cancel dynamic surround.

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #2 on: February 01, 2023, 06:39:06 PM »
I didn't want it to autocomplete though? I didn't press Ctrl+<space> so why is it trying to auto-complete?

Maybe you need a local variable of threadName first, such as:

Code: [Select]
  const char *threadName;

  if (NULL != threadName)
  {
  }

If you still can't repro with this then I will take some time to try and create a self contained project with my user.cfg.xml that repros it.

Dennis

  • Senior Community Member
  • Posts: 3941
  • Hero Points: 515
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #3 on: February 01, 2023, 07:13:29 PM »
You can disable Auto-Complete by going to Document > C/C++ Options... > Auto-Complete > [  ] Enable auto-completion. (uncheck it)

Ctrl+Space will still work, it just won't pop up the list of completions to try to help you while you are typing an identifier.

The event tables for these features stack, since Auto-Complete comes up after Dynamic Surround in your scenario, it gets control of cursor up/down until it is done.

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #4 on: February 01, 2023, 07:33:41 PM »
Thanks Dennis.

Is there a way to turn off the auto-complete from Slick-C code?

Can I turn off the auto-complete for all languages using Slick-C?

Dennis

  • Senior Community Member
  • Posts: 3941
  • Hero Points: 515
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #5 on: February 01, 2023, 07:40:54 PM »
Take a look at the functions AutoCompleteGetOptions() and AutoCompleteSetOptions(), you can mask out the AUTO_COMPLETE_ENABLE when you want to temporarily disable it.

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #6 on: February 01, 2023, 08:26:44 PM »
I turned off auto-complete and then I tried to manual auto-complete by doing Ctrl+<space> for a local variable (ctrl+<space> after 'chil' when there is a local 'childPid'. SE froze for a few seconds and I didn't see the autocomplete box with suggestions.

If you can't repro this I will take the time to make a small sample for you.

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #7 on: February 01, 2023, 08:28:30 PM »
Looks like I didn't wait long enough, I had clicked elsewhere. It is very slow though and this is a local variable. Would be nice if it was faster.

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #8 on: February 01, 2023, 08:35:11 PM »
OK I see if I play with the "Subword matching strategy" I can make the tradeoff of speed vs suggestions.

Would there be a way I could bind different keys to different subword matching strategies?

For example use Ctrl+<space> for no subword matching.
And use Ctrl+<something else> for "stone skipping with subword boundaries"

?

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #9 on: February 01, 2023, 09:16:04 PM »
I think I've seen when I'm in this situation when I do ESC one time to get out of auto-complete and then press down arrow for dynamic surround, I'm back in auto complete and then have to press ESC again to use the dynamic surround down arrow again. It could be useful to not have to do ESC for each time I want to expand the dynamic surround, don't go back to autocomplete after each dynamic surround down?

Dennis

  • Senior Community Member
  • Posts: 3941
  • Hero Points: 515
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #10 on: February 01, 2023, 10:12:19 PM »
This is something we plan on addressing in the next release (v28), maybe 27.0.2, but definitely in v28.  Auto-complete is a bit too reactive right now.  That's helpful, but not always.

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #11 on: February 02, 2023, 01:59:07 PM »
Thanks Dennis!

Would it be possible to have different commands for different auto-complete strategies?

For example with push-tag you added push-tag-filter-overloads for me.

Could it be possible to have commands for each auto-complete strategy (or just a few) so I can decide how long I want each one to take?

Dennis

  • Senior Community Member
  • Posts: 3941
  • Hero Points: 515
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #12 on: February 02, 2023, 03:32:52 PM »
There are no commands involved in the case where auto-complete comes up automatically (thus the "auto" part of the name).

rowbearto

  • Senior Community Member
  • Posts: 2325
  • Hero Points: 132
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #13 on: February 02, 2023, 03:44:14 PM »
I asked this question because I want to disable automatic autocomplete and then use one of these proposed commands (bound to a key) to do a manual autocomplete.

At the time I want to do the manual auto-complete I would know which one is the most desirable, for example, if I know I typed the first few chars I don't need subword matching and wouldn't want to suffer the longer time to do subword matching.

But if I'm not sure that I typed the start but a subword I would want to do the subword matching and take the time hit.

So if I had different commands then with automatic autocomplete turned off I can decide which command I want to use at each instance I encounter it while I write the code.

« Last Edit: February 02, 2023, 03:51:20 PM by rowbearto »

Dennis

  • Senior Community Member
  • Posts: 3941
  • Hero Points: 515
Re: Dynamic surround with "if" need to press ESC 2 times
« Reply #14 on: February 02, 2023, 04:05:04 PM »
I feel like that would be creating a level of complexity that would just get in your way more than help.  The idea behind auto-complete in the first place was to keep things simple, not have a ton of different commands / key shortcuts to learn or remember, just a framework that offers a variety of completions and lets you take control from there.

If you look at Document > C/C++ Options... > Completion Options, you'll see some additional options you might find interesting.

1) Subword matching can be turned off situationally (auto-complete, list-symbols, manual completions, aka Ctrl+Space)
2) For manual completions (Ctrl+Space), you can configure it such that the first attempt does prefix matches only.

What does this mean?  Instead of having two commands to invoke symbol completion with subword matching or without subword matching, you do not have to think about it, and you can just configure it such that it initially just does prefix matching, then if you hit Ctrl+Space to force symbol completions, then it would do subword matching.  If you have auto-complete turned off, that means the command for prefix matching is Ctrl+Space, the command for subword matching is Ctrl+Space, Ctrl+Space.  In fact, because subword matching is hard and can time out, you can even hit it a third time and see if you get additional results (because of caching or luck, depending on how much work it gets done before the timeout).