dgutov / mmm-mode

New official home for mmm-mode, fixed for Emacs >= 23
http://mmm-mode.sourceforge.net/
GNU General Public License v2.0
330 stars 30 forks source link

Handling of functions like (bobp) in c-mode derived major modes (csharp-mode) #96

Open Ruin0x11 opened 5 years ago

Ruin0x11 commented 5 years ago

I'm trying to use mmm-mode in a language with embedded C# blocks. Since csharp-mode is derived from c-mode it fails to parse because it calls c-state-pp-to-literal which depends on the value of (bobp). But (bobp) returns nil even though the fontify function starts at the beginning of the C# region. If there is a C# using directive at the beginning of the embedded region then mmm-mode-idle-reparse will constantly throw errors on every edit command and nothing gets fontified. It also prevents insertion of text sometimes, eventually forcing me to disable it.

Also mmm-derived-c-modes doesn't contain csharp-mode, but adding it doesn't seem to change anything. Strangely c-mode itself doesn't throw any errors so I'll use it in the meantime.

This example is enough to reproduce the error.

#CS
using System;
#ENDCS
(mmm-add-classes
 '((embedded-csharp
    :submode csharp-mode
    :delimiter-mode nil
    :front "^#CS\n"
    :back "^#ENDCS$")))
dgutov commented 5 years ago

CC Mode is tricky. Fontification should happen inside a narrowing (where (bobp) returns t), but maybe some of CC Mode's functions populates the same cache and is called outside of a narrowing. It might take a fair amount of work to track it down, and honestly I would not recommend it, because IME even c-mode doesn't work well with MMM. So if it does work, maybe it's good enough.

You can try to report this problem to the csharp-mode devevloper, though. If c-mode doesn't use bobp, why should csharp-mode do that?