2

I have Emacs Lisp program that I want to work inside either a comint process buffer or an eshell buffer. The code I currently am using is:

https://github.com/rocky/emacs-dbgr/blob/master/realgud/common/track-mode.el#L141-L147

but this is a bit ugly and might be prone to breakage if either the comint or eshell changes.

Any suggestions?

1 Answer 1

4

You can test the current major-mode by querying the major-mode variable.

(if (eq major-mode 'eshell-mode) ...)
(if (eq major-mode 'comint-mode) ...)

If you would like to test a mode, and all of it's child modes, try this instead:

(if (derived-mode-p 'eshell-mode) ...)
(if (derived-mode-p 'comint-mode) ...)
3
  • This is simple and works. Why didn't I think of it? But things are a little more complicated. shell-mode has a parent mode of comint-mode. I could add a test for that as well, but it would be great to handle the general parent-mode case. (If other/better suggestions for handling derived-from-parent-modes, I'll accept this in a day.)
    – rocky
    Commented Mar 31, 2015 at 1:56
  • @rocky try this then. :)
    – PythonNut
    Commented Mar 31, 2015 at 4:36
  • I should have mentioned that I had already did: github.com/rocky/emacs-dbgr/commit/…
    – rocky
    Commented Mar 31, 2015 at 7:11

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.