2014-08-27 10 views
1

주석 및 문자열에서 YASnippet 확장 (예 : "if")을 사용하지 않도록 설정하고 싶지만 일반적인 방법으로이를 수행하는 방법을 찾지 못합니다.주석 및 문자열에서 yasnippets를 확장하지 않는 방법

http://capitaomorte.github.io/yasnippet/snippet-expansion.html#sec-2-2에, 그들은 파이썬을 위해 그것을하는 방법을 말한다. 그러나 나는 모든 prog-modes를 한번에 작동시키고 싶다. 그리고 "string/comment"테스트를하는 어떤 함수도 알지 못한다. , 독립적으로 언어.

아직 방법이 있습니까?

+1

이 아마도 당신이''전무를 t' 또는 반환하는 경우 (n 번째 8 (구문 ppss이))'다른 모드에서 볼 수'평가 테스트를 시도 할 수 문자열과 주석 내부? 그게 효과가 있을지 모르겠지만, 링크 된 기능이하는 것처럼 보인다. – lawlist

+0

또한보십시오 http://stackoverflow.com/questions/12815781/emacs-lisp-and-c-mode-when-am-i-in-a-comment-region/12820339#12820339 – Stefan

답변

2

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) 
+0

그건 작동하지 않습니다. 대단히 감사합니다! – user3341592