default-major-mode is processed in the c function 'set-buffer-major-mode'
which is called by 'find-file-noselect' in files.el
default-major-mode is also called in normal-mode, except when it is
explicitly disabled by the find-file parameter which is passed in by
after-find-file which is called by find-file-noselect.
When the default-major-mode is called, none of the buffer local
variables (like buffer-file-name, default-directory) have been set
with an appropriate value. This usually isn't a problem, except when
text-mode-hooks are running that want to look at the variables of the
current buffer.
For example:
(defun flyspell-mode-check (&rest args)
(if (flyspell-enable-p (buffer-file-name (current-buffer))) (flyspell-mode)))
(add-hook 'text-mode-hook 'flyspell-mode-check)
Basically, I want to turn on flyspell in all text mode files, except
for certain kinds of text files like big log files or csv files. And
I want the default mode to be text-mode.
Unfortunately, the problem is that the code in files.el seems to be
carefully designed to prevent this type of hook from working. It
took me a couple of hours to understand what was going on. I think
this is a flaw in the handling of default-major-mode.
So, I think the code in files.el should be changed in the following
way -
change (normal-mode t) to (normal-mode nil) in after-find-file
and change (set-buffer-major-mode buf) to (set-buffer-fundamental-mode buf)
where (set-buffer-fundamental-mode buf) is equivalent to
(let ((default-major-mode 'fundamental-mode)) (set-buffer-major-mode buf))
-jeff