安裝nix并配置channel:
sudo install -d -m755 -o $(id -u) -g $(id -g) /nix
curl https://nixos.org/nix/install | sh
nix-channel --add https://nixos.org/channels/nixos-20.03 nixos-20.03
nix-channel --update nixos-20.03
安裝gradle:
nix-env -f ~/.nix-defexpr/channels/nixos-20.03 -iA gradle
安裝emacs:
nix-env -f ~/.nix-defexpr/channels/nixos-20.03 -iA emacs
配置emacs:
創(chuàng)建并拷貝github文件內(nèi)容至~/.emacs.d/init.el
https://github.com/clojurians-org/my-emacs/blob/master/init.el
- 安裝paredit插號被合及開發(fā)工具cider
(dolist (package '(paredit restclient json-mode typescript-mode
dap-mode lsp-java gradle-mode
dante cider
))
(unless (package-installed-p package)
(package-install package)))
- 開啟paredit-mode
(add-hook 'clojure-mode-hook #'enable-paredit-mode)
創(chuàng)建項(xiàng)目:
初始化為java項(xiàng)目
larrys-MacBook-Pro:my-test larluo$ mkdir my-test
larrys-MacBook-Pro:my-test larluo$ cd my-test
larrys-MacBook-Pro:my-test larluo$ gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 3
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6]
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2]
Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4]
Project name (default: my-test):
Source package (default: my.test):
> Task :init
Get more help with your project: https://docs.gradle.org/5.6.1/userguide/java_library_plugin.html
BUILD SUCCESSFUL in 5m 14s
2 actionable tasks: 2 executed
添加clojure repl支持
修改build.gradle文件內(nèi)容
- 添加clojure gradle插件
plugins { $
// Apply the java-library plugin to add support for Java Library $
id 'java-library' $
id 'dev.clojurephant.clojure' version '0.5.0' $
} $
- 設(shè)置國內(nèi)源
repositories {
maven {
url "https://mirrors.tuna.tsinghua.edu.cn/clojars/"
}
maven {
url "http://maven.aliyun.com/nexus/content/groups/public"
}
mavenLocal()
}
- 添加依賴
dependencies {
api 'commons-codec:commons-codec:1.14'
implementation 'org.clojure:clojure:1.10.1'
devImplementation 'cider:cider-nrepl:0.24.0'
testImplementation 'junit:junit:4.12'
}
- 配置emacs cider hook:
clojureRepl {
handler = 'cider.nrepl/cider-nrepl-handler'
}
使用emacs編碼
- 創(chuàng)建并打開文件
mkdir -p src/main/clojure
emacs -nw src/main/clojure/larluo.clj
- 導(dǎo)入項(xiàng)目
i==>Import project root /Users/larluo/my-tmp/my-test/src/main/java/my/test/.
I==>Import project by selecting root directory interactively.
d==>Do not ask again for the current project by adding /Users/larluo/my-tmp/my-test/src/main/java/my/test/ to lsp-session-folders-b\
lacklist.
D==>Do not ask again for the current project by selecting ignore path interactively.
n==>Do nothing: ask again when opening other files from the current project.
選擇I, 輸入項(xiàng)目目錄锦茁,后續(xù)可變改
- 啟動(dòng)cider repl進(jìn)行開發(fā)
https://github.com/clojure-emacs/cider
輸入C-c, A-j 啟動(dòng)cider
移動(dòng)代碼颇象,執(zhí)行C-x, C-e運(yùn)行代碼