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.
This commit is contained in:
Danny Freeman 2017-06-04 16:00:08 -04:00 committed by Eivind Fonn
parent 01de4d8b0e
commit 5a7019427e

View file

@ -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