有没有办法,当激活spellchecking
并F6注意到一堆带有红色下划线的拼写错误时,选择所有拼写错误的单词?
显然,我们不能用简单的Ctrl+来做到这一点D。我们的想法是选择所有这些,然后复制到单独的文件中进行检查,或者简单地一次性删除它们。
答案1
您可以轻松创建自定义插件来执行此操作:
- 从
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
答案2
我使用算法来执行它1,500,000 以内的文件81,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 )