Home Download Buy Blog Forum Support

In macro script "find_under_expand" command does not work

In macro script "find_under_expand" command does not work

Postby lguzzon on Thu Feb 09, 2012 10:48 am

Hi,
the following macro does not work
"
[
{
"args": null,
"command": "find_under_expand"
}
]
"
Can you tell me why?
Sublime Linux (Ubuntu) version build 2165

Thanks in advance
Luca
lguzzon
 
Posts: 1
Joined: Fri Jan 27, 2012 1:52 pm

Re: In macro script "find_under_expand" command does not work

Postby lawlist on Sun Mar 17, 2013 1:07 am

Here is a workaround:

Code: Select all
import sublime, sublime_plugin

class Expand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = []
        for s in self.view.sel():
            word = self.view.word(sublime.Region(s.begin(), s.end()))
            if word.end() == s.end():
                # this next part deals with an end of line issue
                word = self.view.word(sublime.Region(s.end(), s.end() + 1))
            regions.append(word)
        for r in regions:
            self.view.sel().add(r)
lawlist
 
Posts: 54
Joined: Thu Feb 21, 2013 6:47 pm

Re: In macro script "find_under_expand" command does not work

Postby whd on Thu Mar 28, 2013 6:54 pm

Speaking as a newbie: how do I apply this workaround?
whd
 
Posts: 4
Joined: Wed Mar 27, 2013 6:14 pm

Re: In macro script "find_under_expand" command does not work

Postby lawlist on Fri Mar 29, 2013 3:14 am

Well, do you mind selecting up to the whitespace on each side of the word block? Or, or do you have a need to select only up to the word separators, such as a periods and commas -- my.word.com?

If it is okay to select something like " my.word.com ", then there is a nice plugin available via package control install. It is also available here:

https://github.com/bits/ExpandSelection ... ublimeText

Mine is based on word separators, and can be placed in a whd.py file and a installed in any folder inside the packages directory, e.g. /Packages/User. When saving a python script, you want to have the python console panel open so that you can see if there are any error messages -- usually caused by one or more lines needing a smaller or lager indent from the left-hand margin. Then you need a keymap assignment that calls the plugin, or you can compose a macro that calls the plugin. Mine is a newbie plugin that could be refined further by someone more experienced -- however, it does work.
lawlist
 
Posts: 54
Joined: Thu Feb 21, 2013 6:47 pm

Re: In macro script "find_under_expand" command does not work

Postby whd on Mon Apr 01, 2013 3:46 pm

Word separators are good.

I guess I misunderstood your workaround. I assumed that it was a fix for find_under_expand's behavior under the same name, i.e., I could drop it in and it would just work. I hadn't realized that it was defining a new command to use instead. Thanks for the clarification!
whd
 
Posts: 4
Joined: Wed Mar 27, 2013 6:14 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 24 guests