Mercurial > dotfiles
annotate .elisp/settings/80.go.el @ 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 | |
children | d77b2e253e99 |
rev | line source |
---|---|
277
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 ;; completions for go |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 (defun af-go-hook () |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 ;; enable tabs |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 (setq tab-width 2) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 (setq-default indent-tabs-mode t) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 (make-variable-buffer-local 'whitespace-style) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 (setq whitespace-style '(trailing lines-tail indentation trailing empty)) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 ) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 (defun af-get-go-elisp-location () |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 (let* ((gobinary (shell-command-to-string "which go")) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 (gobin (substring (file-name-directory gobinary) 0 -1)) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 (goroot (file-name-directory gobin))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 (concat goroot "misc/emacs"))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 (defun af-get-gocode-elisp-location () |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 (let* ((binary (shell-command-to-string "which gocode")) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 (bin (substring (file-name-directory binary) 0 -1)) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 (basedir (file-name-directory bin))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
20 (concat basedir "src/github.com/nsf/gocode/emacs-company/"))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 (let* ((goloc (af-get-go-elisp-location)) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 (goel (concat goloc "/go-mode.el"))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 (if (file-exists-p goel) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
25 (progn |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
26 (message "Go is installed, loading go-mode") |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
27 (add-to-list 'load-path goloc) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
28 (require 'go-mode) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
29 (let* ((loc (af-get-gocode-elisp-location)) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
30 (el (concat loc "/company-go.el"))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
31 (if (file-exists-p el) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
32 (progn |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
33 (message "Found gocode, loading company-mode support...") |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
34 (add-to-list 'load-path loc) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
35 (require 'company-go)) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
36 (message "gocode missing, skipping company-mode support.")))) |
884f7f932a83
emacs go: move go config to a new file
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
37 (message "Go appears to not be installed, skipping Go setup."))) |