I have auto-insert-mode configured to insert a basic XML file in nxml-mode, but nxml-mode is then still configured to use an empty schema, as if the file was still empty. How can I automatically make nxml-mode use the correct schema corresponding to the template? Set schema automatically in the menus does work, but I want to run this automatically.
I never used that but looking at the documentation and code, I think
the function you're talking about is
rng-validate-mode. This minor mode is enabled by default with
Here is what
(if auto-insert-mode (add-hook 'find-file-hook 'auto-insert) (remove-hook 'find-file-hook 'auto-insert)))
The problem is probably that
find-file-hook is considered only after the
major mode has been selected, so
rng-auto-set-schema is called
before your snippet is actually inserted in the buffer.
auto-insert apparently does not provide any hooks, I see two ways to work around that:
auto-insertso that after inserting, it calls
rng-auto-set-schemaif major mode is
add a hook at the end of
find-file-hookto do the same thing.
Here's a tentative for the second solution:
(defun my-set-schema-if-nxml () (if (eq major-mode 'nxml-mode) (rng-auto-set-schema))) (add-hook 'find-file-hook 'my-set-schema-if-nxml t)