Sublime Forum

Plugin events API - custom status message

#1

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:

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
0 Likes

#2

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.

0 Likes

#3

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 :smile:

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)

0 Likes

#4

Right, Just noticed the sticky explaining this. Whoops. Email sent.

0 Likes

#5

[quote=“jps”]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.[/quote]

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?

0 Likes

#6

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.

0 Likes

#7

[quote=“jps”]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.[/quote]

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 :smile:

  • Michael
0 Likes