Function: term-proc-query

term-proc-query is a byte-compiled function defined in term.el.gz.

Signature

(term-proc-query PROC STR)

Source Code

;; Defined in /usr/src/emacs/lisp/term.el.gz
;;; Simple process query facility.
;; ===========================================================================
;; This function is for commands that want to send a query to the process
;; and show the response to the user.  For example, a command to get the
;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
;; to an inferior Common Lisp process.
;;
;; This simple facility just sends strings to the inferior process and pops
;; up a window for the process buffer so you can see what the process
;; responds with.  We don't do anything fancy like try to intercept what the
;; process responds with and put it in a pop-up window or on the message
;; line.  We just display the buffer.  Low tech.  Simple.  Works good.

;; Send to the inferior process PROC the string STR.  Pop-up but do not select
;; a window for the inferior process so that its response can be seen.
(defun term-proc-query (proc str)
  (let* ((proc-buf (process-buffer proc))
	 (proc-mark (process-mark proc)))
    (display-buffer proc-buf)
    (set-buffer proc-buf) ; but it's not the selected *window*
    (let ((proc-win (get-buffer-window proc-buf))
	  (proc-pt (marker-position proc-mark)))
      (term-send-string proc str) ; send the query
      (accept-process-output proc)  ; wait for some output
      ;; Try to position the proc window so you can see the answer.
      ;; This is bogus code.  If you delete the (sit-for 0), it breaks.
      ;; I don't know why.  Wizards invited to improve it.
      (when (not (pos-visible-in-window-p proc-pt proc-win))
	(let ((opoint (window-point proc-win)))
	  (set-window-point proc-win proc-mark) (sit-for 0)
	  (if (not (pos-visible-in-window-p opoint proc-win))
	      (push-mark opoint)
	    (set-window-point proc-win opoint)))))))