1

I am trying to understand how forward-list matches template delimiters <> in c++-mode.

forward-list in lisp.el calls scan-lists with the appropriate arguments. The documentation for scan-lists says

(scan-lists FROM COUNT DEPTH)

Scan from character number FROM by COUNT lists. Scan forward if COUNT is positive, backward if COUNT is negative. Return the character number of the position thus found.

A "list", in this context, refers to a balanced parenthetical grouping, as determined by the syntax table.

Looking at the syntax table in a c++-mode buffer, I don't find an entry of which indicates that < and > match each other. Is my reading of the syntax table incorrect? I am assuming that matching entries look like this:

(       ()  which means: open, matches )
)       )(  which means: close, matches (

To summarize, how does forward-list match the template delimiters < and > in c++-mode?

  • 1
    It looks like some magic from scan_lists in syntax.c. For instance, delimiters in #include <vector> aren't matched, while in vector<int> they are. – abo-abo Jan 24 '15 at 14:51
  • C++ is horribly hard to parse. Simply matching < to > wouldn't work because you have both binary comparisons, and bitshift operators. Any C++ mode will need to determine whether any given chevron "belongs" to another or stands on its own. – PythonNut Jan 24 '15 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.