Permalink
Browse files

-

  • Loading branch information...
1 parent b4a0000 commit 0b04753b0d50d0716c2fced9748b1661428bc850 Naomichi Yamakita committed Aug 30, 2012
Showing with 49 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +30 −0 PhpSyntaxChecker.py
  3. +18 −2 README.md
View
@@ -0,0 +1 @@
+*.py[co]
View
@@ -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)
View
@@ -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.