import pn import scintilla import subprocess from pypn.decorators import script @script("PHP Code beautifier", "PHP") def Indent_php(): editor = scintilla.Scintilla(pn.CurrentDoc()) text = editor.GetTextRange (0, editor.Length) params = '-l "Pear(newline_class=true) Pear(newline_function=true) ArrayNested() Lowercase()" -s4 -l "NewLines(before=if:switch:T_CLASS) NewLines(after=T_COMMENT:function) Pear(add_header=lgpl) ListClassFunction(list_functions=true) IndentStyles(style=k&r)"' proc = subprocess.Popen('php_beautifier ' + params, shell=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE) idented = proc.communicate (text)[0] editor.BeginUndoAction() editor.ClearAll() editor.AddText(len(idented), idented) editor.EndUndoAction()