forked from textmate/php.tmbundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsert Call to Parent.tmCommand
executable file
·126 lines (112 loc) · 3.48 KB
/
Insert Call to Parent.tmCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env php
<?php
$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
for ($x = 0; $x < $numTokens; $x++) {
if (is_array($tokens[$x]) && $tokens[$x][2] >= $seekLine) {
$startToken = $x;
break;
}
}
// Could not find the line, so just start from the end
if (false === $startToken) {
$startToken = $numTokens - 1;
}
$functionToken = false;
$functionName = false;
// 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;
}
}
}
}
// No function declaration found, so let's act like we were never here
if (false === $functionToken || false === $functionName) {
echo 'parent';
if ('YES' === getenv('TM_SOFT_TABS')) {
// Only use enough spaces to get to the next "tab stop"
$tabSize = getenv('TM_TAB_SIZE');
$col = intval(getenv('TM_COLUMN_NUMBER')) + 5;
echo str_repeat(' ', $tabSize - ($col % $tabSize));
} else {
echo "\t";
}
exit(TM_EXIT_INSERT_TEXT);
}
$firstParenFound = false;
$skipParens = 0;
$numParams = 0;
$params = array();
for ($x = $functionToken + 1; $x < $numTokens; $x++) {
$token = $tokens[$x];
if ($firstParenFound && is_array($token)) {
if (T_VARIABLE === $token[0]) {
$numParams++;
$params[] = "\${{$numParams}:" . str_replace('$', '\$', $token[1]) . '}';
}
} else {
switch ($token) {
case '(':
if ($firstParenFound) {
$skipParens++;
} else {
$firstParenFound = true;
}
break;
case ')':
if ($skipParens) {
$skipParens--;
} else if ($firstParenFound) {
break 2;
}
break;
default:
break;
}
}
}
echo "parent::{$functionName}(" . implode(', ', $params) . ');$0';</string>
<key>input</key>
<string>document</string>
<key>inputFormat</key>
<string>text</string>
<key>name</key>
<string>Insert Call to Parent</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>snippet</string>
<key>outputLocation</key>
<string>replaceSelection</string>
<key>scope</key>
<string>source.php - comment.block.documentation.phpdoc.php</string>
<key>tabTrigger</key>
<string>parent</string>
<key>uuid</key>
<string>978B5E5E-F5C6-4FD8-B346-B0C85883D600</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>