Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #451] respect project root dir suggested by custom function #452

Merged
merged 6 commits into from
Oct 8, 2017
Merged

[Fix #451] respect project root dir suggested by custom function #452

merged 6 commits into from
Oct 8, 2017

Conversation

mbuczko
Copy link
Contributor

@mbuczko mbuczko commented Oct 6, 2017

This is a humble attempt to get clojure-mode respecting project root directory suggested by a custom function (like projectile-project-root), as described in #451

@mbuczko mbuczko changed the title [Fix #451] respect project root dir suggested by projectile [Fix #451] respect project root dir suggested by custom function Oct 6, 2017
clojure-mode.el Outdated
(when (> (length choices) 0)
(car (sort choices #'file-in-directory-p)))))
(or (and (fboundp clojure-project-root-locating-function)
(condition-case err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just ignore-errors

clojure-mode.el Outdated
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a type: 'function

clojure-mode.el Outdated
(defcustom clojure-project-root-locating-function nil
"Alternative function to locate clojure project root directory, eg. projectile-project-root"
:type 'symbol
:safe 'symbolp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is funcalled, so no value is safe for it. In fact, we should probably mark it as risky.

clojure-mode.el Outdated
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name this just clojure-project-root-function.

clojure-mode.el Outdated
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why alternative - let's just set it by default to the currently existing function.

clojure-mode.el Outdated
@@ -1607,8 +1612,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 clojure-project-root-locating-function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd simply remove those check here - if the user set something explicitly we can assume they know what they are doing. Fallbacks are pointless and confusing here.

clojure-mode.el Outdated
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defcustom should also have a :package-version property pointing this was added in version 5.7.0.

@vspinu
Copy link
Contributor

vspinu commented Oct 7, 2017

Shouldn't this be using project-find-functions (new emacs 25 functionality in project.el)? If users can already add hooks to project-find-functions, then this functionality seems redundant.

@bbatsov
Copy link
Member

bbatsov commented Oct 7, 2017

Shouldn't this be using project-find-functions (new emacs 25 functionality in project.el)? If users can already add hooks to project-find-functions, then this functionality seems redundant.

In theory - yes. In practice this is more or less a prototype that wasn't really polished. I was actually discussing this with its author just a couple of days ago. He wanted us to collaborate on providing more extension points for Projectile, but frankly I don't really see much point in working towards this universal API given the fact I'm not really interested in using it and apart from a few generic functions each project management library has way too many specifics to it. On the other side - this could allow a lot of modes to drop at least the product root detection code they cart along.

@mbuczko
Copy link
Contributor Author

mbuczko commented Oct 7, 2017

@bbatsov I applied your suggestions but to get rid of unnecessary fallbacks and set clojure-project-root-function customization by default to the function currently used to calculate project root path I had to split clojure-project-dir into 2 parts. I'm not sure if that's done right, any comments nicely welcomed :)

@bbatsov
Copy link
Member

bbatsov commented Oct 7, 2017

Why did you split it in two? I don't see any reason to do, even after taking a look at the code.

@mbuczko
Copy link
Contributor Author

mbuczko commented Oct 7, 2017

This was to set clojure-project-root-function to default value (function) which would call what we have right now in clojure-mode to calculate root-path. I couldn't set it up simply to clojure-project-dir as having my funcall inside, this function would be called in recursive loop (funcall would call clojure-project-dir again which in turn would call funcall and so on...).

@bbatsov
Copy link
Member

bbatsov commented Oct 7, 2017

Ah, yeah - the name you have to the old function confused me a bit. This looks ok overall.

clojure-mode.el Outdated
@@ -192,6 +192,12 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the ' to a #'

@Malabarba
Copy link
Member

Besides that last comment, it looks good to me.

@bbatsov
Copy link
Member

bbatsov commented Oct 8, 2017

It still needs a changelog entry.

clojure-project-root-function defaults to #'clojure-project-root-path now.
@mbuczko
Copy link
Contributor Author

mbuczko commented Oct 8, 2017

Changelog updated.

@bbatsov bbatsov merged commit 35f5d71 into clojure-emacs:master Oct 8, 2017
slipset pushed a commit to slipset/clojure-mode that referenced this pull request Nov 1, 2017
@dgutov
Copy link
Contributor

dgutov commented Nov 2, 2017

this could allow a lot of modes to drop at least the product root detection code they cart along

It would allow e.g. M-x project-find-regexp to use Projectile. And some other functions in core Emacs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants