A file not ending in newline, oh the horror
Newish emacsen don't have comint-last-prompt-overlay

... so we have to check if it's defined and, in its defect, use the
new shiny comint-last-prompt.  A bit of refactoring resulted.