I tried adding hook to term-mode-hook to call comint-send-string:

   (lambda ()
     (comint-send-string (get-buffer-process (current-buffer)) "alias t='echo test'")

But I got (error "Buffer *ansi-term* has no process").

1 Answer 1


term-exec-hook is a variable defined in term.el.

Called each time a process is exec'd by term-exec. This is called after the process is cranked up. It is useful for things that must be done each time a process is executed in a term mode buffer (e.g., set-process-query-on-exit-flag). In contrast, term-mode-hook is only executed once, when the buffer is created.

I would also use the term API for sending input to the process, rather than using comint-send-string.

term-send-string is a compiled Lisp function in term.el.

(term-send-string PROC STR)

Send to PROC the contents of STR as input. This is equivalent to process-send-string, except that long input strings are broken up into chunks of size term-input-chunk-size. Processes are given a chance to output between chunks. This can help prevent processes from hanging when you send them long inputs on some OS's.

  • Thanks! Following codes work for me: ` (add-hook 'term-exec-hook (lambda () (term-send-string (get-buffer-process (current-buffer)) "alias t='echo test'\n") )) `
    – AhLeung
    Sep 18, 2022 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.