Sublime Forum

Automatically set view syntax according to first line

#22

I have replied on SO, but I thought I would also reply here with more details to help you out :slightly_smiling:

As you have discovered, dictionaries in python will raise a KeyError when you try to access the value for a key that doesn’t exist in the dictionary. But dictionaries have a built in method called get, which lets you specify a default for when the key doesn’t exist. This avoids the need to first check if key in dict: etc. :slightly_smiling:

1 Like

#23

I make my first working plugin here. :grin:

2 Likes

#24

ah nice, you even made it work for tmLanguage as well as sublime-syntax files - good job! :slightly_smiling:
to optimize it, you could check that the cursor is on line 1 or 2, so that it doesn’t constantly run unnecessarily when editing the 1000th line of a text file for example :thumbsup:

0 Likes

#25

Awesome, man.   Works great! :+1:

0 Likes

#26

a one big happy family :smile: :tongue:

2 Likes