我想if
在注释和字符串中禁用 YASnippet 扩展(例如,),但找不到如何以通用方式执行此操作。
在条件系统上,他们说如何为 Python 做这件事,但我想让它同时适用于所有 prog 模式,而且我不知道有任何函数可以独立测试“在字符串/注释中”的语言。
还有办法吗?
我想if
在注释和字符串中禁用 YASnippet 扩展(例如,),但找不到如何以通用方式执行此操作。
在条件系统上,他们说如何为 Python 做这件事,但我想让它同时适用于所有 prog 模式,而且我不知道有任何函数可以独立测试“在字符串/注释中”的语言。
还有办法吗?
使用 lawlist 的建议并将其添加到prog-mode-hook
:
(defun yas-no-expand-in-comment/string ()
(setq yas-buffer-local-condition
'(if (nth 8 (syntax-ppss)) ;; non-nil if in a string or comment
'(require-snippet-condition . force-in-comment)
t)))
(add-hook 'prog-mode-hook 'yas-no-expand-in-comment/string)