Last active
March 1, 2016 07:00
-
-
Save CarlOlson/270c9e5d18894f500222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; don't use this, going to do a PR with a better solution | |
;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; Alchemist Helm Help ;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(defvar alchemist-helm-candidates nil) | |
(defvar alchemist-helm-new-candidates nil) | |
(defvar alchemist-helm-filter-output nil) | |
(defvar alchemist-helm-timeout 1) | |
(defvar alchemist-helm-sleep 0.05) | |
(defvar alchemist-helm-required-length 3) | |
(defvar alchemist-helm-source | |
(helm-build-sync-source "Alchemist Help" | |
:name "Alchemist Help" | |
:init (lambda () | |
(setq alchemist-helm-candidates nil) | |
(require 'alchemist)) | |
:candidates #'alchemist-helm-fetch-candidates | |
:action '(("Show Documentation" . alchemist-helm-show-documentation) | |
("Find Definition" . alchemist-helm-find-definition)) | |
:persistent-action #'alchemist-helm-show-documentation | |
:volatile t | |
:fuzzy-match t | |
:keymap helm-map)) | |
(defun alchemist-helm--build-candidates (output) | |
(let* ((output (alchemist-server-prepare-filter-output output)) | |
(list (alchemist-complete--output-to-list | |
(ansi-color-filter-apply output)))) | |
(cl-loop with mod = (car list) | |
for fun in (cdr list) | |
collecting (concat mod fun)))) | |
(defun alchemist-helm-filter (_process output) | |
(setq alchemist-helm-filter-output (cons output alchemist-helm-filter-output)) | |
(when (alchemist-server-contains-end-marker-p output) | |
(let ((candidates (alchemist-helm--build-candidates alchemist-helm-filter-output))) | |
(setq alchemist-helm-filter-output nil | |
alchemist-helm-candidates | |
(-distinct (nconc candidates alchemist-helm-candidates)) | |
alchemist-helm-new-candidates t)))) | |
(defun alchemist-helm-fetch-candidates () | |
(if (< (length helm-pattern) alchemist-helm-required-length) | |
alchemist-helm-candidates | |
(setq alchemist-helm-new-candidates nil) | |
(alchemist-server-complete-candidates | |
(alchemist-company-build-server-arg helm-pattern) | |
#'alchemist-helm-filter) | |
(with-timeout (alchemist-helm-timeout) | |
(while (and (alchemist-server-process-p) | |
(null alchemist-helm-new-candidates)) | |
(sleep-for alchemist-helm-sleep))) | |
alchemist-helm-candidates)) | |
(defun alchemist-helm-find-definition (candidate) | |
(alchemist-goto--open-definition candidate)) | |
(defun alchemist-helm-show-documentation (candidate) | |
(alchemist-company-show-documentation candidate) | |
(display-buffer alchemist-help-buffer-name)) | |
(defun alchemist-helm-help () | |
(interactive) | |
(helm :sources alchemist-helm-source | |
:buffer "*helm alchemist*" | |
:prompt "Search: ")) | |
(eval-after-load "alchemist" | |
'(define-key alchemist-mode-map (kbd "C-c h") #'alchemist-helm-help)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment