-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_code_reference.py
38 lines (33 loc) · 1.03 KB
/
copy_code_reference.py
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
"""
From: Wingware Support <[email protected]>
Date: Tue, Jan 3, 2012 at 12:25 PM
Subject: Re: Copy code reference to clipboard
"""
import wingapi
def copy_reference(include_text=True):
"""Copy filename, lineno (context): followed by the current line or selected
lines to the clipboard"""
app = wingapi.gApplication
editor = app.GetActiveEditor()
if editor is None:
return
doc = editor.GetDocument()
filename = doc.GetFilename()
ana = app.GetAnalysis(filename)
start, end = editor.GetSelection()
startline = doc.GetLineNumberFromPosition(start)
endline = doc.GetLineNumberFromPosition(end)
startpos = doc.GetLineStart(startline)
endpos = doc.GetLineEnd(endline)
txt = doc.GetCharRange(startpos, endpos)
scope = ana.FindScopeContainingLine(startline)
clip_txt = filename + '\n'
if startline == endline:
clip_txt += 'line %i' % startline
else:
clip_txt += 'lines %i-%i' % (startline, endline)
if scope:
clip_txt += ' (%s)' % scope
if include_text:
clip_txt += ':' + editor.GetEol() + txt
app.SetClipboard(clip_txt)