目录

Sublime Text 4 下 LaTeXtool 和 Latex-cwl 插件自动补全问题

目录

Sublime 发布 4 了, 二话不说更新一波. 把 3 的 \Data 直接拷到 4 下能用, 但是 $\LaTeX$ 自动补全这一块出现了问题.

自动补全吃掉了前面的\, 离谱的是如果我字母不按照顺序打, 然后补全, 就不会吃掉.

直接拿 issue1506 上的动图:

自动补全吃掉了`/`
自动补全吃掉了/

还是这个 issue1506 的解决方案, 稍加了一点点改动.

打开 Packages/LaTeXTools/latex_cwl_completions.py, 在最开始加一行

1
_ST4 = sublime.version() >= '4000'

然后找到 LatexCwlCompletion 类下的 on_query_completions 函数的这部分:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
	# autocompleting with slash already on line
	# this is necessary to work around a short-coming in ST where having a
	# keyed entry appears to interfere with it recognising that there is a
	# \ already on the line
	#
	# NB this may not work if there are other punctuation marks in the
	# completion
	if is_prefixed:
		completions = [
			(c[0], c[1][1:]) if c[1].startswith("\\") else c
			for c in completions
		]

issue回答是说由于一个自动补全的bug, 这里需要这么写才有效果, 然而 ST4 应该是修复了这bug, 所以不需要这个了.

顺带一提, 4的自动补全真的比3用起来爽一万倍!

在前面加一个判断, 不是 _ST4 才执行:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
	if not _ST4:
		# autocompleting with slash already on line
		# this is necessary to work around a short-coming in ST where having a
		# keyed entry appears to interfere with it recognising that there is a
		# \ already on the line
		#
		# NB this may not work if there are other punctuation marks in the
		# completion
		if is_prefixed:
			completions = [
				(c[0], c[1][1:]) if c[1].startswith("\\") else c
				for c in completions
			]