From d145da4c994a5db527e8ed38c21f0828db8cc4b0 Mon Sep 17 00:00:00 2001 From: Harald Lapp Date: Fri, 29 Nov 2013 23:48:50 +0100 Subject: [PATCH 1/2] prevent wrong positioning of "parent" in case of early exit by not returning TM_EXIT_INSERT_TEXT (203) as exit-status --- Commands/Insert Call to Parent.tmCommand | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Commands/Insert Call to Parent.tmCommand b/Commands/Insert Call to Parent.tmCommand index bb80e8e..3341940 100755 --- a/Commands/Insert Call to Parent.tmCommand +++ b/Commands/Insert Call to Parent.tmCommand @@ -12,8 +12,6 @@ $seekLine = intval(getenv('TM_LINE_NUMBER')); $tokens = token_get_all(file_get_contents('php://stdin')); $numTokens = count($tokens); -define('TM_EXIT_INSERT_TEXT', 203); - $startToken = false; // Find the first token that's on/after TM_LINE_NUMBER @@ -63,7 +61,7 @@ if (false === $functionToken || false === $functionName) { echo "\t"; } - exit(TM_EXIT_INSERT_TEXT); + exit(); } $firstParenFound = false; From 7068eb5ea2d9e96e59207a498c5c2dab47038d5d Mon Sep 17 00:00:00 2001 From: Harald Lapp Date: Fri, 29 Nov 2013 23:51:14 +0100 Subject: [PATCH 2/2] prevent expansion, if TM_CURRENT_WORD is not empty (eg. when triggered occured for $parent) --- Commands/Insert Call to Parent.tmCommand | 61 +++++++++++++----------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/Commands/Insert Call to Parent.tmCommand b/Commands/Insert Call to Parent.tmCommand index 3341940..08fe9da 100755 --- a/Commands/Insert Call to Parent.tmCommand +++ b/Commands/Insert Call to Parent.tmCommand @@ -8,41 +8,44 @@ #!/usr/bin/env php <?php -$seekLine = intval(getenv('TM_LINE_NUMBER')); -$tokens = token_get_all(file_get_contents('php://stdin')); -$numTokens = count($tokens); +$functionToken = false; +$functionName = false; -$startToken = false; +if (getenv('TM_CURRENT_WORD') == '') { + // try only, if current word is empty (will be '$' if trigger occured for '$parent') + $seekLine = intval(getenv('TM_LINE_NUMBER')); + $tokens = token_get_all(file_get_contents('php://stdin')); + $numTokens = count($tokens); -// Find the first token that's on/after TM_LINE_NUMBER -for ($x = 0; $x < $numTokens; $x++) { - if (is_array($tokens[$x]) && $tokens[$x][2] >= $seekLine) { - $startToken = $x; - break; - } -} + $startToken = false; -// Could not find the line, so just start from the end -if (false === $startToken) { - $startToken = $numTokens - 1; -} + // Find the first token that's on/after TM_LINE_NUMBER + for ($x = 0; $x < $numTokens; $x++) { + if (is_array($tokens[$x]) && $tokens[$x][2] >= $seekLine) { + $startToken = $x; + break; + } + } -$functionToken = false; -$functionName = false; + // Could not find the line, so just start from the end + if (false === $startToken) { + $startToken = $numTokens - 1; + } -// Work backwards until we find the function declaration -for ($x = $startToken; $x >= 0; $x--) { - if (is_array($tokens[$x]) && T_FUNCTION === $tokens[$x][0]) { - // Try to find a function name, which may not exist if this is a closure - for ($y = $x + 1; $y < $numTokens; $y++) { - if (is_array($tokens[$y])) { - if (T_STRING === $tokens[$y][0]) { - $functionToken = $y; - $functionName = $tokens[$y][1]; - break 2; + // Work backwards until we find the function declaration + for ($x = $startToken; $x >= 0; $x--) { + if (is_array($tokens[$x]) && T_FUNCTION === $tokens[$x][0]) { + // Try to find a function name, which may not exist if this is a closure + for ($y = $x + 1; $y < $numTokens; $y++) { + if (is_array($tokens[$y])) { + if (T_STRING === $tokens[$y][0]) { + $functionToken = $y; + $functionName = $tokens[$y][1]; + break 2; + } + } else if ($tokens[$y] === '(') { + break; } - } else if ($tokens[$y] === '(') { - break; } } }