Inspect the value of the variable major-mode
. From the docs:
Symbol for current buffer’s major mode. The default value (normally ‘fundamental-mode’) affects new buffers. A value of nil means to use the current buffer’s major mode, provided it is not marked as "special".
Example:
(defun example ()
(cond ((eq major-mode 'foo-mode) (foo))
((eq major-mode 'bar-mode) (bar))))