I'm writing a custom build mode (mybuild-mode) for custom build tool and want that mode to be autoloaded in case I'm in the folder which contains
mybuild.sh file. Also my mode depends on projectile (so the directory should contain the
I assume that your
mybuild-mode is actually a minor mode that should be loaded additionally to the major mode for your source files.
In this case you can use
find-file-hook to activate that minor mode depending on the presence of
(define-minor-mode mybuild-mode "Mode activated if mybuild.sh file is present in the same directory." :lighter " ⚒" (if mybuild-mode (message "Doing some stuff at start-up.") (message "Doing some stuff at shutting-down."))) (defun mybuild-start-maybe () "Starts mybuild-mode if mybuild.sh is present in `default-directory'." (when (file-readable-p "mybuild.sh") (mybuild-mode t))) (add-hook 'find-file-hook #'mybuild-start-maybe)