The short answer is:
M-x eval-buffer in the Lisp buffer then
M-x normal-mode in the XYZ mode buffer.
To test the changes in your mode, you need to do two things: load the modified Lisp code, and apply the modifications to the buffer.
To load the modified Lisp code,
M-x eval-buffer in
xyz-mode.el mostly works, but there are a few limitations. This runs all the code in the buffer, and in particular it updates all the function definitions. However the values of variables set by
defvar and the like (
defface) are not updated:
defvar does not change the value of a variable that already has one. Updating the value of an existing variable when evaluating a
defvar form is a special feature of
C-M-x). Keeping the value of an existing variable is the right thing when it has been set by the user, but when it was set by a previous version of the code, you aren't testing the new code.
xyz-mode code was originally loaded by
require or the like, you can run
M-x unload-feature xyz-mode RET to unload all the definitions provided by the loaded module, then re-run the code that would load or autoload the module (e.g. re-evaluate
(autoload 'xyz-mode "xyz-mode")). This way you'll get the new value for all variables, as long as those variables were loaded as part of the module. Also, if you removed some definition as part of your changes, it won't exist anymore, so you don't risk validating code that's actually using a definition that no longer exists. But note that variables and functions that were created with
C-M-x during development won't have been unloaded since they weren't recorded as being part of the module.
Whatever method you use to load the changed implementation of the major mode, you also need to apply the changes to the existing buffer. Reloading the Lisp code applies some changes automatically, but some things require initialization in each buffer (e.g. syntax table, keymap, sometimes font lock settings). Re-run the major mode function in the
M-x xyz-mode RET or (assuming the mode is the default for a file by that name)
M-x normal-mode RET or
M-x revert-buffer RET.
If this was a minor mode, turn it off and back on.
There is still a risk that the new code accidentally depends on some old feature that still exists in your session. Therefore, I recommend that from time to time, you run a new Emacs session to test the file. Keep your existing Emacs session open and run a new one just with the
abc.xyz file to see that all is well. Do keep your existing Emacs session, so that for instance if you wrote a new function and then accidentally deleted it, you can recover it through undo or through the kill ring.