Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (73 sloc) 2.52 KB
;;; 46-go-mode.el --- go-mode設定 -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'go-mode)
(require 'go-autocomplete)
(require 'go-flymake)
(setq gofmt-command "goimports")
(add-hook 'go-mode-hook
'(lambda()
(add-hook 'before-save-hook 'gofmt-before-save)
(common-mode-init)
(setq indent-tabs-mode t)
(go-eldoc-setup)))
;; helm-ghq-list
(defun helm-ghq--get-candidates ()
(let* ((cmd-result (funcall 'shell-command-to-string "ghq list"))
(candidates (split-string cmd-result "\n"))
(candidates (sort candidates 'string<))
(candidates (cdr candidates)))
candidates))
(defvar helm-ghq-list-source
(helm-build-sync-source "Helm ghq list"
:candidates (helm-ghq--get-candidates)
:candidate-number-limit 300
:action 'helm-ghq--dired))
(defun helm-ghq--dired (name)
(when (one-window-p)(split-window-horizontally))
(other-window 1)
(dired (concat (getenv "GOPATH") "/src/" name)))
(defun helm-ghq-list ()
(interactive)
(helm :sources '(helm-ghq-list-source) :buffer "*helm ghq list*"))
;; helm-go-packages
(defvar helm-go-packages-source
(helm-build-sync-source "Helm Go Packages"
:candidates (go-packages)
:candidate-number-limit 300
:action 'godoc))
(defun helm-go-package-import-add (candidate)
(dolist (package (helm-marked-candidates))
(go-import-add current-prefix-arg package)))
(defun helm-go-packages ()
(interactive)
(helm :sources '(helm-go-packages-source) :buffer "*helm go packages*"))
;; Change godoc buffer name
(defun godoc--get-buffer (query)
"Get an empty buffer for a godoc QUERY."
(let* ((buffer-name "*godoc*")
(buffer (get-buffer buffer-name)))
;; Kill the existing buffer if it already exists.
(when buffer (kill-buffer buffer))
(get-buffer-create buffer-name)))
;; Docoument Popup
(defun godoc-popup ()
(interactive)
(unless (use-region-p)
(error "Dose not region selection"))
(let ((query (buffer-substring-no-properties (region-beginning) (region-end))))
(run-at-time 0.1 nil 'deactivate-mark)
(popup-tip
(with-temp-buffer
(let ((standard-output (current-buffer))
(help-xref-following t))
(prin1 (funcall 'shell-command-to-string (concat "go doc " query)))
(buffer-substring-no-properties (+ (point-min) 1) (- (point-max) 3)))))))
;; Shortcut
(defun insert-go-channel-arrow ()
(interactive)
(insert "<-"))
(defun insert-go-expression ()
(interactive)
(insert ":="))
;;; 46-go-mode.el ends here