Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
Naomichi Yamakita committed Aug 30, 2012
1 parent b4a0000 commit 0b04753
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
*.py[co]
30 changes: 30 additions & 0 deletions PhpSyntaxChecker.py
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)
20 changes: 18 additions & 2 deletions README.md
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

0 comments on commit 0b04753

Please sign in to comment.