didibus / anakondo

Minor mode for Clojure[Script] completion powered by clj-kondo.
MIT License
114 stars 1 forks source link

+TITLE: anakondo

+PROPERTY: LOGGING nil

Note: This readme works with the org-make-toc https://github.com/alphapapa/org-make-toc package, which automatically updates the table of contents.

This package makes use of clj-kondo's analysis data to provide code editing facilities related to Clojure, ClojureScript and cljc source. This means you get advanced editing features like auto-complete without the need for a connected REPL, because clj-kondo performs its magic using static source code analysis.

Current Features:

Clojure completion of namespaces and global Vars and fns without needing to be connected to a REPL:

+CAPTION: Example Clojure global Vars and namespace completion using anakondo

[[./screenshots/anakondo-auto-completion-no-repl-demo.gif]]

Clojure completion of local bindings without needing to be connected to a REPL, which works even with unbalanced expressions:

+CAPTION: Example Clojure local binding completion using anakondo

[[./screenshots/anakondo-locals-auto-completion-no-repl-demo.gif]]

Java completion of qualified classes, default Java class imports (like Math, Thread, Integer, etc.), and of public static methods and fields, all without needing to be connected to a REPL:

+CAPTION: Example Java classes and static methods and fields completion using anakondo

[[./screenshots/anakondo-java-auto-completion-no-repl-demo.gif]]

** Prerequisites

For Clojure[Script] completion, Anakondo needs the Clojure CLI tools.deps and clj-kondo to be installed and accessible from Emacs in order to run properly. To do so:

  1. Install clj-kondo by following its [[https://github.com/borkdude/clj-kondo/blob/master/doc/install.md][install instructions]].
  2. Make sure =clj-kondo= is in your shell's ~PATH~.
  3. Install the Clojure CLI tools.deps by following its [[https://clojure.org/guides/getting_started#_clojure_installer_and_cli_tools][install instruction]].
  4. Make sure the =clojure= CLI is in your shell's ~PATH~.

For Java completion, you also need to be sure that you have a JDK installed and that its ~/bin~ folder is on the environment PATH used by Emacs.

** MELPA

  1. Run: ~M-x package-install anakondo~
  2. Now put this in your init file:
    • If you want to pre-load it:

      +BEGIN_SRC elisp

      ;; Load anakondo to make available its minor mode in clojure buffers (require 'anakondo)

      +END_SRC

    • If you want to lazy load it:

      +BEGIN_SRC elisp

      ;; Delays loading of anakondo until a clojure buffer is used (autoload 'anakondo-minor-mode "anakondo")

      +END_SRC

** use-package

Put this in your in your init file:

+begin_src emacs-lisp :tangle yes

(use-package anakondo :ensure t :commands anakondo-minor-mode)

+end_src

** Manual

  1. Clone this repo somewhere on your computer.
  2. Make sure that somewhere is in your Emacs ~load-path~.
  3. Now put this in your init file:
    • If you want to pre-load it:

      +BEGIN_SRC elisp

      ;; Load anakondo to make available its minor mode in clojure buffers (require 'anakondo)

      +END_SRC

    • If you want to lazy load it:

      +BEGIN_SRC elisp

      ;; Delays loading of anakondo until a clojure buffer is used (autoload 'anakondo-minor-mode "anakondo")

      +END_SRC

Turn on anakondo minor mode in one or more Clojure, ClojureScript or cljc buffer:

Run one of these commands:

To have it on by default for all your Clojure, ClojureScript and cljc buffers, add to your Emacs init file, after the anakondo require/autoload:

+begin_src elisp

;; Enable anakondo-minor-mode in all Clojure buffers (add-hook 'clojure-mode-hook #'anakondo-minor-mode) ;; Enable anakondo-minor-mode in all ClojureScript buffers (add-hook 'clojurescript-mode-hook #'anakondo-minor-mode) ;; Enable anakondo-minor-mode in all cljc buffers (add-hook 'clojurec-mode-hook #'anakondo-minor-mode)

+end_src

If you are also using Cider, the order in which you add the hooks matters in the resulting completion behavior:

  1. If you add anakondo to the Clojure mode hooks first, then completion will first try to use anakondo's, and only if it can't complete the form will it then try to use Cider's completion. This means if you try to complete a keyword for example, it'll fallback to Cider's, but for completing symbols it won't, even if it finds no candidates.
  2. Otherwise, if you add Cider to the Clojure mode hooks first, then completion will first try to use Cider's, and only if Cider completion is not available, because there is no connected REPL, will it then fallback to try anakondo's completion. If Cider completion is available (because you have a REPL connected), it will never fallback to trying anakondo's completion, even if Cider doesn't find any completion candidates.

Currently, I recommend adding anakondo after Cider. This will make it so when no REPL is connected, you have anakondo's clj-kondo based static analysis completion. While when a REPL is running, you have Cider's completion. If you do it the other way around, when a REPL is running, if anakondo find completions you will only see the ones it found. I'll be exploring options to have the completions merged in the future, so we get the best of both worlds.

This also goes if you turn on/off the modes manually, except in that case, order and effect are reversed. The last mode you turn on will be the one who is in charge of completion first. While with the hooks, it is the first mode you add to the hook that will be in charge of completion first.

** Tips

** 0.2.1

Changes

Fixes

** 0.2

Additions

Changes

Fixes

Internal

** 0.1.2

Internal

** 0.1.1

Fixes

** 0.1

Additions

Internal

Planned Features

This package would not have been possible without the following packages:

Thanks to all of them and their author/contributors.

MIT License, see accompanying [[https://github.com/didibus/anakondo/blob/master/LICENSE][LICENSE]] file.

Local Variables:

eval: (require 'org-make-toc)

before-save-hook: org-make-toc

End: