Files
gnatstudio/examples/python/autoformat.py
Arnaud Charlet 93a6dc2a92 Minor editing.
Part of H103-005


git-svn-id: svn+ssh://svn.eu/Dev/trunk/gps@125596 936e1b1b-40f2-da11-902a-00137254ae57
2008-06-12 13:58:03 +00:00

28 lines
693 B
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""This plug-in will automatically reformat a source file each time it is
saved on disk.
"""
import GPS
# Actions to be performed each time a file is saved
def on_file_saved (hook, file):
buf = GPS.EditorBuffer.get ()
# Save the cursor location
view = buf.current_view()
cursor = view.cursor().create_mark()
# Select the whole buffer
buf.select (buf.beginning_of_buffer(), buf.end_of_buffer())
# Reformat the buffer
GPS.execute_action ("Format Selection")
# Restore the cursor location
view.goto (cursor.location())
view.center (view.cursor())
# Register the callback on the "before_file_saved" hook
GPS.Hook ("before_file_saved").add (on_file_saved)