"php_beautifier.py" by avion

Rating: (0 votes)

Report this Script

Name: php_beautifier.py
Uploaded By: avion
Date Created: June 23, 2009 2:31 p.m.
Date Modified: June 23, 2009 2:31 p.m.
Description: Script which calls php_beautifier.php from your PATH. It needs php / pear / beautifier installed in your path (or you could change command to point to absolute path)
Num Views: 358
Num Downloads: 121

Contents

Download this script

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()

Comments: