-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Naomichi Yamakita
committed
Aug 30, 2012
1 parent
b4a0000
commit 0b04753
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
*.py[co] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
import sublime, sublime_plugin, os, commands, re | |||
|
|||
class PhpSyntaxChecker(sublime_plugin.EventListener): | |||
# Command refers to $PATH environment variable | |||
EXECUTE_COMMAND = "php -l" | |||
|
|||
# If want to add other extensions, please add array elements. | |||
# [".php", ".twig", ...] | |||
TARGET_SUFFIXES = [".php"] | |||
|
|||
def on_post_save(self, view): | |||
path = view.file_name() | |||
root, extension = os.path.splitext(path) | |||
|
|||
if extension in self.TARGET_SUFFIXES: | |||
command = self.EXECUTE_COMMAND + " " + path | |||
response = commands.getoutput(command) | |||
|
|||
r = re.compile("Parse error.* on line (\d+)") | |||
match = r.search(response) | |||
|
|||
if match != None: | |||
line = int(match.group(1)) - 1 | |||
|
|||
offset = view.text_point(line, 0) | |||
view.sel().clear() | |||
view.sel().add(sublime.Region(offset)) | |||
view.show(offset) | |||
|
|||
sublime.error_message("PHP Syntax error\n" + response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,18 @@ | |||
php_syntax_checker | PHP Syntax Checker | ||
================== | ================== | ||
This package is plugins for Sublime Text 2. | |||
When you save PHP file, perform syntax check of PHP. | |||
|
|||
Usage notes | |||
----------- | |||
Just save the file! | |||
|
|||
Licence | |||
------- | |||
MIT Licence: | |||
* http://opensource.org/licenses/MIT | |||
|
|||
Contacts | |||
-------- | |||
Writen by: | |||
* Naomichi Yamakita - yamakita@dtx.co.jp |