2

我想if在注释和字符串中禁用 YASnippet 扩展(例如,),但找不到如何以通用方式执行此操作。

条件系统上,他们说如何为 Python 做这件事,但我想让它同时适用于所有 prog 模式,而且我不知道有任何函数可以独立测试“在字符串/注释中”的语言。

还有办法吗?

4

1 回答 1

3

使用 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)
于 2014-08-27T16:17:14.863 回答