dhruvasagar / vim-pairify

A simplistic vim plugin to deal with pairs non-intrusively
14 stars 3 forks source link

Possible to make pairify cursor movement invisible? #1

Closed xoihiox closed 4 years ago

xoihiox commented 4 years ago

This little plugin is fabulous, thank you.

I simply do not understand all of those other overly complicated, difficult-to-use solutions for single-character pair completions, nor do I understand how they still manage to fail so consistently.

This is perfect for my needs, though I have one question. When the pairify function is finding pairs, do you know if it is possible to do so silently, so I don't have to watch the cursor jump around the line?

Cheers.

dhruvasagar commented 4 years ago

@xoihiox Thanks for your feedback, although I hadn't advertised this plugin since it's kinda experimental. I'll look into the particular issue you describe.

dhruvasagar commented 4 years ago

@xoihiox Can you share some examples where you observed this issue ? Based on your description it appears to be a performance issue, however I don't see it in most basic examples I have used. Are you working with a lisp maybe ?

xoihiox commented 4 years ago

Thanks for the speedy reply. Not programming in lisp, was just testing the plugin. For example, if I type this line "(this is a 'test and complete 3 times at the end of the line, on the second completion (and for all closing brackets and braces), the cursor jumps to the matching pair before inputting the closing brace such as occurs when you type %.

I failed to mention that single and double quotes complete as desired.

I am not too handy with vimscript, but I had looked through the code to see if I could find where this occurred, but nothing stood out. Please let me know if this is not typical, as it seems it might be due to another plugin, in which case sorry to bother you!

Thanks.

dhruvasagar commented 4 years ago

@xoihiox Yea it may be something else conflicting with what I am doing, because I am unable to reproduce it. I will however still look into it to make sure I use vim native api to avoid plugin overrides from affecting this plugin.

xoihiox commented 4 years ago

In that case, sorry to bring it up. It must be my rainbow-colored braces plugin. Thanks for narrowing it down for me, though.

By the way, I am currently experimenting with completion characters. Currently I am completing with the semicolon key, so completions only require a single keypress. It works pretty well, though semi-colon insertion is still a bit awkward (current mapping below).

imap ; <Plug>(pairify-complete)                                                       
inoremap : ;                                                                          
inoremap :: :  

To get to my point, I'll just share a couple of thoughts before closing out this issue:

  1. I like that it completes only on the current line. Keeps it simple and covers the majority of pair-completions without any fuss. Plus, more complicated solutions exist for more complicated desired behavior.
  2. It might be nice to ignore escaped punctuation so as to properly complete this string, for example : "he called me a \"loser\"". I suppose this is where things get just a bit complicated because current behavior is not so bad here: "he called me a \'loser\'". I think I maybe like the logic of manually completing all escaped punctuation, though, for two reasons. First, since I am manually escaping it, I am already thinking about it enough to type it correctly myself. Second, if I want to put punctuation somewhere where I know it will break the parser, I know I can do so without breaking the parser simply by escaping it.
  3. Anyway, my point was that I think this plugin covers 80% of use-cases very well in an unobtrusive way that rarely fails, so would be surprised if there was not broader appeal should you decide to plug it here and there.
  4. Just adding one more point to cover all the bases I can think of, which is for when we are writing something other than code. I am sure it has crossed your mind, but ignoring standard English contractions might be helpful: some subset of these. That of course leaves a bunch of corner cases, but we can just rely on the logic of 2 above and either escape here: "He called Jonas\' name" or just manually type out the punctuation if escaped characters are unacceptable. Because the plugin only works on a single line at a time, it is difficult to get into too much trouble, so I would say it is not necessary for a more complicated solution here, such as the ability for the user to cycle through all the RHS possibilities for punctuation occurring on the initial, unpopped stack via successive completion presses or a completion menu, or the developer to write more complicated parsing logic that will end up biting him or her in the ass.
dhruvasagar commented 4 years ago

@xoihiox

  1. That was exactly my motivation behind creating this plugin, I wanted it to not be too smart and pre decide what I want and kinda give control to me to decide if or not I want completion so it doesn't come in my way.

  2. I am aware of this, I had planned to implement this but didn't get around to doing it. Will try to get back to this.

  3. Thanks!

Regarding the imap with semicolon key, I like the idea. I can add support for this.

The idea would be to output back the mapping in case no matches are found (nothing to complete), otherwise it will output the matching pair.

xoihiox commented 4 years ago

@dhruvasagar, that'd be great! All for now, cheers.

dhruvasagar commented 4 years ago

@xoihiox The commit linked above adds support for the custom mapping.

PS : There's one edge case which you may not be aware of. If the cursor is on a matching pair that is already matched, it just shifts over it.

dhruvasagar commented 4 years ago

@xoihiox Did you get a chance to have a look at this ?

xoihiox commented 4 years ago

@dhruvasagar, sorry for the delay (I didn't realize you had paged me). I do have some more feedback, but unfortunately I am going to have to make you wait a bit longer (2-3 weeks). I have a looming deadline that is keeping me busy.

dhruvasagar commented 4 years ago

No worries