2011-09-28 39 views
1

我写了一个小主要的模式下,C++ - 语言一样(所以我现在用的是C++语法表):emacs的parenthethes匹配错误

(setq tacc-mode-syntax-table c++-mode-syntax-table) 
但是

,似乎在注释字符“'”前baces可以搞砸了括号匹配:

Foo { 
    Bar { 
     //This doesn't work - The } are not matched with the { 
    } 
} 

简装模式还是引起了这个问题:

(setq tacc-mode-syntax-table c++-mode-syntax-table) 

(setq tacc-font-lock-keywords c++-font-lock-keywords) 

(define-derived-mode tacc-mode nil "Tacc" 
    "tacc" 
    (set (make-local-variable 'font-lock-defaults) 
     '(tacc-font-lock-keywords nil nil nil nil))) 

(provide 'tacc) 

据我所知,语法表应该控制这个 - 我应该如何解决这个问题?

,缓冲区中的desribe语法的结果是:

C-j    > b which means: endcomment (comment style b) 
RET    > b which means: endcomment (comment style b) 
% .. &   . which means: punctuation 
'    " which means: string 
*    . 23 which means: punctuation, 
     is the second character of a comment-start sequence, 
     is the first character of a comment-end sequence 
+    . which means: punctuation 
-    . which means: punctuation 
/    . 124b which means: punctuation, 
     is the first character of a comment-start sequence, 
     is the second character of a comment-start sequence, 
     is the second character of a comment-end sequence (comment style b) 
<..>   . which means: punctuation 
\    \ which means: escape 
_    _ which means: symbol 
|    . which means: punctuation 
     . which means: punctuation 

The parent syntax table is: 
[email protected] .. C-h  . which means: punctuation 
TAB .. C-j   which means: whitespace 
C-k    . which means: punctuation 
C-l .. RET   which means: whitespace 
C-n .. C-_  . which means: punctuation 
SPC     which means: whitespace 
!    . which means: punctuation 
"    " which means: string 
#    . which means: punctuation 
$ .. %   w which means: word 
&    _ which means: symbol 
'    . which means: punctuation 
(    () which means: open, matches) 
)    )( which means: close, matches (
* .. +   _ which means: symbol 
,    . which means: punctuation 
-    _ which means: symbol 
.    . which means: punctuation 
/    _ which means: symbol 
0 .. 9   w which means: word 
: .. ;   . which means: punctuation 
<..>   _ which means: symbol 
? .. @   . which means: punctuation 
A .. Z   w which means: word 
[    (] which means: open, matches ] 
\    \ which means: escape 
]    )[ which means: close, matches [ 
^    . which means: punctuation 
_    _ which means: symbol 
`    . which means: punctuation 
a .. z   w which means: word 
{    (} which means: open, matches } 
|    _ which means: symbol 
}    ){ which means: close, matches { 
~ .. DEL  . which means: punctuation 
..  w which means: word 

回答

1

parse-sexp潜入意见,除非parse-sexp-ignore-comments是真实的。 C++模式将parse-sexp-ignore-comments设置为true,就像许多其他编程模式一样。

此外,您需要声明使用语法表(define-derived-mode不会隐式使用它)。

(define-derived-mode tacc-mode nil "Tacc" 
    "tacc" 
    :syntax-table tacc-mode-syntax-table 
    (set (make-local-variable 'parse-sexp-ignore-comments) t) 
) 
+0

我知道它在C++ - 模式 - 添加描述语法的输出(对我来说很好) –

+0

百思不得其解(我得到正是从用C'描述-syntax' ++模式输出相同)。你使用的是什么版本的Emacs?如果你用'emacs -q'启动Emacs,它会改变什么吗?如果不是,那么'emacs -Q'呢?你怎么知道没有完成大括号匹配(例如,我用'C-M-b'和'C-M-e'来确认它是在我的测试中完成的)? – Gilles

+0

emacs-version 23.1.1,仍然发生在emacs -q - 我也一直在使用C-M b。除了语法表以外,还有什么可能导致这种情况? –