 ;; This file is not part of GNU Emacs.
 ;;
 ;;; License: GPLv3
+
+(defface spacemacs-micro-state-header-face
+  `((t (:background
+        "DarkGoldenrod2"
+        :foreground "black"
+        :bold t :box ,(face-attribute 'mode-line :box))))
+  "Face for micro-state header in echo area.
+The header is composed of the text before the first `:'"
+  :group 'spacemacs)
+
+(defface spacemacs-micro-state-binding-face
+    `((t (:foreground ,(face-attribute 'error :foreground) :bold t)))
+  "Face for micro-state key binding in echo area.
+Characters enclosed in `[]' will have this face applied to them."
+  :group 'spacemacs)
 
 (defmacro spacemacs|define-micro-state (name &rest props)
   "Define a micro-state called NAME.

    `(defun ,func ()
       ,(format "%s micro-state." (symbol-name name))
       (interactive)
       (let ((doc ,@doc)) (when doc (echo doc)))
       ,@on-enter
       (,(if (version< emacs-version "24.4")
             'set-temporary-overlay-map

               (equal (this-command-keys) (kbd key)))
      (not (plist-get wrapper :exit)))))

(defun spacemacs//micro-state-propertize-doc (doc)
  "Return a propertized doc string from DOC."
  (when (string-match "^\\(.+?\\):\\([[:ascii:]]*\\)$" doc)
    (let* ((header (match-string 1 doc))
           (pheader (when header
                      (propertize (concat " " header " ")
                                  'face 'spacemacs-micro-state-header-face)))
           (tail (spacemacs//micro-state-propertize-doc-1
                  (match-string 2 doc))))
      (message (concat pheader tail))
      (concat pheader tail))))

(defun spacemacs//micro-state-propertize-doc-1 (doc)
  "Recursively propertize keys"
  (message "doc %s" doc)
  (if (string-match "^\\([[:ascii:]]*?\\)\\(\\[.+?\\]\\)\\([[:ascii:]]*\\)$" doc)
      (let* ((head (match-string 1 doc))
             (key (match-string 2 doc))
             (pkey (when key
                     (propertize key 'face 'spacemacs-micro-state-binding-face)))
             (tail (spacemacs//micro-state-propertize-doc-1
                    (match-string 3 doc))))
        (concat head pkey tail))
    doc))

(provide 'core-micro-state)
