What I want to do from inside a term shell is have a function called when there is new output or a certain regexp (e.g. a prompt) appears in in a term's output. The callback function should then be able to access text from the either the last time it was called, or from the last time that pattern was seen.

In comint this would be a function stored in comint-output-filter-functions, and for eshell: eshell-output-filter-functions

Can this be done in term.el? If so, how?

  • You could add a :before advice to term-emulate-terminal -- the process-filter of the buffer-process of a term buffer. – Tobias Aug 21 '17 at 15:45
  • 1
    I don't understand. And I'm not good at inference. I can try experimenting but I need more details. Perhaps code snippets and/or links to concepts you are referring to? – rocky Aug 23 '17 at 1:44

Here is a concrete example using the old style advice:

(defadvice term-emulate-terminal (before out-terminal-string activate)
  (message "%s" str))


  • term-emulate-terminal is the output process filter for terminals
  • output-terminal-string is a label for this advice, change as you please
  • The variable str matches the string variable used in term-emulate-terminal. In this advice style you are allowed to directly reference the original arguments by name.
  • Seems interesting although I don't have time right now to check it out. I will later. Thanks. – rocky Jan 23 '18 at 16:47
  • Take your time. I spent a reasonable amount of time messing with this recently, so if you have any questions don't hesitate to ask. My purpose was to get pdbtrack working with term/ansi-term, which I was successful with. – John Lunzer Jan 24 '18 at 13:28
  • Want to get realgud working with term/ansi-term? I'd be eternally grateful. github.com/realgud/realgud/blob/master/realgud/common/… – rocky Jan 24 '18 at 17:14
  • I'll even add a bounty for it if you do it - name your price :-) – rocky Jan 24 '18 at 17:22
  • I don't use realgud at the moment, partially because I often don't have access to more than vanilla emacs 24+. However, looking at your comint hook, it looks like you take the approach that pdbtrack takes with its comint hook, you track the actual comint buffer rather than the text string passed to the hook function. When getting pdbtrack working with term/ansi-term I use the actual text passed to my hook/advice. This was enough in my case, but there is a note in your hook comments about "piecing the text together", could you elaborate? JohnLunzer@github. – John Lunzer Jan 29 '18 at 11:43

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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