Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helpful snippet for using Hatch from Emacs #1769

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/how-to/integrate/emacs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# How to use Hatch environments from Emacs

-----

The [pyvenv](https://github.com/jorgenschaefer/pyvenv) package is
frequently used to manage virtual environments in Emacs (with
[elpy](https://github.com/jorgenschaefer/elpy) for instance). To make
it easier to use with Hatch, you can add the following function to
your `.emacs` to add the command `hatch-activate`, which works like
`pyvenv-activate` but activates the default environment for the
current directory:

```lisp
(require 'subr-x)
(require 'pyvenv)
(defun hatch-activate (directory)
"Activate the default hatch virtual environment for DIRECTORY"
(interactive (list (read-directory-name "Activate for project: ")))
(let ((expdir (expand-file-name directory))
(default-directory directory))
(let ((hatch-env
(string-trim
(shell-command-to-string "hatch env find"))))
(pyvenv-activate hatch-env)
)))
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ nav:
- Report issues: how-to/meta/report-issues.md
- Integrate:
- Visual Studio Code: how-to/integrate/vscode.md
- Emacs: how-to/integrate/emacs.md
- Run:
- Python scripts: how-to/run/python-scripts.md
- Config:
Expand Down
Loading