I'm trying to tail the output from a command into a buffer, and I just learned that the command occasionally uses long strings of ^H to backspace over previous lines.

Like, the command stdout will first send this line is temporary then send ^H^H^H^H^H^H^H^H^Hpermanent next, so the result in my terminal just looks like this line is permanent.

Is there a simple way to recreate this effect in a buffer? If at all possible I'd really prefer to avoid iterating over the characters in the output stream and replacing each ^H with a call to delete-char.

I've tried variations on (insert ?^H) but no joy. ^H appears in the buffer at point, but I want the character before point to be deleted.

  • 1
    How about C-q C-h, AKA (insert ?\C-h), AKA (insert 8)? See (emacs) Inserting Text.
    – Basil
    May 17, 2018 at 21:38
  • Edited to clarify what happens when I try these insert-based solutions, and why that does t work for me May 17, 2018 at 21:40
  • 1
    If you want to interpret carriage returns, backspaces, etc. I think the easiest way is to use comint-output-filter, specifically its subroutine comint-carriage-motion. See the function shell-command, for example.
    – Basil
    May 17, 2018 at 21:44
  • Ah, bummer. Looks like that function does the thing I was hoping to avoid -- it runs over the string transforming control characters into function calls. Eh, so it goes. Mind writing up an answer and I'll accept it? May 17, 2018 at 21:53
  • 1
    In that case it's not at all clear just what behavior you are requesting.
    – Drew
    May 17, 2018 at 22:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.