# HG changeset patch # User Augie Fackler # Date 1335563405 18000 # Node ID 884f7f932a836a9ee4ad4d38b782ec6d93966709 # Parent 46979cef73b640dbfd2b6804e692ac121243f470 emacs go: move go config to a new file This uses some clever shell tricks to identify the location (if any) of the go installation and gocode and load their supporting packages if available. diff --git a/.elisp/settings/40.modes.el b/.elisp/settings/40.modes.el --- a/.elisp/settings/40.modes.el +++ b/.elisp/settings/40.modes.el @@ -27,25 +27,6 @@ point." (add-hook 'rst-mode-hook 'af-no-clean-whitespace) (add-hook 'makefile-mode-hook 'af-no-clean-whitespace) - -(defun af-go-hook () - ;; enable tabs - (setq tab-width 2) - (setq-default indent-tabs-mode t) - (make-variable-buffer-local 'whitespace-style) - (setq whitespace-style '(trailing lines-tail indentation trailing empty)) - (message "Fixed whitespace style") - ) - - -(let ((go-emacs (concat (getenv "GOROOT") "/misc/emacs"))) - (message (concat go-emacs "/go-mode.el")) - (if (file-exists-p (concat go-emacs "/go-mode.el")) - (progn (add-to-list 'load-path go-emacs) - (require 'go-mode-load) - (add-hook 'go-mode-hook 'af-go-hook)) - (message "Go appears to not be installed, skipping go-mode."))) - (autoload 'js2-mode "js2" nil t) (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) (add-hook 'js2-mode-hook 'af-tab-fix) diff --git a/.elisp/settings/80.go.el b/.elisp/settings/80.go.el new file mode 100644 --- /dev/null +++ b/.elisp/settings/80.go.el @@ -0,0 +1,37 @@ +;; completions for go +(defun af-go-hook () + ;; enable tabs + (setq tab-width 2) + (setq-default indent-tabs-mode t) + (make-variable-buffer-local 'whitespace-style) + (setq whitespace-style '(trailing lines-tail indentation trailing empty)) + ) + +(defun af-get-go-elisp-location () + (let* ((gobinary (shell-command-to-string "which go")) + (gobin (substring (file-name-directory gobinary) 0 -1)) + (goroot (file-name-directory gobin))) + (concat goroot "misc/emacs"))) + +(defun af-get-gocode-elisp-location () + (let* ((binary (shell-command-to-string "which gocode")) + (bin (substring (file-name-directory binary) 0 -1)) + (basedir (file-name-directory bin))) + (concat basedir "src/github.com/nsf/gocode/emacs-company/"))) + +(let* ((goloc (af-get-go-elisp-location)) + (goel (concat goloc "/go-mode.el"))) + (if (file-exists-p goel) + (progn + (message "Go is installed, loading go-mode") + (add-to-list 'load-path goloc) + (require 'go-mode) + (let* ((loc (af-get-gocode-elisp-location)) + (el (concat loc "/company-go.el"))) + (if (file-exists-p el) + (progn + (message "Found gocode, loading company-mode support...") + (add-to-list 'load-path loc) + (require 'company-go)) + (message "gocode missing, skipping company-mode support.")))) + (message "Go appears to not be installed, skipping Go setup.")))