Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/brianjcj/gocode
Browse files Browse the repository at this point in the history
  • Loading branch information
nsf committed Dec 7, 2014
2 parents 56d7ca8 + 42bbb9a commit b4017a7
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions emacs/go-autocomplete.el
Expand Up @@ -113,8 +113,48 @@

(defun ac-go-action ()
(let ((item (cdr ac-last-completion)))
(if (stringp item)
(message "%s" (get-text-property 0 'summary item)))))
(when (stringp item)
(setq symbol (get-text-property 0 'summary item))
(message "%s" symbol)
(when (featurep 'yasnippet)
(ac-go-insert-yas-snippet-string symbol)))))

(defun ac-go-insert-yas-snippet-string (s)
(let ((ret "") (pos (point)) match-res match args)
(save-match-data
(setq match-res (string-match "func(." s))
(when (and match-res (= 0 match-res))
(setq match (match-string 0 s))
(unless (string= match "func()")
(setq args (ac-go-split-args s))
(dolist (arg args)
(setq ret (concat ret "${" arg "}, ")))
(when (> (length ret) 2)
(setq ret (substring ret 0 (- (length ret) 2)))))
(setq ret (concat "(" ret ")"))
(yas/expand-snippet ret pos pos)))))

(defun ac-go-split-args (args-str)
(let ((cur 5)
(pre 5)
(unmatch-l-paren-count 1)
(args (list))
c)
(while (> unmatch-l-paren-count 0)
(setq c (aref args-str cur))
(cond ((= ?\( c)
(setq unmatch-l-paren-count (1+ unmatch-l-paren-count)))
((= ?\) c)
(setq unmatch-l-paren-count (1- unmatch-l-paren-count))
(when (= 0 unmatch-l-paren-count)
(push (substring args-str pre cur) args)))
((= ?\, c)
(when (= 1 unmatch-l-paren-count)
(push (substring args-str pre cur) args)
(setq cur (+ cur 2))
(setq pre cur))))
(setq cur (1+ cur)))
(nreverse args)))

(defun ac-go-document (item)
(if (stringp item)
Expand Down

0 comments on commit b4017a7

Please sign in to comment.