Function: idlwave-shell-filter

idlwave-shell-filter is a byte-compiled function defined in idlw-shell.el.gz.

Signature

(idlwave-shell-filter PROC STRING)

Documentation

Watch for IDL prompt and filter incoming text.

When the IDL prompt is received executes idlwave-shell-post-command-hook and then calls idlwave-shell-send-command for any pending commands.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/idlw-shell.el.gz
(defun idlwave-shell-filter (proc string)
  "Watch for IDL prompt and filter incoming text.
When the IDL prompt is received executes `idlwave-shell-post-command-hook'
and then calls `idlwave-shell-send-command' for any pending commands."
  ;; We no longer do the cleanup here - this is done by the process sentinel
  (if (eq (process-status idlwave-shell-process-name) 'run)
      ;; OK, process is still running, so we can use it.
      (let ((data (match-data)) p full-output)
	(unwind-protect
	    (progn
	      ;; Ring the bell if necessary
	      (while (setq p (string-search "\C-G" string))
		(ding)
		(aset string p ?\C-j ))
	      (if idlwave-shell-hide-output
		  (save-excursion
		    (while (setq p (string-search "\C-M" string))
		      (aset string p ?\  ))
		    (set-buffer
		     (get-buffer-create idlwave-shell-hidden-output-buffer))
		    (goto-char (point-max))
		    (insert string))
		(comint-output-filter proc string))
	      ;; Watch for magic - need to accumulate the current line
	      ;; since it may not be sent all at once.
	      (if (string-search "\n" string)
		  (progn
		    (if idlwave-shell-use-input-mode-magic
			(idlwave-shell-input-mode-magic
			 (concat idlwave-shell-accumulation string)))
		    (setq idlwave-shell-accumulation
			  (substring string
				     (progn (string-match "\\(.*[\n\r]+\\)*"
							  string)
					    (match-end 0)))))
		(setq idlwave-shell-accumulation
		      (concat idlwave-shell-accumulation string)))


              ;; ;; Test/Debug code
	      ;;(with-current-buffer
	      ;;    (get-buffer-create "*idlwave-shell-output*")
	      ;;  (goto-char (point-max))
	      ;;  (insert "\nReceived STRING\n===>\n" string "\n<====\n"))

	      ;; Check for prompt in current accumulating output
	      (when (setq idlwave-shell-ready
			  (string-match idlwave-shell-prompt-pattern
					idlwave-shell-accumulation))
		;; Gather the command output
		(if idlwave-shell-hide-output
		    (with-current-buffer idlwave-shell-hidden-output-buffer
		      (setq full-output (buffer-string))
		      (goto-char (point-max))
		      (re-search-backward idlwave-shell-prompt-pattern nil t)
		      (goto-char (match-end 0))
		      (setq idlwave-shell-command-output
			    (buffer-substring-no-properties
			     (point-min) (point)))
		      (delete-region (point-min) (point)))
		  (setq idlwave-shell-command-output
			(with-current-buffer (process-buffer proc)
			(buffer-substring-no-properties
			 (save-excursion
			   (goto-char (process-mark proc))
			   (forward-line 0) ; Emacs 21 (beginning-of-line nil)
			   (point))
			 comint-last-input-end))))

		;; Scan for state and do post commands - bracket
		;; them with idlwave-shell-ready=nil since they may
		;; call idlwave-shell-send-command themselves.
		(let ((idlwave-shell-ready nil))
		  (idlwave-shell-scan-for-state)
		  ;; Show the output in the shell if it contains an error
		  (if idlwave-shell-hide-output
		      (if (and idlwave-shell-show-if-error
			       (eq idlwave-shell-current-state 'error))
			  (comint-output-filter proc full-output)
			;; If it's only *mostly* hidden, filter % lines,
			;; and show anything that remains
			(if (eq idlwave-shell-hide-output 'mostly)
			    (let ((filtered
				   (idlwave-shell-filter-hidden-output
				    full-output)))
			      (if filtered
				  (comint-output-filter
				   proc filtered))))))

		  ;; Call the post-command hook
		  (if (functionp idlwave-shell-post-command-hook)
		      ;;(message "Calling command function")
		      (funcall idlwave-shell-post-command-hook)
		    ;;(message "Calling list")
		    ;;(prin1 idlwave-shell-post-command-hook)
		    (eval idlwave-shell-post-command-hook t))

		  ;; Reset to default state for next command.
		  ;; Also we do not want to find this prompt again.
		  (setq idlwave-shell-accumulation nil
			idlwave-shell-command-output nil
			idlwave-shell-post-command-hook nil
			idlwave-shell-hide-output nil
			idlwave-shell-show-if-error nil))
		;; Done with post command.  Do pending command if
		;; any.
		(idlwave-shell-send-command)))
	  (store-match-data data)))))