Skip to content

Commit ae91cae

Browse files
author
Dennis Hillmann
committed
Adding the needed files
1 parent ac92664 commit ae91cae

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed

Default (Linux).sublime-keymap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["ctrl+alt+f"], "command": "php_cbf"},
3+
]

Default (OSX).sublime-keymap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["ctrl+alt+f"], "command": "php_cbf"},
3+
]

Default (Windows).sublime-keymap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
{ "keys": ["ctrl+alt+f"], "command": "php_cbf"},
3+
]

Main.sublime-menu

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[
2+
{
3+
"id": "tools",
4+
"children": [
5+
{
6+
"caption": "PHP CodeBeautifier",
7+
"command": "php_cbf",
8+
}
9+
]
10+
},
11+
{
12+
"id": "preferences",
13+
"children": [
14+
{
15+
"id": "package-settings",
16+
"children": [
17+
{
18+
"caption": "PHP Code Beautifier",
19+
"children": [
20+
{
21+
"command": "open_file",
22+
"args": {
23+
"file": "${packages}/phpcbf/phpcbf.sublime-settings"
24+
},
25+
"caption": "Settings - Default"
26+
},
27+
{
28+
"command": "open_file",
29+
"args": {
30+
"file": "${packages}/User/phpcbf.sublime-settings"
31+
},
32+
"caption": "Settings - User"
33+
},
34+
{
35+
"caption": "-"
36+
},
37+
{
38+
"caption": "Key Bindings – Default",
39+
"command": "open_file", "args":
40+
{
41+
"file": "${packages}/phpcbf/Default (OSX).sublime-keymap",
42+
"platform": "OSX"
43+
}
44+
},
45+
{
46+
"caption": "Key Bindings – User",
47+
"command": "open_file", "args":
48+
{
49+
"file": "${packages}/User/Default (OSX).sublime-keymap",
50+
"platform": "OSX"
51+
}
52+
},
53+
{
54+
"caption": "Key Bindings – Default",
55+
"command": "open_file", "args":
56+
{
57+
"file": "${packages}/phpcbf/Default (Linux).sublime-keymap",
58+
"platform": "Linux"
59+
}
60+
},
61+
{
62+
"caption": "Key Bindings – User",
63+
"command": "open_file", "args":
64+
{
65+
"file": "${packages}/User/Default (Linux).sublime-keymap",
66+
"platform": "Linux"
67+
}
68+
},
69+
{
70+
"caption": "Key Bindings – Default",
71+
"command": "open_file", "args":
72+
{
73+
"file": "${packages}/phpcbf/Default (Windows).sublime-keymap",
74+
"platform": "Windows"
75+
}
76+
},
77+
{
78+
"caption": "Key Bindings – User",
79+
"command": "open_file", "args":
80+
{
81+
"file": "${packages}/User/Default (Windows).sublime-keymap",
82+
"platform": "Windows"
83+
}
84+
}
85+
]
86+
}
87+
]
88+
}
89+
]
90+
}
91+
]

phpcbf.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sublime, sublime_plugin, subprocess, os
2+
3+
class PhpCbfCommand(sublime_plugin.TextCommand):
4+
5+
def run(self, edit):
6+
settings = sublime.load_settings("phpcbf.sublime-settings")
7+
syntaxes = settings.get('syntaxes')
8+
cur_syntax = self.view.settings().get('syntax')
9+
if cur_syntax not in syntaxes:
10+
return
11+
path = settings.get('path', "")
12+
level = settings.get('level', 'psr2')
13+
patch = settings.get('patch', False)
14+
suffix = settings.get('suffix', '')
15+
sniffs = settings.get('sniffs', '')
16+
tab_width = settings.get('tab_width', False)
17+
if not patch:
18+
patch = "--no-patch"
19+
else:
20+
patch = ""
21+
encoding = self.view.encoding()
22+
if encoding == 'Undefined':
23+
encoding = settings.get('encoding', 'UTF-8')
24+
if not path:
25+
path = "phpcbf"
26+
if suffix:
27+
suffix = ' --suffix='+suffix
28+
sniff_string = ''
29+
if sniffs:
30+
sniff_string = ' --sniffs='
31+
for sniff in sniffs:
32+
sniff_string += sniff+','
33+
sniff_string.rtrim(',')
34+
if tab_width:
35+
tab_width = ' --tab_width='+tab_width
36+
file_name = self.view.file_name()
37+
if file_name:
38+
call = path+" "+patch+suffix+sniff_string+tab_width+' --standard='+level+" --encoding="+encoding+" "+file_name
39+
try:
40+
output = subprocess.check_output(call, shell=True,universal_newlines=True)
41+
except subprocess.CalledProcessError as e:
42+
print(e.output)
43+
sublime.status_message("An error occured while fixing, please check the console")
44+
else:
45+
sublime.status_message("All fixable errors have been fixed")
46+
else:
47+
sublime.status_message("Please save the file first")
48+
class PhpCbfListener(sublime_plugin.EventListener):
49+
def on_post_save(self, view):
50+
settings = sublime.load_settings("phpcbf.sublime-settings")
51+
if(settings.get('on_save', True)):
52+
view.run_command('php_cbf')
53+
def on_load(self, view):
54+
settings = sublime.load_settings("phpcbf.sublime-settings")
55+
if(settings.get('on_load', True)):
56+
view.run_command('php_cbf')
57+
58+
59+
60+
61+
62+
63+
64+
65+

phpcbf.sublime-settings

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"path": "",
3+
"level": "psr2",
4+
"patch": "true",
5+
"encoding": "UTF-8",
6+
"on_save": true,
7+
"on_load": false,
8+
"syntaxes": [
9+
"Packages/PHP/PHP.sublime-syntax",
10+
//"Packages/HTML/HTML.sublime-syntax",
11+
]
12+
}

0 commit comments

Comments
 (0)