Home Download Buy Blog Forum Support

Sorting Tabs

Re: Sorting Tabs

Postby agibsonsw on Fri Mar 09, 2012 7:33 pm

@facelessuser Ta.

Code: Select all
I guess technically index will always equal 0 first so you won't try and compare prev_group until after it gets set where index = 0...but it still kind of bugs me, oh well, it is technically sound unless index doesn't equal 0 first.

Yes, I was being clever 8-) - making use of the fact that index would always be zero initially.

In JavaScript I can do things like:

Code: Select all
some_thing = some_thing || 0;

That is, "if it doesn't exist..".

Is there a way to do something similar in Python? I can't test an attribute if it doesn't yet exist (Catch 22)?? Otherwise, I'll end up with lots of 'new_thing = 0' :o
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sorting Tabs

Postby facelessuser on Fri Mar 09, 2012 7:57 pm

agibsonsw wrote:Is there a way to do something similar in Python? I can't test an attribute if it doesn't yet exist (Catch 22)?? Otherwise, I'll end up with lots of 'new_thing = 0' :o


Code: Select all
if "prev_group" in locals():


You can also check if in globals
Code: Select all
if "prev_group" in globals():


What you are doing works; it just caught me off guard, doing what you see above is more explicit.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: Sorting Tabs

Postby agibsonsw on Fri Mar 09, 2012 8:10 pm

Hi @facelessuser and thank you.

I was just reading around this subject and I noted that there can be occasions when the var falls between locals() and globals(). A Try..Catch can also be used.. I'm not happy with either of these, so I suppose 'moving_index = 0; prev_group = 0/None' will have to do ;)

Added But index will always be zero, so I hope it doesn't ruin your weekend if I leave as-is :D
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sorting Tabs

Postby quodlibet on Fri Mar 09, 2012 8:39 pm

I have only the vaguest idea of what the last four posts were about.

You had me at:

agibsonsw wrote:This should "do it" for unsaved files


Thanks a lot Andy!
quodlibet
 
Posts: 553
Joined: Sat Jun 18, 2011 5:53 pm

Re: Sorting Tabs

Postby agibsonsw on Fri Mar 09, 2012 8:57 pm

@quodlibet I addressed the recent posts @facelessuser ;)

agibsonsw wrote:
This should "do it" for unsaved files

"The code will now sort all open tabs, even if some of them are unsaved files"
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sorting Tabs

Postby facelessuser on Fri Mar 09, 2012 9:08 pm

agibsonsw wrote:Hi @facelessuser and thank you.

I was just reading around this subject and I noted that there can be occasions when the var falls between locals() and globals(). A Try..Catch can also be used.. I'm not happy with either of these, so I suppose 'moving_index = 0; prev_group = 0/None' will have to do ;)

Added But index will always be zero, so I hope it doesn't ruin your weekend if I leave as-is :D


No it is fine :) . Hope I didn't come off as a code snob. Looked like an issue at first, but after second look, I realized it was all accounted for. Great work.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: Sorting Tabs

Postby agibsonsw on Fri Mar 09, 2012 9:57 pm

@facelessuser No problem :) and thank you.

Coming from a JS perspective it bugs me a little to have to look out for unassigned variables. I'm used to writing:

Code: Select all
blah = blah || "TaDa!";

It's also odd behaviour (to me) that in Python:

Code: Select all
class Mine:
    class_attr = "shared"
    def method(self):
        self.class_attr = ".. no it's not"    # 'magic' attribute!
        Mine.class_attr = "..yes it is!"

But I like 'list comprehensions' (and a curry is not out of the question..)

But I realise that this is off topic :)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sorting Tabs

Postby facelessuser on Sat Mar 10, 2012 1:09 am

agibsonsw wrote:It's also odd behaviour (to me) that in Python:

Code: Select all
class Mine:
    class_attr = "shared"
    def method(self):
        self.class_attr = ".. no it's not"    # 'magic' attribute!
        Mine.class_attr = "..yes it is!"



This seemed a little odd to me at first until I thought about it. Mine is the class object not that particular instance. When you instantiate it, self is an instance of Mine, a child if you will, derived from the Mine object. Mine and self are not the same thing.

agibsonsw wrote:Coming from a JS perspective it bugs me a little to have to look out for unassigned variables. I'm used to writing:

Code: Select all
blah = blah || "TaDa!";

It's also odd behaviour (to me) that in Python:


Coming from a C/C++ background, javascript is bonkers :). I do like fooling with javascript though. I hated it at first, but I grew to like it; I realized what I really hated was the inconsistencies of web browsers. But I still have a habit of looking out for non-accounted for variables even in javascript. It's a cool language once you get into it; probably why nodeJS is getting so popular.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: Sorting Tabs

Postby agibsonsw on Sat Mar 10, 2012 1:44 am

@facelessuser JS is weirdand wonderful.

BTW If I bung the ST API methods into 'Python.tmLanguage' as part of, for example, 'support.function.builtin.python' then at least they would appear in a different colour. But I wonder how tricky it might be to create a new category, and amend my theme to include this category? I can't really create a new language syntax, as it's still a '.py' file. But might it be possible to create a language-syntax file that checks for 'import sublime' specifically?

But I should probably start a new topic ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Previous

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests