There are no general guidelines (other than "do things in the right order" which is not helpful), but there is one thing that you probably should NOT do in the initialization file and that is to open the specific file that you will be working on: the (find-file ".../notes.org")
should not be there. Instead, you should open the file interactively with C-x C-f, after initialization is complete. That way, the settings will all have been (ahem) set by the time that you open the file and you will have fewer surprises.
In this particular case, the hook setting
(add-hook 'text-mode-hook (lambda () (flyspell-mode 1)))
would be done as part of initialization, and it would be ready and waiting for you when you open the file to work on it. Note, BTW, that dolist
is a looping construct and since you are only setting one hook here, you do not need a loop.
The why is a bit complicated and understanding it will come with experience. But the gist of it is that often you customize the behavior of emacs by setting hooks
: these are variables whose values are lists of functions. A hook is run at a specific time in the processing of e.g. a file, and when it is run, it executes each function in the list. In this case, you are adding a function to the hook text-mode-hook
. When that function is run, it turns on flyspell mode in the buffer that is visiting the file.
This particular hook is run whenever a text
file is visited. There are many types of files that are considered text files by emacs: org files is one type of text file.
So when you open your org file, emacs creates a buffer that visits that file; it then determines that it is a text file and runs the text-mode-hook
. When the hook is run, it executes the function that you added to it, which enables flyspell mode.
So you see that in order for that to happen, the hook has to be set BEFORE you open the file. If you do it in the other order, the hook is not set when you open the file (its value is nil
, the empty list). Everything happens as before, but when emacs comes to run the hook, it finds NO functions added to it, so nothing happens.
As I said before, all of this will become clearer with experience (and by reading the emacs manuals): for many of us in this forum, emacs has been our work environment for many years - and we are still learning. So, don't be discouraged (or annoyed): it's a journey of a thousand miles and you are just taking the first step.