Function: term-send-input
term-send-input is an interactive and byte-compiled function defined
in term.el.gz.
Signature
(term-send-input)
Documentation
Send input to process.
After the process output mark, sends all text from the process mark to
point as input to the process. Before the process output mark, calls value
of variable term-get-old-input to retrieve old input, copies it to the
process mark, and sends it. A terminal newline is also inserted into the
buffer and sent to the process. The functions in term-input-filter-functions
are called on the input before sending it.
The input is entered into the input history ring, if the value of variable
term-input-filter returns non-nil when called on the input. Any history
reference may be expanded depending on the value of the variable
term-input-autoexpand.
If variable term-eol-on-send is non-nil, then point is moved to the
end of line before sending the input.
The values of term-get-old-input, term-input-filter-functions, and
term-input-filter are chosen according to the command interpreter running
in the buffer. E.g.,
If the interpreter is the csh,
term-get-old-input is the default: take the current line, discard any
initial string matching regexp term-prompt-regexp.
term-input-filter-functions monitors input for "cd", "pushd", and
"popd" commands. When it sees one, it cd's the buffer.
term-input-filter is the default: returns t if the input isn't all white
space.
If the term is Lucid Common Lisp,
term-get-old-input snarfs the sexp ending at point.
term-input-filter-functions does nothing.
term-input-filter returns nil if the input matches input-filter-regexp,
which matches (1) all whitespace (2) :a, :c, etc.
Similarly for Soar, Scheme, etc.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/term.el.gz
;;;
;;; Input processing stuff [line mode]
;;;
(defun term-send-input ()
"Send input to process.
After the process output mark, sends all text from the process mark to
point as input to the process. Before the process output mark, calls value
of variable `term-get-old-input' to retrieve old input, copies it to the
process mark, and sends it. A terminal newline is also inserted into the
buffer and sent to the process. The functions in `term-input-filter-functions'
are called on the input before sending it.
The input is entered into the input history ring, if the value of variable
`term-input-filter' returns non-nil when called on the input. Any history
reference may be expanded depending on the value of the variable
`term-input-autoexpand'.
If variable `term-eol-on-send' is non-nil, then point is moved to the
end of line before sending the input.
The values of `term-get-old-input', `term-input-filter-functions', and
`term-input-filter' are chosen according to the command interpreter running
in the buffer. E.g.,
If the interpreter is the csh,
`term-get-old-input' is the default: take the current line, discard any
initial string matching regexp `term-prompt-regexp'.
`term-input-filter-functions' monitors input for \"cd\", \"pushd\", and
\"popd\" commands. When it sees one, it cd's the buffer.
`term-input-filter' is the default: returns t if the input isn't all white
space.
If the term is Lucid Common Lisp,
`term-get-old-input' snarfs the sexp ending at point.
`term-input-filter-functions' does nothing.
`term-input-filter' returns nil if the input matches input-filter-regexp,
which matches (1) all whitespace (2) :a, :c, etc.
Similarly for Soar, Scheme, etc."
(interactive)
;; Note that the input string does not include its terminal newline.
(let ((proc (get-buffer-process (current-buffer))))
(if (not proc) (error "Current buffer has no process")
(let* ((pmark (process-mark proc))
(pmark-val (marker-position pmark))
(input-is-new (>= (point) pmark-val))
(intxt (if input-is-new
(progn (if term-eol-on-send (end-of-line))
(buffer-substring pmark (point)))
(funcall term-get-old-input)))
(input (if (not (eq term-input-autoexpand 'input))
;; Just whatever's already there
intxt
;; Expand and leave it visible in buffer
(term-replace-by-expanded-history t)
(buffer-substring pmark (point))))
(history (if (not (eq term-input-autoexpand 'history))
input
;; This is messy 'cos ultimately the original
;; functions used do insertion, rather than return
;; strings. We have to expand, then insert back.
(term-replace-by-expanded-history t)
(let ((copy (buffer-substring pmark (point))))
(delete-region pmark (point))
(insert input)
copy))))
(when (term-pager-enabled)
(save-excursion
(goto-char (process-mark proc))
(setq term-pager-count (term-current-row))))
(when (and (funcall term-input-filter history)
(or (null term-input-ignoredups)
(not (ring-p term-input-ring))
(ring-empty-p term-input-ring)
(not (string-equal (ring-ref term-input-ring 0)
history))))
(ring-insert term-input-ring history))
(run-hook-with-args 'term-input-filter-functions (concat input "\n"))
(setq term-input-ring-index nil)
;; Update the markers before we send the input
;; in case we get output amidst sending the input.
(set-marker term-last-input-start pmark)
(set-marker term-last-input-end (point))
(when input-is-new
;; Set up to delete, because inferior should echo.
(when (marker-buffer term-pending-delete-marker)
(delete-region term-pending-delete-marker pmark))
(set-marker term-pending-delete-marker pmark-val)
(set-marker (process-mark proc) (point)))
(goto-char pmark)
(funcall term-input-sender proc input)))))