Skip to content

Commit

Permalink
Merge pull request #4293 from Carreau/tooltip-mkp
Browse files Browse the repository at this point in the history
Factorise code in tooltip for julia monkeypatching
  • Loading branch information
Carreau committed Oct 17, 2013
2 parents eb6d398 + b920c5f commit b311424
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions IPython/html/static/notebook/js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ var IPython = (function (IPython) {
}, that.time_before_tooltip);
}

Tooltip.prototype._request_tooltip = function (cell, func) {
// easy access for julia monkey patching.
Tooltip.last_token_re = /[a-z_][0-9a-z._]+$/gi;

Tooltip.prototype.extract_oir_token = function(line){
// use internally just to make the request to the kernel
// Feel free to shorten this logic if you are better
// than me in regEx
Expand All @@ -205,21 +208,25 @@ var IPython = (function (IPython) {
// remove everything between matchin bracket (need to iterate)
var matchBracket = /\([^\(\)]+\)/g;
var endBracket = /\([^\(]*$/g;
var oldfunc = func;
var oldline = line;

func = func.replace(matchBracket, "");
while (oldfunc != func) {
oldfunc = func;
func = func.replace(matchBracket, "");
line = line.replace(matchBracket, "");
while (oldline != line) {
oldline = line;
line = line.replace(matchBracket, "");
}
// remove everything after last open bracket
func = func.replace(endBracket, "");
line = line.replace(endBracket, "");
return Tooltip.last_token_re.exec(line)
}


var re = /[a-z_][0-9a-z._]+$/gi; // casse insensitive
Tooltip.prototype._request_tooltip = function (cell, line) {
var callbacks = {
'object_info_reply': $.proxy(this._show, this)
}
var msg_id = cell.kernel.object_info_request(re.exec(func), callbacks);
var oir_token = this.extract_oir_token(line)
cell.kernel.object_info_request(oir_token, callbacks);
}

// make an imediate completion request
Expand Down

0 comments on commit b311424

Please sign in to comment.