Answers:
您可以轻松创建自定义插件来执行此操作:
Tools
菜单 - > Developer
- > New Plugin...
(基于Dev Build 3111的说明。对于稳定通道3103,它只是Tools
- > New Plugin...
)import sublime, sublime_plugin
class SelectAllSpellingErrorsCommand(sublime_plugin.TextCommand):
def run(self, edit):
regions = []
while True:
self.view.run_command('next_misspelling')
if self.view.sel()[0] not in regions:
regions.append(self.view.sel()[0])
else:
break
self.view.sel().clear()
self.view.sel().add_all(regions)
Packages/User
文件夹)中spelling.py
select_all_spelling_errors
view.run_command('select_all_spelling_errors')
从控制台运行即可。
我使用该算法在一个文件中执行它,在一个文件中,在一万个拼写错误的单词中,在1.500.000行/单词内。这是个人资料结果:
1.555.756 function calls in 9.196,582 seconds ~2,5 hours
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.077 0.077 9196.582 9196.582 <string>:1(<module>)
1 6.087 6.087 9196.505 9196.505 select_all_spelling_errors.py:23(findRegions)
245644 1.042 0.000 1.042 0.000 sublime.py:550(__init__)
163763 2.559 0.000 2.559 0.000 sublime.py:557(__str__)
245644 1.357 0.000 15.908 0.000 sublime.py:638(__getitem__)
1 0.000 0.000 0.000 0.000 sublime.py:659(clear)
81881 0.611 0.000 56.255 0.001 sublime.py:662(add)
1 0.385 0.385 56.640 56.640 sublime.py:668(add_all)
81882 0.884 0.000 9114.968 0.111 sublime.py:829(run_command)
245646 0.344 0.000 0.344 0.000 sublime.py:832(sel)
1 0.001 0.001 9196.582 9196.582 {built-in method exec}
81881 0.071 0.000 0.071 0.000 {built-in method isinstance}
81882 9114.084 0.111 9114.084 0.111 {built-in method view_run_command}
81881 55.573 0.001 55.573 0.001 {built-in method view_selection_add_region}
1 0.000 0.000 0.000 0.000 {built-in method view_selection_clear}
245644 13.509 0.000 14.551 0.000 {built-in method view_selection_get}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'values' of 'dict' objects}
在那里,我们可能会看到几乎一直吃的罪魁祸首:
81882 9114.084 0.111 9114.084 0.111 {built-in method view_run_command}
这是使用的源代码:
import sublime
import sublime_plugin
import cProfile
class SelectAllSpellingErrorsCommand(sublime_plugin.TextCommand):
def run(self, edit):
cProfile.runctx( 'findRegions(self, edit)', globals(), locals() )
def findRegions(self, edit):
regionsList = []
while True:
self.view.run_command('next_misspelling')
if self.view.sel()[0] not in regionsList:
regionsList.append( self.view.sel()[0] )
else:
break
self.view.sel().clear()
self.view.sel().add_all( regionsList )