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?

rocky
  • 888
  • 7
  • 26

1 Answers1

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) ...)
PythonNut
  • 10,243
  • 2
  • 29
  • 75
  • 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 Mar 31 '15 at 01:56
  • @rocky try this then. :) – PythonNut Mar 31 '15 at 04:36
  • I should have mentioned that I had already did: https://github.com/rocky/emacs-dbgr/commit/395db6d7723c67e86eb171feececb546b9a66a4b – rocky Mar 31 '15 at 07:11