Use derived-mode-p.