0

Emacs 27.1

M-x ansi-term

run some process that outputs lots of text.

Then C-c and type Linux command clear.

Only the current page is cleared, in the buffer. But I need to clear all text from the buffer.

Drew
  • 77,472
  • 10
  • 114
  • 243
a_subscriber
  • 4,062
  • 1
  • 18
  • 56

1 Answers1

1
(defun my-term-reset-terminal ()
  (interactive)
  (let ((inhibit-read-only t))
    (term-reset-terminal)))

In char mode you can call it after typing C-c (or maybe C-x). E.g.:

C-cM-x my-term-reset-terminal

Or you might prefer:

(with-eval-after-load "term"
  (define-key term-raw-escape-map (kbd "C-l") 'my-term-reset-terminal))

Which gives you the C-cC-l binding when in char mode.


I think you should M-x report-emacs-bug though, as the code for term-emulate-terminal comments that the clear command will result in a call to term-reset-terminal and seemingly that doesn't happen.

phils
  • 50,977
  • 3
  • 79
  • 122
  • In my case this help: (define-key term-mode-map (kbd "C-l") #'my-term-reset-terminal) – a_subscriber Jul 07 '23 at 07:47
  • If I execute my-term-reset-terminal when ansi-term have some live ouput then clear not working correctly. I need to stop output (e.g. by C-c) and the only then run my-term-reset-terminal. It not very convinient. – a_subscriber Jul 10 '23 at 07:26
  • 1
    Typing clear in a terminal emulator also doesn't abort the process you're running in the terminal. It would not be expected behaviour for that to happen. If you want to programmatically send C-c to the inferior process you can use (term-send-raw-string "\C-c"). – phils Jul 10 '23 at 11:18