Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;;; -*- lexical-binding: t -*-
(require 'company)
(with-eval-after-load "company"
;; everywhere
(global-company-mode)
;;
;;(global-set-key (kbd "<tab>") #'helm-company)
(global-set-key (kbd "M-TAB") #'company-complete)
(defun miracle-eval-wrapping-sexp ()
(interactive)
(let* ((pt (point))
(prev (start-of-sexp pt)))
(when prev
(let ((next (end-of-sexp prev)))
(when next
(miracle-eval-region prev next))))))
;; for once have escape key cancel things in emacs...
(define-key company-active-map (kbd "ESC") 'company-abort))
(with-eval-after-load "miracle"
(defun miracle-eval-string (s callback)
(miracle-send-eval-string
s
(lambda (response)
(miracle-dbind-response response (id value status)
(when (member "done" status)
(remhash id miracle-requests))
(when value
(funcall callback nil value))))))
(defun miracle-get-completions (word callback)
(interactive)
(miracle-eval-string
(format "(do (require '[%s]) (%s/completions \"%s\"))"
"complete.core" "complete.core" word)
(lambda (err s)
(progn
;; XXX
(message (format "received str: %s" s))
(message (format "err: %s" err))
(when (not err)
(funcall callback (read-from-whole-string s)))))))
(defun company-miracle (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-miracle))
(prefix (and (or ;;(eq major-mode 'clojurec-mode)
;;(eq major-mode 'clojure-mode)
(eq major-mode 'miracle-mode))
(get-buffer "*miracle-connection*")
(substring-no-properties (company-grab-symbol))))
(candidates (lexical-let ((arg (substring-no-properties arg)))
(cons :async (lambda (callback)
(miracle-get-completions arg callback)))))))
;; XXX: problems w/o the following when invoking company-grab-symbol
(setq cider-mode nil)
(add-to-list 'company-backends 'company-miracle)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.