1

I found this really cool in emacs

M-! t

t is ~/bin/t, and runs tests for whatever thing I'm working on. I added ~/bin/ to my /etc/path.d/, and I always use emacs -nw.

My issue is, the command output is not displayed properly in Emacs.

enter image description here

Newlines are messed up, and there's a ^M shown in the screen.

How can I tell M-! command to give me a more realistic view of the output, as if it was typed in a true bash terminal

  • 1
    I removed the emacs25 tag. Please do not use irrelevant tags in your posts. – Dan Dec 19 '17 at 15:20
  • What @Dan said. I've removed the same tag several times now. And elisp, which is about the language itself, not about how to do XYZ in Elisp. – Drew Dec 19 '17 at 15:28
  • I think you have to use a custom shell process to get all escape sequences and apply colors correctly. But I think ansi-colors.el is broken. However I do know that the package xterm-color is working. – bertfred Dec 19 '17 at 15:29
  • thanks for mentioning xterm-color, so how do I use it? – american-ninja-warrior Dec 19 '17 at 15:58
  • The shell command functionality provides only a dumb terminal, so "as if it was typed in a true bash terminal" is very different. You might want to update your test script to support dumb terminals; or you could try using the term.el process filter term-emulate-terminal. – phils Mar 19 '18 at 22:05
1

Something like this

(defun my-shell-process ()
  (interactive)
  (let ((buf "my-shell-process")
        (coding-system-for-read 'binary)
        (process-environment (nconc
                              (list (format "TERM=%s" "notdumb"))
                              process-environment)))
    (start-process "my-shell-process"
                   buf
                   "/bin/bash")
    (let ((proc (get-buffer-process buf)))
      (set-process-filter proc 'my-filter)
      (accept-process-output proc 0.1))))

(defun my-filter (proc output)
  (let ((buf (process-buffer proc)))
    (with-current-buffer buf
      (goto-char (point-max))
      (setq truncate-lines t)
      (insert (xterm-color-filter output)))))

You need to send a command to the process this way (process-send-string "my-shell-process" "ls -la\n")

  • is my use case so niche that emacs doesn't have a package or builtin for this? – american-ninja-warrior Dec 20 '17 at 1:31
  • Maybe there is a package for this, but I doubt it. – bertfred Dec 20 '17 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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