ITADN
bhauman/rebel-readline
bhauman/rebel-readline · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

Rebel Readline

Clojars Project Clojars Project Clojars Project

欢迎使用 Rebel Readline – 一款炫酷的 Clojure 终端 REPL!

asciicast

功能

Rebel Readline 提供了一个 Clojure REPL,具备以下特性:

  • 轻松的多行编辑
  • 自动缩进
  • TAB 补全
  • 输入函数名后显示参数文档
  • 内联求值,允许在不按回车键的情况下求值代码
  • 快速访问光标下符号的文档、源码和 apropos
  • 熟悉的终端键绑定,包括历史搜索等

Rebel Readline 也是一个为 Clojure 方言提供行读取器的库。

目的

有关创建此终端 readline 库背后的动机,请参阅此处

nREPL 支持

最近的更新包括 nREPL 支持。详情参见 rebel-readline-nrepl

重要说明

行读取器需要直接访问终端。因此,请勿使用 clj 或任何其他 readline 进程(如 rlwrap)启动 Rebel Readline,以避免冲突。请使用以下选项之一启动 JVM:

  • java 命令
  • Clojure clojure 工具(不带 readline 支持)
  • lein trampoline
  • boot(必须在 Boot 的 worker pod 中运行)

Java 22+ 原生访问警告

在 Java 22 及更高版本中,Rebel Readline 可能会显示来自 JLine 或其某个终端支持库的原生访问警告。该警告并不意味着 Rebel Readline 启动失败。要抑制它,请传递此 JVM 选项:

clojure -J--enable-native-access=ALL-UNNAMED -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.11\"}}}" -M -m rebel-readline.main

对于别名,将选项添加到 :jvm-opts

:aliases
{:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.11"}}
         :main-opts ["-m" "rebel-readline.main"]
         :jvm-opts ["--enable-native-access=ALL-UNNAMED"]}}

快速开始

若要快速试用 Rebel Readline,安装 Clojure CLI 工具 并执行:

clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.11\"}}}" -M -m rebel-readline.main

要从最新的 Git 发布标签安装 Rebel Readline 作为 Clojure 工具:

clojure -Ttools install-latest :lib com.github.bhauman/rebel-readline :coord '{:git/url "https://github.com/bhauman/rebel-readline.git" :deps/root "rebel-readline"}' :as rebel

然后从项目目录中启动它:

clojure -Trebel repl

用法

REPL 中的按键绑定

Rebel Readline 默认使用 Emacs 风格的按键绑定,这些绑定可以进行配置。

主要按键绑定:

  • Ctrl-C:中止当前行
  • Ctrl-D 在行首:发送流结束信号(通常退出 REPL)
  • TAB:单词补全或代码缩进
  • Ctrl-X Ctrl-D:显示当前符号的文档
  • Ctrl-X Ctrl-S:显示当前符号的源代码
  • Ctrl-X Ctrl-A:显示当前符号的 apropos 信息
  • Ctrl-X Ctrl-E:对 SEXP 进行内联求值

你可以使用 :repl/key-bindings 命令探索更多的按键绑定。

REPL 中的命令

命令以 :repl/... 关键字开头。要查看可用命令,请输入 :repl/help:repl 后跟 TAB。

你可以通过为 rebel-readline.commands/command 多方法实现方法并使用 rebel-readline.commands/command-doc 进行文档化来添加新命令。

安装

在你的 ~/.clojure/deps.edn 中将 Rebel Readline 添加为一个工具:

{
 ...
 :aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.11"}}
                   :exec-fn rebel-readline.tool/repl
                   :exec-args {}
                   :main-opts ["-m" "rebel-readline.main"]}}
 ...
}

然后,您可以在项目目录中使用以下命令启动 REPL:

clojure -Xrebel 

请记住使用 clojure 而不是 clj,以避免其他 readline 工具的干扰。

或者,将其作为独立工具运行:

clojure -T:rebel 

CLI 参数

在启动 REPL 时,您可以传入 可配置参数

clojure -Xrebel :highlight false 

也可以在您的 ~/.clojure/deps.edn:exec-args 键中指定参数。

使用 rebel-readline.main 的 CLI 用法

您也可以通过 rebel-readline.main CLI 启动。使用上述配置,您可以使用:

clojure -Mrebel --no-highlight
Options:
  -h, --help                                       Display help
  -k, --key-map KEYMAP         :emacs              Choose between :viins or :emacs
  -t, --color-theme THEME      :dark-screen-theme  :(light, dark, or neutral)-screen-theme
      --no-highlight                               Disable syntax highlighting
      --no-completion                              Disable code completion
      --no-eldoc                                   Disable function documentation display
      --no-indent                                  Disable auto indentation
      --no-redirect-output                         Disable output redirection
  -b, --key-bindings BINDINGS                      Specify custom key bindings
  -c, --config CONFIG                              Path to a config file

使用 Leiningen 安装

将依赖项添加到您的 project.clj

[com.bhauman/rebel-readline "0.1.11"]

使用以下命令启动 REPL:

lein trampoline run -m rebel-readline.main

您还可以将其添加到 $HOME/.lein/profiles.clj 中,这样您就无需 将其添加到各个项目中。

为了简化 REPL 启动,请在 project.clj 中创建一个别名:

:aliases {"rebl" ["trampoline" "run" "-m" "rebel-readline.main"]}

这允许你使用 lein rebl 启动 REPL。

Boot 集成

使用 Boot 启动 Rebel Readline:

boot -d com.bhauman/rebel-readline call -f rebel-readline.main/-main

默认使用 vi 键位绑定

你可以在 deps.edn~/.clojure/rebel_readline.edn 中设置 vi 键位绑定:

{:key-map :viins}

配置

您可以在 deps.edn~/.clojure/rebel_readline.edn 中提供各种可配置选项:

:config          - path to an edn configuration file

:key-map         - :viins or :emacs (default: :emacs)

:color-theme     - (:light, :dark or :neutral)-screen-theme

:highlight       - (boolean) enable syntax highlighting (default: true)

:completion      - (boolean) enable code completion (default: true)

:eldoc           - (boolean) enable function documentation display (default: true)

:indent          - (boolean) enable auto indentation (default: true)

:redirect-output - (boolean) rebinds output during read (default: true)

:key-bindings    - map of key bindings to apply after others

按键绑定配置

要配置按键绑定,请使用您的配置文件。确保按键名称的正确序列化。

使用 Rebel Readline 作为 Readline 库

Rebel Readline 可以替换 clojure.main/repl-read 的行为:

(rebel-readline.core/with-line-reader
  (rebel-readline.clojure.line-reader/create
    (rebel-readline.clojure.service.local/create {:highlight false}))
  (clojure.main/repl
     :prompt (fn []) ;; prompt is handled by line-reader
     :read (rebel-readline.clojure.main/create-repl-read)))

你也可以使用 rebel-readline.core/with-readline-in 以便更轻松地换行:

(rebel-readline.core/with-readline-in
  (rebel-readline.clojure.line-reader/create
    (rebel-readline.clojure.service.local/create))
  (clojure.main/repl :prompt (fn [])))

服务

行读取器通过服务提供补全、文档和求值等功能。通用服务是 rebel-readline.services.clojure.local,它查询本地的 Clojure 进程。

对于没有合适服务的环境,你可以使用 clojure.service.localclojure.service.simple,尽管结果可能不太理想。

CLJS 支持

对于 ClojureScript,请访问 此仓库部分

SocketREPL 和 pREPL 支持

目前,SocketREPL 和 pREPL 的服务不可用。

贡献

我们欢迎贡献!寻找标记为 help wanted 的问题作为良好的切入点。

在贡献时:

  • 在创建 PR 之前,为非平凡更改提交一个问题。
  • 将 PR 更改合并为一个提交。
  • 使更改小而易于理解;这有助于更好的审查。
  • 将较大的解决方案拆分为可管理的 PR。
  • 如果 PR 代表更多探索性工作,请进行沟通。

如果你需要关于该做什么的帮助,请随时在 Clojurians Slack 频道上联系我们。

许可证

版权所有 © 2018 Bruce Hauman

根据 Eclipse 公共许可证,版本 1.0 或(在你选择的情况下)任何后续版本分发。