I use both Sonnet 4.5 and Opus 4.5 to edit lisp (emacs lisp to be be precise) and run into this issue extremely infrequently. Not sure if they have some special handling for this but seems to work ok. I have this problem with Gemini, and less frequently, with Qwen.