From 5a7019427e63b76e85c729916148a701bda51e39 Mon Sep 17 00:00:00 2001 From: Danny Freeman Date: Sun, 4 Jun 2017 16:00:08 -0400 Subject: [PATCH] Fixed bug so hy command work when hy is installed on a virtualenv Hy is typically installed on a python virtual environment, not globally. When that is the case, init-hy-mode doesn't set any leader keys for hy since it can't find the hy executable on the path. When a virtual environment is activated, init-hy-mode is run again to see if it can find a hy executable and setup the leader keys for hy. --- layers/+lang/python/packages.el | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/layers/+lang/python/packages.el b/layers/+lang/python/packages.el index 14938a43c..710d12f91 100644 --- a/layers/+lang/python/packages.el +++ b/layers/+lang/python/packages.el @@ -129,23 +129,26 @@ :init (spacemacs/set-leader-keys-for-major-mode 'python-mode "hd" 'helm-pydoc))) +(defun python/find-hy-executable () + (setq-local hy-executable (or (spacemacs/pyenv-executable-find "hy") "hy")) + (setq-local hy-mode-inferior-lisp-command (concat hy-executable " --spy"))) + (defun python/init-hy-mode () (use-package hy-mode :defer t :init (progn - (let ((hy-path (executable-find "hy"))) - (when hy-path - (setq hy-mode-inferior-lisp-command (concat hy-path " --spy")) - (spacemacs/set-leader-keys-for-major-mode 'hy-mode - "si" 'inferior-lisp - "sb" 'lisp-load-file - "sB" 'switch-to-lisp - "se" 'lisp-eval-last-sexp - "sf" 'lisp-eval-defun - "sF" 'lisp-eval-defun-and-go - "sr" 'lisp-eval-region - "sR" 'lisp-eval-region-and-go)))))) + (add-hook 'hy-mode-hook 'python/find-hy-executable) + (add-hook 'pyvenv-post-activate-hooks 'python/find-hy-executable) + (spacemacs/set-leader-keys-for-major-mode 'hy-mode + "si" 'inferior-lisp + "sb" 'lisp-load-file + "sB" 'switch-to-lisp + "se" 'lisp-eval-last-sexp + "sf" 'lisp-eval-defun + "sF" 'lisp-eval-defun-and-go + "sr" 'lisp-eval-region + "sR" 'lisp-eval-region-and-go)))) (defun python/init-live-py-mode () (use-package live-py-mode