Skip to content

Commit f36f405

Browse files
committed
[Fix clojure-emacs#384] Add cljr-auto-sort-project-dependencies
1 parent 408ab1f commit f36f405

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- [#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.
6+
- [#384](https://github.com/clojure-emacs/clj-refactor.el/issues/384) Add `cljr-auto-sort-project-dependencies`.
67

78
## 2.3.1
89

clj-refactor.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
:group 'cljr
5959
:type 'boolean)
6060

61+
(defcustom cljr-auto-sort-project-dependencies nil
62+
"If t, sort project dependencies after any command that changes them."
63+
:group 'cljr
64+
:type 'boolean)
65+
6166
(defcustom cljr-magic-requires t
6267
"Whether to automatically require common namespaces when they are used.
6368
These are the namespaces listed in `cljr-magic-require-namespaces'.
@@ -2183,6 +2188,11 @@ possible choices. If the choice is trivial, return it."
21832188
(paredit-backward-down)
21842189
(cljr-hotload-dependency))))
21852190

2191+
(defun cljr--maybe-sort-project-dependencies ()
2192+
"If allowed, sort project dependencies in the current buffer."
2193+
(when cljr-auto-sort-project-dependencies
2194+
(cljr-sort-project-dependencies)))
2195+
21862196
;;;###autoload
21872197
(defun cljr-add-project-dependency (force)
21882198
"Add a dependency to the project.clj file.
@@ -2194,7 +2204,8 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-project-depe
21942204
(cljr--prompt-user-for "Artifact: ")))
21952205
(version (thread-last (cljr--get-versions-from-middleware lib-name)
21962206
(cljr--prompt-user-for "Version: "))))
2197-
(cljr--add-project-dependency lib-name version)))
2207+
(cljr--add-project-dependency lib-name version)
2208+
(cljr--maybe-sort-project-dependencies)))
21982209

21992210
;;;###autoload
22002211
(defun cljr-update-project-dependency ()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Feature: Add project dependencies
2+
3+
Background:
4+
Given I have a project "cljr" in "tmp"
5+
And I open file "tmp/project.clj"
6+
And I clear the buffer
7+
8+
Scenario: Add project dependency without sorting
9+
When I insert:
10+
"""
11+
(defproject example-project "1.0.0"
12+
:description "Example project"
13+
:dependencies [[org.clojure/clojure "1.8.0"]
14+
[clj-time "0.12.0"]]
15+
:main example-project.core)
16+
"""
17+
And I don't want my project dependencies to be sorted automatically
18+
And I start an action chain
19+
And I press "C-! ap"
20+
And I type "com.github.bdesham/clj-plist"
21+
And I press "RET"
22+
And I type "0.10.0"
23+
And I press "RET"
24+
And I execute the action chain
25+
Then I should see:
26+
"""
27+
(defproject example-project "1.0.0"
28+
:description "Example project"
29+
:dependencies [[org.clojure/clojure "1.8.0"]
30+
[clj-time "0.12.0"]
31+
[com.github.bdesham/clj-plist "0.10.0"]]
32+
:main example-project.core)
33+
"""
34+
35+
Scenario: Add project dependency with sorting
36+
When I insert:
37+
"""
38+
(defproject example-project "1.0.0"
39+
:description "Example project"
40+
:dependencies [[org.clojure/clojure "1.8.0"]
41+
[clj-time "0.12.0"]]
42+
:main example-project.core)
43+
"""
44+
And I want my project dependencies to be sorted automatically
45+
And I press "C-! ap"
46+
And I type "com.github.bdesham/clj-plist"
47+
And I press "RET"
48+
And I type "0.10.0"
49+
And I press "RET"
50+
Then I should see:
51+
"""
52+
(defproject example-project "1.0.0"
53+
:description "Example project"
54+
:dependencies [[clj-time "0.12.0"]
55+
[com.github.bdesham/clj-plist "0.10.0"]
56+
[org.clojure/clojure "1.8.0"]]
57+
:main example-project.core)
58+
"""

features/step-definitions/clj-refactor-steps.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
(lambda ()
4141
(setq cljr-use-multiple-cursors nil)))
4242

43+
(Given "^I don't want my project dependencies to be sorted automatically"
44+
(lambda ()
45+
(setq cljr-auto-sort-project-dependencies nil)))
46+
47+
(Given "^I want my project dependencies to be sorted automatically"
48+
(lambda ()
49+
(setq cljr-auto-sort-project-dependencies t)))
50+
4351
(defun cljr--plist-to-hash (plist)
4452
(let ((h (make-hash-table)))
4553
(dolist (k (-filter #'keywordp plist))

0 commit comments

Comments
 (0)