File: formatfile.py

package info (click to toggle)
gnat-gps 18-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,716 kB
  • sloc: ada: 362,679; python: 31,031; xml: 9,597; makefile: 1,030; ansic: 917; sh: 264; java: 17
file content (25 lines) | stat: -rw-r--r-- 791 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
This plugin provides a new menu to reformat the whole buffer.
Select /Edit/Format Whole File
or create a keybinding to the Editor/Format Whole File action via
the menu /Edit/Key Shortcuts.

This is basically the same thing as "Select All", followed by
"Format Selection", but this preserves the current location of the
cursor, which Select All cannot do.
"""


import GPS
import gps_utils


@gps_utils.interactive(category="Editor",
                       name="Format Whole File",
                       menu="/Edit/Format Whole File",
                       after="/Edit/Format Selection")
@gps_utils.with_save_excursion
def format_whole_file():
    buf = GPS.EditorBuffer.get()
    buf.select(buf.beginning_of_buffer(), buf.end_of_buffer())
    GPS.execute_action("Format Selection")