Metadata-Version: 2.4
Name: hy-nrepl
Version: 1.0.4
Summary: nREPL implementation for Hy (Hylang)
Author: Morten Linderud, Gregor Best, Satoshi Imai
License: MIT
Project-URL: Homepage, https://github.com/masatoi/hy-nrepl
Project-URL: Issues, https://github.com/masatoi/hy-nrepl/issues
Project-URL: CI, https://github.com/masatoi/hy-nrepl/actions
Keywords: hy,hylang,nrepl,repl
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Lisp
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: hy>=0.29.0
Requires-Dist: hyrule>=0.6.0
Requires-Dist: toolz
Provides-Extra: test
Requires-Dist: pytest>=8.3; extra == "test"
Dynamic: license-file

# hy-nrepl
[![hy-nrepl unit test](https://github.com/masatoi/hy-nrepl/actions/workflows/hy_nrepl_test.yaml/badge.svg)](https://github.com/masatoi/hy-nrepl/actions/workflows/hy_nrepl_test.yaml)

hy-nrepl is an implementation of the [nREPL](https://nrepl.org) protocol for [Hy](https://github.com/hylang/hy).

hy-nrepl is a fork from [HyREPL](https://github.com/allison-casey/HyREPL) and has been adjusted to work with the current Hy.

## Implemented Operations

from [nREPL Built-in Ops](https://nrepl.org/nrepl/1.3/ops.html)

- [ ] add-middleware
- [x] clone
- [x] close
- [x] completions
- [x] describe
- [x] eval
- [x] interrupt
- [x] load-file
- [x] lookup
- [ ] ls-middleware
- [x] ls-sessions
- [x] stdin
- [ ] swap-middleware

## Usage
hy-nrepl requires Python >= 3.11 and Hy >= 0.29.0.

To install:

```sh
pip install hy-nrepl
````

To run the server (default port is 7888):

```sh
hy-nrepl

# Output debug log and specify port
hy-nrepl --debug 7888
```

## Testing

Install test dependencies, then run pytest:

```sh
pip install -e .[test]

pytest tests
```

## Known Issues

Code evaluation is performed in a thread that is not Python's main thread. Therefore, some libraries that expect to be run on the main thread will not work as expected.

  - **GUI Libraries**: Libraries like **Tkinter** will not function correctly.
  - **Plotting Libraries**: **Matplotlib** is known to have issues. As an alternative, you can use libraries like **Plotly**, which work without relying on the main thread.

## Confirmed working nREPL clients

### Emacs

The following combinations are currently confirmed to work stably.

  - [hy-mode](https://github.com/hylang/hy-mode) + [Rail](https://github.com/masatoi/Rail)
      - REPL (Eval and Interruption)
      - Symbol completion
      - Eldoc (Function arg documentations)
      - Jump to source

### Emacs Configuration Example

Here is an example configuration for a plain Emacs setup using `use-package`.

**1. Install Rail**

This setup uses a forked version of `Rail` that has been modified to work well with `hy-nrepl`.

Clone the forked `Rail` repository from GitHub. This example clones it to the home directory (`~/Rail`).

```sh
git clone [https://github.com/masatoi/Rail.git](https://github.com/masatoi/Rail.git) ~/Rail
```

**2. Configure Emacs**

Add the following settings to your Emacs initialization file (e.g., `~/.emacs.d/init.el`). This setup assumes you are using `package.el` and `use-package`.

```emacs-lisp
;;; Assumes use-package is already installed.
;;; If not, add bootstrap code for package.el and use-package.
(require 'package)
(add-to-list 'package-archives '("melpa" . "[https://melpa.org/packages/](https://melpa.org/packages/)") t)
(package-initialize)

;;; hy-mode (will be installed from MELPA)
;;; jedhy is disabled as Rail provides completion.
(use-package hy-mode
  :mode "\\.hy\\'"
  :custom (hy-jedhy--enable? nil))

;;; Rail (loaded from the local path)
(use-package rail
  :ensure nil
  :load-path "~/Rail" ; Must match the path where you cloned Rail
  :commands (rail rail-interaction-mode)
  :hook ((hy-mode . rail-interaction-mode)
         (hy-mode . rail-setup-eldoc)
         (rail-mode . rail-setup-eldoc)))
```

**3. How to Connect**

1.  **Start the nREPL server in your terminal.** It will listen on `localhost:7888` by default.

    ```sh
    hy-nrepl
    ```

2.  **Connect to the nREPL server from Emacs.** Run `M-x rail`, and you will be prompted for the host and port. Enter the default value, `localhost:7888`, and press Enter. This will complete the connection and open a REPL buffer.

3.  **Developing with `.hy` files.** Once connected, opening a `.hy` file will automatically enable the minor mode `rail-interaction-mode`. This provides features like:

      - Evaluating Hy S-expressions within the buffer
      - Symbol completion
      - Displaying function argument information via Eldoc

4.  **Interrupting Execution.** While an evaluation is running in the REPL buffer, you can interrupt it by pressing `C-c C-c`.

<!-- end list -->
