-
-
Save mk0x9/756494 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defun ac-go-candidates () | |
(ac-go-autocomplete)) | |
(defvar ac-source-go | |
'((candidates . ac-go-candidates) | |
(prefix . "\\.\\(.*\\)") | |
(requires . 0))) | |
(defun ac-go-get-candidate-strings (tmpbuf) | |
(split-string (with-current-buffer tmpbuf (buffer-string)) "\n")) | |
(defun ac-go-get-candidates (strs) | |
(mapcar (lambda (entry) | |
(let ((name (nth 0 entry)) | |
(summary (nth 1 entry))) | |
(propertize name | |
'summary summary))) | |
(mapcar (lambda (str) | |
(split-string str ",,")) | |
strs))) | |
(defun ac-go-autocomplete () | |
(let ((tmpbuf (generate-new-buffer "*gocode*"))) | |
(call-process-region (point-min) (point-max) "gocode" nil tmpbuf nil "-f=emacs" "autocomplete" "" (int-to-string (- (point) 1))) | |
(prog1 | |
(ac-go-get-candidates (ac-go-get-candidate-strings tmpbuf)) | |
(kill-buffer tmpbuf)))) | |
(add-hook 'go-mode-hook '(lambda() | |
(auto-complete-mode 1) | |
(setq ac-sources '(ac-source-go)))) | |
(provide 'go-autocomplete) | |
; in .emacs | |
; (require 'go-autocomplete) | |
; (require 'auto-complete-config) | |
; (define-key ac-mode-map (kbd "M-TAB") 'auto-complete) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment