changeset 277:884f7f932a83

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.
author Augie Fackler <raf@durin42.com>
date Fri, 27 Apr 2012 16:50:05 -0500
parents 46979cef73b6
children c65cc71d7ba1
files .elisp/settings/40.modes.el .elisp/settings/80.go.el
diffstat 2 files changed, 37 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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)
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.")))