2011-09-28 54 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。除了語法表以外,還有什麼可能導致這種情況? –