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
Changes from 1 commit
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
Next Next commit
docs: add notes on using from Emacs
dhdaines committed Oct 25, 2024
commit 042bcfd1e4f0a68d94ee396470644063cee1817b
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)
)))
```