File: url.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 (27 lines) | stat: -rw-r--r-- 586 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
"""Provides support for some common URLs via the hyper mode in GPS:
   - http://
   - https://
   - file://
   - file:\\
"""


import GPS

# Callback for {file,http*}:// URLs


def view_url(url):
    try:
        if url.startswith("file"):
            GPS.MDI.get_by_child(
                GPS.EditorBuffer.get(
                    GPS.File(url[7:])).current_view()).raise_window()
        else:
            GPS.HTML.browse(url)
    except:
        pass

# Register a highlighter to URLs
GPS.EditorHighlighter(
    r'(file:[\\/][\\/][^\s]*|http(s)?://[^\s:,]*)', view_url, 0, view_url)