> but I see no reason to not call (erase-buffer) altogether. > > Do you? Yes, obviously, multiline input, I forgot. Nevertheless I found the origin of the problem. Somehow when company is enabled in the shell buffer python-shell-font-lock-comint-output-filter-function is getting empty strings as output and then the ";; Otherwise just add a newline." clause is activated. No matter the reason why empty output is being passed to the filter, it's wrong for the filter to add a new line to the font lock buffer if this happens. I'm attaching two patches, since python-shell-font-lock-comint-output-filter-function is an old friend of mine and we have spent many nights together now: 1. The first one (Avoid-spurious...) strictly fixes this issue by moving the not-empty condition to the top and doing everything else unless not-empty. Period. That works. 2. The second one (Fix-font-lock...) combines 1 with my previous patch for fixing ipython multiline input (#32390) since both changes overlap. I suggest to directly apply patch 2 since it improves prompt detection heuristic and fixes two bugs. Then you can close this and #32390. Regards -- Carlos