如何永远不要在注释和字符串中扩展yasnippets

时间:2014-08-27 08:02:57

标签: emacs autocomplete expansion yasnippet

我想在评论和字符串中禁用YASnippet扩展(例如,“if”),但是没有找到如何以通用方式执行此操作。

http://capitaomorte.github.io/yasnippet/snippet-expansion.html#sec-2-2上,他们说如何为Python做这件事,但我想让它同时适用于所有的prog模式,而且我不知道任何在字符串中测试的函数/ comment“,独立于语言。

还有办法吗?

1 个答案:

答案 0 :(得分:2)

使用法律清单的建议并将其添加到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)