An email about wily rather than spam

  • From: Sam Holden <sholden@xxxxxxxxxxxxxx>
  • To: Wilyfans <wilyfans@xxxxxxxxxxxxx>
  • Date: Fri, 04 Mar 2005 09:27:20 +1100

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



Other related posts:

  • » An email about wily rather than spam