Sublime Forum

In macro script "find_under_expand" command does not work

#1

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

0 Likes

#2

Here is a workaround:

[code]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®[/code]

0 Likes

#3

Speaking as a newbie: how do I apply this workaround?

0 Likes

#4

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:

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.

0 Likes

#5

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!

0 Likes