0

When using a normal terminal application (like Konsole, for example), I regularly use Control-L or the clear command to clear the terminal's contents, leaving the cursor on the top. When I do this, I can still scroll up and read the output of the commands I ran previously (they are not discarded).

In Emacs shell mode (M-x shell), I've been using comint-clear-buffer to clear the contents of the terminal and leave the point (and prompt) on the top. The problem with this command is that it also discards the output of all the commands I have run up to that moment. Using recenter-top-bottom doesn't help, because when I use it to position the point and prompt at the top, as soon as I input a command and hit ENTER, the point 'jumps' back to its original position.

The question I would like to ask is: is there a command similar to comint-clear-buffer that doesn't discard the output of previous commands?

1

1 Answer 1

1

comint-postoutput-scroll-to-bottom in the hook comint-output-filter-functions is causing to scroll to bottom and so to remove it from the hook add this snippet to emacs config

(add-hook 'comint-mode-hook
          (defun rm-comint-postoutput-scroll-to-bottom ()
            (remove-hook 'comint-output-filter-functions
                         'comint-postoutput-scroll-to-bottom)))

after this you can use C-l C-l to clear screen in shell and proceed with any commands without scroll

0

Your Answer

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

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