From beed375f7726b2135776639ad510006d9744517c Mon Sep 17 00:00:00 2001 From: Michal Buczko Date: Fri, 6 Oct 2017 17:19:20 +0100 Subject: [PATCH 1/6] [Fix #451] respect project root dir suggested by projectile --- clojure-mode.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clojure-mode.el b/clojure-mode.el index 8ed7f5f9..0dc66d75 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -1607,8 +1607,12 @@ Return nil if not inside a project." (mapcar (lambda (fname) (locate-dominating-file dir-name fname)) clojure-build-tool-files)))) - (when (> (length choices) 0) - (car (sort choices #'file-in-directory-p))))) + (or (and (fboundp 'projectile-project-root) + (condition-case err + (projectile-project-root) + (error nil))) + (when (> (length choices) 0) + (car (sort choices #'file-in-directory-p)))))) (defun clojure-project-relative-path (path) "Denormalize PATH by making it relative to the project root." From 5ffb46c2b28e5d4cf2a728fe300b793591fabca1 Mon Sep 17 00:00:00 2001 From: Michal Buczko Date: Fri, 6 Oct 2017 19:18:37 +0100 Subject: [PATCH 2/6] Added customizable function to locate project root directory --- clojure-mode.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clojure-mode.el b/clojure-mode.el index 0dc66d75..ef948bd3 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -192,6 +192,11 @@ Out-of-the box `clojure-mode' understands lein, boot and gradle." (and (listp value) (cl-every 'stringp value)))) +(defcustom clojure-project-root-locating-function nil + "Alternative function to locate clojure project root directory, eg. projectile-project-root" + :type 'symbol + :safe 'symbolp) + (defcustom clojure-refactor-map-prefix (kbd "C-c C-r") "Clojure refactor keymap prefix." :type 'string @@ -1607,9 +1612,9 @@ Return nil if not inside a project." (mapcar (lambda (fname) (locate-dominating-file dir-name fname)) clojure-build-tool-files)))) - (or (and (fboundp 'projectile-project-root) + (or (and (fboundp clojure-project-root-locating-function) (condition-case err - (projectile-project-root) + (funcall clojure-project-root-locating-function) (error nil))) (when (> (length choices) 0) (car (sort choices #'file-in-directory-p)))))) From 3e58acd55aea7c44e9f00b904567c6dcf5db88f8 Mon Sep 17 00:00:00 2001 From: Michal Buczko Date: Sat, 7 Oct 2017 17:53:02 +0100 Subject: [PATCH 3/6] Customization renamed to clojure-project-root-function Type changed to function and marked as risky. --- clojure-mode.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/clojure-mode.el b/clojure-mode.el index ef948bd3..85e5c1b7 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -192,10 +192,11 @@ Out-of-the box `clojure-mode' understands lein, boot and gradle." (and (listp value) (cl-every 'stringp value)))) -(defcustom clojure-project-root-locating-function nil - "Alternative function to locate clojure project root directory, eg. projectile-project-root" - :type 'symbol - :safe 'symbolp) +(defcustom clojure-project-root-function 'clojure-project-dir + "Function to locate clojure project root directory." + :type 'function + :risky t + :package-version '(clojure-mode . "5.7.0")) (defcustom clojure-refactor-map-prefix (kbd "C-c C-r") "Clojure refactor keymap prefix." @@ -1612,10 +1613,8 @@ Return nil if not inside a project." (mapcar (lambda (fname) (locate-dominating-file dir-name fname)) clojure-build-tool-files)))) - (or (and (fboundp clojure-project-root-locating-function) - (condition-case err - (funcall clojure-project-root-locating-function) - (error nil))) + (or (ignore-errors + (funcall clojure-project-root-function)) (when (> (length choices) 0) (car (sort choices #'file-in-directory-p)))))) From 766fc5bf8b6432eaa6b8d8f359936fd16b204c99 Mon Sep 17 00:00:00 2001 From: Michal Buczko Date: Sat, 7 Oct 2017 19:36:23 +0100 Subject: [PATCH 4/6] clojure-project-dir delegates call to clojure-project-root-function --- clojure-mode.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clojure-mode.el b/clojure-mode.el index 85e5c1b7..03554772 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -192,7 +192,7 @@ Out-of-the box `clojure-mode' understands lein, boot and gradle." (and (listp value) (cl-every 'stringp value)))) -(defcustom clojure-project-root-function 'clojure-project-dir +(defcustom clojure-project-root-function 'clojure-project-root-path "Function to locate clojure project root directory." :type 'function :risky t @@ -1606,6 +1606,13 @@ nil." (defun clojure-project-dir (&optional dir-name) "Return the absolute path to the project's root directory. +Call is delegated down to `clojure-project-root-function' with +optional DIR-NAME as argument." + (funcall clojure-project-root-function dir-name)) + +(defun clojure-project-root-path (&optional dir-name) + "Return the absolute path to the project's root directory. + Use `default-directory' if DIR-NAME is nil. Return nil if not inside a project." (let* ((dir-name (or dir-name default-directory)) From cd71981f0ff6373bd4c567b345004d1377957743 Mon Sep 17 00:00:00 2001 From: Michal Buczko Date: Sat, 7 Oct 2017 19:49:19 +0100 Subject: [PATCH 5/6] Got rid of unecessary funcall --- clojure-mode.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clojure-mode.el b/clojure-mode.el index 03554772..3a9ffc81 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -1620,10 +1620,8 @@ Return nil if not inside a project." (mapcar (lambda (fname) (locate-dominating-file dir-name fname)) clojure-build-tool-files)))) - (or (ignore-errors - (funcall clojure-project-root-function)) - (when (> (length choices) 0) - (car (sort choices #'file-in-directory-p)))))) + (when (> (length choices) 0) + (car (sort choices #'file-in-directory-p))))) (defun clojure-project-relative-path (path) "Denormalize PATH by making it relative to the project root." From 607a2ce6bcb448c7bf67eff5e0ba60dd93a614ea Mon Sep 17 00:00:00 2001 From: Michal Buczko Date: Sun, 8 Oct 2017 10:45:17 +0100 Subject: [PATCH 6/6] Changelog updated. clojure-project-root-function defaults to #'clojure-project-root-path now. --- CHANGELOG.md | 1 + clojure-mode.el | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da1a6d9d..3006d136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [#443](https://github.com/clojure-emacs/clojure-mode/issues/443): Fix behavior of `clojure-forward-logical-sexp` and `clojure-backward-logical-sexp` with conditional macros. * [#429](https://github.com/clojure-emacs/clojure-mode/issues/429): Fix a bug causing last occurrence of expression sometimes is not replaced when using `move-to-let`. * [#423](https://github.com/clojure-emacs/clojure-mode/issues/423): Make `clojure-match-next-def` more robust against zero-arity def-like forms. +* [#451](https://github.com/clojure-emacs/clojure-mode/issues/451): Make project root directory calculation customized by `clojure-project-root-function` ### New features diff --git a/clojure-mode.el b/clojure-mode.el index 3a9ffc81..11a4ab66 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -192,7 +192,7 @@ Out-of-the box `clojure-mode' understands lein, boot and gradle." (and (listp value) (cl-every 'stringp value)))) -(defcustom clojure-project-root-function 'clojure-project-root-path +(defcustom clojure-project-root-function #'clojure-project-root-path "Function to locate clojure project root directory." :type 'function :risky t