Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Introduce inf-clojure-project-type defcustom #114

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

Merged
merged 1 commit into from
Dec 13, 2017

Conversation

arichiardi
Copy link
Contributor

This patch adds a defcustom, inf-clojure-skip-project-detection, that when
non-nil skips the project detection so that only inf-clojure-generic-cmd will
be used. This is very useful for projects that don't have standard layouts.


  • The commits are consistent with our [contribution guidelines][1]
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)

@bbatsov
Copy link
Member

bbatsov commented Nov 4, 2017

Frankly, I don't understand what exactly is the point of doing this change. You can always override the lein/boot command for a specific project, so if something is lein/boot and you need a different command to be used the option is always there for you. If it's not - you end up using the generic command anyways.

@arichiardi
Copy link
Contributor Author

I know very well that trick, using it all the time. However the scenario here is different: in lumo projects you don't need to have a build.boot or a project.clj...except that sometimes you want to resolve maven dependencies, which comes afterwards in most of my projects.

So all of a sudden you introduce the file (say project.clj) and boom, nothing works anymore because now inf-clojure detects and wants you to customize inf-clojure-lein-cmd. Ok I am going to do it. Say some time ago you realize that you want to switch to build.boot, because it is better (it really is faster for maven resolution). Boom again, now you have to customize inf-clojure-boot-cmd.

This back and forth happens in many scenarios (one other weird one is when you generate a project with lein new but you are not actually using lein, it is just for having a ready project.clj).

My rationale on this is that when I am in a lumo project I want to be able to decide what to do independently from the project type.

@bbatsov
Copy link
Member

bbatsov commented Nov 13, 2017

I think what you really want to do is not to skip project detection but to be able to specify a generic project type via .dir-locals.el. That'd be the Emacs way of doing things.

@arichiardi
Copy link
Contributor Author

I am fine with that too, it still involves adding one more line in .dir-locals.el, same as this patch. Probably no difference. Will try that out cause if no patch necessary it its better.

@arichiardi
Copy link
Contributor Author

Hello again @bbatsov, I have checked the code but it seems that there is no defcustom for project type.

What would you suggest me to do here? Add one for project type? Then we'd need also a more flexible one for the command..(handle any possible commands for any possible project type?).

Seems like a bigger change.

@arichiardi
Copy link
Contributor Author

So to explain the problem better, in my folder I have both project.clj and build.boot and this is my .dir-locals.el with this patch.

((nil . ((eval . (add-hook 'clojure-mode-hook #'inf-clojure-minor-mode))
         (inf-clojure-repl-use-same-window . "different")
         (inf-clojure-skip-project-detection . t)
         (inf-clojure-generic-cmd . ("localhost" . 5044)))))

@bbatsov
Copy link
Member

bbatsov commented Nov 20, 2017

What would you suggest me to do here? Add one for project type? Then we'd need also a more flexible one for the command..(handle any possible commands for any possible project type?).

This just had to be checked by the inf-clojure-project-type command and take precedence over the existing detection logic. Doesn't seem like a big change to me.

@arichiardi
Copy link
Contributor Author

arichiardi commented Nov 21, 2017

Got it, so you would prefer to create a defcustom containing a custom project type.

What would the project type use as -cmd? I am not that elisp expert, can you create a defvar like inf-clojure-${project-type}-cmd from .dir-locals.el?

At the moment we have three defcustom: inf-clojure-boot-cmd, inf-clojure-lein-cmd and the catch all inf-clojure-generic-cmd.

@arichiardi
Copy link
Contributor Author

I see in projectile something like this, which makes total sense, but this changes things a bit:

(projectile-register-project-type 'npm '("package.json")
				  :compile "npm install"
				  :test "npm test"
				  :run "npm start"
				  :test-suffix ".spec")

@arichiardi
Copy link
Contributor Author

Maybe our detection can interact with projectile and see if there is a declared project type already and use that command declared in there. Projectile would need to handle the :repl tag though.

Fairly complicated I know, I still like my small hack better.

@bbatsov
Copy link
Member

bbatsov commented Dec 1, 2017

Got it, so you would prefer to create a defcustom containing a custom project type.

A defvar actually. It shouldn't be a custom project type. Just something that overrides the regular detection, that in your case you'd set to generic and also override the generic cmd.

Seems to me that this solves your problem completely.

Maybe our detection can interact with projectile and see if there is a declared project type already and use that command declared in there. Projectile would need to handle the :repl tag though.

We can always add some integration with projectile as well - that'd be pretty simple. But this should be something optional, as we don't want to force Projectile on everyone.

@arichiardi
Copy link
Contributor Author

arichiardi commented Dec 1, 2017

Isn't a defvar that overrides the logic exactly what I am doing? Maybe I don't understand your solution here.

@arichiardi
Copy link
Contributor Author

The inf-clojure-skip-project-detection overrides code detection so that we always take the generic command.

@bbatsov
Copy link
Member

bbatsov commented Dec 2, 2017

Yeah, but you're making something very specific (you can just make something generic) and it should be able to force whatever project type you want to. That's what started all of my comments. I don't like very specific options, normally I'd make something as generic as possible.

inf-clojure.el Outdated
@@ -189,6 +189,15 @@ number (e.g. (\"localhost\" . 5555))."
(stringp (car x))
(numberp (cdr x))))

(defcustom inf-clojure-skip-project-detection nil
Copy link
Member

Choose a reason for hiding this comment

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

Basically this should be inf-clojure-project-type and the docstring should say it's purpose is to override the default project type resolution via .dir_locals.el.

(let ((default-directory (inf-clojure-project-root)))
(cond ((file-exists-p "project.clj") "lein")
((file-exists-p "build.boot") "boot")
(t nil))))
Copy link
Member

Choose a reason for hiding this comment

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

We should be returning "generic" if the project type can't be determined, so we can leverage the defcustom - if it's nil it does nothing, otherwise it takes precedence over this.

@bbatsov
Copy link
Member

bbatsov commented Dec 2, 2017

I've explained in the code exactly what I mean. Hopefully now you understand me.

@arichiardi
Copy link
Contributor Author

Thanks should be clear now, will change this patch.

@arichiardi arichiardi changed the title Introduce inf-clojure-skip-project-detection Introduce inf-clojure-project-type defcustom Dec 12, 2017
@arichiardi
Copy link
Contributor Author

@bbatsov done, can you review please. I want to be sure I got it right.

inf-clojure.el Outdated
(cond ((file-exists-p "project.clj") "lein")
((file-exists-p "build.boot") "boot")
(t nil))))
(when (null inf-clojure-project-type)
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you use or here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No wait, the code should run if this is nil. So basically something else than nil will not trigger the detection.

Copy link
Member

Choose a reason for hiding this comment

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

Well, that's what or will do - (or type (detect-type)). That seems pretty clear to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I was confused for a moment 😄

This patch adds a defcustom, inf-clojure-project-type, so that when it is
not-nil we skip the project detection and choose which inf-clojure-*-cmd will
be used.  This is very useful for projects that don't have standard layouts.
@bbatsov bbatsov merged commit 5d76920 into clojure-emacs:master Dec 13, 2017
@arichiardi arichiardi deleted the skip-prj-detection branch January 2, 2018 02:58
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.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.