Now I'm trying to use .dir-locals.el for my own projects. However it is saved at the end of init.el whenever I choose to save it permanently. I'd like to change it to an another seperate file - eg ~/mydirlocals.el.
Please let me know what could be the solution for this.
PS : I've already tried to change custom file to a seperate one. But unfortunately it saved my dir-local variables with other custom variables. I want to avoid this and save my dir-locals variables in a completely seperate file.
You can't use the customize interface to update
.dir-locals.el
files. Customize is for your own config. If you want to edit/update a directory-local variables file, you need to either edit that file directly, or use M-xadd-dir-local-variable
.The latter command will prompt you for the details. Note that no default value is offered at the prompt for the value of the variable, but that you can type M-n or <down> to obtain the variable's value in the current buffer.
Note also that the command does not ask which directory the variables are local to -- it will create/update a
.dir-locals.el
file in the default directory for the current buffer. Issuing the command from a dired buffer for the intended directory is a safe approach, naturally, but you may wish to do so from a buffer in the mode for which you wish to add variables -- that way the default suggestion for the mode, and the current values of the variables in question, will be more useful to you.(If there is no file of the appropriate type in the directory, you can always C-xC-f a new/unsaved buffer of an appropriate filename, use
add-dir-local-variable
as many times as necessary, and then when you're done just kill any new buffers you created without saving them.)That all said, I'm still not 100% sure what your requirement is, as your question is a little confused; but you may also like to know that you can use directory-local variables without a
.dir-locals.el
file at all, as you can alternatively configure them entirely in your init file.See https://www.emacswiki.org/emacs/DirectoryVariables for details and examples of that.