tags:

views:

81

answers:

1

I want Emacs' syntax motion functions to ignore certain regions of the buffer; i.e. to correctly parse non-contiguous regions. This can be done effectively if you can define the region to ignore as a comment and set parse-sexp-ignore-comments variable to true.

Here's the problem. The primary mode has comments starting with '!' and ending with newline ('\n') and the buffer region I want ignored as a comment starts with "%{" and ends with "}%". However, I cannot see any way to define these both as comments. The mechanism to cope with multi-character comment delimiters in the syntax table is too specific to C to use here. Does anyone have any other suggestions, text-properties, for example?

+1  A: 

Yes you can modify the syntax table similarly to what C does. You can read up on syntax tables here. Basically, you'll need to define % as punctuation and as a comment character, same with the { and }.

The description for the / character in C is:

        character: / (47, #o57, #x2f)
preferred charset: ascii (ASCII (ISO646 IRV))
       code point: 0x2F
           syntax: . 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)

Note: to get the description of a character, type M-x describe-char and it'll tell you all about the char after the point.

Similarly, the * character has the description (in C):

        character: * (42, #o52, #x2a)
preferred charset: ascii (ASCII (ISO646 IRV))
       code point: 0x2A
           syntax: . 23 which means: punctuation,
      is the second character of a comment-start sequence,
      is the first character of a comment-end sequence

Basically, you need to set up the comment-start and comment-end sequences, as described in this part of the info pages.

I think you'd want to modify the syntax entries something like this:

(modify-syntax-entry ?% ".14")
(modify-syntax-entry ?{ "(}2")
(modify-syntax-entry ?} "){3")

Though, I think keeping the { and } as a matched pair of parenthesis might confuse things...

Trey Jackson
Thanks for the reply. Unfortunately, I already tried this before I came here to ask the question. I found that the mechanism is too specific to C; the 'b' type of comment has to start with the first symbol of the 'a' type of comment, in this case '!' and '%' respectively. In C, these are conveniently both '/'
Alex