 ;;; Code:
 
 ;; -- additional packages not provided by Prelude
-(require 'package)
-(setq package-enable-at-startup nil)
-(package-initialize)
-
-;; (add-to-list 'package-archives
-;;              '("marmalade" .
-;;                "http://marmalade-repo.org/packages/"))
-(prelude-require-packages '(nginx-mode
-                            company-web
-                            linum
-                            linum-off
-                            editorconfig
-                            multi-term
+(prelude-require-packages '(editorconfig
                             ranger
                             use-package))
 
 
-;; This is only needed once, near the top of the file
 (eval-when-compile
   (require 'use-package))
 

  )


;; -- multi-term settings
(require 'multi-term)
(setq multi-term-program "/usr/local/bin/bash")


;; -- Git gutter
(prelude-require-packages '(git-gutter))
(require 'git-gutter)
(require 'zenburn-theme)
(require 'diff-hl)

(global-diff-hl-mode -1)    ;; git-gutter works better in terminal than diff-hl
(global-git-gutter-mode +1)
(git-gutter:linum-setup)

(custom-set-variables
 '(git-gutter:modified-sign "!")
 '(git-gutter:added-sign "+")
 '(git-gutter:deleted-sign "-"))

;; copied from zenburn colors set for diff-hl
(zenburn-with-color-variables
  (custom-theme-set-faces
   'zenburn
   `(git-gutter:modified ((t (:foreground ,zenburn-blue
                              :background ,zenburn-blue-2))))
   `(git-gutter:added ((t (:foreground ,zenburn-green+1



;; -- custom ace-window shortcut (<s-w>, i.e., Command-w doesn't work in terminal)
(use-package ace-window
  :bind* ("M-o" . ace-window))


;; -- disable advanced purist mode
(use-package prelude-custom
  :config
  (setq prelude-guru nil))


;; -- line numbers
(prelude-require-packages '(linum linum-off))

(use-package linum
  :bind ("C-x n" . linum-mode)
  :config
  (global-linum-mode 0))

(defvar-local linum-format-fmt nil)

(defun linum-format-func (line)
  "Add separator between LINE numbers and text."
  (concat
   (propertize (format linum-format-fmt line) 'face 'linum)
   (propertize " " 'face 'mode-line)))

(defun linum-set-format-fmt ()
  "Dynamically compute linum-format.  Fancy but still slow!"
  (setq-local linum-format-fmt
              (let ((w (length (number-to-string
                                (count-lines (point-min) (point-max))))))
                (concat "%" (number-to-string w) "d"))))

(use-package linum
  :unless window-system
  :init
  (add-hook 'linum-before-numbering-hook 'linum-set-format-fmt)
  :config
  (setq linum-format 'linum-format-func)
  )


;; -- spell checker
(use-package prelude-custom
  :disabled
  :config
  (setq prelude-flyspell nil))

(use-package ispell
  :config
  (setq ispell-dictionary "en_US"))


;;  -- linter
(use-package flycheck
  :bind ("<f7>" . flycheck-buffer-and-list-errors)
  :init
  (add-hook 'after-init-hook #'global-flycheck-mode)
  :config
  (defun flycheck-buffer-and-list-errors ()
    "Execute command flycheck-buffer and flycheck-list-errors."
    (interactive)
    (flycheck-buffer)
    (flycheck-list-errors)
    (other-window 1)
    )
  (setq flycheck-check-syntax-automatically '(mode-enabled save))
  (setq flycheck-indication-mode 'left-fringe)
  (setq-default flycheck-emacs-lisp-load-path 'inherit)
  )


;; -- web
(prelude-require-packages '(nginx-mode company-web))

(use-package web-mode
  :init
  (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
