Procházet zdrojové kódy

Added configurations for go enviorment

Includes setting some environment variables and emacs auto-
complete/syntax checking.
Thomas Flucke před 7 roky
rodič
revize
dff7572491
3 změnil soubory, kde provedl 90 přidání a 41 odebrání
  1. 9 0
      .config/env/go.sh
  2. 4 7
      .emacs.d/Thomas-Experiement-theme.el
  3. 77 34
      .emacs.d/init.el

+ 9 - 0
.config/env/go.sh

@@ -0,0 +1,9 @@
+#!/usr/bin/sh
+
+export GOPATH="$HOME/workspace/go"
+export GOROOT="/usr/lib/go-1.10/"
+
+if [ ! -f "$GOPATH/bin/gocode" ] && which gocode > /dev/null; then
+    mkdir -p "$GOPATH/bin"
+    ln -s $(which gocode) "$GOPATH"/bin/gocode
+fi

+ 4 - 7
.emacs.d/Thomas-Experiement-theme.el

@@ -1,5 +1,5 @@
 (deftheme Thomas-Experiement
-  "Created 2018-08-17.")
+  "Created 2018-09-04.")
 
 (custom-theme-set-faces
  'Thomas-Experiement
@@ -7,7 +7,6 @@
  '(fixed-pitch ((t (:family "Monospace"))))
  '(variable-pitch ((((type w32)) (:foundry "outline" :family "Arial")) (t (:family "Sans Serif"))))
  '(escape-glyph ((((background dark)) (:foreground "cyan")) (((type pc)) (:foreground "magenta")) (t (:foreground "brown"))))
- '(homoglyph ((((background dark)) (:foreground "cyan")) (((type pc)) (:foreground "magenta")) (t (:foreground "brown"))))
  '(minibuffer-prompt ((t (:foreground "blue"))))
  '(highlight ((t (:background "color-88"))))
  '(region ((t (:background "brightblue"))))
@@ -46,13 +45,11 @@
  '(match ((t (:inverse-video t :foreground "blue" :background "brightgreen"))))
  '(next-error ((t (:inherit (region)))))
  '(query-replace ((t (:inherit (isearch)))))
- '(ensime-errline-highlight ((t (:inherit nil :foreground "brightred" :underline (:color foreground-color :style wave) :slant italic :weight semi-bold))))
- '(ensime-warnline-highlight ((t (:inherit font-lock-warning-face))))
- '(scala-font-lock:var-face ((t (:inherit font-lock-variable-name-face))))
  '(show-paren-match ((t (:background "blue" :foreground "green"))))
- '(show-paren-match-expression ((t (:inherit (show-paren-match)))))
  '(show-paren-mismatch ((t (:background "red" :foreground "white" :underline (:color foreground-color :style wave)))))
+ '(c-annotation-face ((t (:inherit font-lock-preprocessor-face))))
  '(default ((t (:family "default" :foundry "default" :width normal :height 1 :weight normal :slant normal :underline nil :overline nil :strike-through nil :box nil :inverse-video nil :foreground "white" :background "black" :stipple nil :inherit nil))))
- '(c-annotation-face ((t (:inherit font-lock-preprocessor-face)))))
+ '(flycheck-error ((((supports :underline (:style wave))) (:underline (:color "Red1" :style wave))) (t (:inherit (error) :underline (:color foreground-color :style line)))))
+ '(error ((t (:foreground "red" :weight bold)))))
 
 (provide-theme 'Thomas-Experiement)

+ 77 - 34
.emacs.d/init.el

@@ -1,10 +1,8 @@
 ;; Requires:
-;; aspell
+;; aspell - Spell checking
+;; xclip  - Copy/Paste
 ;; Optional:
-;; clang
-
-;; TODO
-;; Look up authors of projects.  See what other useful things they make.
+;; gocode - Go auto complete
 
 ;; ----------- Default Variables -----------
 ;; Global variables
@@ -18,8 +16,6 @@
 			  show-paren-delay 0.25
               tab-width 4
 	          indent-tabs-mode nil
-              ;x-select-enable-clipboard t
-              ;interprogram-paste-function 'x-cut-buffer-or-selection-value
               backup-directory-alist `(("." . ,backup-directory))
               delete-old-versions t)
 
@@ -28,7 +24,13 @@
 ;; Delete selected text when typing (normal editor behavior)
 (delete-selection-mode t)
 
-;; ------------- Keybindings -------------
+;; ------------ Utility Code -------------
+(defun package-installed (package)
+  "Checks whether or not a package is installed.
+
+Includes the package if it's available"
+    (require package  nil :noerror))
+
 (defun smart-beginning-of-line ()
   "Move point to first non-whitespace character or beginning-of-line.
 
@@ -42,6 +44,7 @@ If point was already at that position, move point to beginning of line."
     (and (= oldpos (point))
          (beginning-of-line))))
 
+;; ------------- Keybindings -------------
 (global-set-key [home] 'smart-beginning-of-line)
 (global-set-key (kbd "C-c /") 'comment-or-uncomment-region)
 (global-set-key (kbd "C-c C-k") 'compile)
@@ -66,12 +69,14 @@ If point was already at that position, move point to beginning of line."
       package-archive-priorities '(("melpa" . 1)))
 (package-initialize)
 
+;; Configure use-package
 (unless (package-installed-p 'use-package)
   (package-refresh-contents)
   (package-install 'use-package))
 (require 'use-package)
 (setq use-package-always-ensure t)
 
+;; Auto update packages
 (use-package auto-package-update
   :config
   (add-hook 'auto-package-update-before-hook
@@ -88,10 +93,6 @@ If point was already at that position, move point to beginning of line."
 ;; Also seems to ignore most properties. (e.g. overline, underline,
 ;; strike-though, etc.)  Maybe it's an xterm problem?
 (use-package color-theme
-  :init
-  ;; TODO: Fixes error about missing directory.  Don't know why.
-  ;(unless (file-exists-p "~/.emacs.d/elpa/color-theme-20070910.1007/themes")
-  ;  (make-directory "~/.emacs.d/elpa/color-theme-20070910.1007/themes"))
   :config
   (color-theme-initialize)
   (load-theme 'Thomas-Experiement t))
@@ -99,20 +100,24 @@ If point was already at that position, move point to beginning of line."
 ;; ---------- Use X11 clipboard -----------
 (use-package xclip
   :if (executable-find "xclip")
-  :config
+  :init
   (add-to-list 'load-path "~/.emacs.d/elpa/xclip-1.4/")
+  :config
   (xclip-mode 1))
 
 ;; --------- Parentheses Matching ---------
 (show-paren-mode)
 (use-package highlight-parentheses
-  :config
+  :init
   (define-globalized-minor-mode global-highlight-parentheses-mode
 	highlight-parentheses-mode
 	(lambda ()
 	  (highlight-parentheses-mode t)))
+  :config
   (global-highlight-parentheses-mode t))
 
+;; Use built-in pairing if available.
+;; Otherwise install substitute
 (if (version<= "24.4" emacs-version)
     (electric-pair-mode)
   (use-package autopair
@@ -126,15 +131,34 @@ If point was already at that position, move point to beginning of line."
   :config
   (xterm-mouse-mode t))
 
+;; ---------- Auto-complete -----------
+(use-package company
+  :init
+  (add-hook 'after-init-hook 'global-company-mode)
+  :config
+  (setq
+   company-minimum-prefix-length   2
+  ;; company-idle-delay              nil
+  ;;       company-show-numbers            t
+  ;;       company-tooltip-limit           20
+  ;;      company-dabbrev-downcase        nil
+   )
+  ;; :bind ("C-;" . company-complete-common)
+  )
+
+;; ---------- Syntax Checking -----------
+(use-package flycheck
+  :config
+  (setq flycheck-check-syntax-automatically '(mode-enabled idle-change save)))
+
 ;; ----------- Ensime -----------
 ;; Java/Scala featues.  Includes:
 ;; * Inferred types
-;; * Autocomplete
+;; * Auto-complete
 ;; * Syntax highlighting
 ;; * Jump to source/docs
 ;; * Refactoring
 ;; * Error detection
-(use-package company)
 
 (if (version<= "24.4" emacs-version)
     (use-package ensime
@@ -170,19 +194,6 @@ If point was already at that position, move point to beginning of line."
 ;;   (add-hook 'irony-mode-hook irony-cdb-autosetup-compile-options)
 ;;   )
 
-;; (use-package company
-;;   :init (add-hook 'after-init-hook 'global-company-mode)
-;;   :config
-;;   (setq company-idle-delay              nil
-;;         company-minimum-prefix-length   2
-;;         company-show-numbers            t
-;;         company-tooltip-limit           20
-;;         company-dabbrev-downcase        nil
-;;         company-backends                '((company-irony company-gtags))
-;;         )
-;;   :bind ("C-;" . company-complete-common)
-;;   )
-
 ;; (use-package company-irony
 ;;   :requires company)
 
@@ -229,15 +240,39 @@ an opening tag that is not followed by a matching closing tag."
 
 ;; ----------- Rust Mode ------------
 (use-package rust-mode)
+
 (use-package rust-playground
   :requires rust-mode)
-(use-package cargo
-  :after rust-mode)
-(use-package flycheck-rust
-  :after rust-mode)
+
+(use-package cargo)
+
+(use-package flycheck-rust)
 
 ;; ----------- Go Mode -------------
-(use-package go-mode)
+(defun go-sanitize-env ()
+  "Check that then environment is configured properly for Go"
+  (unless (getenv "GOPATH")
+    (error "GOPATH is not set."))
+  (unless (getenv "GOROOT")
+    (error "GOROOT is not set.")))
+
+(defun my-go-mode-hook ()
+  (add-hook 'before-save-hook 'gofmt-before-save)
+  (setq gofmt-command "goimports")
+  (if (not (string-match "go" compile-command))
+      (set (make-local-variable 'compile-command)
+           "go build -v && go test -v && go vet")))
+
+(use-package go-mode
+  :config
+  (add-hook 'go-mode-hook 'my-go-mode-hook)
+  (add-hook 'go-mode-hook 'flycheck-mode))
+
+(use-package company-go
+  :if (executable-find "gocode")
+  :config
+  (add-hook 'go-mode-hook 'go-sanitize-env)
+  (push 'company-go company-backends))
 
 ;; ----------- i3 Support ----------
 (use-package i3wm
@@ -394,3 +429,11 @@ an opening tag that is not followed by a matching closing tag."
              lpr-region)
   :config
   (pr-update-menus t))
+
+;; Configure auto-complete if installed
+;; Used in case something installs it as a dependency
+(when (package-installed 'auto-complete)
+  (ac-config-default)
+  ;; Fix conflict between flyspell and auto-complete
+  (when (package-installed 'flyspell)
+    (ac-flyspell-workaround)))