New layer Hy extracted from Python layer
This commit is contained in:
parent
862e81e49a
commit
ea8991ac90
|
@ -0,0 +1,72 @@
|
|||
#+TITLE: Hy layer
|
||||
|
||||
[[file:img/hy.png]]
|
||||
|
||||
* Table of Contents :TOC_4_gh:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#features][Features:]]
|
||||
- [[#install][Install]]
|
||||
- [[#layer][Layer]]
|
||||
- [[#key-bindings][Key Bindings]]
|
||||
- [[#debug][Debug]]
|
||||
- [[#repl][REPL]]
|
||||
- [[#tests][Tests]]
|
||||
|
||||
* Description
|
||||
This layer adds support for the Hy language based on Python.
|
||||
|
||||
** Features:
|
||||
- syntax-highlighting
|
||||
- Auto-completion
|
||||
- Code Navigation
|
||||
- Python test runners (see [[file:../python/README.org][python layer]])
|
||||
- Virtual Environment using [[https://github.com/jorgenschaefer/pyvenv][pyvenv]] and [[https://github.com/yyuu/pyenv][pyenv]]
|
||||
- Org Babel support
|
||||
|
||||
* Install
|
||||
** Layer
|
||||
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
||||
add =hy= to the existing =dotspacemacs-configuration-layers= list in this file.
|
||||
|
||||
To install =hy= globally:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
pip install hy
|
||||
#+END_SRC
|
||||
|
||||
* Key Bindings
|
||||
|
||||
** Debug
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+---------------------|
|
||||
| ~SPC m d d~ | insert pdb |
|
||||
| ~SPC m d t~ | insert pdb threaded |
|
||||
|
||||
** REPL
|
||||
Start a Hy inferior repel process with ~SPC m s i~. If =hy= is
|
||||
available in system executable search paths, =hy= will be used to
|
||||
launch the shell. You may change your system executable search path
|
||||
by activating a virtual environment.
|
||||
|
||||
Send code to hy REPL commands:
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+-----------------------------------------------------------------|
|
||||
| ~SPC m s b~ | send buffer to the REPL |
|
||||
| ~SPC m s B~ | send buffer to the REPL and switch to it |
|
||||
| ~SPC m s c~ | send form containing current point to the REPL |
|
||||
| ~SPC m s C~ | send form containing current point to the REPL and switch to it |
|
||||
| ~SPC m s i~ | start and/or switch to REPL |
|
||||
| ~SPC m s r~ | send current region to the REPL |
|
||||
| ~SPC m s R~ | send current region to the REPL and switch to it |
|
||||
| ~SPC m s s~ | start and/or swithc to REPL |
|
||||
|
||||
** Tests
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+------------------------------------------------------|
|
||||
| ~SPC m t a~ | launch all tests of the project |
|
||||
| ~SPC m t A~ | launch all tests of the project in debug mode |
|
||||
| ~SPC m t m~ | launch all tests of the current module |
|
||||
| ~SPC m t M~ | launch all tests of the current module in debug mode |
|
|
@ -0,0 +1,31 @@
|
|||
;;; funcs.el --- Hy Layer functions File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Muneeb Shaikh <muneeb@reversehack.in>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
|
||||
;; REPL
|
||||
|
||||
(defun spacemacs/hy-shell-eval-buffer-and-go ()
|
||||
"Send current buffer to REPL and focus it."
|
||||
(interactive)
|
||||
(hy-shell-eval-buffer)
|
||||
(hy-shell-start-or-switch-to-shell))
|
||||
|
||||
(defun spacemacs/hy-shell-eval-current-form-and-go ()
|
||||
"Send current buffer to REPL and focus it."
|
||||
(interactive)
|
||||
(hy-shell-eval-current-form)
|
||||
(hy-shell-start-or-switch-to-shell))
|
||||
|
||||
(defun spacemacs/hy-shell-eval-region-and-go ()
|
||||
"Send current buffer to REPL and focus it."
|
||||
(interactive)
|
||||
(hy-shell-eval-region)
|
||||
(hy-shell-start-or-switch-to-shell))
|
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
|
@ -0,0 +1,12 @@
|
|||
;;; layers.el --- Hy Layer layers File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(configuration-layer/declare-layers '(python))
|
|
@ -0,0 +1,74 @@
|
|||
;;; packages.el --- Hy Layer packages File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(setq hy-packages
|
||||
'(
|
||||
company
|
||||
hy-mode
|
||||
ob-hy
|
||||
pyenv-mode
|
||||
pyvenv-mode
|
||||
smartparens
|
||||
))
|
||||
|
||||
(defun hy/post-init-company ()
|
||||
;; Autocompletion now fit for use, not all symbols complete, hy bug
|
||||
(spacemacs|add-company-backends
|
||||
:backends company-hy
|
||||
:modes hy-mode inferior-hy-mode))
|
||||
|
||||
(defun hy/init-hy-mode ()
|
||||
(use-package hy-mode
|
||||
:defer t
|
||||
:init
|
||||
(progn
|
||||
;; need to do this as they are not auloaded by the package
|
||||
(add-to-list 'auto-mode-alist '("\\.hy\\'" . hy-mode))
|
||||
(add-to-list 'interpreter-mode-alist '("hy" . hy-mode))
|
||||
;; Disable this unless using special branch
|
||||
(setq hy-shell-use-control-codes? nil)
|
||||
;; key bindings
|
||||
(spacemacs/declare-prefix-for-mode 'hy-mode "me" "eval")
|
||||
(spacemacs/declare-prefix-for-mode 'hy-mode "md" "debug")
|
||||
(spacemacs/declare-prefix-for-mode 'hy-mode "mt" "test")
|
||||
(spacemacs/declare-prefix-for-mode 'hy-mode "mV" "pyvenv")
|
||||
(spacemacs/set-leader-keys-for-major-mode 'hy-mode
|
||||
"dd" 'hy-insert-pdb
|
||||
"dt" 'hy-insert-pdb-threaded
|
||||
"hh" 'hy-describe-thing-at-point
|
||||
"sb" 'hy-shell-eval-buffer
|
||||
"sB" 'spacemacs/hy-shell-eval-buffer-and-go
|
||||
"sc" 'hy-shell-eval-current-form
|
||||
"sC" 'spacemacs/hy-shell-eval-current-form-and-go
|
||||
"si" 'hy-shell-start-or-switch-to-shell
|
||||
"sr" 'hy-shell-eval-region
|
||||
"sR" 'spacemacs/hy-shell-eval-region-and-go
|
||||
"ss" 'hy-shell-start-or-switch-to-shell
|
||||
"tA" 'spacemacs/python-test-pdb-all
|
||||
"ta" 'spacemacs/python-test-all
|
||||
"tM" 'spacemacs/python-test-pdb-module
|
||||
"tm" 'spacemacs/python-test-module))))
|
||||
|
||||
(defun hy/pre-init-ob-hy ()
|
||||
(spacemacs|use-package-add-hook org
|
||||
:post-config
|
||||
(use-package ob-hy
|
||||
:init (add-to-list 'org-babel-load-languages '(hy . t)))))
|
||||
(defun hy/init-ob-hy ())
|
||||
|
||||
(defun hy/pre-init-pyenv-mode ()
|
||||
(add-to-list 'spacemacs--python-pyenv-modes 'hy-mode))
|
||||
|
||||
(defun hy/pre-init-pyvenv-mode ()
|
||||
(add-to-list 'spacemacs--python-pyvenv-modes 'hy-mode))
|
||||
|
||||
(defun hy/post-init-smartparens ()
|
||||
(add-hook 'hy-mode-hook 'smartparens-mode))
|
|
@ -18,7 +18,6 @@
|
|||
- [[#automatic-save-of-buffer-when-testing][Automatic save of buffer when testing]]
|
||||
- [[#autoflake][autoflake]]
|
||||
- [[#pylookup][pylookup]]
|
||||
- [[#hy-mode][Hy-mode]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#fill-column][Fill column]]
|
||||
- [[#sort-imports][Sort imports]]
|
||||
|
@ -33,7 +32,6 @@
|
|||
- [[#refactoring][Refactoring]]
|
||||
- [[#pip-package-management][Pip package management]]
|
||||
- [[#live-coding][Live coding]]
|
||||
- [[#hy-repl-process][Hy REPL process]]
|
||||
- [[#other-python-commands][Other Python commands]]
|
||||
|
||||
* Description
|
||||
|
@ -187,14 +185,6 @@ To be able to suppress unused imports easily, install [[https://github.com/myint
|
|||
To use =pylookup= on ~SPC m h H~, make sure you update the database first, using
|
||||
~SPC SPC pylookup-update~.
|
||||
|
||||
** Hy-mode
|
||||
To be able to connect to an inferior lisp repl in =hy-mode=, you need to make sure
|
||||
that hy is installed.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
pip install hy
|
||||
#+END_SRC
|
||||
|
||||
* Configuration
|
||||
** Fill column
|
||||
If you want to customize the fill column value, use something like this inside
|
||||
|
@ -357,25 +347,6 @@ Live coding is provided by the [[https://github.com/donkirkby/live-py-plugin][li
|
|||
|-------------+---------------------|
|
||||
| ~SPC m l~ | Toggle live-py-mode |
|
||||
|
||||
** Hy REPL process
|
||||
Start a Hy inferior repel process with ~SPC m s i~. If =hy= is
|
||||
available in system executable search paths, =hy= will be used to
|
||||
launch the shell. You may change your system executable search path
|
||||
by activating a virtual enviornment.
|
||||
|
||||
Send code to hy REPL commands:
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+-----------------------------------------------------------|
|
||||
| ~SPC m s b~ | send buffer and keep code buffer focused |
|
||||
| ~SPC m s B~ | switch to REPL |
|
||||
| ~SPC m s e~ | send sexp in front of the cursor to the REPL |
|
||||
| ~SPC m s f~ | send function to REPL and stay in buffer |
|
||||
| ~SPC m s F~ | send function to REPL and switch to repl buffer |
|
||||
| ~SPC m s i~ | start inferior hy repl |
|
||||
| ~SPC m s r~ | send current region to the REPL and stay in buffer |
|
||||
| ~SPC m s R~ | send current region to the REPL and switch to repl buffer |
|
||||
|
||||
** Other Python commands
|
||||
|
||||
| Key Binding | Description |
|
||||
|
|
|
@ -45,3 +45,9 @@ Possible values are `on-visit', `on-project-switch' or `nil'.")
|
|||
|
||||
(defvar python-sort-imports-on-save nil
|
||||
"If non-nil, automatically sort imports on save.")
|
||||
|
||||
(defvar spacemacs--python-pyenv-modes nil
|
||||
"List of major modes where to add pyenv support.")
|
||||
|
||||
(defvar spacemacs--python-pyvenv-modes nil
|
||||
"List of major modes where to add pyvenv support.")
|
||||
|
|
|
@ -136,10 +136,6 @@ as the pyenv version then also return nil. This works around https://github.com/
|
|||
(setq python-shell-interpreter-args "-i")
|
||||
(setq python-shell-interpreter "python"))))
|
||||
|
||||
(defun spacemacs//python-setup-hy (&rest args)
|
||||
(setq hy-mode-inferior-lisp-command
|
||||
(concat (or (spacemacs/pyenv-executable-find "hy") "hy")
|
||||
" --spy")))
|
||||
|
||||
(defun spacemacs//python-setup-checkers (&rest args)
|
||||
(when (fboundp 'flycheck-set-checker-executable)
|
||||
|
@ -152,7 +148,6 @@ as the pyenv version then also return nil. This works around https://github.com/
|
|||
|
||||
(defun spacemacs/python-setup-everything (&rest args)
|
||||
(apply 'spacemacs//python-setup-shell args)
|
||||
(apply 'spacemacs//python-setup-hy args)
|
||||
(apply 'spacemacs//python-setup-checkers args))
|
||||
|
||||
(defun spacemacs/python-toggle-breakpoint ()
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
helm-cscope
|
||||
helm-gtags
|
||||
(helm-pydoc :requires helm)
|
||||
hy-mode
|
||||
importmagic
|
||||
live-py-mode
|
||||
(nose :location local)
|
||||
|
@ -130,22 +129,7 @@
|
|||
:init
|
||||
(spacemacs/set-leader-keys-for-major-mode 'python-mode "hd" 'helm-pydoc)))
|
||||
|
||||
(defun python/init-hy-mode ()
|
||||
(use-package hy-mode
|
||||
:defer t
|
||||
:init
|
||||
(progn
|
||||
(spacemacs/set-leader-keys-for-major-mode 'hy-mode
|
||||
"si" 'inferior-lisp
|
||||
"sb" 'lisp-load-file
|
||||
"sB" 'switch-to-lisp
|
||||
"ee" 'lisp-eval-last-sexp
|
||||
"ef" 'lisp-eval-defun
|
||||
"eF" 'lisp-eval-defun-and-go
|
||||
"er" 'lisp-eval-region
|
||||
"eR" 'lisp-eval-region-and-go)
|
||||
;; call `spacemacs//python-setup-hy' once, don't put it in a hook (see issue #5988)
|
||||
(spacemacs//python-setup-hy))))
|
||||
|
||||
|
||||
(defun python/init-importmagic ()
|
||||
(use-package importmagic
|
||||
|
@ -227,6 +211,8 @@
|
|||
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
||||
"rI" 'py-isort-buffer))))
|
||||
|
||||
(defun python/pre-init-pyenv-mode ()
|
||||
(add-to-list 'spacemacs--python-pyenv-modes 'python-mode))
|
||||
(defun python/init-pyenv-mode ()
|
||||
(use-package pyenv-mode
|
||||
:if (executable-find "pyenv")
|
||||
|
@ -235,9 +221,9 @@
|
|||
(progn
|
||||
(pcase python-auto-set-local-pyenv-version
|
||||
(`on-visit
|
||||
(spacemacs/add-to-hooks 'spacemacs//pyenv-mode-set-local-version
|
||||
'(python-mode-hook
|
||||
hy-mode-hook)))
|
||||
(dolist (m spacemacs--python-pyenv-modes)
|
||||
(add-hook (intern (format "%s-hook" m))
|
||||
'spacemacs//pyenv-mode-set-local-version)))
|
||||
(`on-project-switch
|
||||
(add-hook 'projectile-after-switch-project-hook
|
||||
'spacemacs//pyenv-mode-set-local-version)))
|
||||
|
@ -248,6 +234,8 @@
|
|||
"vu" 'pyenv-mode-unset
|
||||
"vs" 'pyenv-mode-set))))
|
||||
|
||||
(defun python/pre-init-pyvenv-mode ()
|
||||
(add-to-list 'spacemacs--python-pyvenv-modes 'python-mode))
|
||||
(defun python/init-pyvenv ()
|
||||
(use-package pyvenv
|
||||
:defer t
|
||||
|
@ -255,14 +243,14 @@
|
|||
(progn
|
||||
(pcase python-auto-set-local-pyvenv-virtualenv
|
||||
(`on-visit
|
||||
(spacemacs/add-to-hooks 'spacemacs//pyvenv-mode-set-local-virtualenv
|
||||
'(python-mode-hook
|
||||
hy-mode-hook)))
|
||||
(dolist (m spacemacs--python-pyvenv-modes)
|
||||
(add-hook (intern (format "%s-hook" m))
|
||||
'spacemacs//pyvenv-mode-set-local-virtualenv)))
|
||||
(`on-project-switch
|
||||
(add-hook 'projectile-after-switch-project-hook
|
||||
'spacemacs//pyvenv-mode-set-local-virtualenv)))
|
||||
(dolist (mode '(python-mode hy-mode))
|
||||
(spacemacs/set-leader-keys-for-major-mode mode
|
||||
(dolist (m spacemacs--python-pyvenv-modes)
|
||||
(spacemacs/set-leader-keys-for-major-mode m
|
||||
"va" 'pyvenv-activate
|
||||
"vd" 'pyvenv-deactivate
|
||||
"vw" 'pyvenv-workon))
|
||||
|
@ -383,8 +371,6 @@ fix this issue."
|
|||
(error nil))))
|
||||
|
||||
(defun python/pre-init-smartparens ()
|
||||
(spacemacs/add-to-hooks 'smartparens-mode '(inferior-python-mode-hook
|
||||
hy-mode-hook))
|
||||
(spacemacs|use-package-add-hook smartparens
|
||||
:post-config
|
||||
(defadvice python-indent-dedent-line-backspace
|
||||
|
@ -394,6 +380,8 @@ fix this issue."
|
|||
(if pythonp
|
||||
ad-do-it
|
||||
(call-interactively 'sp-backward-delete-char))))))
|
||||
(defun python/post-init-smartparens ()
|
||||
(add-hook 'inferior-python-mode-hook 'smartparens-mode))
|
||||
|
||||
(defun python/post-init-stickyfunc-enhance ()
|
||||
(add-hook 'python-mode-hook 'spacemacs/load-stickyfunc-enhance))
|
||||
|
|
Loading…
Reference in New Issue