2

I want to send a command to a comint shell-mode without it printing an additional prompt. I'm trying to use the comint-redirect-* API, but I am still getting an additional prompt. What would be an easy way to either avoid the prompt printing altogether, or to track back and delete it?

My redirect,

(defun my-comint-redirect-silently (proc string)
  (let (comint-redirect-perform-sanity-check)
    (with-temp-buffer
      ;; possible to have shell not print prompt?
      (comint-redirect-send-command-to-process
       string (current-buffer) proc nil 'no-display)))
  (with-current-buffer (process-buffer proc)
    ;; necessary to track back and delete here?
    (comint-redirect-cleanup)))

Example of a call in a shell-hook,

(add-hook 'shell-mode-hook
          (lambda ()
            (my-comint-redirect-silently
             (get-buffer-process (current-buffer)) "TERM=xterm-256color")))

But, the comint shell then prints the following (notice the double prompt)

me@me-M51AC: ~
$ me@me-M51AC: ~ 
$ 

Not directly relevant, but to show it is printing twice, the prompt here is set as

$ echo $PS1
${debian_chroot:+($debian_chroot)}\[\e[32m\]\u@\h: \[\e[33m\]\w\[\e[0m\]\n\$
Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • side note: If i `edebug` the `my-comint-redirect-silently` and start a shell the prompt only prints once – Rorschach Oct 08 '17 at 14:05
  • I think you are interested in things like `comint-send-string`, `comint-send-input`, and the like .... For advanced stuff, see also `process-send-string`. – lawlist Oct 08 '17 at 18:46
  • @lawlist well not really, I am trying to temporarily redirect the output, hence the "silently". I already have a generic inferior process redirect library, similar to `ess`'s silent redirect, but I would rather use the new(?) comint one. – Rorschach Oct 08 '17 at 19:46
  • err not new, I see in the git log mentions of it back to 1999 – Rorschach Oct 08 '17 at 19:48

1 Answers1

3

I took at look at how comint-redirect-results-list-from-process worked and bodged this.

(defun comint-run-thing-process (process command)
  "Send COMMAND to PROCESS."
  (let ((output-buffer " *Comint Redirect Work Buffer*"))
    (with-current-buffer (get-buffer-create output-buffer)
      (erase-buffer)
      (comint-redirect-send-command-to-process command
                                               output-buffer process nil t)
      ;; Wait for the process to complete
      (set-buffer (process-buffer process))
      (while (and (null comint-redirect-completed)
                  (accept-process-output process)))
      ;; Collect the output
      (set-buffer output-buffer)
      (goto-char (point-min))
      ;; Skip past the command, if it was echoed
      (and (looking-at command)
           (forward-line))
      ;; Grab the rest of the buffer
      (buffer-substring-no-properties (point) (- (point-max) 1)))))

Hope it helps

Baggers
  • 3,183
  • 20
  • 31
  • thanks a lot, I was missing `accept-process-output`. I didn't actually need the redirected output for my scenario, but this cleared it up for me. – Rorschach Jul 18 '18 at 21:54