Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Hinterland should only hint for nontrivial prefixes #651

Closed
dmyersturnbull opened this issue Jun 28, 2016 · 8 comments
Closed

Hinterland should only hint for nontrivial prefixes #651

dmyersturnbull opened this issue Jun 28, 2016 · 8 comments

Comments

@dmyersturnbull
Copy link

Steps to reproduce (simplest example):

  1. In an empty line in a Python cell, press # to start a comment.
  2. Press enter to end the line.

Actual result: The line now reads #%%! (the first completion).

Expected result: The line should be an empty comment (just #).

The above example isn't especially annoying, but in a day of using Hinterland, I've repeatedly had to trim %%! from meaningful lines of code, not just comments.

@jcb91
Copy link
Member

jcb91 commented Jun 28, 2016

Yes, this was a problem I ran into when writing it with the colon :. It's made a little more tricky to get right in general because of not knowing which language kernel may be in use. As a result, I think perhaps it makes sense to have a user-configurable set of characters after which hinting is not triggered, with the default including the #.

I've repeatedly had to trim %%! from meaningful lines of code, not just comments.

Is this a result of other problematic characters, or something worth addressing more generally?

@jcb91
Copy link
Member

jcb91 commented Nov 27, 2016

@dmyersturnbull any suggestion for what constitutes a non-trivial prefix?

@dmyersturnbull
Copy link
Author

@jcb91 Good question. Perhaps trivial prefixes are just ^[^A-Za-z\!]$ with the ! just to catch external commands. That might be too conservative for a definition of trivial.

@jcb91
Copy link
Member

jcb91 commented Nov 29, 2016

Hmm, I hadn't thought about the external command prefix. I'm not sure I follow your regex, given the ^[^A-Za-z, you want to consider trivial anything beginning with a non-alphabetic character - wouldn't this include the external-command ! already? Unless you mean you think external-command lines should be considered non-trivial, but for me they don't give useful completion suggestions, so that seems unlikely? Also, does this test apply to just the character preceding the cursor (seems like it would be enough?), or to the entirety of the line before the cursor? It's possible also that people will want to use unicode characters for variables etc, which would put a hole in this regex, but I can't think of a (simple) better one right now, other than listing every character with a special definition in python syntax. Anyway, this is getting complicated, so I think it would be best to make this a configurable option, since it will also vary between kernel languages...

@jcb91
Copy link
Member

jcb91 commented Nov 29, 2016

Actually, it might be worth using the Completer.reinvoke_re at notebook/static/notebook/js/completer.js#L107 as a start point, since it seems from the comment that it may be adjusted to suit the kernel.

Probably worth also adding user-configurable positive & negative include/excludes (e.g. I don't like completion on colons, even though they are included in Completer.reinvoke_re)

@jcb91
Copy link
Member

jcb91 commented Dec 2, 2016

So, I've made a stab at configurable regexes, with the default as Completer.reinvoke_re, which by default is /[%0-9a-z._/\\:~-]/i, so should hopefully get rid of your problems with #. If you could give the PR a try, and let me know whether it's helpful, that'd be great

@jfbercher
Copy link
Member

@jcb91 It seems very nice, and the way to go. I will give a try this afternoon.

@jcb91
Copy link
Member

jcb91 commented Dec 18, 2016

Assuming this has been fixed by #815 and #819. Please reopen if not!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants