Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Latest commit

 

History

History
171 lines (115 loc) · 5.82 KB

editors.md

File metadata and controls

171 lines (115 loc) · 5.82 KB

Babashka text editor integrations

nREPL

Emacs: CIDER

This is the one that started it all, and its Orchard ecosystem powers many of the other plug-ins.

  1. Install Emacs for your platform.

  2. Choose an existing emacs distribution (Prelude, Spacemacs and Doom Emacs are all great) or add this to your init.el:

(unless (package-installed-p 'cider)
  (package-install 'cider))
  
(add-hook 'clojure-mode-hook #'cider-mode)

Summarized from the CIDER docs:

Start the nREPL server from the project directory:

$ bb --nrepl-server

Create or open any Clojure file (.clj) with C-x C-f and connect to it using C-c C-x c j (cider-connect-clj).

The basic CIDER keybindings:

  • cider-load-buffer - C-c C-k
  • cider-eval-last-sexp - C-x C-e or C-c C-e
  • cider-eval-defun-at-point - C-M-x or C-c C-c

VSCode: Calva

  1. Install VSCode.

  2. Install Calva.

Currently, Calva understands your source code to be in the context of a folder, i.e. a Clojure project. A nice way to create one is with clj-new:

$ clj -A:new lib myorg/bbtest
Generating a project called bbtest based on the 'lib' template.
The lib template is intended for library projects, not applications.
  1. Start the nREPL server from the project's directory:
$ cd bbtest
bbtest$ bb --nrepl-server 1667
Started nREPL server at localhost:1667
For more info visit https://github.com/borkdude/babashka/blob/master/doc/repl.md#nrepl.

Open the project folder in VSCode (Ctrl+K Ctrl+O) or from another terminal:

$ cd bbtest
bbtest$ code .
  1. In VSCode, run the Calva command Connect to a running REPL (ctrl+alt+c ctrl+alt+c). Choose Generic project when prompted, and enter localhost:1667.

REPL commands:

  • Load Current File and Dependencies ctrl+alt+c enter
  • Evaluate Current Form Inline ctrl+alt+c e
  • Evaluate Current Top Level Form (defun) ctrl+alt+c space

IntelliJ: Cursive

  1. Download IntelliJ here.
  2. Install Cursive by following the user guide and configure deps.
  3. See Cursive: Working with Babashka for more info.

Socket REPL

Atom: chlorine

  1. Install atom

  2. Install the chlorine package

  3. Start socket REPL:

$ bb --socket-repl 1666
Babashka socket REPL started at localhost:1666
  1. Open Atom command palette (ctrl+shift+p) and execute command Connect Clojure Socket REPL with localhost 1666

  2. Edit key bindings in keymap.cson via Edit menu -> Keymap...:

'atom-text-editor[data-grammar="source clojure"]':
  'ctrl-; y':       'chlorine:connect-clojure-socket-repl'
  'ctrl-; e':       'chlorine:disconnect'
  'ctrl-; k':       'chlorine:clear-console'
  'ctrl-shift-enter':       'chlorine:load-file'
  'ctrl-enter':       'chlorine:evaluate-block'
  'shift-enter':       'chlorine:evaluate-top-block'
  'ctrl-; i':       'chlorine:inspect-block'
  'ctrl-; I':       'chlorine:inspect-top-block'
  'ctrl-; s':       'chlorine:evaluate-selection'
  'ctrl-; c':       'chlorine:break-evaluation'
  'ctrl-; S':       'chlorine:source-for-var'
  'ctrl-; d':       'chlorine:doc-for-var'
  'ctrl-; x':       'chlorine:run-tests-in-ns'
  'ctrl-; t':       'chlorine:run-test-for-var'

For Emacs, install inf-clojure by adding this to your init.el:

(unless (package-installed-p 'inf-clojure)
  (package-refresh-contents)
  (package-install 'inf-clojure))

(add-hook 'clojure-mode-hook #'inf-clojure-minor-mode)

Start the socket REPL as above, and in emacs execute M-x inf-clojure-connect (C-c M-c).

Evaluate forms with C-c C-e. For a list of all available commands in inf-clojure-mode (a.k.a. the REPL) and inf-clojure-minor-mode you can either invoke C-h f RET inf-clojure-mode and C-h f RET inf-clojure-minor-mode or simply browse their menus.

Download the Neovim appimage and alias it to vim.

$ curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Create ~/.config/nvim/init.vim:

call plug#begin('~/.vim/plugged')

Plug 'liuchengxu/vim-clap'
Plug 'guns/vim-sexp',    {'for': 'clojure'}
Plug 'liquidz/vim-iced', {'for': 'clojure'}

call plug#end()

" Enable vim-iced's default key mapping
" This is recommended for newbies
let g:iced_enable_default_key_mappings = v:true

Open Neovim and run the command :PlugInstall.

Add the iced command to the $PATH:

$ export PATH=$PATH:~/.vim/plugged/vim-iced/bin

  • Start the socket REPL server, open source file and execute :IcedConnectSocketRepl 1666.

Default REPL commands (default <Leader> is \):

  • <Leader>ei : Evaluate inner element
  • <Leader>ee : Evaluate outer list
  • <Leader>et : Evaluate outer top list