diff --git a/julia-mode.el b/julia-mode.el index 57c2874..78ff357 100644 --- a/julia-mode.el +++ b/julia-mode.el @@ -38,6 +38,7 @@ (require 'cl-lib) (require 'julia-mode-latexsubs) +(require 'project nil t) (defvar julia-mode-hook nil) @@ -758,7 +759,14 @@ Return nil if point is not in a function, otherwise point." (setq-local end-of-defun-function #'julia-end-of-defun) (setq indent-tabs-mode nil) (setq imenu-generic-expression julia-imenu-generic-expression) - (imenu-add-to-menubar "Imenu")) + (imenu-add-to-menubar "Imenu") + ;; project.el integration + (when (featurep 'project) + (add-hook 'project-find-functions + (lambda (dir) + (let ((root (or (locate-dominating-file dir "JuliaProject.toml") + (locate-dominating-file dir "Project.toml")))) + (when root (cons 'julia root))))))) (defun julia-manual-deindent () "Deindent by `julia-indent-offset' regardless of current @@ -819,6 +827,19 @@ following commands are defined: (if julia-math-mode (setq-local LaTeX-math-insert-function #'julia-math-insert))))) +;;; project.el integration +;; project.el was added to emacs in 25.1, so we can't assume it's available +(when (featurep 'project) + (defun julia--project-try (dir) + "Return project instance if DIR is part of a Julia project. +Otherwise return nil." + (let ((root (or (locate-dominating-file dir "JuliaProject.toml") + (locate-dominating-file dir "Project.toml")))) + (when root (cons 'julia root)))) + + (cl-defmethod project-roots ((project (head julia))) + (list (cdr project)))) + ;; Code for `inferior-julia-mode' (require 'comint)