开发者

emacs parenthethes matching wrong

I wrote a small major-mode for a C++-like language(so I am using the C++ syntax table):

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

however, it seems that the character "'" in comments before baces can mess up the brace matching:

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

The stripped-down mode that still causes this problem is:

(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)

As far as I'm aware, the syntax table should be controlling开发者_运维技巧 this - how should I fix this?

The results of desribe-syntax in the buffer are:

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:
C-@ .. 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


parse-sexp dives into comments unless parse-sexp-ignore-comments is true. C++ mode sets parse-sexp-ignore-comments to true, as do many other programming modes.

Additionally, you need to declare the use of the syntax table (define-derived-mode doesn't use it implicitly).

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜