File: sparkcomments.py

package info (click to toggle)
gnat-gps 4.3-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 49,096 kB
  • ctags: 20,461
  • sloc: ada: 274,120; ansic: 154,849; python: 9,890; tcl: 9,812; sh: 8,192; xml: 7,970; cpp: 4,737; yacc: 3,520; makefile: 2,136; lex: 2,043; java: 1,638; perl: 302; awk: 265; sed: 161; asm: 14; fortran: 2; lisp: 1
file content (53 lines) | stat: -rw-r--r-- 1,755 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
## This file demonstrates how one could implement special highlighting
## rules in the editors.
## This examples highlights the SPARK annotations, ie special Ada comments
## that start with "--#". This code is not actually useful since GPS has its
## own built-in mechanism for these highlights now, but it might still be
## used for special annotations, like the convention we use in the GNAT and
## GPS sources with ??? in comments to indicate code to be reviewed

spark_comments_fg_color = "red"

highlight_on_edit = True
## Set to False to only highlight when a file is loaded or saved. This
## is more efficient in case the default setting is too slow

from GPS import *

def highlight_spark_comments (buffer):
   try:
      buffer.remove_overlay (buffer.spark_overlay)
   except:
      buffer.spark_overlay = buffer.create_overlay ("spark")
      buffer.spark_overlay.set_property ("foreground", spark_comments_fg_color)

   loc = buffer.beginning_of_buffer()

   while True:
     loc = loc.search ("--#", dialog_on_failure=False)
     if not loc:
        return
     loc = loc[0]
     endloc = loc.end_of_line()
     buffer.apply_overlay (buffer.spark_overlay, loc, endloc)
     loc = endloc + 1

def on_file_edited (hook, file):
   highlight_spark_comments (EditorBuffer.get (file))

def on_character_added (hook, file):
   highlight_spark_comments (EditorBuffer.get (file))

def on_gps_started (hook):
   Hook ("file_edited").add (on_file_edited)
   Hook ("file_saved").add (on_file_edited)
   Hook ("file_changed_on_disk").add (on_file_edited)

   if highlight_on_edit:
      Hook ("character_added").add (on_character_added)

   for l in EditorBuffer.list():
      highlight_spark_comments (l)
      

Hook ("gps_started").add (on_gps_started)