Skip to content

Commit

Permalink
Feature: Autostarting/killing jedhy/company
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaschalk committed Jun 11, 2019
1 parent fc75dd8 commit 702b023
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
24 changes: 15 additions & 9 deletions hy-jedhy.el
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,26 @@ shift-K keybinding that executes `spacemacs/evil-smart-doc-lookup'."
;;; Company

(defun company-hy (command &optional prefix-or-candidate-str &rest ignored)
"Implements autocompletion for `hy-mode'."
(interactive (list 'interactive))

(cl-case command
(prefix (company-grab-symbol))
(candidates (hy-jedhy--prefix-str->candidates prefix-or-candidate-str))
(annotation (hy-jedhy--candidate-str->annotation prefix-or-candidate-str))
(meta (hy-jedhy--candidate-str->eldoc prefix-or-candidate-str))))
(when (hy-shell--live-internal?)
(cl-case command
(prefix (company-grab-symbol))
(candidates (hy-jedhy--prefix-str->candidates prefix-or-candidate-str))
(annotation (hy-jedhy--candidate-str->annotation prefix-or-candidate-str))
(meta (hy-jedhy--candidate-str->eldoc prefix-or-candidate-str)))))

;;; Run Jedhy

(defun run-jedhy--pyvenv-post-active-hook ()
"Perform `run-jedhy', killing previous instance if running."
(hy-shell--kill-internal)
(run-jedhy))
(defun run-jedhy--pyvenv-post-deactive-hook ()
"Kill jedhy without notifying and possibly rerun for global context."
(let ((hy-shell--notify?))
(hy-shell--kill-internal)

;; The activation hook handles switching the environment rerunning jedhy
(unless pyvenv-virtual-env-name
(run-jedhy))))

;;;###autoload
(defun run-jedhy ()
Expand Down
24 changes: 14 additions & 10 deletions hy-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ commands."

;; Lispy indent with hy-specialized indentation
(setq-local indent-tabs-mode nil)
(setq-local indent-line-function 'lisp-indent-line)
(setq-local lisp-indent-function 'hy-indent-function))
(setq-local indent-line-function #'lisp-indent-line)
(setq-local lisp-indent-function #'hy-indent-function))

;;;; Support

Expand All @@ -259,18 +259,16 @@ commands."
(defun hy-mode--setup-jedhy ()
"Auto-start jedhy for company, eldoc, and other `hy-mode' IDE features."
(let ((hy-shell--notify?))
(run-jedhy)) ; Unlikely that jedhy installed globally
(run-jedhy)) ; Unlikely that jedhy installed globally so dont warn

(when (fboundp 'pyvenv-mode)
(add-hook 'pyvenv-post-activate-hooks #'run-jedhy--pyvenv-post-active-hook)))
(add-hook 'pyvenv-post-activate-hooks #'run-jedhy)
(add-hook 'pyvenv-post-deactivate-hooks
#'run-jedhy--pyvenv-post-deactive-hook)))

(defun hy-mode--support-company ()
"Support `company-mode' autocompletion."
;; (add-to-list 'company-backends 'company-hy)
;; (spacemacs|add-company-backends
;; :backends company-hy
;; :modes hy-mode inferior-hy-mode)
)
(add-to-list 'company-backends #'company-hy))

(defun hy-mode--support-eldoc ()
"Support `eldoc-mode' with lispy docstring leaders."
Expand All @@ -294,7 +292,9 @@ commands."
(hy-mode--setup-jedhy)

(hy-mode--support-eldoc)
(hy-mode--support-company)))
(hy-mode--support-company)

(add-hook 'inferior-hy-mode-hook #'hy-mode--support-company)))

;;; Bindings

Expand All @@ -303,11 +303,15 @@ commands."
;;;; Shell

(define-key hy-mode-map (kbd "C-c C-z") #'run-hy)

(define-key hy-mode-map (kbd "C-c C-b") #'hy-shell-eval-buffer)
(define-key hy-mode-map (kbd "C-c C-r") #'hy-shell-eval-region)
(define-key hy-mode-map (kbd "C-c C-e") #'hy-shell-eval-last-sexp)
(define-key hy-mode-map (kbd "C-M-x") #'hy-shell-eval-current-form)

(define-key hy-mode-map (kbd "C-c C-d d") #'hy-describe-thing-at-point)
(define-key hy-mode-map (kbd "C-c C-d C-d") #'hy-describe-thing-at-point)

;;;; Misc

;;;###autoload
Expand Down

0 comments on commit 702b023

Please sign in to comment.