I have tried to search Google and look in the manual, but still cannot find how to get major mode of a buffer object. Can you help me with an example or a reference. Thanks
only solution I could find was to query major-mode after changing the buffer and then changing back to original buffer. Is there a better way to do it?
A simple way to do this is to use the
buffer-local-value
function sincemajor-mode
is a buffer-local variable:Just extending from previous answers - call with no arguments to get the current buffer's mode:
E.g. in *scratch* buffer:
Simply evaluate this:
Is there a problem with that?
with-current-buffer
will restore your buffer when it returns.For current buffer:
Well, describe-mode takes an optional buffer argument, but that displays the help... and I'm not exactly sure what it returns...
But that's the best I could find in a brief search... sorry...