forked from psynaptic/php-drupal.tmbundle
/
Create snippet.tmCommand
44 lines (39 loc) · 1.16 KB
/
Create snippet.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
<?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
$document = file_get_contents('php://stdin');
$search = array('$', '`');
$replace = array('\$', '\`');
$document = str_replace($search, $replace, $document);
if (strpos($document, '/**') !== 0) {
preg_match('@\s([hook_|theme_][a-z_]*)@i', $document, $matches);
if (is_array($matches) && $matches && strpos($matches[1], 'hook_') === 0) {
$output = "/**\n * Implements $matches[1]().\n */\n";
}
else {
$output = "/**\n * Overrides $matches[1]().\n */\n";
}
}
$output .= $document;
print $output;
</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>@N</string>
<key>name</key>
<string>Format document as snippet</string>
<key>output</key>
<string>replaceSelectedText</string>
<key>scope</key>
<string>text.html.basic, text.plain</string>
<key>uuid</key>
<string>DAC597AC-2BCE-45E6-9DEF-E67150445F6F</string>
</dict>
</plist>