|
An email about wily rather than spam: msg#00004editors.wily
I've just started working trying to get my head around a reasonably large chunk of python code. And finally got the three button usb mouse to play nice with my laptop so I'm using wily to help. So I'm hoping there's a python programmer somewhere round these parts who can tell me I'm dumb and should do X, Y, and Z. I use my own pure-python interface to wily's mesage interface which I mentioned here before, it's similar enough to the standard python wrapper around the C lib... Anyway I found BicycleRepairMan which seems unmaintained, lacking in features, and buggy, but it does do a couple of things that seem useful. It's written with IDE integration in mind so I'm integrating it with wily. The annoyance is that it assumes a line/column approach to files which wily just doesn't have. Anyway, enough with the ranting and on to a code snippet, to find the definition of something that is selected you middle click a command which executes: ---start code--- #!/usr/bin/python import os import wily import bike def get_name_line_column(filename=None): if filename is None: filename = os.getenv('WILYPATH') if filename is None: filename = '' connection = wily.Connection() window, range = connection.win(filename).goto((0,0), ':.') text = window.read((0,range[0])) line_number = text.count('\n') + 1 col_number = len(text) if line_number > 1 : col_number = col_number - text.rfind('\n') return filename, line_number, col_number brm = bike.init() name, line, col = get_name_line_column() for instance in brm.findDefinitionByCoordinates(name, line, col): print "%s:%d (%d%%)" % (instance.filename, instance.lineno, instance.confidence) ---end code--- Is there a "better" way to get the line and column number of the start of the current selection? The code above tries to get the character offsets of the current section and then extract all the text and count the newline characters (it may in fact do something else, since it isn't well tested). Has anyone else used this bicyclerepairman thing? With wily? I have a nasty hack which overrides the built-in open/file constructors with functions that first check if the file is in a wily window and if so read/write to that window instead of the file system to get around the fact that BRM likes to munge files on the disk directly which isn't nice... I'm hoping there's a better way :) Oh well, back to your normal spam filled programming. -- Sam Holden |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | What's so good about it? :): 00004, Disbarring O. Progression |
|---|---|
| Next by Date: | fix for big bug, trashed multi-byte utf: 00004, Tommy Pettersson |
| Previous by Thread: | Adieu.i: 00004, Brad Q. Enquiry |
| Next by Thread: | fix for big bug, trashed multi-byte utf: 00004, Tommy Pettersson |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |