4

While resolving complex conflicts manually, I usually want emacs to treat conflict markers and region between them as comment, since it breaks major-mode's syntactic analysis (fontification, electric-indent, etc) :

<<<<<<< HEAD          <- comment
aaa
bbb
=======               <- comment
ccc                   <- comment
>>>>>>> brabrabrabra  <- comment

It seems possible to visually highlight them as comment with search-based fontification, but is it possible to treat them as comment not just visually but also syntactically ?

  • That would be very cool. I guess you could try to modify the syntax table to add <<<<<<< and >>>>>>> as comment-start strings, but that might have unintended side effects. Have you tried using ediff-mode? The UI is a bit arcane, but it works pretty well once you get the hang of it, and it handles conflict blocks correctly. – blujay Oct 14 '16 at 10:05
1

Yes, it's possible, but AFAIK noone has written the corresponding code. This would need to be done via the syntax-propertize-function, to place appropriate syntax-table properties at the appropriate places.

It might be somewhat tricky to handle all cases, tho, such as when the conflict markers are within strings or comments. But it's definitely worth a try and I'd welcome a patch to smerge-mode to provide that functionality.

  • Interestingly there are programming languages with multi-line strings. In those languages the conflict markers are ambiguous. Most simple case: A full conflict zone is within one string. Is this the actual string contents or is it a conflict zone?? – Tobias Oct 14 '16 at 13:40
  • @Tobias I think it's no big deal: smerge-mode is only enabled when actually dealing with merge conflicts (during which I assume it's acceptable to see false positives), and is disabled the rest of the time. – YoungFrog Oct 15 '16 at 6:25
  • Thanks, syntax-propertize-function worked! Here's a minimal solution I tried (no considerations for such false positives): gist.github.com/zk-phi/01e67291b5e43d0c2839bed3cc778906 . – zk_phi Oct 16 '16 at 5:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.