Sublime Forum

This maybe a bug

#1

I want to write a tiny plugin which read the first line of the view and set its syntax to markdown if the line has some string.
For convenience, I copy some lines from another plugin which is named StatusBarFileSize, but forgot to modify the class name:

class StatusBarFileSize(sublime_plugin.EventListener):
    ... ...

After finish my new plugin, I found it can’t work, then I realised I should change the classname. But after the correction, the plugin still can’t work, and I got lots of something like StatusBarFileSize object has no attribute view error.

I guess there is some conflict due to the previous mistake, and restart sublime, after that, my new plugin works as expected.

So, is the error a bug?

0 Likes

#2

You need to show more of your code, we can’t see what is wrong with it.

0 Likes

#3

if it were a bug, it may not be worth the time investigating and fixing :wink:

0 Likes

#4

The parent class of your plugin class is an event listener. Event listeners receive the view the event was fired for as an argument and not as an instance attribute like TextCommands.

0 Likes

#5

Hi, below is the original StatusBarFileSize class and my tiny plugin:

class StatusBarFileSize(sublime_plugin.EventListener):
    KEY_SIZE = "FileSize"
    SETTINGS = "StatusBarFileSize.sublime-settings"
    ESTIMATE_DEFAULT = True

    @property
    def setting_estimate_file_size(self):
        settings = sublime.load_settings(self.SETTINGS)
        return settings.get("estimate_file_size", self.ESTIMATE_DEFAULT)

    def update_file_size(self, view):

        if not view.file_name():
            pass
        ... ...
import sublime
import sublime_plugin
import re

class MiscCommand(sublime_plugin.EventListener):

    def mod_syntax(self, view):
        file = view.file_name()
        if file and file.endswith(".html"):
            r = sublime.Region(0, 13)
            line = view.substr(r)
            if line == '# format: md\n':
                view.set_syntax_file("Markdown.sublime-syntax")
            else:
                view.set_syntax_file("HTML.sublime-syntax")

    on_load_save_async = mod_syntax
    on_activated_async = mod_syntax
    on_post_save_async = mod_syntax
    on_clone_save_async = mod_syntax

When edit the plugin, I once wrote a line with self.view, but remove it when I found that error, and the errors in console I described above occurs even after the correction.

0 Likes

#6

Do you have error with MiscCommand ? because it works fine for me.
If your error is StatusBarFileSize object has no attribute view error then your issue is with StatusBarFileSize, and maybe you have the same issue of having self.view in this file …

0 Likes

#7

I got no error after the restart, all is OK now.

I got errors when I’ sure there are no mistakes in my plugin, and after a restart, all error messages gone and the plugin work well, I didn’t change both the StatusBarFileSize the MiscCommand after the restart, that’s why I doubt there maybe a bug.

0 Likes