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 .projectile file).

1 Answer 1


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 mybuild.sh:

(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)
  • In my case, due to I use projectile - (projectile-verify-file "mybuild.sh")
    – denys
    Oct 31, 2016 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.