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
(add-hook 'before-save-hook 'gofmt-before-save)
(setq indent-tabs-mode t)
;; 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)))
(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 ()
(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 ()
(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 ()
(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)
(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 ()
(insert "<-"))
(defun insert-go-expression ()
(insert ":="))
;;; 46-go-mode.el ends here