Function: tramp-check-for-regexp

tramp-check-for-regexp is a byte-compiled function defined in tramp.el.gz.

Signature

(tramp-check-for-regexp PROC REGEXP)

Documentation

Check, whether REGEXP is contained in process buffer of PROC.

Erase echoed commands if exists.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defun tramp-check-for-regexp (proc regexp)
  "Check, whether REGEXP is contained in process buffer of PROC.
Erase echoed commands if exists."
  (with-current-buffer (process-buffer proc)
    (goto-char (point-min))

    ;; Check whether we need to remove echo output.  The max length of
    ;; the echo mark regexp is taken for search.  We restrict the
    ;; search for the second echo mark to PIPE_BUF characters.
    (when (and (tramp-get-connection-property proc "check-remote-echo")
	       (search-forward-regexp
		tramp-echoed-echo-mark-regexp
		(+ (point) (* 5 tramp-echo-mark-marker-length)) t))
      (let ((begin (match-beginning 0)))
	(when
	    (search-forward-regexp
	     tramp-echoed-echo-mark-regexp
	     (+ (point) (tramp-get-connection-property proc "pipe-buf" 4096)) t)
	  ;; Discard echo from remote output.
	  (tramp-flush-connection-property proc "check-remote-echo")
	  (tramp-message proc 5 "echo-mark found")
	  (forward-line 1)
	  (delete-region begin (point))
	  (goto-char (point-min)))))

    (when (or (not (tramp-get-connection-property proc "check-remote-echo"))
	      ;; Sometimes, the echo string is suppressed on the remote side.
	      (not (string-equal
		    (substring-no-properties
		     tramp-echo-mark-marker
		     0 (min tramp-echo-mark-marker-length (1- (point-max))))
		    (buffer-substring-no-properties
		     (point-min)
		     (min (+ (point-min) tramp-echo-mark-marker-length)
			  (point-max))))))
      ;; No echo to be handled, now we can look for the regexp.
      ;; Sometimes, lines are much too long, and we run into a "Stack
      ;; overflow in regexp matcher".  For example, //DIRED// lines of
      ;; directory listings with some thousand files.  Therefore, we
      ;; look from the end.
      (tramp-search-regexp regexp))))