 ;;       + s
 ;;       + powerline
 ;;       + projectile
-;;       + DejaVu Mono for Powerline font <https://github.com/powerline/fonts>
 ;;   + OPTIONAL
 ;;       + evil-mode
 ;;       + anzu + evil-anzu
 ;;       + iedit and evil-multiedit
 ;;       + flycheck
 ;;
-;; The only external functions used are:
-;;  `doom-fix-unicode'  in core/core-defuns.el
-;;  `doom/project-root' in core/defuns/defuns-projectile.el
-;;
-;; Both are simple, isolated functions and, besides projectile, has no other
+;; Both are simple, isolated functions and, besides projectile, have no other
 ;; dependencies.
 
-(defvar mode-line-height 30
+(defvar doom-modeline-height 30
   "How tall the mode-line should be. This is only respected in GUI emacs.")
 
-;; Load powerline only when uncompiled, in order to generate the xpm bitmaps for
-;; the mode-line. This is the tall blue bar on the left of the mode-line.
-;; NOTE Compile this file for a faster startup!
-(eval-when-compile (require 'powerline))
-;; FIXME Don't hardcode colors in
-(defvar mode-line-bar          (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 "#00B3EF" nil)))
-(defvar mode-line-eldoc-bar    (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 "#B3EF00" nil)))
-(defvar mode-line-inactive-bar (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 nil nil)))
-
 ;; Custom faces
-(defface mode-line-is-modified nil
-  "Face for mode-line modified symbol")
-
-(defface mode-line-2 nil
-  "The alternate color for mode-line text.")
-
-(defface mode-line-highlight nil
+(defface doom-modeline-alternate '((t (:inherit mode-line)))
+  "Secondary color for the modeline.")
+
+(defface doom-modeline-highlight '((t (:inherit mode-line)))
   "Face for bright segments of the mode-line.")
 
-(defface mode-line-count-face nil
+(defface doom-modeline-count '((t (:inherit mode-line)))
+  "Face for 'X out of Y' segments, such as `*anzu', `*evil-substitute' and
+`iedit'")
+
+(defface doom-modeline-bar '((t (:inherit doom-modeline-highlight)))
+  "The face used for the left-most bar on the mode-line of an active window.")
+
+(defface doom-modeline-eldoc-bar '((t (:inherit doom-modeline-bar)))
+  "The face used for the left-most bar on the mode-line when eldoc-eval is
+active.")
+
+(defface doom-modeline-inactive-bar '((t (:inherit mode-line-inactive)))
+  "The face used for the left-most bar on the mode-line of an inactive window.")
+
+(defface doom-modeline-count '((t (:inherit mode-line)))
   "Face for anzu/evil-substitute/evil-search number-of-matches display.")
 
-;; Git/VCS segment faces
-(defface mode-line-vcs-info '((t (:inherit warning)))
-  "")
-(defface mode-line-vcs-warning '((t (:inherit warning)))
-  "")
-
-;; Flycheck segment faces
-(defface doom-flycheck-error '((t (:inherit error)))
-  "Face for flycheck error feedback in the modeline.")
-(defface doom-flycheck-warning '((t (:inherit warning)))
-  "Face for flycheck warning feedback in the modeline.")
+(defface doom-modeline-info    '((t (:inherit success)))
+  "Face for info-level messages in the modeline. Used by `*vc'.")
+(defface doom-modeline-warning '((t (:inherit warning)))
+  "Face for warnings in the modeline. Used by `*flycheck'")
+(defface doom-modeline-urgent  '((t (:inherit error)))
+  "Face for errors in the modeline. Used by `*flycheck'")
+
+
+;;
+;; Dependencies
+;;
+
+(require 'powerline)
+
+(require 'all-the-icons)
+
+(use-package eldoc-eval
+  :config
+  (setq eldoc-in-minibuffer-show-fn 'doom-eldoc-show-in-mode-line)
+  (eldoc-in-minibuffer-mode +1))
 
 
 ;;

  (when buffer-file-name
    (propertize
     (f-dirname
      (let ((buffer-path (file-relative-name buffer-file-name (doom/project-root)))
            (max-length (truncate (/ (window-body-width) 1.75))))
        (concat (projectile-project-name) "/"
                (if (> (length buffer-path) max-length)

                        (setq output (substring output 0 -1)))
                      output)
                  buffer-path))))
     'face (if active 'doom-modeline-alternate))))

(defun *buffer-name ()
  "The buffer's base name or id."
  (if buffer-file-name
      (f-filename buffer-file-name)
    (s-trim-left (format-mode-line "%b"))))

(defun *buffer-pwd ()
  "Displays `default-directory', for special buffers like the scratch buffer."
  (concat
   (all-the-icons-octicon
    "file-directory"
    :face 'doom-modeline-alternate :v-adjust -0.05 :height 1.3)
   (propertize (concat " " (abbreviate-file-name default-directory))
               'face `(:inherit doom-modeline-alternate))))

(defun *buffer-state ()
  "Displays symbols representing the buffer's state; which can be one or more
of: non-existent, modified or read-only."
  (let ((state (list)))
    (when buffer-file-name
      (if (file-exists-p buffer-file-name)
          (when (buffer-modified-p)
            (push (all-the-icons-octicon "primitive-dot" :face 'font-lock-keyword-face :height 1.1 :v-adjust -0.05) state))
        (push (all-the-icons-octicon "circle-slash" :face 'doom-modeline-urgent :height 1.1 :v-adjust -0.05) state)))
    (if buffer-read-only (push (all-the-icons-octicon "lock" :face 'doom-modeline-urgent :height 1.1 :v-adjust -0.05) state))
    (when state
      (concat (s-join " " state) " "))))

(defun *buffer-encoding-abbrev ()
  "The line ending convention used in the buffer."
