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 #384] Add cljr-auto-sort-project-dependencies #385

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- [#394](https://github.com/clojure-emacs/clj-refactor.el/issues/394) New config option `cljr-assume-language-context`: by default, when clj-refactor encounters an ambiguous context (clj vs cljs) it creates a popup asking user which context is meant. If this option is changed to "clj" or "cljs", clj-refactor will use that as the assumed context in such ambigous cases.
- [#384](https://github.com/clojure-emacs/clj-refactor.el/issues/384) Add `cljr-auto-sort-project-dependencies`.

## 2.3.1

Expand Down
13 changes: 12 additions & 1 deletion clj-refactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
:group 'cljr
:type 'boolean)

(defcustom cljr-auto-sort-project-dependencies nil
"If t, sort project dependencies after any command that changes them."
:group 'cljr
:type 'boolean)

(defcustom cljr-magic-requires t
"Whether to automatically require common namespaces when they are used.
These are the namespaces listed in `cljr-magic-require-namespaces'.
Expand Down Expand Up @@ -2183,6 +2188,11 @@ possible choices. If the choice is trivial, return it."
(paredit-backward-down)
(cljr-hotload-dependency))))

(defun cljr--maybe-sort-project-dependencies ()
"If allowed, sort project dependencies in the current buffer."
(when cljr-auto-sort-project-dependencies
(cljr-sort-project-dependencies)))

;;;###autoload
(defun cljr-add-project-dependency (force)
"Add a dependency to the project.clj file.
Expand All @@ -2194,7 +2204,8 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-project-depe
(cljr--prompt-user-for "Artifact: ")))
(version (thread-last (cljr--get-versions-from-middleware lib-name)
(cljr--prompt-user-for "Version: "))))
(cljr--add-project-dependency lib-name version)))
(cljr--add-project-dependency lib-name version)
(cljr--maybe-sort-project-dependencies)))

;;;###autoload
(defun cljr-update-project-dependency ()
Expand Down
58 changes: 58 additions & 0 deletions features/add-project-dependency.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Feature: Add project dependencies

Background:
Given I have a project "cljr" in "tmp"
And I open file "tmp/project.clj"
And I clear the buffer

Scenario: Add project dependency without sorting
When I insert:
"""
(defproject example-project "1.0.0"
:description "Example project"
:dependencies [[org.clojure/clojure "1.8.0"]
[clj-time "0.12.0"]]
:main example-project.core)
"""
And I don't want my project dependencies to be sorted automatically
And I start an action chain
And I press "C-! ap"
And I type "com.github.bdesham/clj-plist"
And I press "RET"
And I type "0.10.0"
And I press "RET"
And I execute the action chain
Then I should see:
"""
(defproject example-project "1.0.0"
:description "Example project"
:dependencies [[org.clojure/clojure "1.8.0"]
[clj-time "0.12.0"]
[com.github.bdesham/clj-plist "0.10.0"]]
:main example-project.core)
"""

Scenario: Add project dependency with sorting
When I insert:
"""
(defproject example-project "1.0.0"
:description "Example project"
:dependencies [[org.clojure/clojure "1.8.0"]
[clj-time "0.12.0"]]
:main example-project.core)
"""
And I want my project dependencies to be sorted automatically
And I press "C-! ap"
And I type "com.github.bdesham/clj-plist"
And I press "RET"
And I type "0.10.0"
And I press "RET"
Then I should see:
"""
(defproject example-project "1.0.0"
:description "Example project"
:dependencies [[clj-time "0.12.0"]
[com.github.bdesham/clj-plist "0.10.0"]
[org.clojure/clojure "1.8.0"]]
:main example-project.core)
"""
8 changes: 8 additions & 0 deletions features/step-definitions/clj-refactor-steps.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
(lambda ()
(setq cljr-use-multiple-cursors nil)))

(Given "^I don't want my project dependencies to be sorted automatically"
(lambda ()
(setq cljr-auto-sort-project-dependencies nil)))

(Given "^I want my project dependencies to be sorted automatically"
(lambda ()
(setq cljr-auto-sort-project-dependencies t)))

(defun cljr--plist-to-hash (plist)
(let ((h (make-hash-table)))
(dolist (k (-filter #'keywordp plist))
Expand Down