Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[hinterland] make all regexes configurable #815

Merged
merged 3 commits into from
Dec 9, 2016

Conversation

jcb91
Copy link
Member

@jcb91 jcb91 commented Dec 2, 2016

for deciding whether to trigger autocompletion/tooltip.
Addresses #651

for deciding whether to trigger autocompletion/tooltip
Copy link
Member

@jfbercher jfbercher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice way to tackle the general problem!
I tested that and noticed some small issues and possible improvements. See comments in the code.

config[regexp_names[ii]] = new RegExp(config[regexp_names[ii]]);
}
catch (err) {
console.warning(log_prefix, 'error parsing', regexp_names[ii] + ':', err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.warn() instead of console.warning() for me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True! Too used to python logging, which seems to accept either

Compatibility: 4.x
Parameters:
- name: enable_at_start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hinterland prefix missing for parameters (since the hinterland section is read in the js source)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, good spot!

if ( pre_cursor !== '' &&
config.include_regexp.test(pre_cursor) &&
!config.exclude_regexp.test(pre_cursor) ) {
if (config.tooltip_regexp.test(pre_cursor)) {
cell.tooltip.request(cell);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tooltip_regexp character(s) must be included in the include_regexp characters, otherwise this is not fired. Perhaps that the the two regexp have to be merged (or more simply, the test modified perhaps (config.include_regexp.test(pre_cursor) || config.tooltip_regexp.test(pre_cursor) ) && .. (untested)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, good point. Probably simplest/best to alter the test

Copy link
Member

@jfbercher jfbercher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot two comments just before in the review.

value of the notebook's Completer.reinvoke_re parameter is used, which can
be modified by kernels, but defaults to /[%0-9a-z._/\\:~-]/i
input_type: text
default: ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex entered here is case sensitive, because the /i flag is not added for now when creating the regex object. Perhaps warn the user on that and provide an example regex, eg [%0-9A-Za-z._/\:~-]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, worth adding

autocompletion. For python, this is useful for example for function calls,
so the default regex matches opening parentheses.
input_type: text
default: '\\('
Copy link
Member

@jfbercher jfbercher Dec 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that a single '\' is enough: '\(' ; the corresponding re is /\(/ which is correct (and works)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually both work... sorry :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. Depends on the regex engine, some will break given a single unescaped bracket as it would denote the start of a capturing group, but I guess javascript is prepared to treat a single bracket as a literal...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, wait, sorry, I think this is actually to the complexities of YAML string parsing, which shares some similarities with bash: strings in single-quotes are more-or-less like python's 'raw' strings, which I hadn't realised. Those in double quotes allow use of \ to escape special characters. I'm guessing that it still worked only because the yaml default doesn't actually get used, as I'd expect to end up with a regex of /\(/? Anyway, I think I'll switch to use the double-quoted string in the YAML...

@jfbercher jfbercher merged commit 66c3db3 into ipython-contrib:master Dec 9, 2016
@jfbercher
Copy link
Member

It works nicely and is very useful.
Thanks @jcb91!

@jcb91
Copy link
Member Author

jcb91 commented Dec 12, 2016

nice, glad to hear it's useful :)

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

Successfully merging this pull request may close these issues.

2 participants