Home Download Buy Blog Forum Support

Plugin events API - custom status message

Plugin events API - custom status message

Postby toothrot on Thu Feb 11, 2010 5:33 am

I'm writing a pyflakes plugin (pychcker/lint type module) and I was thinking I would prefer to have the error lines highlighted, and display the error messages in the status bar for the line my cursor is in.

The only problem is, I can't see that there's any kind of way to accomplish this currently. The best idea I could come up with off the top of my head was a callback of this sort:

Code: Select all
def getStatusMessage(self, view, line, col):
     errmsgs = get_pyflake_errors(line)
     if errmsgs:
          return 'Line %i, Column %i - PyFlakes: %s'(line, col, errmsgs)
     else:
        # show default
        # return None ? perhaps.
        # or handle everything?:
        return 'Line %i, Column %i(%(line, col)


This would allow plugins to display a custom message based on the current position.

(I tried searching for a mention of something that could accomplish this, hopefully I've not overlooked it)

Thanks for hearing me, keep up the good work.

- Michael H
Last edited by toothrot on Thu Feb 11, 2010 1:11 pm, edited 1 time in total.
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Plugin events API - custom status message

Postby jps on Thu Feb 11, 2010 1:09 pm

You can highlight the lines using the regions API - add a region representing the entire line. You'll likely want to use the DRAW_OUTLINED flag to not override the normal syntax highlighting. I'm planning to add support for adding icons in the gutter, but it's not there yet.

One option for adding line-specific status messages is to build a table of them in your plugin, and implement the onSelectionModified callback in your plugin, setting the status message if the selection is now on an interesting line.

Both the above APIs require the current beta.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Plugin events API - custom status message

Postby toothrot on Thu Feb 11, 2010 1:17 pm

Yes, I've already completed everything but the statusMessages in a similar manner...

I didn't realize that onSelectionModified would give me the updated cursor position even if i had nothing selected... Upon quickly testing it looks like it works perfect. I knew I must be missing something quite obvious :)

Thanks.

EDIT: maybe it wasn't that obvious, since I don't see onSelectionModified in the official docs. Next time I will check the beta change sets. What does it take to get commit access to the community plugins/wiki? I'd like to give the wiki a little love. (and upload my plugin when it's completed)
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Plugin events API - custom status message

Postby toothrot on Thu Feb 11, 2010 2:13 pm

Right, Just noticed the sticky explaining this. Whoops. Email sent.
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Plugin events API - custom status message

Postby toothrot on Fri Feb 12, 2010 3:03 pm

jps wrote:You can highlight the lines using the regions API - add a region representing the entire line. You'll likely want to use the DRAW_OUTLINED flag to not override the normal syntax highlighting. I'm planning to add support for adding icons in the gutter, but it's not there yet.

One option for adding line-specific status messages is to build a table of them in your plugin, and implement the onSelectionModified callback in your plugin, setting the status message if the selection is now on an interesting line.

Both the above APIs require the current beta.



For the most part this is working well, I'm trying to use setStatus() but it doesn't seem like there's a way to put my message _after_ the default 'Line X, Column Y' message.

(I also the tried .statusMessage() but that temporarily persists that message, so if I enter a line with an error and then move the cursor to a line without an error, it's still displaying the previous message.)

I could just append spaces to the end of my message to push the default one off, or just handle all the status messages, but this seems like a bad idea and would interfere with other plugin's messages.

Anyone have any suggestions?
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Plugin events API - custom status message

Postby jps on Sat Feb 13, 2010 4:09 am

It sounds like you should just use setStatus(), and not worry too much about the position of the 'Line X, Column Y' message.

You can clear the status message by calling sublime.statusMessage(''), but you'll want to be careful, and only clear it when going from a line with a status message to one without, otherwise you'll end up always overwriting what should be getting displayed with the status message, such as what the find panel prints.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Plugin events API - custom status message

Postby toothrot on Sat Feb 13, 2010 8:05 pm

jps wrote:It sounds like you should just use setStatus(), and not worry too much about the position of the 'Line X, Column Y' message.

You can clear the status message by calling sublime.statusMessage(''), but you'll want to be careful, and only clear it when going from a line with a status message to one without, otherwise you'll end up always overwriting what should be getting displayed with the status message, such as what the find panel prints.



That is in fact what I settled on, for now. It would be nice to have just a little more control over the order that default message gets placed in the statusbar (also be nice to be able to change the separator),

(maybe by making it subject to the regular status key ordering and allowing that key to be changed)

It's not so much that I personally can't stand that the message is no longer where it usually is, but that I think as much of the default behavior should be unaffected by a plugin I write. If that's where people usually look to see where they are in a file, they'll have to search to the arbitrary end of whatever message my plugin sticks in there. (I look there somewhat often to check my line lengths)

But, I can see it's obviously not something that people are clamoring for.

Also, in regard to the suggestion of sublime.statusMessage(''), clearing the status bar is just a matter of removing my part of the message: calling view.eraseStatus(mykey), sublime worries about the rest.

Thanks for considering :)

- Michael
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 9 guests