Sublime Forum

Soft tabs, selection wrap and switch syntax

#5

YES! It works. Great, thanks!

Unfortunately, i didn’t fully understand how to call custom plugins. I saw there are plugins named in a way, saved with another name and called with a totally different name. How is this possible? :open_mouth:

0 Likes

Dev Build 2063
#6

Sublime Text converts camel-case plugin names (eg SetFileSyntaxCommand), removed the “Command” at the end and separates the capitalized words with underscores. So in this case, “SetFileSyntaxCommand” becomes “set_file_syntax”.

From the “Conventions for Command Names” section in the documentation (http://sublimetext.info/docs/reference/plugins.html)):

0 Likes

#7

Sweet! Now make a lot of sense.

Thanks!

0 Likes

#8

Thank you really much, very usefull extensions.

0 Likes

#9

…an updated version using the quick panel introduced in build 2069:

import sublime, sublime_plugin, os, fnmatch

class SetFileSyntaxCommand(sublime_plugin.WindowCommand):
    def callback(self, index):
        if index >= 0:
            self.window.active_view().set_syntax_file(self.syntaxList[index][1])

    def run(self):
        self.populate_map()
        self.window.show_quick_panel(self.syntaxList, self.callback)

    def populate_map(self):
        """Get a list of valid syntax highlighting options"""
        self.syntaxList = ]
        for root, dirnames, filenames in os.walk(sublime.packages_path()):
            for filename in fnmatch.filter(filenames, '*.tmLanguage'):
                name = os.path.splitext(filename)[0]
                full_path = os.path.join(root, filename)
                relative_path = full_path.replace(sublime.packages_path(), 'Packages')
                relative_path = relative_path.replace('\\', '/') # fix windows paths

                self.syntaxList.append([name, relative_path])

Updated callback to correctly handle no highlight being selected

0 Likes

#10

Isn’t it redundant with the new Command Palette ?

I tried this key binding:

    { "keys": "ctrl+shift+y"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Set Syntax:"} }
]

but it doesn’t work properly, look like the “text” parameter is ignored. Maybe Jon could make it work.

0 Likes

#11

Right you are, this is totally redundant now. I hadn’t really played with the command palette yet but it looks quite cool!

0 Likes

#12

[quote=“iamntz”]First thing that was annoying to me was the soft tabs.

The only two thing that I need to replace E completely is: translate all snippets from E to ST and make ctrl+tab to behave (is very redundant right now). Go to last active tab would be great. Any clues?[/quote]

I’m a bit late here, but could you explain what you mean by soft tabs? It’s generally used in text editor parlance to mean inserting spaces when you press tab, which is done in Sublime Text with the translate_tabs_to_spaces setting.

Ctrl+tab behaves just as it does is almost every other application: it cycles through a stack of files, with the most recently selected one on top. “Go to last active tab” is done by pressing ctrl+tab once.

0 Likes

#13

@Jps: fortunately, i migrated to ST without these things. i like the release cycle and your activity on the forums, which compensate somehow :mrgreen:

Ctrl+tab doesnt behave normally. Let me explain.

If we have 5 files opened ( a, B, c, D, e, f ). If B is active and previous active was D, when i press ctrl+tab, it goes to D, but now, the last active tab should be B. No? (just noticed is working like it should if i press ctrl+tab, release ctrl+tab then press again)

And about soft tabs, check out this video, should be explicit enough: screencast.com/t/5JziAePQGrY4

0 Likes

#14

That’s right, the stack of recent files is only updated when you let go of the ctrl key - alt tab (or command tab on osx) works the same way.

0 Likes

#15

Yes, you are right.
I guess i was… familiar with the editor that we don’t name it ( :ugeek: ) and i thought that is normal. Now, if I’m thinking a little at this, it kind of make sense…

0 Likes

#16

[quote=“bizoo”]Isn’t it redundant with the new Command Palette ?

I tried this key binding:

    { "keys": "ctrl+shift+y"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Set Syntax:"} }
]

but it doesn’t work properly, look like the “text” parameter is ignored. Maybe Jon could make it work.[/quote]

Note that it work now with Build 2070.

0 Likes

#17

@jps: any news with soft tabs thing? screencast.com/t/5JziAePQGrY4
I’m using the following key shortcut config:

{ "keys": "tab"], "command": "move_to", "args": { "to": "bol", "forward":true }, "context": { "key": "following_text", "operator": "regex_contains", "operand": "\t", "match_all": false } ] }

But there are some issues if the code is like this:

[tab][tab]some things[tab] {

and translate_tabs_to_spaces setting doesn’t really do anything. Any hint please?

thanks!

0 Likes

#18

Can you explain exactly what you mean by soft tabs? Different programs use the phrase to mean different things.

0 Likes

#19

Look at the movie posted at start there is no smart tab and at 0:15 there are. (i just remembered they are called SMART tabs not soft tabs. Sorry about this confusion.)

Long story short, when i have tabs after current cursor position is not inserting new tabs.

So if i have this:

[cursor][tab]{

and i press tab key, the cursor will jump just before { without inserting any new tabs. The problem is, however, the key i used is considering all tabs in that line, not all tabs untill first non-tab char. I tried to use \t\b as operand with no luck.

0 Likes

#20

If I understand what you want correctly, you may be able to get by with the move by words command, which will advance the cursor to the start of the next word:

"command": "move", "args": {"by": "words", "forward": true} }

If that doesn’t do it, then you’ll likely have to resort to a plugin.

0 Likes

#21

:cry: still doesn’t work how I would like (even if the next word thing it’s a interesting feature)
I made another video, with some caption: http://www.youtube.com/watch?v=

It is the correct behavior or there is a problem in regex parser?

0 Likes

#22

It has nothing to do with the regex, the command you’re using is move_to bol, i.e., move to the beginning of line, it’s the same command that the home key is bound to on windows.

0 Likes

#23

Yes, but the move to BOL works ok. WHEN should move (the condition) at the BOL doesn’t seems to work well.
Just curious, did I explain well what’s the problem? Or we both shoot in the dark and hope that the other one will understand ? :laughing:

Thanks.

0 Likes

#24

I don’t know what’s going in this thread, but iamtz, do you mean “\t\b” or “\t\b”? In the first case, you’re escaping both sequences at the Json level (tab + backspace), not at the regexp engine level (tab + word boundary anchor).

0 Likes