emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ergoemacs-mode 48c6d90 274/325: Merge branch 'mattfidle


From: Stefan Monnier
Subject: [elpa] externals/ergoemacs-mode 48c6d90 274/325: Merge branch 'mattfidler-master'
Date: Sat, 23 Oct 2021 18:49:09 -0400 (EDT)

branch: externals/ergoemacs-mode
commit 48c6d90aca9f3fefeedef1552e8a75fc20885788
Merge: f9d6e3f b815b1d
Author: Matthew Fidler <514778+mattfidler@users.noreply.github.com>
Commit: Matthew Fidler <514778+mattfidler@users.noreply.github.com>

    Merge branch 'mattfidler-master'
---
 Makefile                        |    6 +-
 ergoemacs-advice.el             |  318 +----
 ergoemacs-calculate-bindings.el |  179 +++
 ergoemacs-command-loop.el       |  170 ++-
 ergoemacs-component.el          | 1870 ------------------------
 ergoemacs-debug.el              |    4 +-
 ergoemacs-functions.el          |  366 ++---
 ergoemacs-key-description.el    |  101 +-
 ergoemacs-layouts.el            |   60 +-
 ergoemacs-lib.el                |  594 +-------
 ergoemacs-macros.el             |  824 +----------
 ergoemacs-map-properties.el     | 1232 ----------------
 ergoemacs-map.el                |  778 +---------
 ergoemacs-mode.el               |  904 +++---------
 ergoemacs-score.el              |  439 ------
 ergoemacs-test.el               | 1313 +----------------
 ergoemacs-theme-engine.el       |  832 ++---------
 ergoemacs-themes.el             | 2988 ++++++++++++++++-----------------------
 ergoemacs-translate.el          |   60 +-
 19 files changed, 2123 insertions(+), 10915 deletions(-)

diff --git a/Makefile b/Makefile
index 09b4822..6773e83 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,8 @@ TRAVIS_FILE=.travis.yml
          test test-interactive clean edit test-dep-1 test-dep-2 test-dep-3     
\
          test-dep-4 test-dep-5 test-dep-6 test-dep-7 test-dep-8 test-dep-9
 
+.DEFAULT_GOAL = compile
+
 24.1 :
        $(eval 
EMACS:="c:\Users\fidlema3\EmacsPortable.App\App\emacs-24.1\bin\emacs.exe")
 
@@ -105,12 +107,12 @@ start0:
        $(EMACS) -Q -L . -L .. -l ergoemacs-mode -l ergoemacs-test --eval 
"(ergoemacs-mode)"
 
 ert :
-       $(EMACS) $(EMACS_BATCH) -L . -L .. -l cl -l ergoemacs-mode -l 
ergoemacs-test --eval \
+       $(EMACS) $(EMACS_BATCH) -L . -L .. -l cl-lib -l ergoemacs-mode -l 
ergoemacs-test --eval \
            "(progn (setq ergoemacs-command-loop-type nil)                      
                    \
              (ert-run-tests-batch-and-exit '(and \"$(TESTS)\" $(SELECT) (not 
(tag :interactive)))))" || exit 1; \
 
 erti :
-       $(EMACS) $(EMACS_BATCH) -L . -L .. -l cl -l ergoemacs-mode -l 
ergoemacs-test --eval \
+       $(EMACS) $(EMACS_BATCH) -L . -L .. -l cl-lib -l ergoemacs-mode -l 
ergoemacs-test --eval \
            "(progn (setq ergoemacs-command-loop-type nil)                      
                   \
              (fset 'ert--print-backtrace 'ignore)  \
              (ert-run-tests-batch-and-exit '(and \"$(TESTS)\" $(SELECT) (not 
(tag :interactive)))))" || exit 1; \
diff --git a/ergoemacs-advice.el b/ergoemacs-advice.el
index 2908bea..feb7724 100644
--- a/ergoemacs-advice.el
+++ b/ergoemacs-advice.el
@@ -34,24 +34,13 @@
   (require 'ergoemacs-macros))
 
 (require 'mouse)
+(require 'nadvice)
 
 (defvar ergoemacs-mode)
 (defvar ergoemacs-keymap)
 (defvar ergoemacs-map--unbound-keys)
-(defvar ergoemacs-saved-global-map)
 (defvar ergoemacs-user-keymap)
 
-(declare-function ergoemacs-map-- "ergoemacs-map")
-
-(declare-function ergoemacs-map-properties--hook-define-key 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--ignore-global-changes-p 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--installed-p 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--label "ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--map-fixed-plist 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--original 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--original-user 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--global-submap-p 
"ergoemacs-map-properties")
-
 (declare-function ergoemacs-key-description--substitute-command-keys 
"ergoemacs-key-description")
 
 (declare-function ergoemacs-translate--define-key "ergoemacs-translate")
@@ -65,290 +54,35 @@
 (declare-function ergoemacs-command-loop--temp-message 
"ergoemacs-command-loop")
 (declare-function ergoemacs-key-description "ergoemacs-key-description")
 
-(defvar ergoemacs-advice--temp-replace-functions nil
-  "List of `ergoemacs-mode' temporary replacement functions.
-
-These replacement functions are are turned on when
-`ergoemacs-mode' is turned on.")
-
-(defvar ergoemacs-advice--permanent-replace-functions nil
-  "List of `ergoemacs-mode' permanent replacement functions.
- 
-These replacement functinos are turned on after `ergoemacs-mode'
-is loaded, but not turned off.")
-
-(defun ergoemacs-advice--enable-replacement (ad &optional disable)
-  "Enable ergoemacs-c advice AD (or optionally DISABLE)."
-  (cond
-   (disable
-    (when (fboundp (intern (concat "ergoemacs-advice--real-" (symbol-name 
ad))))
-      (defalias ad (intern (concat "ergoemacs-advice--real-" (symbol-name ad)))
-        (documentation (intern (concat "ergoemacs-advice--real-" (symbol-name 
ad)))))))
-   (t
-    (when (fboundp (intern (concat "ergoemacs-advice--" (symbol-name ad))))
-      (defalias ad (intern (concat "ergoemacs-advice--" (symbol-name ad)))
-        (documentation (intern (concat "ergoemacs-advice--" (symbol-name 
ad)))))))))
-
-(defun ergoemacs-advice--enable-replacements (&optional disable permanent)
-  "Enable the function replacements.
-
-When DISABLE is non-nil, disable the replacements.
-
-When PERMANENT is non-nil, these replacements are permanent, not temporary."
-  (dolist (ad (or (and permanent ergoemacs-advice--permanent-replace-functions)
-                  ergoemacs-advice--temp-replace-functions))
-    (ergoemacs-advice--enable-replacement ad disable)))
-
-(add-hook 'ergoemacs-mode-startup-hook 'ergoemacs-advice--enable-replacements)
-
-(defun ergoemacs-advice--disable-replacements ()
-  "Disable the function replacements."
-  (ergoemacs-advice--enable-replacements t))
-
-(add-hook 'ergoemacs-mode-shutdown-hook 
'ergoemacs-advice--disable-replacements)
-
-(defun ergoemacs-advice--enable-permanent-replacements ()
-  "Enable permanent replacements."
-  (ergoemacs-advice--enable-replacements nil t))
-
-(add-hook 'ergoemacs-mode-intialize-hook 
'ergoemacs-advice--enable-permanent-replacements)
-
-(defvar ergoemacs--original-local-map nil
-  "Original keymap used with `use-local-map'.")
-
-(ergoemacs-advice use-local-map (keymap)
-  "Load `ergoemacs-mode' is the local keymap.
-
-The original keymap is untouched."
-  :type :before
-  (set (make-local-variable 'ergoemacs--original-local-map) keymap))
-
-;; FIXME for emacs 25
-(ergoemacs-advice substitute-command-keys (string)
+(defun ergoemacs-advice-substitute-command-keys (orig-fun &rest args)
   "Use `ergoemacs-substitute-command-keys' when `ergoemacs-mode' is enabled"
-  :type :replace
-  (if ergoemacs-mode
-      (ergoemacs-key-description--substitute-command-keys string)
-    (ergoemacs-advice--real-substitute-command-keys string)))
-
-(defvar ergoemacs-run-mode-hooks nil)
-(ergoemacs-advice run-mode-hooks (&rest hooks)
-  "Setup properties for `ergoemacs-map-properties--protect-local' before each 
function is run."
-  :type :around
-  (unwind-protect
-      (progn
-        (when (and (not ergoemacs-run-mode-hooks)
-                  (fboundp 'ergoemacs-map-properties--modify-run-mode-hooks)
-                   (boundp 'ergoemacs-mode))
-         (setq ergoemacs-run-mode-hooks t)
-          (ergoemacs-map-properties--modify-run-mode-hooks hooks))
-        ad-do-it
-       (setq ergoemacs-run-mode-hooks nil))
-    (when (and (fboundp 'ergoemacs-map-properties--reset-run-mode-hooks)
-               (boundp 'ergoemacs-mode))
-      (setq ergoemacs-run-mode-hooks t)
-      (ergoemacs-map-properties--reset-run-mode-hooks hooks)
-      (setq ergoemacs-run-mode-hooks nil))))
-
-(ergoemacs-advice run-hooks (&rest hooks)
-  "Setup properties for `ergoemacs-map-properties--protect-local' before each 
function is run."
-  :type :around
-  (unwind-protect
-      (progn
-        (when (and (fboundp 'ergoemacs-map-properties--modify-run-mode-hooks)
-                   (boundp 'ergoemacs-mode))
-          (ergoemacs-map-properties--modify-run-mode-hooks hooks))
-        ad-do-it)
-    (when (and (fboundp 'ergoemacs-map-properties--reset-run-mode-hooks)
-               (boundp 'ergoemacs-mode))
-      (ergoemacs-map-properties--reset-run-mode-hooks hooks))))
-
-(defvar ergoemacs-define-key-after-p nil
-  "Flag to tell `ergoemacs-mode' to suppress `define-key' advice.")
-
-(defun ergoemacs-define-key-after (keymap key def)
-  "`ergoemacs-mode' modification to `define-key' called after `define-key'.
-
-KEYMAP is the keymap being modified
-KEY is the key that is being defined
-DEF is the key definition
-
-These should be the same as what is used in `define-key'.
-
-To protect from infinite recurion, the flag
-`ergoemacs-define-key-after-p' is set while applying
-`ergoemacs-mode' adjustments.
-
-`ergoemacs-mode' adjusts any globally defined keys so they will
-appear in the `ergoemacs-mode' keymaps.
-
-This advice also appempts to protcet local keymaps when
-`ergoemacs-map-properties--protect-local' is non-nil.  This is
-part of how `ergoemacs-mode' determines that a hook changed a key
-definition."
-  (when (eq keymap global-map) ;; (current-global-map)
-    (ergoemacs :define-key ergoemacs-user-keymap key def)
-    (when (ergoemacs-keymapp ergoemacs-saved-global-map)
-      (ergoemacs :define-key ergoemacs-saved-global-map key def))
-    (cond
-     ((not def)
-      (ergoemacs :apply-key key
-                (lambda(trans-new-key)
-                  (push trans-new-key ergoemacs-map--unbound-keys))))
-     (def
-      (let (trans-keys
-           new-lst)
-       (ergoemacs :apply-key key
-                  (lambda(trans-new-key)
-                    (push trans-new-key trans-keys)))
-       (push key trans-keys)
-       (dolist (cur-key ergoemacs-map--unbound-keys)
-         (unless (member cur-key trans-keys)
-           (push cur-key new-lst)))
-       (setq ergoemacs-map--unbound-keys new-lst)))))
-    
-  (unless ergoemacs-define-key-after-p
-    (setq ergoemacs-define-key-after-p t)
-    (unwind-protect
-        (progn
-          (when (and (boundp 'ergoemacs-map-properties--protect-local)
-                     ergoemacs-map-properties--protect-local)
-            (ergoemacs-map-properties--hook-define-key keymap key def)))
-      (setq ergoemacs-define-key-after-p nil))))
-
-(ergoemacs-advice define-key (keymap key def)
-  "Protect keymaps when changing keys from a hook."
-  :type :after
-  (ergoemacs-define-key-after keymap key def))
-
-
-(ergoemacs-advice set-temporary-overlay-map (map &optional keep-pred on-exit)
-  "Assume map properties"
-  :type :before
-  (ergoemacs-map--temporary-map-properties map))
-
-(ergoemacs-advice set-transient-map (map &optional keep-pred on-exit)
-  "Assume map properties"
-  :type :before
-  (ergoemacs-map--temporary-map-properties map))
-
-(ergoemacs-advice er/prepare-for-more-expansions ()
-  "Don't let `ergoemacs-mode' modify the transient keymap."
-  :type :around
-  (let ((old ergoemacs-modify-transient-maps))
-    (unwind-protect
-        (progn
-          (setq ergoemacs-modify-transient-maps t)
-          ad-do-it)
-      (setq ergoemacs-modify-transient-maps old))))
-
-(ergoemacs-advice ace-jump-do (re-query-string)
-  "Don't let `ergoemacs-mode' modify the transient keymap."
-  :type :around
-  (let ((old ergoemacs-modify-transient-maps))
-    (unwind-protect
-        (progn
-          (setq ergoemacs-modify-transient-maps t)
-          ad-do-it)
-      (setq ergoemacs-modify-transient-maps old))))
-
-(ergoemacs-advice undo-tree-overridden-undo-bindings-p ()
-  "Use `ergoemacs-mode' remaps to determine if `undo' has been changed."
-  :type :around
   (if ergoemacs-mode
-      (key-binding [ergoemacs-remap undo])
-    ad-do-it))
-
-
-(ergoemacs-advice read-from-minibuffer (prompt &optional initial-contents 
keymap read hist default-value inherit-input-method)
-  "Modify keymap to confirm to `ergoemacs-mode'."
-  :type :before
-  (defvar ergoemacs-read-from-minibuffer-map)
-  (if keymap
-      (setq ergoemacs-map--breadcrumb (format "read-from-minibuffer:%s" 
this-command)
-            ergoemacs-read-from-minibuffer-map keymap)
-    (setq ergoemacs-map--breadcrumb "minibuffer-local-map"
-          ergoemacs-read-from-minibuffer-map minibuffer-local-map)))
-
-(ergoemacs-advice icicle-read-from-minibuffer (prompt &optional 
initial-contents keymap read hist-m default-value inherit-input-method)
-  "Use `ergoemacs-mode' for `icicle-read-from-minibuffer'"
-  :type :before
-  (defvar ergoemacs-read-from-minibuffer-map)
-  (if keymap
-      (setq ergoemacs-map--breadcrumb (format "icy-read-from-minibuffer:%s" 
this-command)
-            ergoemacs-read-from-minibuffer-map keymap)
-    (setq ergoemacs-map--breadcrumb "icy-minibuffer-local-map"
-          ergoemacs-read-from-minibuffer-map minibuffer-local-map)))
-
-
-(ergoemacs-advice read-string (prompt &optional initial history default 
inherit-input-method)
-  "Modify keymap to confirm to `ergoemacs-mode'."
-  :type :before
-  (defvar ergoemacs-read-from-minibuffer-map)
-  (setq ergoemacs-map--breadcrumb "minibuffer-local-map"
-        ergoemacs-read-from-minibuffer-map minibuffer-local-map))
+      (ergoemacs-key-description--substitute-command-keys (nth 0 args))
+    (funcall orig-fun args)))
 
-(ergoemacs-advice icicle-read-string (prompt &optional initial history default 
inherit-input-method)
-  "Modify keymap to confirm to `ergoemacs-mode'."
-  :type :before
-  (defvar ergoemacs-read-from-minibuffer-map)
-  (setq ergoemacs-map--breadcrumb "icy-minibuffer-local-map"
-        ergoemacs-read-from-minibuffer-map minibuffer-local-map))
-
-(ergoemacs-advice read-no-blanks-input (prompt &optional initial 
inherit-input-method)
-  "Modify keymap to confirm to `ergoemacs-mode'."
-  :type :before
-  (defvar ergoemacs-read-from-minibuffer-map)
-  (setq ergoemacs-map--breadcrumb "minibuffer-local-ns-map"
-        ergoemacs-read-from-minibuffer-map minibuffer-local-ns-map))
-
-(ergoemacs-advice command-execute (cmd &optional record-flag keys special)
-  "Modify ergoemacs command-loop to execute the actual command.
-
-When increasing `max-specpdl-size' and `max-lisp-eval-depth',
-this allows `smex' and `execute-extended-command' to run the
-command selected, instead of rerunning `smex' and
-`execute-extended-command'."
-  :type :before
-  (setq ergoemacs-command-loop--grow-command cmd
-       ergoemacs-command-loop--grow-record record-flag
-       ergoemacs-command-loop--grow-keys keys
-       ergoemacs-command-loop--grow-special special))
-
-(ergoemacs-advice ispell-region (reg-start reg-end &optional recheckp shift)
-  "Clear `unread-command-events' before starting spelling."
-  :type :before
-  (setq unread-command-events nil))
-
-
-(ergoemacs-advice read-key (&optional prompt)
-  "Drop single command keys for read-key." ; For compataiblity with emacs 25.5
-  :type :before
-  (setq ergoemacs-command-loop--single-command-keys nil))
-
-(defvar ergoemacs-command-loop--history)
 
 (defun ergoemacs-mode--undefined-advice (&optional type)
   "Advice for undefined.
 
 TYPE is the type of translation installed."
   (let* ((keys (this-single-command-keys))
-        (type (or type :normal))
-        (translation (ergoemacs-translate--get type))
-        (local-keymap (ergoemacs-translate--keymap translation))
-        (local-key (substring keys -1))
-        modal-p)
+            (type (or type :normal))
+            (translation (ergoemacs-translate--get type))
+            (local-keymap (ergoemacs-translate--keymap translation))
+            (local-key (substring keys -1))
+            modal-p)
     (when (setq modal-p (ergoemacs :modal-p))
       (setq local-keymap (ergoemacs-translation-struct-keymap-modal modal-p)))
+    ;; This starts the command loop when DEL or MENU is replaced in the proper 
place.
     (if (lookup-key local-keymap local-key)
-       (let ((i 1)) ;; Setup history
-         (setq ergoemacs-command-loop--history nil)
-         (while (<= i (- (length keys) 1))
-           (push (list (substring keys 0 i) :normal nil
-                       current-prefix-arg (aref (substring keys (- i 1) i) 0))
-                 ergoemacs-command-loop--history)
-           (setq i (+ 1 i)))
-         (ergoemacs-command-loop--internal keys nil nil nil 
ergoemacs-command-loop--history))
+           (let ((i 1)) ;; Setup history
+             (setq ergoemacs-command-loop--history nil)
+             (while (<= i (- (length keys) 1))
+               (push (list (substring keys 0 i) :normal nil
+                                   current-prefix-arg (aref (substring keys (- 
i 1) i) 0))
+                         ergoemacs-command-loop--history)
+               (setq i (+ 1 i)))
+             (ergoemacs-command-loop--internal keys nil nil nil 
ergoemacs-command-loop--history))
       (ding)
       (ergoemacs-command-loop--temp-message "%s does not do anything!"
                                             (ergoemacs-key-description 
(this-single-command-keys)))
@@ -360,19 +94,21 @@ TYPE is the type of translation installed."
             (when (memq 'down (event-modifiers last-command-event))
               current-prefix-arg)))))
 
-(ergoemacs-advice undefined ()
+(defun ergoemacs-advice-undefined (orig-fun)
   "Allow `ergoemacs-mode' to display keys, and intercept ending <apps> keys."
-  :type :around
-  (if (not ergoemacs-mode)
-      ad-do-it
-    (ergoemacs-mode--undefined-advice)))
+  (if ergoemacs-mode
+      (ergoemacs-mode--undefined-advice)
+    (call-interactively orig-fun)))
 
-(ergoemacs-advice handle-shift-selection ()
+ (defun ergoemacs-advice-handle-shift-selection ()
   "Allow `ergoemacs-mode' to do shift selection on keys like Alt+# to Alt+3."
-  :type :before
   (when (eq 'ergoemacs-command-loop--shift-translate (key-binding 
(this-single-command-keys)))
     (setq this-command-keys-shift-translated t)))
 
+(defun ergoemacs-advice-read-key ()
+  "Drop single command keys for read-key." ; For compataiblity with emacs 25.5
+  (setq ergoemacs-command-loop--single-command-keys nil))
+
 (provide 'ergoemacs-advice)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; ergoemacs-advice.el ends here
diff --git a/ergoemacs-calculate-bindings.el b/ergoemacs-calculate-bindings.el
new file mode 100644
index 0000000..f09b8e7
--- /dev/null
+++ b/ergoemacs-calculate-bindings.el
@@ -0,0 +1,179 @@
+;;; ergoemacs-calculate-bindings.el --- Keyboard keybinding translation -*- 
lexical-binding: t -*-
+
+;; Copyright © 2013-2021  Free Software Foundation, Inc.
+
+;; Filename: ergoemacs-translate.el
+;; Description:
+;; Author: Matthew L. Fidler
+;; Maintainer:
+;; Created: Sat Sep 28 20:08:09 2013 (-0500)
+;; Version:
+;; Last-Updated:
+;;           By:
+;;     Update #: 0
+;; URL:
+;; Doc URL:
+;; Keywords:
+;; Compatibility:
+;;
+;; Features that might be required by this library:
+;;
+;;   None
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Commentary:
+;;
+;;
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Change Log:
+;;
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Code:
+(defcustom ergoemacs-lookup-bindings-list
+  '(("C-x o" other-window)
+    ("C-b" backward-char)
+    ("C-f" forward-char)
+    ("M-b" backward-word)
+    ("M-f" foward-word)
+    ("C-p" previous-line)
+    ("C-n" next-line)
+    ("M-s o" occur)
+    ("C-SPC" set-mark-command)
+    ("DEL" delete-backward-char)
+    ("C-d" delete-char )
+    ("M-d" kill-word)
+    ("M-DEL" backward-kill-word)
+    ("M-{" backward-paragraph)
+    ("M-}" forward-paragraph)
+    ("M-{" ergoemacs-backward-block)
+    ("M-}" ergoemacs-forward-block)
+    ("C-e" ergoemacs-end-of-line-or-what)
+    ("C-a" ergoemacs-beginning-of-line-or-what)
+    ("C-e" ergoemacs-end-of-line-or-what)
+    ("C-a" move-beginning-of-line)
+    ("C-e" move-end-of-line)
+    ("C-v" scroll-down-command)
+    ("M-v" scroll-up-command)
+    ("<begin>" beginning-of-buffer)
+    ("<C-end>" end-of-buffer)
+    ("C-M-b" ergoemacs-backward-open-bracket)
+    ("C-M-f" ergoemacs-backward-open-bracket)
+    ("M-w" ergoemacs-copy-line-or-region)
+    ("C-y" ergoemacs-paste)
+    ("M-y" ergoemacs-paste-cycle)
+    ("C-_" ergoemacs-undo)
+    ;("C-/" ergoemacs-undo)
+    ("M-%" query-replace)
+    ("C-s" isearch-forward)
+    ("C-M-s" isearch-forward-regexp)
+    ("C-r" isearch-backward)
+    ("C-M-r" isearch-backward-regexp)
+    ("C-x 1" delete-other-windows)
+    ("C-x 0" delete-window)
+    ("C-x 2" split-window-below)
+    ("C-x 3" split-window-right)
+    ("C-x b" switch-to-buffer)
+    ("C-x C-b" ibuffer)
+    ("C-x C-b" execute-extended-command)
+    ("C-k" kill-line)
+    ("M-TAB" ergoemacs-call-keyword-completion))
+  "Ergoemacs short command names."
+  :group 'ergoemacs-themes
+  :type '(repeat :tag "Command abbreviation"
+                 (list
+                  (string :tag "original keybinding in Emacs")
+                  (sexp :tag "Ergoemacs Command"))))
+
+(defvar ergoemacs-override-keymap)
+(defvar ergoemacs-keyboard-layout)
+
+(declare-function ergoemacs-translate--event-layout "ergoemacs-translate")
+(declare-function help--symbol-completion-table "help-fns")
+
+(defun ergoemacs-calculate-bindings-for-current-binding (keymap space cb)
+  "Calculate ergoemcs keybindings for a KEYMAP and dislay in another buffer.
+SPACE represents the amount of sacing to add
+CB is the buffer to use  for keymap"
+  (dolist (elt ergoemacs-lookup-bindings-list)
+    (let* ((command (nth 1 elt))
+           (key (nth 0 elt))
+           (key-code (read-kbd-macro key))
+           (bind (with-current-buffer cb
+                   (lookup-key (symbol-value keymap) key-code))))
+      (when (commandp bind)
+        (dolist (ergoemacs-command (where-is-internal command 
ergoemacs-override-keymap nil t t))
+          (insert (format "%s(ergoemacs-define-key %s (kbd \"%s\") '%s)" space 
(symbol-name keymap) 
+                   (key-description (ergoemacs-translate--event-layout 
ergoemacs-command "us" ergoemacs-keyboard-layout))
+                   (symbol-name bind))))))))
+
+
+(defvar ergoemacs-calculate-bindings-for-both-theme--tmp nil)
+(defun ergoemacs-calculate-bindings-for-both-themes (keymap)
+  "Calculates ergoemacs-style bindings for KEYMAP."
+  (interactive
+   (save-excursion
+     (let* ((v (variable-at-point))
+               (enable-recursive-minibuffers t)
+            (orig-buffer (current-buffer))
+               val)
+       (setq val (completing-read
+                  (if (and (symbolp v) (keymapp (symbol-value v)))
+                      (format
+                       "Calculate egoemacs-mode keybindings for keymap 
(default %s): " v)
+                    "Calculate ergoemacs-mode keybindings: ")
+                  #'help--symbol-completion-table
+                  (lambda (vv)
+                    ;; In case the variable only exists in the buffer
+                    ;; the command we switch back to that buffer before
+                    ;; we examine the variable.
+                    (with-current-buffer orig-buffer
+                      (and (boundp vv) (keymapp (symbol-value vv)))))
+                  t nil nil
+                  (if (and (symbolp v) (keymapp (symbol-value v)))
+                      (symbol-name v))))
+       (list (if (equal val "") v (intern val))))))
+  (let ((cb (current-buffer)))
+    (unless cb
+      (error "Cannot determine the buffer"))
+    (prin1 (type-of keymap))
+    (setq ergoemacs-calculate-bindings-for-both-theme--tmp
+          (copy-keymap ergoemacs-override-keymap)
+          ergoemacs-override-keymap (make-sparse-keymap))
+    (let ((buf (get-buffer-create (format "*ergoemacs keybindings for keymap 
%s*" (symbol-name keymap)))))
+      (with-output-to-temp-buffer buf
+        (with-current-buffer buf
+          (insert "(ergoemacs-save-key-state '")
+          (insert (symbol-name keymap))
+          (insert " (if (string-equal ergoemacs-theme \"reduction\")\n  
(progn")
+          (ergoemacs-install-reduction-theme)
+          (ergoemacs-calculate-bindings-for-current-binding keymap "\n    " cb)
+          (insert ")")
+          (setq ergoemacs-override-keymap (make-sparse-keymap))
+          (ergoemacs-install-standard-theme)
+          (ergoemacs-calculate-bindings-for-current-binding keymap "\n  " cb)
+          (insert "))")))))
+ (setq ergoemacs-override-keymap 
ergoemacs-calculate-bindings-for-both-theme--tmp
+       ergoemacs-calculate-bindings-for-both-theme--tmp nil))
+
+(provide 'ergoemacs-calculate-bindings)
+;;; ergoemacs-calculate-binding.el ends here
diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el
index 2ec495f..3f1540b 100644
--- a/ergoemacs-command-loop.el
+++ b/ergoemacs-command-loop.el
@@ -183,15 +183,76 @@ ignore the post-command hooks.")
 (defvar ergoemacs-command-loop--modal-stack '()
   "The Modal Stack.")
 
-(defvar ergoemacs-command-loop-swap-translation)
+(defcustom ergoemacs-command-loop-swap-translation
+  '(((:normal :normal) :unchorded-ctl)
+    ((:normal :unchorded-ctl) :ctl-to-alt)
+    ((:normal :unchorded-ctl) :normal)
+    ((:ctl-to-alt :ctl-to-alt) :unchorded-ctl)
+    ((:ctl-to-alt :unchorded-ctl) :ctl-to-alt)
+    ((:unchorded-ctl :unchorded-ctl) :ctl-to-alt)
+    ((:unchorded-ctl :ctl-to-alt) :unchorded-ctl))
+  "How the translation will be swapped."
+  :type '(repeat
+          (list
+           (list
+            (sexp :tag "First Type")
+            (sexp :tag "Current Type"))
+           (sexp :tag "Translated Type")))
+  :group 'ergoemacs-command-loop)
+
+(defcustom ergoemacs-command-loop-blink-character "•"
+  "Blink character."
+  :type '(choice
+          (string :tag "Cursor")
+          (const :tag "No cursor" nil))
+  :group 'ergoemacs-command-loop)
+
+(defcustom ergoemacs-command-loop-blink-rate 0.4
+  "Rate that the ergoemacs-command loop cursor blinks."
+  :type 'number
+  :group 'ergoemacs-command-loop)
+
+(defcustom ergoemacs-command-loop-type nil
+  "Type of `ergoemacs-mode' command loop."
+  :type '(choice
+          (const :tag "Replace emacs command loop (full)" :full)
+          ;; (const :tag "Test mode; Don't actually run command " :test)
+          (const :tag "No command loop support" nil))
+  :group 'ergoemacs-comamnd-loop)
+
+(defcustom ergoemacs-command-loop-hide-shift-translations t
+  "Hide shift translations in the command loop help."
+  :type 'boolean
+  :group 'ergoemacs-command-loop)
+
+
+(defcustom ergoemacs-command-loop-echo-keystrokes 1
+  "The amount of time before `ergoemacs-mode' displays keystrokes."
+  :type 'number
+  :group 'ergoemacs-command-loop)
+
+(defcustom ergoemacs-command-loop-timeout 2
+  "The number of seconds before hook has froze."
+  :type 'number
+  :group 'ergoemacs-command-loop)
+
+(defcustom ergoemacs-echo-function :on-translation
+  "Shows the function evaluated with a key."
+  :type '(choice
+          (const :tag "Always echo" t)
+          (const :tag "For multi-key commands" :multi-key)
+          (const :tag "Echo on translations" :on-translation)
+          (const :tag "Don't Echo" nil))
+  :group 'ergoemacs-command-loop)
+
+
+
 (defvar ergoemacs-command-loop-time-before-blink)
-(defvar ergoemacs-command-loop-blink-character)
-(defvar ergoemacs-command-loop-blink-rate)
 (defvar ergoemacs-command-loop-hide-shift-translations)
 (defvar ergoemacs-mode)
 (defvar ergoemacs-command-loop-type)
 (defvar ergoemacs-keymap)
-(defvar ergoemacs-handle-ctl-c-or-ctl-x)
+(defvar ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x)
 (defvar ergoemacs-ctl-c-or-ctl-x-delay)
 
 
@@ -284,7 +345,7 @@ with this function."
   (let ((cur-input (current-input-mode))
         (new-key (listify-key-sequence (or key [7]))))
     (when (> 1 (length new-key))
-      (error "Will not set a key sequence to the emacs key sequence"))
+      (error "Will not set a key sequence to the Emacs key sequence"))
     (setf (nth 3 cur-input) new-key)
     (and (ignore-errors (apply 'set-input-mode cur-input))
          (message "Redefined Emacs quit key to %s"
@@ -493,12 +554,12 @@ UNIVERSAL"
                     (and (not universal) "")
                     (or (and (string= ergoemacs-command-loop--read-key-prompt 
"") "") " ")
                     (and ergoemacs-command-loop-blink-character
-                         (or (and blink-on (ergoemacs :unicode-or-alt 
ergoemacs-command-loop-blink-character "-"))
+                         (or (and blink-on 
ergoemacs-command-loop-blink-character)
                              " "))
                     " ")
                    (or
                     (and (not universal) "")
-                    (ergoemacs :unicode-or-alt "▸" ">"))))
+                    "▸")))
       (format
        "%s%s%s %s "
        (cond
@@ -507,13 +568,13 @@ UNIVERSAL"
         (t current-prefix-arg))
        (or (and (not universal) "")
            (and ergoemacs-command-loop-blink-character
-                (or (and blink-on (ergoemacs :unicode-or-alt 
ergoemacs-command-loop-blink-character "-"))
+                (or (and blink-on ergoemacs-command-loop-blink-character)
                     " "))
            " ")
        (or (and (listp current-prefix-arg)
                 (format "%s" current-prefix-arg))
            "")
-       (ergoemacs :unicode-or-alt "▸" ">"))))
+       "▸")))
 
 (defun ergoemacs-command-loop--ensure-sane-variables ()
   "Make sure that certain variables won't lock up Emacs.
@@ -593,7 +654,7 @@ This is not done when the event is [ergoemacs-ignore]"
                      ((not (stringp prompt)))
                      ((not (string= "" 
ergoemacs-command-loop--read-key-prompt)) prompt)
                      ((or (string= prompt " ")
-                          (string-match-p prompt (concat " *" (ergoemacs 
:unicode-or-alt ergoemacs-command-loop-blink-character "-") " *")))
+                          (string-match-p prompt (concat " *" 
ergoemacs-command-loop-blink-character  " *")))
                       nil)
                      (ergoemacs-command-loop--universal prompt)
                      (ergoemacs-command-loop--echo-keystrokes-complete prompt)
@@ -786,7 +847,7 @@ KEYS is the keys information"
          (or (and (string= ergoemacs-command-loop--read-key-prompt "") "") " ")
          (or (and universal "")
              (and ergoemacs-command-loop-blink-character
-                  (or (and blink-on (ergoemacs :unicode-or-alt 
ergoemacs-command-loop-blink-character "-"))
+                  (or (and blink-on ergoemacs-command-loop-blink-character)
                       " "))
              " ")
          trans
@@ -812,9 +873,11 @@ KEYS is the keys information"
 (defvar ergoemacs-this-command-keys-shift-translated nil
   "ergoemacs override of shift translation in command loop.")
 
-(defun ergoemacs-command--echo-prefix ()
-  "Echos prefix keys in the ergoemacs-mode way."
-  (let ((keys (this-single-command-keys)))
+(defun ergoemacs-command--echo-prefix (&optional new-keys)
+  "Echos prefix keys in the ergoemacs-mode way.
+
+NEW-KEYS replaces the value of `this-single-command-keys' if specified."
+  (let ((keys (or new-keys (this-single-command-keys))))
     (when (and ergoemacs-command--timeout-timer
               (not (equal keys ergoemacs-command--timeout-keys)))
       (cancel-timer ergoemacs-command--timeout-timer)
@@ -823,26 +886,11 @@ KEYS is the keys information"
     (unless (or (equal [] keys)
                (ergoemacs-command-loop-p))
       (when (ergoemacs-keymapp (key-binding keys))
-       (when (key-binding (vconcat keys [ergoemacs-timeout]))
-         (cond
-          ((eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut) 
-           (push 'ergoemacs-timeout unread-command-events))
-          ((not (region-active-p))) ;; active
-          ((and (or ergoemacs-this-command-keys-shift-translated 
this-command-keys-shift-translated)
-                 (eq ergoemacs-handle-ctl-c-or-ctl-x 'both)))
-          ((and (not ergoemacs-ctl-c-or-ctl-x-delay) ;; Immediate
-                 (eq ergoemacs-handle-ctl-c-or-ctl-x 'both))
-           (push 'ergoemacs-timeout unread-command-events))
-           (t
-            (setq ergoemacs-command--timeout-keys keys
-                 ergoemacs-command--timeout-timer
-                  (run-at-time t ergoemacs-ctl-c-or-ctl-x-delay 
#'ergoemacs-command--timer-timeout)))))
         (unless unread-command-events
          (ergoemacs-command-loop--message
           "%s" (ergoemacs-command-loop--key-msg
                 (setq ergoemacs-command--blink-on (not 
ergoemacs-command--blink-on))
-                nil nil
-                (this-single-command-keys)
+                nil nil keys
                 nil nil nil)))))))
 
 (defun ergoemacs-command--echo-timer ()
@@ -891,7 +939,8 @@ read."
          raw-input
          mod-keys tmp
          reset-key-p
-         double)
+         double
+         first)
     ;; Setup modal translation
     (when (and (eq type :normal) modal)
       (setq type (ergoemacs-translation-struct-key modal)
@@ -931,7 +980,7 @@ read."
                                             ;;      (string-match-p 
"\\<mouse\\>" tmp))
                                              (format "%s%s%s"
                                                      (ergoemacs :modifier-desc 
(nth 0 elt))
-                                                     (ergoemacs 
:unicode-or-alt "↔" "<->")
+                                                     "↔"
                                                      (ergoemacs :modifier-desc 
(nth 1 elt))))
                                            double ", "))
                                      "")
@@ -940,7 +989,7 @@ read."
                                   (lambda(elt)
                                     (format "%s%s%s"
                                             (ergoemacs :modifier-desc (nth 0 
elt))
-                                            (ergoemacs :unicode-or-alt "→" 
"->")
+                                            "→"
                                             (ergoemacs :modifier-desc (nth 1 
elt))))
                                   trans ", "))) ""))
     (maphash
@@ -951,8 +1000,8 @@ read."
            (setq tmp (format "%s%s%s"
                              (ergoemacs-key-description local-key)
                              (if (eq (nth 1 item) :force)
-                                 (ergoemacs :unicode-or-alt "⇒" "=>")
-                               (ergoemacs :unicode-or-alt "→" "->"))
+                                 "⇒" 
+                               "→")
                              (ergoemacs :modifier-desc (nth 0 item))))
            (push (elt local-key 0) mod-keys)
            (setq keys (or (and (not keys) tmp)
@@ -961,7 +1010,9 @@ read."
 
     (setq keys (or (and keys (concat "\nKeys: " keys)) ""))
     (setq unchorded (or (and unchorded (concat " " (ergoemacs :modifier-desc 
unchorded))) ""))
-    
+    (when (not first)
+      (message (ergoemacs-command-loop--key-msg blink-on universal text 
current-key unchorded trans keys))
+      (setq first t))
     (while (not input)
       (while (not input)
         (setq blink-on (not blink-on)
@@ -1223,7 +1274,7 @@ from within the ergoemacs-mode command loop."
           ergoemacs-command-loop--single-command-keys 
(this-single-command-keys)
           this-command 'ergoemacs-command-loop-start)))
 
-(add-hook 'ergoemacs-pre-command-hook 
#'ergoemacs-command-loop--start-with-pre-command-hook)
+;;(add-hook 'ergoemacs-pre-command-hook 
#'ergoemacs-command-loop--start-with-pre-command-hook)
 
 
 (defvar ergoemacs-command-loop--internal-end-command-p nil)
@@ -1247,7 +1298,7 @@ to start with
                                          (ergoemacs-command-loop-start))))
       (push 'ergoemacs-ignore unread-command-events))))
 
-(add-hook 'ergoemacs-post-command-hook 
#'ergoemacs-command-loop--start-with-post-command-hook)
+;; (add-hook 'ergoemacs-post-command-hook 
#'ergoemacs-command-loop--start-with-post-command-hook)
 
 (defvar ergoemacs-command-loop--point-motion-last-point nil
   "Record the last point.")
@@ -1580,9 +1631,7 @@ The RECORD-FLAG and KEYS are sent to 
`ergoemacs-command-loop--grow-interactive'.
    ((and (symbolp command) (not (commandp command)))
     (ergoemacs-command-loop--message "Command `%s' cannot be called from a 
key" command))
    ((and (consp ergoemacs-command-loop-describe-key-functions)
-        (memq command ergoemacs-command-loop-describe-key-functions))
-    (ergoemacs-specials
-     (ergoemacs-command-loop--grow-interactive command record-flag keys)))
+        (memq command ergoemacs-command-loop-describe-key-functions)))
    (t
     (ergoemacs-command-loop--grow-interactive command record-flag keys)))
   (setq ergoemacs-this-command-keys-shift-translated nil))
@@ -1807,7 +1856,7 @@ Emacs versions)."
                     unread-command-events (or (and unread-command-events tmp 
(append tmp unread-command-events)) tmp)
                     ergoemacs-command-loop--first-type first-type
                     ergoemacs-command-loop--history initial-history
-                    ergoemacs-command-loop-start nil)
+                    ergoemacs-command-loop-start  nil)
               (while continue-read
                (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil)
                 (unless (eq ergoemacs-command-loop-type :read-key-sequence)
@@ -2077,7 +2126,7 @@ TRANSLATED-KEY is what the assumed key is actually bound."
              (eq ergoemacs-echo-function :multi-key)))
     (ergoemacs-command-loop--temp-message "%s%s%s%s"
                                      (ergoemacs-key-description key)
-                                     (ergoemacs :unicode-or-alt "→" "->")
+                                     "→"
                                      lookup
                                      (or (and translated-key
                                               (format " (from %s)" 
(ergoemacs-key-description translated-key)))
@@ -2147,7 +2196,7 @@ pressed the translated key by changing
     ;; Make sure to lookup the keys in the selected buffer
     (ergoemacs-command-loop--sync-point)
     (let ((trials (ergoemacs-translate--trials key))
-        tmp tmp2 ret)
+        tmp ret)
       (setq this-command-keys-shift-translated nil)
     (catch 'found-command
       (dolist (cur-key trials)
@@ -2193,43 +2242,10 @@ pressed the translated key by changing
                ((equal orig-key (nth 0 trials))
                 (setq ergoemacs-command-loop--single-command-keys new-key)
                ;; (message "History %s" (length 
ergoemacs-command-loop--history))
-                (when (and (not (eq ergoemacs-handle-ctl-c-or-ctl-x 
'only-C-c-and-C-x))
-                          (ergoemacs-keymapp ret)
-                           (setq tmp (lookup-key ret [ergoemacs-timeout])))
-                  (cond
-                   ((eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)
-                    (setq ret tmp))
-                  ((< 1  (length ergoemacs-command-loop--history)))
-                   ((not (region-active-p))) ;; its a key sequence.
-                   
-                   ((and (or ergoemacs-this-command-keys-shift-translated 
this-command-keys-shift-translated)
-                         (eq ergoemacs-handle-ctl-c-or-ctl-x 'both)))
-
-                   ;; Immediate
-                   ((and (not ergoemacs-ctl-c-or-ctl-x-delay)
-                        (eq ergoemacs-handle-ctl-c-or-ctl-x 'both))
-                    (setq ret tmp))
-                   
-                   (t ;; with delay
-                   (if ergoemacs-command-loop--decode-event-timeout-p
-                       (setq tmp2 nil
-                             ergoemacs-command-loop--decode-event-timeout-p 
nil))
-                    (setq tmp2 (with-timeout (ergoemacs-ctl-c-or-ctl-x-delay 
nil)
-                                 (ergoemacs-command-loop--read-event nil key)))
-                    (if (not tmp2)
-                        (setq ret tmp) ;; timeout, use copy/cut
-                      ;; Actual key
-                      (setq ret (ergoemacs-command-loop--key-lookup (vconcat 
key (vector tmp2))))))))
                 (ergoemacs-command-loop--message-binding new-key ret))
                ((equal orig-key (nth 1 trials)) ;; `ergoemacs-mode' shift 
translation
                 (setq this-command-keys-shift-translated t
                       ergoemacs-command-loop--single-command-keys (nth 0 
trials))
-                
-                ;; Shift+Control+c
-                (when (and (ergoemacs-keymapp ret)
-                           (setq tmp (lookup-key ret [ergoemacs-timeout]))
-                           (eq ergoemacs-handle-ctl-c-or-ctl-x 'both))
-                  (setq ret tmp))
                 (ergoemacs-command-loop--message-binding new-key ret key))
                (t
                 (ergoemacs-command-loop--message-binding new-key ret key)
diff --git a/ergoemacs-component.el b/ergoemacs-component.el
deleted file mode 100644
index 8920885..0000000
--- a/ergoemacs-component.el
+++ /dev/null
@@ -1,1870 +0,0 @@
-;;; ergoemacs-component.el --- Ergoemacs map interface -*- lexical-binding: t 
-*-
-
-;; Copyright © 2013-2015  Free Software Foundation, Inc.
-
-;; Filename: ergoemacs-component.el
-;; Description:
-;; Author: Matthew L. Fidler
-;; Maintainer: Matthew L. Fidler
-;; Created: Sat Sep 28 20:10:56 2013 (-0500)
-;;
-;;; Commentary:
-;;
-;; Code for ergoemacs components.
-;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as
-;; published by the Free Software Foundation; either version 3, or
-;; (at your option) any later version.
-;; 
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;; General Public License for more details.
-;; 
-;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
-;; 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 
-;;; Code:
-;; (require 'guide-key nil t)
-(require 'cl-lib)
-
-(eval-when-compile
-  (require 'ergoemacs-macros))
-
-(require 'help-mode)
-(require 'find-func)
-
-(defvar ergoemacs-command-loop--minibuffer-unsupported-p)
-(defvar ergoemacs-map-properties--label-atoms-maps)
-(defvar ergoemacs--last-start-emacs-state-2)
-(defvar ergoemacs--start-emacs-state-2)
-(defvar ergoemacs-component-hash)
-(defvar ergoemacs-display-key-use-face)
-(defvar ergoemacs-keyboard-layout)
-(defvar ergoemacs-keymap)
-(defvar ergoemacs-map-properties--known-maps)
-(defvar ergoemacs-mode--fast-p)
-(defvar ergoemacs-mode-version)
-(defvar ergoemacs-saved-global-map)
-(defvar ergoemacs-theme-hash)
-(defvar ergoemacs-theme-version)
-(defvar ergoemacs-translate--translation-hash)
-(defvar ergoemacs-translation-hash)
-(defvar package--initialized)
-
-(declare-function diminish "diminish")
-(declare-function diminish-undo "diminish")
-
-(declare-function ergoemacs--emacs-state "ergoemacs-mode")
-(declare-function ergoemacs-timing-- "ergoemacs-mode")
-(declare-function ergoemacs-mode--setup-hash-tables--setq "ergoemacs-mode")
-(declare-function ergoemacs-mode-clear-cache "ergoemacs-mode")
-
-(declare-function ergoemacs-set "ergoemacs-lib")
-(declare-function ergoemacs-reset "ergoemacs-lib")
-(declare-function ergoemacs-warn "ergoemacs-lib")
-
-(declare-function ergoemacs-theme-components "ergoemacs-theme-engine")
-(declare-function ergoemacs-theme--regexp "ergoemacs-theme-engine")
-
-(declare-function ergoemacs-translate "ergoemacs-translate")
-(declare-function ergoemacs-translate--apply-key "ergoemacs-translate")
-(declare-function ergoemacs-translate--define-key "ergoemacs-translate")
-
-(declare-function ergoemacs-map-properties--label-known 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--original 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--map-list 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--put "ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--key-hash 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--map-regexp 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--empty-p "ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--label "ergoemacs-map-properties")
-
-(declare-function ergoemacs-theme--get-version "ergoemacs-theme-engine")
-
-(declare-function ergoemacs-map-- "ergoemacs-map")
-
-(declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
-
-(declare-function ergoemacs-key-description "ergoemacs-key-description")
-(declare-function ergoemacs-key-description--keymap 
"ergoemacs-key-description")
-(declare-function ergoemacs-key-description--unicode-char 
"ergoemacs-key-description")
-
-(declare-function package-installed-p "package")
-
-(declare-function ergoemacs-layout--regexp "ergoemacs-layouts")
-(declare-function ergoemacs-layouts--list "ergoemacs-layouts")
-
-
-;; ergoemacs-translate
-
-(defcustom ergoemacs-ignore-prev-global t
-  "If non-nil, the ergoemacs-mode will ignore previously defined global 
keybindings."
-  :type 'boolean
-  :group 'ergoemacs-mode)
-
-;; for compatability
-;;;###autoload
-(defun ergoemacs-ignore-prev-global ()
-  "Ignore previously defined global keys."
-  (setq ergoemacs-ignore-prev-global t))
-
-(defun ergoemacs-remap (function)
-  "Remap the FUNCTION to the appropriate key and then call that function."
-  (let ((key (where-is-internal function ergoemacs-keymap t)))
-    (call-interactively (key-binding key t  nil (point)))))
-
-
-;;; Translation between layouts
-
-(cl-defstruct ergoemacs-component-struct
-  "A basic ergoemacs component map structure."
-  (name "default-name")
-  (plist '())
-  (map nil)
-  (maps (make-hash-table))
-  (cond-maps (make-hash-table))
-  (hook-maps (make-hash-table))
-  (hook-plists (make-hash-table))
-  (when-condition nil)
-  (hook nil)
-  (dynamic-keys '())
-  (version nil)
-  (versions '())
-  (undefined '())
-  (unbind '())
-  (variables nil)
-  (just-first-keys nil :read-only t)
-  (variable-modifiers '(meta) :read-only t)
-  (variable-prefixes '([apps] [menu] [27]) :read-only t)
-  (package-name nil)
-  (autoloads nil)
-  (ensure nil)
-  (layout "us" :read-only t)
-  (calculated-layouts (make-hash-table :test 'equal))
-  (relative-to 'global-map)
-  (defer nil))
-
-(defvar ergoemacs-component-struct--define-key-current nil)
-
-(defvar ergoemacs-component-struct--ensure-refreshed-p t)
-(defun ergoemacs-component-struct--ensure (package &optional defer autoloads)
-  "Ensure PACKAGE is installed.
-
-When DEFER is non-nil, dont `require' the package, just make sure
-it is installed.
-
-The AUTOLOADS is a list of functions that need to be autoloaded
-if the package is deferred."
-  (when package
-    (ergoemacs-timing ensure
-      (ergoemacs-timing (intern (format "ensure-%s" package))
-        (let ((package (or (and (symbolp package) package)
-                           (and (stringp package) (intern package)))))
-          (unless (or defer (featurep package))
-            (require package nil t))
-          (when (and package (not (featurep package)) (numberp defer))
-            (run-with-idle-timer defer nil #'require package)
-            )
-          (when (and defer autoloads)
-            (dolist (c autoloads)
-              (unless (fboundp (car c))
-                (autoload (car c) (format "%s" (cdr c)) nil t))))
-          (unless (featurep package)
-            (unless package--initialized
-              (package-initialize))
-            (if (package-installed-p package) t
-              (unless ergoemacs-component-struct--ensure-refreshed-p
-                (package-refresh-contents)
-                (setq ergoemacs-component-struct--ensure-refreshed-p t))
-              (unless (progn (ignore-errors (package-install package))
-                             (package-installed-p package))
-                (ergoemacs-warn "ergoemacs-mode could not install %s." 
package))
-              (unless defer
-                (require package nil t)))))))))
-
-(defun ergoemacs-component-struct--parse-list (list function &rest args)
-  "Handle :bind and :mode LIST and call FUNCTION.
-
-The FUNCTION calls the with the first argument as the string
-piece and the second argument the symbol piece of the definition.
-It also passes ARGS if any are specified."
-  (let (arg1 arg2)
-    (cond
-     ;; :list ("a" b "c" d)
-     ((ignore-errors (and (consp list) (> (length list) 2)
-                          (stringp (car list))
-                          (setq arg1 (pop list))
-                          (setq arg2 (pop list))))
-      (while (and arg1 arg2)
-        (apply function arg1 arg2 args)
-        (setq arg1 (pop list)
-              arg2 (pop list))))
-     ((and (consp list) (stringp (car list)))
-      ;; :list ("C-." . ace-jump-mode)
-      ;; :list ("C-." ace-jump-mode)
-      (apply function (car list)
-             (or (and (consp (cdr list)) (nth 1 list))
-                 (cdr list))
-             args))
-     ((and (consp list) (consp (car list)))
-      (dolist (elt list)
-        (when (and (consp elt) (stringp (car elt)))
-          (apply function (car elt)
-                 (or (and (consp (cdr elt)) (nth 1 elt))
-                     (cdr elt))
-                 args)))))))
-
-(defun ergoemacs-component-struct--handle-bind-1 (kbd-str def keymap)
-  "Tell `ergoemacs-mode' to bind KBD-STR to DEF in KEYMAP."
-  (ergoemacs-component-struct--define-key keymap (read-kbd-macro kbd-str) def))
-
-(defun ergoemacs-component-struct--handle-bind (bind &optional keymap)
-  "Handle :bind and related properties.
-
-BIND is the property list from the component definition.
-
-KEYMAP is the symbol of a bound keymap.  If unspecified, the
-binding assumes KEYMAP is `global-map'."
-  (let ((keymap (or keymap 'global-map)))
-    (ergoemacs-component-struct--parse-list
-     bind #'ergoemacs-component-struct--handle-bind-1 keymap)))
-
-(defun ergoemacs-component-struct--handle-mode-1 (regexpr mode)
-  "Add (cons REGEXPR MODE) to `auto-mode-alist'.
-Also autoload MODE.
-
-Requires `ergoemacs-component-struct--define-key-current' to be
-an `ergoemacs-component-struct' object."
-  ;; (message "Handle Mode #2: %s %s" regexpr mode)
-  (when (ergoemacs-component-struct-p 
ergoemacs-component-struct--define-key-current)
-    (let* ((c (cons regexpr mode))
-           (obj ergoemacs-component-struct--define-key-current)
-           (package-name (ergoemacs-component-struct-package-name obj)))
-      (ergoemacs-component-struct--deferred
-       `(unless (member ',c auto-mode-alist)
-          (push ',c auto-mode-alist)))
-      (when (and package-name mode (not (fboundp mode)))
-        ;; Create autoload.
-        (autoload mode (format "%s, a major mode defined in %s" mode 
package-name) nil t)
-        (setq c (cons mode package-name))
-        (unless (member c (ergoemacs-component-struct-autoloads obj))
-          (push (cons mode package-name) (ergoemacs-component-struct-autoloads 
obj)))))))
-
-(defun ergoemacs-component-struct--handle-mode (mode)
-  "Handle MODE list from :mode keyword."
-  (when mode
-    (ergoemacs-component-struct--parse-list mode 
#'ergoemacs-component-struct--handle-mode-1)))
-
-(defun ergoemacs-component-struct--create-component (plist body file)
-  "Create ergoemacs component.
-
-PLIST is the component properties
-
-BODY is the body of function.
-
-FILE is the file name where the component was created."
-  (ergoemacs-timing (intern (format "create-component-%s" (plist-get plist 
:name)))
-    (unwind-protect
-        (progn
-          (setq ergoemacs-component-struct--define-key-current
-                (make-ergoemacs-component-struct
-                 :name (plist-get plist :name)
-                 :plist (plist-put plist :file file)
-                 :just-first-keys (or (plist-get plist :just-first-keys) nil)
-                 :variable-modifiers (or (plist-get plist :variable-modifiers) 
'(meta))
-                 :variable-prefixes (or (plist-get plist :variable-prefixes) 
'([apps] [menu] [27]))
-                 :package-name (plist-get plist :package-name)
-                 :ensure (plist-get plist :ensure)
-                 :layout (or (plist-get plist :layout) "us")
-                 :defer (plist-get plist :defer)))
-          (let* ((tmp (plist-get plist :bind-keymap))
-                 (package-name (plist-get plist :package-name))
-                 (demand (plist-get plist :demand))
-                 (defer (if demand nil (plist-get plist :defer)))
-                 (defer-present-p (or demand defer (memq :defer plist))))
-            
-            ;; Handle :bind-keymap commands
-            (when (and tmp (not defer-present-p) (not defer))
-              (setq defer-present-p t defer t)
-              (setf (ergoemacs-component-struct-defer 
ergoemacs-component-struct--define-key-current) t))
-            (ergoemacs-component-struct--handle-bind tmp)
-
-            ;; Handle :bind-keymap* commands
-            (setq tmp (plist-get plist :bind-keymap*))
-            (when (and tmp (not defer-present-p) (not defer))
-              (setq defer-present-p t defer t)
-              (setf (ergoemacs-component-struct-defer 
ergoemacs-component-struct--define-key-current) t))
-            (ergoemacs-component-struct--handle-bind tmp 
'ergoemacs-override-keymap)
-            
-            ;; Handle :bind keys
-            (setq tmp (plist-get plist :bind))
-            (when (and tmp (not defer-present-p) (not defer))
-              (setq defer-present-p t defer t)
-              (setf (ergoemacs-component-struct-defer 
ergoemacs-component-struct--define-key-current) t))
-            (ergoemacs-component-struct--handle-bind tmp)
-            
-            ;; Handle :bind* commands
-            (setq tmp (plist-get plist :bind*))
-            (when (and tmp (not defer-present-p) (not defer))
-              (setq defer-present-p t defer t)
-              (setf (ergoemacs-component-struct-defer 
ergoemacs-component-struct--define-key-current) t))
-            (ergoemacs-component-struct--handle-bind tmp 
'ergoemacs-override-keymap)
-
-            ;; Handle :mode
-            (setq tmp (plist-get plist :mode))
-            (when (and tmp (not defer-present-p) (not defer))
-              (setq defer-present-p t defer t)
-              (setf (ergoemacs-component-struct-defer 
ergoemacs-component-struct--define-key-current) t))
-            (ergoemacs-component-struct--handle-mode tmp)
-            
-            ;; Handle :commands
-            (setq tmp (plist-get plist :commands))
-            (when (and tmp (not defer-present-p) (not defer))
-              (setq defer-present-p t defer t)
-              (setf (ergoemacs-component-struct-defer 
ergoemacs-component-struct--define-key-current) t))
-            (when package-name
-              (cond
-               ((and tmp (symbolp tmp))
-                (autoload tmp (format "%s" package-name) nil t)
-                (push (cons tmp package-name) 
(ergoemacs-component-struct-autoloads 
ergoemacs-component-struct--define-key-current)))
-               ((consp tmp)
-                (dolist (f tmp)
-                  (when (and f (symbolp f))
-                    (autoload f (format "%s" package-name) nil t)
-                    (push (cons f package-name) 
(ergoemacs-component-struct-autoloads 
ergoemacs-component-struct--define-key-current))))))))
-          (funcall body)
-          (setf (ergoemacs-component-struct-variables 
ergoemacs-component-struct--define-key-current)
-                (reverse (ergoemacs-component-struct-variables 
ergoemacs-component-struct--define-key-current))))
-      
-      (puthash (concat (ergoemacs-component-struct-name 
ergoemacs-component-struct--define-key-current)
-                       (and (ergoemacs-component-struct-version 
ergoemacs-component-struct--define-key-current)
-                            (concat "::" (ergoemacs-component-struct-version 
ergoemacs-component-struct--define-key-current))))
-               ergoemacs-component-struct--define-key-current 
ergoemacs-component-hash)
-      (setq ergoemacs-component-struct--define-key-current nil))))
-
-(defun ergoemacs-component-struct--with-hook (when-condition plist body 
&optional object)
-  "How the (when...) conditions in an ergoemacs-mode theme are handled.
-WHEN-CONDITION is the when condition that is defined in a theme.
-
-PLIST is the theme's property
-
-BODY is the (when ...) body.
-
-OBJECT is the ergoemacs component object, and defaults to
-`ergoemacs-component-struct--define-key-current'."
-  (cond
-   ((and (not ergoemacs-component-struct--define-key-current) (not object)) ;; 
Old
-    (error "`ergoemacs-component-struct--with-hook' is confused"))
-   (t
-    (let ((obj (or object ergoemacs-component-struct--define-key-current))
-          (hook
-           (or (and (symbol-name when-condition) (string-match-p 
"\\(-hook\\|-mode\\|\\`mark-active\\)\\'" (symbol-name when-condition)) 
when-condition)
-               (and (symbol-name when-condition) (string-match-p "mode-.*" 
(symbol-name when-condition))
-                    (save-match-data
-                      (intern-soft
-                       (replace-regexp-in-string
-                        "-mode-.*" "mode-hook"
-                        (symbol-name when-condition)))))
-               (and (string-match-p "(key)?map" (symbol-name when-condition))
-                    (save-match-data
-                      (intern-soft
-                       (replace-regexp-in-string
-                        "(key)?map.*" "hook"
-                        (symbol-name when-condition))))))))
-      (if (not (ergoemacs-component-struct-p obj))
-          (error "OBJECT is not an ergoemacs-component-structure")
-       (puthash hook plist (ergoemacs-component-struct-hook-plists obj))
-        (setf (ergoemacs-component-struct-when-condition obj) when-condition)
-        (setf (ergoemacs-component-struct-hook obj) hook)
-        (funcall body)
-        (setf (ergoemacs-component-struct-when-condition obj) nil)
-        (setf (ergoemacs-component-struct-hook obj) nil))))))
-
-(defun ergoemacs-component-struct--component-description (component)
-  "Gets the description of a COMPONENT.
-Allows the component not to be calculated."
-  (let* ((comp-name (or (and (symbolp component) (symbol-name component))
-                        component))
-         (comp (ergoemacs-gethash comp-name ergoemacs-component-hash)))
-    (cond
-     ((functionp comp)
-      (replace-regexp-in-string "[\n ]*(fn)[ \n]*\\'" "" (documentation comp 
t)))
-     ((ergoemacs-component-struct-p comp)
-      (plist-get (ergoemacs-component-struct-plist comp) :description))
-     (t ""))))
-
-(defun ergoemacs-component-struct--new-version (version &optional object)
-  "Add VERSION to component OBJECT."
-  (cond
-   ((and (not ergoemacs-component-struct--define-key-current) (not object)) ;; 
Old
-    (error "`ergoemacs-component-struct--new-version' is confused"))
-   (t
-    (let ((obj (or object ergoemacs-component-struct--define-key-current))
-          new-obj tmp)
-      (if (not (ergoemacs-component-struct-p obj))
-          (error "OBJECT is not an ergoemacs-component-structure")
-        (puthash (concat (ergoemacs-component-struct-name obj)
-                         (and (ergoemacs-component-struct-version obj)
-                              (concat "::" (ergoemacs-component-struct-version 
obj))))
-                 ergoemacs-component-struct--define-key-current 
ergoemacs-component-hash)
-        ;; Get the base object without version changes
-        (setq new-obj (ergoemacs-gethash (ergoemacs-component-struct-name obj) 
ergoemacs-component-hash))
-        ;; Update all versions to include the new version information.
-        (dolist (old-version (ergoemacs-component-struct-versions new-obj))
-          (setq tmp (ergoemacs-gethash (concat 
(ergoemacs-component-struct-name new-obj) "::" old-version) 
ergoemacs-component-hash))
-          (when (ergoemacs-component-struct-p tmp)
-            (push version (ergoemacs-component-struct-versions tmp))))
-        (push version (ergoemacs-component-struct-versions new-obj))
-        ;; Use the last object as the base of the new object
-        (setq ergoemacs-component-struct--define-key-current (copy-tree obj t))
-        (setf (ergoemacs-component-struct-version 
ergoemacs-component-struct--define-key-current) version))))))
-
-(defvar ergoemacs-component-struct--define-key-temp-map nil)
-
-(defun ergoemacs-component-struct--define-key-get-def (def)
-  "Gets the `ergoemacs-mode' function definition for DEF."
-  (let (tmp)
-    (cond
-     ((and (consp def) (memq (nth 0 def) '(kbd read-kbd-macro))
-           (stringp (nth 1 def)))
-      (read-kbd-macro (nth 1 def)))
-     ((and (consp def) (= 1 (length def)) (symbolp (nth 0 def)))
-      (nth 0 def))
-     ((and (consp def) (= 1 (length def)) (consp (nth 0 def))
-           (= 2 (length (nth 0 def)))
-           (eq (nth 0 (nth 0 def)) 'quote)
-           (symbolp (nth 1 (nth 0 def))))
-      (nth 1 (nth 0 def)))
-     ((and (consp def) (= 2 (length def)) (eq (nth 1 def) 'quote) (symbolp 
(nth 1 def)))
-      (nth 1 def))
-     ((and (consp def)
-           (= 2 (length def))
-           (stringp (nth 0 def))
-           (eq (nth 1 def) :emacs)
-           (setq tmp (lookup-key global-map (read-kbd-macro (nth 0 def))))
-           (commandp tmp))
-      tmp)
-     ((and (consp def)
-           (= 2 (length def))
-           (stringp (nth 0 def))
-           (or (not (nth 1 def))
-               (ergoemacs-gethash (nth 1 def) ergoemacs-translation-hash)))
-      `(lambda(&optional arg)
-         (interactive "P")
-        (setq ergoemacs-this-command-keys-shift-translated t)
-         (ergoemacs-command-loop ,(nth 0 def) ',(nth 1 def))))
-     ((ergoemacs-keymapp (ergoemacs-sv def))
-      (ergoemacs-sv def))
-     (t def))))
-
-(defun ergoemacs-component-struct--refresh-keys (&optional obj)
-  "Refreshes the keys in OBJ based on any new interactive functions found."
-  (let ((obj (or obj (ergoemacs-theme-components))))
-    (if (consp obj)
-        (dolist (cur-obj (ergoemacs-component-struct--lookup-hash obj))
-          (ergoemacs-component-struct--refresh-keys cur-obj))
-      (let* ((obj (ergoemacs-component-struct--lookup-hash obj))
-             (cur-dynamic (ergoemacs-component-struct-dynamic-keys obj))
-             new-dynamic keymap key global-map-p cur-map
-             fn-lst new-fn-lst new-fn cur-layout)
-        (dolist (cur-lst cur-dynamic)
-          (setq keymap (nth 0 cur-lst)
-                key (nth 1 cur-lst)
-                fn-lst (nth 2 cur-lst)
-                global-map-p (eq keymap 'global-map)
-                cur-map (or (and global-map-p (ergoemacs-component-struct-map 
obj))
-                            (ergoemacs-gethash keymap 
(ergoemacs-component-struct-maps obj)))
-                new-fn-lst '())
-          (if (catch 'found-fn
-                (dolist (fn fn-lst)
-                  (if (not (commandp fn t))
-                      (push new-fn-lst fn)
-                    (setq new-fn fn)
-                    (throw 'found-fn nil)))
-                t) (push cur-lst new-dynamic)
-            (when new-fn-lst ;; For later checks
-              (push (list keymap key (reverse new-fn-lst)) new-dynamic))
-            (ergoemacs :define-key cur-map key new-fn)
-            ;; Now fix cached layouts
-            (maphash
-             (lambda(key value)
-               (setq cur-layout (nth 1 key))
-               (when (or (and global-map-p (not (nth 0 key)))
-                         (eq (nth 0 key) keymap))
-                 ;; Update keymap (in place).
-                 (ergoemacs :define-key value
-                            (ergoemacs-translate
-                             key (ergoemacs-component-struct-just-first-keys 
obj)
-                             (ergoemacs-component-struct-variable-modifiers 
obj)
-                             (ergoemacs-component-struct-variable-prefixes 
obj) cur-layout
-                             (ergoemacs-component-struct-layout obj)) new-fn)))
-             (ergoemacs-component-struct-calculated-layouts obj))))
-        ;; Update dynamic/deferred keys
-        (fset (ergoemacs-component-struct-dynamic-keys obj) new-dynamic)))))
-
-(defun ergoemacs-component-struct--ini-map (obj)
-  "Initilize keymap in OBJ.
-
-OBJ is an `egoemacs-component-struct' object.
-
-Returns the map, if it hasn't been initialized, initialize
-with the label, and then return."
-  (or (ergoemacs-component-struct-map obj)
-      (let ((map (make-sparse-keymap)))
-        (ergoemacs map :label
-                   (list (ergoemacs (ergoemacs :global-map) :key-hash)
-                         (intern (format "%s%s" 
(ergoemacs-component-struct-name obj) (or (ergoemacs-component-struct-version 
obj) "")))
-                         (intern (ergoemacs-component-struct-layout obj))))
-        (setf (ergoemacs-component-struct-map obj) map)
-        map)))
-
-(defun ergoemacs-component-struct--define-key (keymap key def &optional object)
-  "In KEYMAP, define KEY to be DEF for OBJECT.
-If not specified, OBJECT is `ergoemacs-component-struct--define-key-current'."
-  (cond
-   ((and (not ergoemacs-component-struct--define-key-current) (not object)) ;; 
Old
-    (error "`ergoemacs-component-struct--define-key' is confused"))
-   (t
-    (let ((obj (or object ergoemacs-component-struct--define-key-current))
-          (key (or (and (consp key) (memq (car key) '(kbd read-kbd-macro))
-                        (stringp (nth 1 key)) (read-kbd-macro (nth 1 key)))
-                   key))
-          (def (ergoemacs-component-struct--define-key-get-def def)))
-      (if (not (ergoemacs-component-struct-p obj))
-          (error "OBJECT not a ergoemacs-component-structure")
-        (setq key (vconcat key))
-        (let* ((global-map-p (or (eq keymap 'global-map) (eq keymap 
'ergoemacs-mode-map)
-                                 (eq keymap 'ergoemacs-keymap)))
-               (when-condition (ergoemacs-component-struct-when-condition obj))
-               (hook (ergoemacs-component-struct-hook obj))
-               (cur-map (or (and global-map-p (not when-condition)
-                                 (ergoemacs-component-struct--ini-map obj))
-                            (and (not when-condition) (ergoemacs-gethash 
keymap (ergoemacs-component-struct-maps obj)))
-                            (and global-map-p when-condition 
(ergoemacs-gethash when-condition (ergoemacs-component-struct-cond-maps obj)))
-                            (and when-condition hook (ignore-errors 
(ergoemacs-gethash keymap (ergoemacs-gethash hook 
(ergoemacs-component-struct-hook-maps obj)))))))
-               (package-name (ergoemacs-component-struct-package-name obj))
-               fn-lst
-               (key (or (and (vectorp key) key)
-                        (and (stringp key) (vconcat key))))
-               tmp)
-          (cond
-           ((and (not cur-map) (not when-condition))
-            (cl-pushnew keymap ergoemacs-map-properties--known-maps)
-           (cl-pushnew keymap ergoemacs-map-properties--label-atoms-maps)
-            (setq cur-map (make-sparse-keymap))
-            (puthash keymap cur-map (ergoemacs-component-struct-maps obj)))
-           ((and (not cur-map) when-condition global-map-p)
-            (setq cur-map (make-sparse-keymap))
-            (puthash when-condition cur-map 
(ergoemacs-component-struct-cond-maps obj)))
-           ((and (not cur-map) when-condition hook)
-            (unless (ergoemacs-gethash hook 
(ergoemacs-component-struct-hook-maps obj))
-              (puthash hook (make-hash-table) 
(ergoemacs-component-struct-hook-maps obj)))
-            (cl-pushnew keymap ergoemacs-map-properties--known-maps)
-           (cl-pushnew keymap ergoemacs-map-properties--label-atoms-maps)
-            (setq cur-map (make-sparse-keymap))
-            (puthash keymap cur-map (ergoemacs-gethash hook 
(ergoemacs-component-struct-hook-maps obj)))))
-          (cond
-           ((and global-map-p (not when-condition) (not def) (setq tmp 
(lookup-key (ergoemacs-component-struct-map obj) key))
-                 (not (integerp tmp)))
-            ;; Remove the key from the keymap, do not set it to
-            ;; nil; Its as if it was never defined
-            (setq ergoemacs-component-struct--define-key-temp-map 
(make-sparse-keymap))
-            (ergoemacs-timing remove-global-map-map-keymap
-              (ergoemacs-map-keymap
-               (lambda (cur-key item)
-                 (if (consp cur-key)
-                     (ergoemacs-warn "Keymap range currently not supported %s 
%s" cur-key item)
-                   (unless (eq item 'ergoemacs-prefix)
-                     (unless (equal key cur-key)
-                       (ergoemacs :define-key 
ergoemacs-component-struct--define-key-temp-map cur-key item)))))
-               cur-map))
-            (setf (ergoemacs-component-struct-map obj)
-                  (copy-keymap 
ergoemacs-component-struct--define-key-temp-map))
-            (setq ergoemacs-component-struct--define-key-temp-map nil))
-           ((and global-map-p (not (eq keymap 'global-map)) (not 
when-condition) (not def));; Add to unbind keys
-            (unless (member key (ergoemacs-component-struct-unbind obj))
-              (push key (ergoemacs-component-struct-unbind obj))))
-           ((and global-map-p (not when-condition) (not def)) ;; Add to 
undefined keys
-            (unless (member key (ergoemacs-component-struct-undefined obj))
-              (push key (ergoemacs-component-struct-undefined obj))))
-           ((and (not when-condition) (lookup-key cur-map key) (not def))
-            ;; Remove the key from the keymap.  Do not set it to nil.
-            ;; Its as if it was never defined.
-            (setq ergoemacs-component-struct--define-key-temp-map 
(make-sparse-keymap))
-            (ergoemacs-timing remove-local-keymap-map-keymap
-              (ergoemacs-map-keymap
-               (lambda (cur-key item)
-                 (if (consp cur-key)
-                     (message "Key range not supported %s, %s" cur-key item)
-                   (unless (eq item 'ergoemacs-prefix)
-                     (unless (equal key cur-key)
-                       (ergoemacs :define-key 
ergoemacs-component-struct--define-key-temp-map cur-key item)))))
-               cur-map))
-            (puthash keymap (copy-keymap 
ergoemacs-component-struct--define-key-temp-map) 
(ergoemacs-component-struct-maps obj))
-            (setq ergoemacs-component-struct--define-key-temp-map nil))
-           ((and (consp def) (stringp (nth 0 def)) (symbolp (nth 1 def)) (eq 
(nth 1 def) 'keymap))
-            (ergoemacs :define-key cur-map key def))
-           ((and (consp def) (symbolp (nth 1 def))) ;; (fn1 fn2 fn3 fn4)
-            (unless (catch 'found-fn
-                      (dolist (cur-def def)
-                        (if (not (commandp cur-def t))
-                            (push cur-def fn-lst)
-                          (if (ergoemacs-keymapp cur-def)
-                             (ergoemacs :define-key cur-map key (copy-keymap 
cur-def))
-                           (ergoemacs :define-key cur-map key cur-def))
-                          (throw 'found-fn t)))
-                      nil)
-              ;; Not found
-              (ergoemacs :define-key cur-map key `(lambda() (interactive) 
(error ,(format "This key is undefined without one of the following functions: 
%s" fn-lst)))))
-            (when fn-lst ;; Test for later
-              (push (list keymap key fn-lst)
-                    (ergoemacs-component-struct-dynamic-keys obj))))
-           (t
-            (if (ergoemacs-keymapp def)
-               (ergoemacs :define-key cur-map key (copy-keymap def))
-             (ergoemacs :define-key cur-map key def))
-            (when (and package-name def (not (fboundp def)))
-              ;; Create autoload.
-              (autoload def (format "%s" package-name) nil t)
-              (push (cons def package-name) 
(ergoemacs-component-struct-autoloads obj)))))))))))
-
-(defun ergoemacs-component-struct--clear-cache (struct-map)
-  "Clears STRUCT-MAP's cache of keymaps.
-
-STRUCT-MAP can be a list of `ergoemacs-component-struct' structures as well."
-  (cond
-   ((ergoemacs-component-struct-p struct-map)
-    (setf (ergoemacs-component-struct-calculated-layouts struct-map) 
(make-hash-table :test 'equal)))
-   ((consp struct-map)
-    (dolist (cur-map struct-map)
-      (ergoemacs-component-struct--clear-cache cur-map)))))
-
-(defun ergoemacs-component-struct--closest-version (version version-list)
-  "Return the closest version to VERSION in VERSION-LIST.
-Formatted for use with `ergoemacs-theme-component-hash' it will return 
::version or an empty string"
-  (if (or (not version) (string= "nil" version)) ""
-    (if version-list
-        (let ((use-version (version-to-list version))
-              biggest-version
-              biggest-version-list
-              smallest-version
-              smallest-version-list
-              best-version
-              best-version-list
-              test-version-list
-              ret)
-          (dolist (v version-list)
-            (setq test-version-list (version-to-list v))
-            (if (not biggest-version)
-                (setq biggest-version v
-                      biggest-version-list test-version-list)
-              (when (version-list-< biggest-version-list test-version-list)
-                (setq biggest-version v
-                      biggest-version-list test-version-list)))
-            (if (not smallest-version)
-                (setq smallest-version v
-                      smallest-version-list test-version-list)
-              (when (version-list-< test-version-list smallest-version-list)
-                (setq smallest-version v
-                      smallest-version-list test-version-list)))
-            (cond
-             ((and (not best-version)
-                   (version-list-<= test-version-list use-version))
-              (setq best-version v
-                    best-version-list test-version-list))
-             ((and (version-list-<= best-version-list test-version-list) ;; 
Better than best
-                   (version-list-<= test-version-list use-version))
-              (setq best-version v
-                    best-version-list test-version-list))))
-          (if (version-list-< biggest-version-list use-version)
-              (setq ret "")
-            (if best-version
-                (setq ret (concat "::" best-version))
-              (setq ret (concat "::" smallest-version))))
-          ret)
-      "")))
-
-(defun ergoemacs-component-struct--lookup-closest (comp &optional 
current-version)
-  "Look up closest component version from `ergoemacs-component-hash'.
-
-COMP is the component where the version information should be stored.
-
-Optionally assume that CURRENT-VERSION is active"
-  (if (not (ergoemacs-component-struct-p comp)) nil
-    (let (versions)
-      (cond
-       ((not (setq versions (ergoemacs-component-struct-versions comp)))
-        comp)
-       ((string= "" (setq versions (ergoemacs-component-struct--closest-version
-                                    (or current-version (ergoemacs 
:current-version))  versions)))
-        comp)
-       (t
-        (ergoemacs-component-struct--lookup-hash (concat 
(ergoemacs-component-struct-name comp) versions)))))))
-
-(defun ergoemacs-component-struct--lookup-hash (map-or-map-list &optional 
version)
-  "Lookup `ergoemacs-component-hash' from MAP-OR-MAP-LIST if necessary.
-
-VERSION is the version of the `ergoemacs-mode' keys that you wish
-to lookup.
-
-This takes into consideration any versions defined, and the
-closest `ergoemacs-theme-version' calculated from
-`ergoemacs-component-struct--closest-version' by using
-`ergoemacs-component-struct--lookup-closest'"
-  (if (consp map-or-map-list)
-      (mapcar #'ergoemacs-component-struct--lookup-hash map-or-map-list)
-    (if (ergoemacs-component-struct-p map-or-map-list)
-        (ergoemacs-component-struct--lookup-closest map-or-map-list version)
-      (let ((map map-or-map-list)
-            ret)
-        (when (symbolp map) ;; If map is a symbol, change to string.
-          (setq map (symbol-name map)))
-        (when (stringp map) ;; If map is a string, get the component from 
`ergoemacs-component-hash'
-          (setq ret (ergoemacs-gethash map ergoemacs-component-hash))
-          (when (and ret (functionp ret))
-            (funcall ret)
-            (setq ret (ergoemacs-gethash map ergoemacs-component-hash))))
-        (if (and map (string-match-p "::" map)) ret
-         (ergoemacs-component-struct--lookup-closest ret version))))))
-
-(defvar ergoemacs-component-struct--get-keymap nil)
-(defvar ergoemacs-component-struct--get-keymap-extra nil)
-(defun ergoemacs-component-struct--lookup-list (lookup-keymap &optional layout 
obj map-list)
-  "Get list of extra maps based on LOOKUP-KEYMAP.
-
-The LAYOUT argument specifies the ergoemacs layout to use.
-Otherwise, the layout used is `ergoemacs-keyboard-layout'.
-
-The OBJ list is the list of ergoemacs theme components to use.
-If it is nil, it is the components specifed by
-`ergoemacs-theme-components'.
-
-The MAP-LIST is the list symbols that LOOKUP-KEYMAP is bound to.
-If unspecified, use `ergoemacs-map-properties--map-list' to try
-to figure out what variables LOOKUP-KEYMAP is bound to."
-  (let ((obj (ergoemacs-component-struct--lookup-hash (or obj (reverse 
(ergoemacs-theme-components)))))
-        (cur-layout (or layout ergoemacs-keyboard-layout))
-        (map-list (or map-list (ergoemacs lookup-keymap :map-list)))
-        ;; (ergoemacs-component-struct--lookup-list org-mode-map)
-        extra-hash
-        ret extra-map)
-    (if (consp obj)
-        (dolist (cobj obj)
-          (setq extra-hash (ergoemacs-component-struct-maps cobj))
-          (dolist (map-name map-list)
-            (setq extra-map (ergoemacs-gethash map-name extra-hash))
-            (when extra-map
-              (push (ergoemacs-component-struct--get cobj cur-layout map-name 
extra-map) ret)))))
-    ret))
-
-(defun ergoemacs-component-struct--get (map cur-layout &optional lookup-key 
translate-map)
-  "Get component MAP and return keymap updating MAP cache.
-
-CUR-LAYOUT is the current keymboard layout used.
-
-This keymap is cached using LOOKUP-KEY.
-
-The keymap to translate is TRANSLATE-MAP, otherwise it is the
-`ergoemacs-component-struct-map' for MAP."
-  (let* (ret
-         (cmap (or translate-map (ergoemacs-component-struct-map map)))
-         (just-first-keys (ergoemacs-component-struct-just-first-keys map))
-         (variable-modifiers (ergoemacs-component-struct-variable-modifiers 
map))
-         (variable-prefixes (ergoemacs-component-struct-variable-prefixes map))
-         (layout-from (ergoemacs-component-struct-layout map))
-         (hash (ergoemacs-component-struct-calculated-layouts map)))
-    (cond
-     ((string= layout-from cur-layout)
-      (setq ret (copy-keymap cmap))
-      ret)
-     ((setq ret (ergoemacs-gethash (list lookup-key (intern cur-layout)) hash))
-      ret)
-     (t
-      (setq ergoemacs-component-struct--get-keymap (make-sparse-keymap))
-      (ergoemacs-timing translate-keymap
-        (ergoemacs-timing (intern (format "translate-keymap-%s" 
(ergoemacs-component-struct-name map)))
-          (ergoemacs-map-keymap
-           (lambda (key item)
-             (if (consp key)
-                 (ergoemacs-warn "Keymap range currently not supported %s,%s" 
key item)
-               (unless (eq item 'ergoemacs-prefix)
-                 (ergoemacs :define-key
-                            ergoemacs-component-struct--get-keymap
-                            (ergoemacs-translate
-                             key just-first-keys variable-modifiers
-                             variable-prefixes cur-layout layout-from) item))))
-           cmap)))
-      (setq ret (copy-keymap ergoemacs-component-struct--get-keymap))
-      (ergoemacs ret :label (list (or lookup-key (ergoemacs (ergoemacs 
:global-map) :key-hash)) (intern (format "%s%s" 
(ergoemacs-component-struct-name map) (or (ergoemacs-component-struct-version 
map) ""))) (intern cur-layout)))
-      (puthash (list lookup-key (intern cur-layout)) ret hash)
-      (setq ergoemacs-component-struct--get-keymap nil)
-      ret))))
-
-(defun ergoemacs-component-struct--minor-mode-map-alist-hash (&optional obj 
layout)
-  "Get `minor-mode-map-alist' additions in hash-table form.
-
-OBJ is the ergoemacs theme components.  Defaults to the value
-returned from the function `ergoemacs-theme-components'.
-
-LAYOUT is the current keyboard layout.  Defaults to
-`ergoemacs-keyboard-layout'"
-  (let ((obj (ergoemacs-component-struct--lookup-hash (or obj 
(ergoemacs-theme-components))))
-        (cur-layout (or layout ergoemacs-keyboard-layout))
-        (hash (make-hash-table)))
-    (cond
-     ((consp obj)
-      (dolist (cur-obj obj)
-        (maphash
-         (lambda(key value)
-           (puthash key (append (ergoemacs-gethash key hash) value) hash))
-         (ergoemacs-component-struct--minor-mode-map-alist-hash cur-obj)))
-      hash)
-     (t
-      (maphash
-       (lambda(key value)
-         ;; Put the translated keymap in a list in the hash.
-         (puthash key (list (ergoemacs-component-struct--get obj cur-layout 
(list 'cond-map key) value)) hash))
-       (ergoemacs-component-struct-cond-maps obj))
-      hash))))
-
-
-(defvar ergoemacs-component-struct--unbound-maps nil)
-
-(defun ergoemacs-component-struct--minor-mode-map-alist (&optional obj)
-  "Get the ending maps for `minor-mode-map-alist' using the ergoemacs 
structures OBJ."
-  (let (ret map parent)
-    (maphash
-     (lambda(key value)
-       (setq parent (make-composed-keymap value)
-             map (make-sparse-keymap))
-       (ergoemacs map :label (list 'cond-map key (intern 
ergoemacs-keyboard-layout)))
-       (set-keymap-parent map parent)
-       (if (boundp key)
-           (push (cons key map) ret)
-         (push (cons key map) ergoemacs-component-struct--unbound-maps)))
-     (ergoemacs-component-struct--minor-mode-map-alist-hash obj))
-    ret))
-
-(defun ergoemacs-component-struct--add-unbound (&rest _ignore)
-  "Add recently bound variables to `minor-mode-map-alist'."
-  (let (new)
-    (dolist (elt ergoemacs-component-struct--unbound-maps)
-      (if (boundp (car elt))
-          (push elt minor-mode-map-alist)
-        (push elt new)))
-    (setq ergoemacs-component-struct--unbound-maps new)))
-
-(add-hook 'ergoemacs-mode-after-load-hook 
'ergoemacs-component-struct--add-unbound)
-
-(defun ergoemacs-component-struct--hooks (&optional obj ret)
-  "Gets a list of hooks that need to be defined for OBJ.
-
-You can prespecify RET so that new hooks are pushed to the list."
-  (let ((obj (ergoemacs-component-struct--lookup-hash (or obj 
(ergoemacs-theme-components))))
-        tmp
-        (ret ret))
-    (cond
-     ((consp obj)
-      (dolist (cur-obj obj)
-        (setq ret (ergoemacs-component-struct--hooks cur-obj ret)))
-      ret)
-     (t
-      (when (and (setq tmp (ergoemacs-component-struct-hook-maps obj))
-                 (hash-table-p tmp))
-        (maphash
-         (lambda(hook _value)
-           (cl-pushnew hook ret))
-         tmp))
-      ret))))
-
-(defun ergoemacs-component-struct--hook-hash (hook &optional layout obj)
-  "Get HOOK hash.
-
-LAYOUT is the keyboard layout, defaulting to `ergoemacs-keyboard-layout'.
-
-OBJ is the theme components, defaulting to `ergoemacs-theme-components'."
-  (let ((obj (ergoemacs-component-struct--lookup-hash (or obj 
(ergoemacs-theme-components))))
-        (cur-layout (or layout ergoemacs-keyboard-layout))
-        tmp
-        (hash (make-hash-table)))
-    (cond
-     ((consp obj)
-      (dolist (cur-obj obj)
-        (maphash
-         (lambda(key value)
-           (puthash key (append (ergoemacs-gethash key hash) value) hash))
-         (ergoemacs-component-struct--hook-hash hook layout cur-obj)))
-      hash)
-     (t
-      (when (and (setq tmp (ergoemacs-gethash hook 
(ergoemacs-component-struct-hook-maps obj)))
-                 (hash-table-p tmp))
-        (maphash
-         (lambda(key value)
-           ;; Put the translated keymap in a list in the hash.
-           (puthash key (list (ergoemacs-component-struct--get obj cur-layout 
(list 'hook-maps hook key) value)) hash))
-         tmp))
-      hash))))
-
-(defun ergoemacs-component-struct--hook (hook &optional layout obj)
-  "Get keymaps applied in an alist similiar to `minor-mode-map-alist'.
-
-The `car' of the alist should be the keymap that should be
-modified, the `cdr' of the alsit should be the keymap that should
-be composed over the keymap.  This is done in
-`ergoemacs-component-struct--composed--composed-hook'.
-
-HOOK is the hook that is being run.  In the
-`ergoemacs-theme-component', these are defined as:
-
-\(when icicle-minibuffer-setup-hook
-  ...)
-
-LAYOUT is the current keyboard layout, or the layout of the
-current keyboard theme.
-
-OBJ is the curent ergoemacs-mode object being modified."
-  (let* (ret tmp label parent)
-    (maphash
-     (lambda(key value)
-       (setq tmp (when (ergoemacs-keymapp (ergoemacs-sv key))
-                   (ergoemacs-sv key))
-             label (list 'hook-maps key (or layout ergoemacs-keyboard-layout) 
(if tmp t nil))
-             parent (make-composed-keymap value tmp)
-             tmp (make-sparse-keymap))
-       (ergoemacs tmp :label label)
-       (set-keymap-parent tmp parent)
-       (push (cons key tmp) ret))
-     (ergoemacs-component-struct--hook-hash hook layout obj))
-    ret))
-
-(defvar ergoemacs-component-struct--composed-hook-minibuffer nil
-  "`ergoemacs-mode' hooks deferred until after `ergoemacs-mode' modifies the 
current minibuffer map.")
-
-(defun ergoemacs-component-struct--composed-hook (hook &optional layout obj)
-  "Apply keymaps defined in HOOK.
-
-LAYOUT is the current keyboard layout.
-
-OBJ is the current object being modified, passed to
-`ergoemacs-component-struct--hook'."
-  (dolist (elt (ergoemacs-component-struct--hook hook layout obj))
-    (if (minibufferp)
-       (progn
-         (unless ergoemacs-command-loop--minibuffer-unsupported-p
-           (catch 'unsupported-p
-             (dolist (elt (ergoemacs-component-struct--lookup-hash (or obj 
(ergoemacs-theme-components))))
-               (let ((plist (gethash hook 
(ergoemacs-component-struct-hook-plists elt))))
-                 (when (and plist (plist-get plist 
:command-loop-unsupported-p))
-                   (ergoemacs-save-buffer-state
-                    (set (make-local-variable 
'ergoemacs-command-loop--minibuffer-unsupported-p) t))
-                   (throw 'unsupported-p t))))))
-         (if ergoemacs-component-struct--composed-hook-minibuffer
-             (push elt ergoemacs-component-struct--composed-hook-minibuffer)
-           (ergoemacs-save-buffer-state
-            (set (make-local-variable 
'ergoemacs-component-struct--composed-hook-minibuffer)
-                 (list elt)))))
-      (ergoemacs-save-buffer-state
-       (set (make-local-variable (car elt)) (make-composed-keymap (cdr elt) 
(symbol-value (car elt))))))))
-
-(defvar ergoemacs-component-struct--create-hooks nil)
-(defun ergoemacs-component-struct--create-hooks (&optional obj)
-  "Gets a list of hooks that need to be defined eor OBJ."
-  (dolist (hook (ergoemacs-component-struct--hooks obj))
-    (eval `(progn
-            ;; FIXME: Since Emacs-25 we could use a closure with a computed 
docstring,
-            ;; using (:documentation <exp>).
-             (defun ,(intern (concat "ergoemacs--" (symbol-name hook))) ()
-               ,(format "`ergoemacs-mode' hook for `%s'" (symbol-name hook))
-               (ergoemacs-component-struct--composed-hook ',hook))
-             ;; (push )
-             (push ',hook ergoemacs-component-struct--create-hooks)
-             (add-hook ',hook #',(intern (concat "ergoemacs--" (symbol-name 
hook))))))
-    t))
-
-(defun ergoemacs-component-struct--rm-hooks ()
-  "Remove hooks.
-
-These hooks are those created with
-`ergoemacs-component-struct--create-hooks'."
-  (dolist (hook ergoemacs-component-struct--create-hooks)
-    (remove-hook hook (intern (concat "ergoemacs--" (symbol-name hook)))))
-  (setq ergoemacs-component-struct--create-hooks nil))
-
-(defun ergoemacs-component-struct--translated-list (obj list &optional layout)
-  "Base on OBJ translation, Translate LIST using LAYOUT."
-  (let ((cur-layout (or layout ergoemacs-keyboard-layout))
-        new-list)
-    (dolist (key list)
-      (ergoemacs :apply-key key
-                 (lambda(trans-key)
-                   (push (ergoemacs-translate
-                          trans-key 
(ergoemacs-component-struct-just-first-keys obj)
-                          (ergoemacs-component-struct-variable-modifiers obj)
-                          (ergoemacs-component-struct-variable-prefixes obj) 
cur-layout
-                          (ergoemacs-component-struct-layout obj))
-                         new-list))))
-    new-list))
-
-(defvar ergoemacs-component-struct--refresh-variables nil
-  "To reset a current theme, the variables are refreshed when this is 
non-nil.")
-
-;;; Change variable values.
-(defun ergoemacs-component-struct--set (symbol newval &optional hook object)
-  "Set variables up for components.
-
-SYMBOL is the symbol being set.
-
-NEWVAL is the new value that will be used.
-
-HOOK tells if this was called in the (with ..-hook ...) syntax.
-
-OBJECT is the object being modified, defaulting to
-`ergoemacs-component-struct--define-key-current'."
-  (cond
-   ((and (not ergoemacs-component-struct--define-key-current) (not object)) ;; 
Old
-    (error "`ergoemacs-component-struct--set' is confused"))
-   (t
-    (let ((obj (or object ergoemacs-component-struct--define-key-current)))
-      (if (not (ergoemacs-component-struct-p obj))
-          (error "OBJECT is not an ergoemacs-component-structure")
-        (push (list symbol newval hook) (ergoemacs-component-struct-variables 
obj)))))))
-
-(defun ergoemacs-component-struct--deferred (what &optional object)
-  "Setup deferred initilizations.
-
-WHAT is the defered initilization list.
-
-OBJECT is the `ergoemacs-component-struct' object being changed."
-  (cond
-   ((and (not ergoemacs-component-struct--define-key-current) (not object)) ;; 
Old
-    (error "`ergoemacs-component-struct--deferred' is confused"))
-   (t
-    (let ((obj (or object ergoemacs-component-struct--define-key-current)))
-      (if (not (ergoemacs-component-struct-p obj))
-          (error "OBJECT is not an ergoemacs-component-structure")
-        (push (list what nil nil) (ergoemacs-component-struct-variables 
obj)))))))
-
-(defun ergoemacs-component-struct--variables (&optional obj)
-  "Get a list of variables for the OBJ."
-  (let ((obj (or obj (ergoemacs-theme-components))))
-    (cond
-     ((consp obj)
-      (let (ret)
-        (dolist (cur-obj (ergoemacs-component-struct--lookup-hash obj))
-          (setq ret (append ret (ergoemacs-component-struct--variables 
cur-obj))))
-        ret))
-     ((ergoemacs-component-struct-p obj)
-      (mapcar (lambda(x)
-               (append x (list (ergoemacs-component-struct-name obj))))
-             (ergoemacs-component-struct-variables obj)))
-     (t (ergoemacs-component-struct--variables 
(ergoemacs-component-struct--lookup-hash obj))))))
-
-(defvar ergoemacs-component-struct--refresh-variables nil)
-(defvar ergoemacs-component-struct--applied-inits '())
-(defvar ergoemacs-component-struct--deferred-functions '())
-
-(defvar ergoemacs-component-struct--apply-inits-first-p t)
-(defvar ergoemacs-component-struct--apply-ensure-p nil)
-(defvar ergoemacs-component-struct--applied-plists nil)
-
-(defvar ergoemacs-component-echo-loaded-file-p nil)
-
-(defvar ergoemacs-component-struct--apply-inits nil)
-(defun ergoemacs-component-struct--apply-inits (&optional file obj)
-  "Apply the initializations after loading FILE from the object OBJ.
-
-This is a wrapper for `ergoemacs-component-struct--apply-inits--'
-to prevent infinite recursion."
-  (unless ergoemacs-component-struct--apply-inits
-    (setq ergoemacs-component-struct--apply-inits t)
-    (unwind-protect
-       (ergoemacs-component-struct--apply-inits-- file obj))
-    (setq ergoemacs-component-struct--apply-inits nil)))
-
-(defun ergoemacs-component-struct--apply-inits-- (&optional file obj)
-  "Apply the initializations after loading FILE from the object OBJ."
-  (ergoemacs-map-properties--label-known)
-  (when (and ergoemacs-component-echo-loaded-file-p file)
-    (message "`ergoemacs-mode' Loaded %s" file))
-  (when (eq ergoemacs-component-struct--refresh-variables t)
-    (setq ergoemacs-component-struct--refresh-variables 
ergoemacs-component-struct--applied-inits))
-  (let* ((obj (or obj (ergoemacs-theme-components)))
-         package-name ensure defer comp tmp autoloads)
-    (when ergoemacs-component-struct--apply-inits-first-p
-      (setq ergoemacs-component-struct--apply-inits-first-p nil
-            ergoemacs-component-struct--apply-ensure-p t)
-      (if (not ergoemacs-mode--fast-p)
-          (setq ergoemacs--start-emacs-state-2 (ergoemacs--emacs-state))
-        ;; Check to see if emacs state has changed.
-        (setq ergoemacs--start-emacs-state-2 (ergoemacs--emacs-state))
-        (ergoemacs-mode--setup-hash-tables--setq
-         nil
-         'ergoemacs--last-start-emacs-state-2 nil)
-        (unless (equal ergoemacs--last-start-emacs-state-2 
ergoemacs--start-emacs-state-2)
-          (if (not ergoemacs--last-start-emacs-state-2)
-              (progn
-                (message "Saving fast startup state.")
-                (setq ergoemacs--last-start-emacs-state-2 
ergoemacs--start-emacs-state-2)
-                (ergoemacs-mode--setup-hash-tables--setq
-                 t
-                 'ergoemacs--last-start-emacs-state-2 
ergoemacs--last-start-emacs-state-2))
-            (ergoemacs-mode-clear-cache t)
-            (ergoemacs-warn "ergoemacs-mode cache reset AFTER loading; Keys 
may be slightly inconsistent until emacs restart.")))))
-    (when ergoemacs-component-struct--apply-ensure-p
-      (setq ergoemacs-component-struct--apply-ensure-p nil)
-      ;; Ensure packages
-      (dolist (elt obj)
-        (setq comp (ergoemacs-component-struct--lookup-hash elt)
-              package-name (ergoemacs-component-struct-package-name comp)
-              ensure (ergoemacs-component-struct-ensure comp)
-              autoloads (ergoemacs-component-struct-autoloads comp)
-              defer (ergoemacs-component-struct-defer comp))
-        (cond
-         ((eq ensure t)
-          (ergoemacs-component-struct--ensure package-name defer autoloads))
-         ((and ensure (symbolp ensure))
-          (ergoemacs-component-struct--ensure ensure defer autoloads))
-        ((and (consp ensure) (memq (car ensure) '(memq member and or if when = 
string= not string< eq equal)))
-         ;; FIXME: avoid `eval', e.g. by making
-          ;; ergoemacs-component-struct-ensure hold a function rather than
-         ;; an expression.
-         (when (ignore-errors (eval ensure t))
-           (ergoemacs-component-struct--ensure package-name defer autoloads)))
-         ((consp ensure)
-          (dolist (elt ensure)
-            (cond
-             ((and elt (symbolp elt))
-              (ergoemacs-component-struct--ensure elt defer autoloads))
-             ((stringp elt)
-              (ergoemacs-component-struct--ensure (intern elt) defer 
autoloads)))
-            (setq autoloads nil)))
-         ((stringp ensure)
-          (ergoemacs-component-struct--ensure (intern ensure) defer 
autoloads)))))
-    ;; Turn on plist options (like :diminish)
-    (dolist (elt obj)
-      (unless (memq elt ergoemacs-component-struct--applied-plists)
-        (let* ((comp (ergoemacs-component-struct--lookup-hash elt))
-               (plist (ergoemacs-component-struct-plist comp))
-               fn)
-          (dolist (elt plist)
-            (when (and (symbolp elt)
-                       (setq fn (intern (format "ergoemacs-component--%s-on"
-                                                (substring (symbol-name elt) 
1))))
-                       (fboundp fn))
-              (funcall fn plist)))
-          (push elt ergoemacs-component-struct--applied-plists))))
-    
-    ;; Turn off plist options
-    (setq tmp nil)
-    (dolist (elt ergoemacs-component-struct--applied-plists)
-      (if (memq elt obj)
-          (push elt tmp)
-        (let* ((comp (ergoemacs-component-struct--lookup-hash elt))
-               (plist (ergoemacs-component-struct-plist comp))
-               fn)
-          (dolist (elt plist)
-            (when (and (symbolp elt)
-                       (setq fn (intern (format "ergoemacs-component--%s-off"
-                                                (substring (symbol-name elt) 
1))))
-                       (fboundp fn))
-              (funcall fn plist))))))
-    (setq ergoemacs-component-struct--applied-plists tmp)
-    (dolist (cur-obj obj)
-      (ergoemacs-timing (intern (format "initialize-%s" cur-obj))
-        (dolist (init (ergoemacs-component-struct--variables cur-obj))
-          (if (and (consp (nth 0 init)) (not (nth 1 init)) (not (nth 2 init)))
-              (unless (member (nth 0 init) 
ergoemacs-component-struct--deferred-functions)
-                (cond
-                 ((eq (car (nth 0 init)) 'add-to-list)
-                  (when (ignore-errors (boundp (nth 1 (nth 0 init))))
-                    (ignore-errors
-                      (apply (car (nth 0 init)) (cdr (nth 0 init)))
-                      (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions)))
-                  (when (ignore-errors (eq 'quote (nth 0 (nth 1 (nth 0 
init)))))
-                    (if (ignore-errors (eq 'quote (nth 0 (nth 2 (nth 0 
init)))))
-                        (when (ignore-errors (boundp (nth 1 (nth 1 (nth 0 
init)))))
-                          (apply 'add-to-list  (nth 1 (nth 2 (nth 0 init))) 
(cdr (cdr (cdr (nth 0 init)))))
-                          (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions))
-                      (when (ignore-errors (boundp (nth 1 (nth 1 (nth 0 
init)))))
-                        (apply 'add-to-list (nth 1 (nth 1 (nth 0 init))) (cdr 
(cdr (nth 0 init))))
-                        (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions)))))
-                 ((memq (car (nth 0 init)) '(push pushnew cl-pushnew))
-                  (when (ignore-errors (boundp (nth 2 (nth 0 init))))
-                    (if (ignore-errors (eq 'quote (nth 1 (nth 1 (nth 0 
init)))))
-                        (ignore-errors
-                          (apply (car (nth 0 init)) (nth 1 (nth 1 (nth 0 
init))) (cdr (cdr (nth 0 init))))
-                          (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions))
-                      (ignore-errors
-                        (apply (car (nth 0 init)) (cdr (nth 0 init)))
-                        (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions)))
-                    (ignore-errors
-                      (apply (car (nth 0 init)) (cdr (nth 0 init)))
-                      (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions))))
-                 ((eq (car (nth 0 init)) 'require)
-                  (require (nth 1 (nth 1 (nth 0 init))) nil t)
-                  (when (not (featurep (nth 1 (nth 1 (nth 0 init)))))
-                    ;; Attempt to ensure the feature, if specified.
-                    (ergoemacs-warn "Could not load %s; %s" (nth 1 (nth 1 (nth 
0 init)))
-                          (nth 3 init))))
-                 (t
-                  (condition-case err
-                      (eval (nth 0 init) t)
-                    (error (progn
-                            (ergoemacs-warn "%s while evaluating %s" err (nth 
0 init))
-                            (debug err))))
-                  (push (nth 0 init) 
ergoemacs-component-struct--deferred-functions))
-                 ;; (t (ergoemacs-warn "Theme did not handle: %s" (nth 0 
init)))
-                 ))
-            (let ((x (and ergoemacs-component-struct--refresh-variables 
(boundp (nth 0 init))
-                          (assq (nth 0 init) 
ergoemacs-component-struct--refresh-variables)))
-                  add-hook-p append-p local-p)
-              (cond
-               ((and x
-                     (not (nth 2 init))
-                     (not
-                      (equal (ergoemacs-sv (nth 0 init))
-                             (funcall (nth 1 init)))))
-                ;; Values have changed, so reapply.
-                (setq ergoemacs-component-struct--refresh-variables (delq x 
ergoemacs-component-struct--refresh-variables)
-                      x nil))
-               ((and x (nth 2 init))
-                ;; Reapply hooks
-                (setq ergoemacs-component-struct--refresh-variables (delq x 
ergoemacs-component-struct--refresh-variables)
-                      x nil)))
-              (cond
-               (x ;; Values have not changed
-                (setq ergoemacs-component-struct--refresh-variables (delq x 
ergoemacs-component-struct--refresh-variables)))
-               ((not (boundp (nth 0 init))) ;; Do nothing, not bound yet.
-                )
-               ((and (nth 2 init) ;; Already applied hook?
-                     (setq add-hook-p (nth 0 (nth 2 init))
-                           append-p (nth 1 (nth 2 init))
-                           local-p (nth 2 (nth 2 init)))
-                     (member (list (nth 0 init) (nth 1 init)
-                                   (list (not add-hook-p) append-p local-p))
-                             ergoemacs-component-struct--applied-inits)))
-               ((nth 2 init)
-                ;; Hook
-                (if add-hook-p
-                    (progn
-                      (funcall 'add-hook (nth 0 init) (nth 1 init) append-p 
local-p)
-                      ;; (message "%s: (add-hook %s %s %s %s)"
-                      ;;          cur-obj (nth 0 init) (nth 1 init)
-                      ;;          append-p local-p)
-                      )
-                  (funcall 'remove-hook (nth 0 init) (nth 1 init) local-p)
-                  ;; (message "%s: (remove-hook %s %s %s %s)"
-                  ;;          cur-obj (nth 0 init) (nth 1 init)
-                  ;;          append-p local-p)
-                  )
-                (push (list (nth 0 init) (nth 1 init)
-                            (list (not add-hook-p) append-p local-p))
-                      ergoemacs-component-struct--applied-inits))
-               ((and (not (nth 2 init)) (assq (nth 0 init) 
ergoemacs-component-struct--applied-inits))
-                ;; Already applied, Do nothing for now.
-                )
-               (t
-                ;; (Nth 0 Init)iable state change
-                (when (ergoemacs-set (nth 0 init) (funcall (nth 1 init))
-                                     (ergoemacs-component-struct-defer 
(ergoemacs-component-struct--lookup-hash cur-obj)))
-                  (push (list (nth 0 init) (ergoemacs-sv (nth 0 init)))
-                        ergoemacs-component-struct--applied-inits)
-                  )))))))))
-  ;; Now remove things that were not set
-  (when ergoemacs-component-struct--refresh-variables
-    (let ((tmp ergoemacs-component-struct--applied-inits))
-      (setq ergoemacs-component-struct--applied-inits 
ergoemacs-component-struct--refresh-variables)
-      (setq ergoemacs-component-struct--refresh-variables nil)
-      (unwind-protect
-          (ergoemacs-component-struct--remove-inits)
-        (setq ergoemacs-component-struct--applied-inits tmp)))))
-
-(add-hook 'ergoemacs-mode-startup-hook 
#'ergoemacs-component-struct--apply-inits)
-(add-hook 'ergoemacs-after-load-functions 
#'ergoemacs-component-struct--apply-inits)
-
-(defun ergoemacs-component-struct--remove-inits ()
-  "Remove the applied initializations of modes and variables.
-This assumes the variables are stored in 
`ergoemacs-component-struct--applied-inits'"
-  (if ergoemacs-component-struct--refresh-variables
-      (setq ergoemacs-component-struct--refresh-variables 
ergoemacs-component-struct--applied-inits)
-    (dolist (init ergoemacs-component-struct--applied-inits)
-      (let ((var (nth 0 init))
-            ;; (val (nth 1 init))
-            (hook (nth 2 init)))
-        (cond
-         (hook
-          (let ((add-hook-p (nth 0 hook))
-                (append-p (nth 1 hook))
-                (local-p (nth 2 hook)))
-            (if add-hook-p
-                (funcall 'add-hook (nth 0 init) (nth 1 init) append-p local-p)
-              (funcall 'remove-hook (nth 0 init) (nth 1 init) local-p))))
-         (t
-          (ergoemacs-reset var))))))
-  (setq ergoemacs-component-struct--applied-inits '()))
-
-(add-hook 'ergoemacs-mode-shutdown-hook 
#'ergoemacs-component-struct--remove-inits)
-
-(defun ergoemacs-component-struct--versions (&optional obj)
-  "Get Versions available for OBJ.
-If Object isn't specified assume it is for the current ergoemacs theme."
-  (let ((obj (or obj (ergoemacs-theme-components obj))))
-    (if (not obj)
-        (error "`ergoemacs-theme-components' could not be detected")
-      (sort (cond
-             ((consp obj)
-              (let (ret)
-                (dolist (cur-obj (ergoemacs-component-struct--lookup-hash obj))
-                  (dolist (ver (ergoemacs-component-struct-versions cur-obj))
-                    (unless (member ver ret)
-                      (push ver ret))))
-                ret))
-             (t (ergoemacs-component-struct--versions 
(ergoemacs-component-struct--lookup-hash obj))))
-            'string<))))
-
-(defun ergoemacs-component--regexp (&optional at-end)
-  "Return a regexp of `ergoemacs-mode' components.
-
-AT-END will append a \"$\" to the end of the regular expression."
-  (let (ret)
-    (maphash
-     (lambda(key _item) (push key ret))
-     ergoemacs-component-hash)
-    (setq ret (regexp-opt ret 'symbols))
-    (when at-end
-      (setq ret (concat ret "$")))
-    ret))
-
-
-(defun ergoemacs-component--help-link-1 ()
-  "Setup crosreferences for help."
-  (let (tmp)
-    ;; Link commands
-    (goto-char (match-beginning 0))
-    (when (and (re-search-backward "\\_<\\(.*?\\)\\_> *\\=" nil t)
-               (setq tmp (intern (match-string 1)))
-               (fboundp tmp)
-               (commandp tmp))
-      (help-xref-button 1 'help-function tmp))
-    ;; Add button properties back
-    (when (and tmp ergoemacs-display-key-use-face)
-      (setq tmp (point))
-      (beginning-of-line)
-      (while (and (not (looking-at "Relative To:")) (re-search-forward 
"\\(.*?\\)[ +]" tmp t))
-        (add-text-properties (match-beginning 1) (match-end 1) '(face 
ergoemacs-display-key-face))))
-    (end-of-line)))
-
-(defun ergoemacs-component--help-link ()
-  "Links `ergoemacs-mode' components in `help-mode' buffer."
-  (when (eq major-mode 'help-mode)
-    (save-excursion
-      (goto-char (point-min))
-      (let ((inhibit-read-only t)
-            (ree (format "^ - %s -- " (ergoemacs-component--regexp)))
-            (ret (format "^\"%s\" - " (ergoemacs-theme--regexp)))
-            (re (ergoemacs-component--regexp t))
-            (rem (ergoemacs-map-properties--map-regexp t))
-            (rel1 (ergoemacs-layout--regexp))
-            (rel2 (ergoemacs-layout--regexp 2))
-            tmp)
-        (with-syntax-table emacs-lisp-mode-syntax-table
-          (when (re-search-forward "^\\(\\_<.*\\_>\\) is .* component defined 
in `\\(.*\\)'" nil t)
-            (help-xref-button 2 'ergoemacs-component-def (match-string 1)))
-          (goto-char (point-min))
-          (while (re-search-forward rel1 nil t)
-            (help-xref-button 1 'ergoemacs-layout-help (match-string 1)))
-          (goto-char (point-min))
-          (while (re-search-forward rel2 nil t)
-            (help-xref-button 1 'ergoemacs-layout-help (match-string 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^\\(\\_<.*\\_>\\) is .* component defined 
in `\\(.*\\)'" nil t)
-            (help-xref-button 2 'ergoemacs-component-def (match-string 1)))
-          (goto-char (point-min))
-          (while (re-search-forward "\\(Variable Prefixes:\\|Unbound 
keys:\\|Masked emacs keys:\\) +" nil t)
-            (while (and (not (looking-at " *$")) (re-search-forward 
"\\(.*?\\)\\(, +\\| *$\\|[+ ]+\\)" (point-at-eol) t))
-              (add-text-properties (match-beginning 1) (match-end 1) '(face 
ergoemacs-display-key-face))))
-          (goto-char (point-min))
-          (when (re-search-forward "^\\(\\_<.*\\_>\\) is .* theme defined in 
`\\(.*\\)'" nil t)
-            (help-xref-button 2 'ergoemacs-theme-def (match-string 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^This theme is based on: 
*\\(\\_<.*\\_>\\)" nil t)
-            (help-xref-button 1 'ergoemacs-theme-help (match-string 1)))
-          (goto-char (point-min))
-          (while (re-search-forward ret nil t)
-            (help-xref-button 1 'ergoemacs-theme-help (match-string 1)))
-          (goto-char (point-min))
-          (while (re-search-forward ree nil t)
-            (help-xref-button 1 'ergoemacs-component-help (match-string 1)))
-          (goto-char (point-min))
-          (while (re-search-forward re  nil t)
-            (help-xref-button 1 'ergoemacs-component-help (match-string 1))
-            (ergoemacs-component--help-link-1))
-          (goto-char (point-min))
-          (while (re-search-forward rem  nil t)
-            (when (and (setq tmp (intern (match-string 1)))
-                       (boundp tmp))
-              (help-xref-button 1 'help-variable tmp))
-            (ergoemacs-component--help-link-1))
-          (goto-char (point-min))
-          (when (search-forward "an `ergoemacs-mode' layout defined" nil t)
-            (setq bidi-display-reordering nil)))))))
-
-(define-button-type 'ergoemacs-component-help
-  :supertype 'help-xref
-  'help-function #'ergoemacs-component-describe
-  'help-echo (purecopy "mouse-2, RET: describe this ergoemacs component"))
-
-(define-button-type 'ergoemacs-component-def
-  :supertype 'help-xref
-  'help-function #'ergoemacs-component-find-definition
-  'help-echo (purecopy "mouse-2, RET: find this ergoemacs component's 
definition"))
-
-
-(defcustom ergoemacs-component-find-regexp
-  
(concat"^\\s-*(ergoemacs-\\(?:theme-?\\)?\\(?:component\\|package\\|autoload\\)?"
 find-function-space-re "%s\\(\\s-\\|$\\)")
-  "The regexp used to search for a component definition.
-
-This is used by `ergoemacs-find-component' and it must contain a
-`%s' at the place where `format' should insert the compenent
-name."
-  :type 'regexp
-  :group 'find-function
-  :version "22.1")
-
-(unless (assoc 'ergoemacs-component find-function-regexp-alist)
-  (push (cons 'ergoemacs-component 'ergoemacs-component-find-regexp) 
find-function-regexp-alist))
-
-(defun ergoemacs-component-find-no-select (component &optional type)
-  "Find COMPONENT of TYPE.
-
-TYPE can be 'ergoemacs-theme, if not it defaults to a single component."
-  (let* ((comp (or (and (eq type 'ergoemacs-theme)
-                        (ergoemacs-gethash (format "%s" (or component 
"standard")) ergoemacs-theme-hash))
-                   (ergoemacs-component-struct--lookup-hash (or component 
""))))
-         (plist (and comp (or (and (eq type 'ergoemacs-theme) comp)
-                              (ergoemacs-component-struct-plist comp))))
-         (file (and comp (plist-get plist :file)))
-         (el-file (and file (concat (file-name-sans-extension file) ".el")))
-         (name (plist-get plist :name))
-         (sym (intern name))
-         loc)
-    (if (not comp)
-        (message "Invalid %s %s" (or (and (eq type 'ergoemacs-theme) "theme")
-                                     "component") component)
-      (setq loc (find-function-search-for-symbol sym (or type 
'ergoemacs-component) el-file))
-      (when (and (eq type 'ergoemacs-component) (not (cdr loc)) (< 6 (length 
name)))
-        (setq sym (intern (substring name 0 -6))
-              loc (find-function-search-for-symbol
-                   sym (or type 'ergoemacs-component) el-file)))
-      loc)))
-
-(defun ergoemacs-component-find-1 (symbol type switch-fn &optional 
buffer-point)
-  "Find `ergoemacs-mode' component or theme.
-
-SYMBOL is the symbol representing the component or theme.
-
-TYPE is nil to search for a component definition, or
-'ergoemacs-theme, to find the theme.
-
-The variable `find-function-recenter-line' controls how
-to recenter the display.  SWITCH-FN is the function to call
-to display and select the buffer.
-See also `find-function-after-hook'.
-
-BUFFER-POINT is the point to move to.  If it isn't specified,
-find it with `ergoemacs-component-find-no-select'.
-
-Modified from `find-definition-noselect'.
-
-Set mark before moving, if the buffer already existed."
-  (let* ((orig-point (point))
-         (orig-buffers (buffer-list))
-         (buffer-point (or buffer-point
-                           (save-excursion
-                             (ergoemacs-component-find-no-select symbol 
type))))
-         (new-buf (car buffer-point))
-         (new-point (cdr buffer-point)))
-    (when buffer-point
-      (when (memq new-buf orig-buffers)
-        (push-mark orig-point))
-      (funcall switch-fn new-buf)
-      (when new-point (goto-char new-point))
-      (recenter find-function-recenter-line)
-      (run-hooks 'find-function-after-hook))))
-
-(defun ergoemacs-component-find-definition (component)
-  "Find the definition of COMPONENT.  COMPONENT defaults to the name near 
point.
-
-Finds the `ergoemacs-mode' containing the definition of the component
-near point (selected by `ergoemacs-component-at-point') in a buffer and
-places point before the definition.
-
-Set mark before moving, if the buffer already existed.
-
-The library where FACE is defined is searched for in
-`find-function-source-path', if non-nil, otherwise in `load-path'.
-See also `find-function-recenter-line' and `find-function-after-hook'."
-  (interactive (list (ergoemacs-component-at-point)))
-  (ergoemacs-component-find-1 component 'ergoemacs-component 
'switch-to-buffer))
-
-
-
-(defun ergoemacs-component-at-point (&optional theme-instead)
-  "Get the `ergoemacs-component' defined at or before point.
-
-When THEME-INSTEAD is non-nil, return the theme defined at that
-point instead.
-
-Return 0 if there is no such symbol.  Based on
-`variable-at-point'."
-  (let ((hash-table (or (and theme-instead ergoemacs-theme-hash)
-                        ergoemacs-component-hash)))
-    (with-syntax-table emacs-lisp-mode-syntax-table
-      (or (condition-case ()
-              (save-excursion
-                (skip-chars-forward "'")
-                (or (not (zerop (skip-syntax-backward "_w")))
-                    (eq (char-syntax (following-char)) ?w)
-                    (eq (char-syntax (following-char)) ?_)
-                    (forward-sexp -1))
-                (skip-chars-forward "'")
-                (let ((obj (read (current-buffer))))
-                  (and (symbolp obj)
-                       (ergoemacs-gethash (symbol-name obj) hash-table) obj)))
-            (error nil))
-          (let* ((str (find-tag-default))
-                 (sym (if str (intern str))))
-            (if (and sym (ergoemacs-gethash (symbol-name sym) hash-table))
-                sym
-              (save-match-data
-                (when (and str (string-match "\\`\\W*\\(.*?\\)\\W*\\'" str))
-                  (setq sym (intern (match-string 1 str)))
-                  (and (ergoemacs-gethash (symbol-name sym) hash-table) 
sym)))))
-          0))))
-
-(defun ergoemacs-component--prompt (&optional theme-instead)
-  "Prompt for component or theme (when THEME-INSTEAD is non-nil)."
-  (let ((c (or (and (eq theme-instead :layout) ergoemacs-keyboard-layout)
-               (ergoemacs-component-at-point theme-instead)))
-        (enable-recursive-minibuffers t)
-        val)
-    (setq val (completing-read (if (or (symbolp c) (stringp c))
-                                   (format
-                                    "Describe ergoemacs %s (default %s): "
-                                    (or (and (eq theme-instead :layout) 
"layout")
-                                        (and theme-instead "theme") 
"component")
-                                    c)
-                                 (format
-                                  "Describe ergoemacs %s: "
-                                  (or (and (eq theme-instead :layout) "layout")
-                                      (and theme-instead "theme") 
"component")))
-                               (or (and (eq theme-instead :layout) 
(ergoemacs-layouts--list))
-                                   (and theme-instead ergoemacs-theme-hash)
-                                   ergoemacs-component-hash)
-                               nil
-                               ;; (lambda (vv)
-                               ;;   (or (get vv 'variable-documentation)
-                               ;;       (and (boundp vv) (not (keywordp vv)))))
-                               t nil nil
-                               (format "%s" c)))
-    (list (or (and (equal val "") (format "%s" c)) val))))
-
-(defun ergoemacs-component-cached-p (component)
-  "Determine if COMPONENT is cached instead of loaded."
-  (let* ((component (and component
-                         (or (and (stringp component) component)
-                             (and (symbolp component) (symbol-name 
component)))))
-         (comp (ergoemacs-component-struct--lookup-hash (or component "")))
-         (plist (ergoemacs-component-struct-plist comp))
-         (file (plist-get plist :file))
-         (el-file (and file (concat (file-name-sans-extension file) ".el")))
-         (elc-file (and file (concat (file-name-sans-extension file) ".elc"))))
-    (when file
-      (catch 'loaded
-       (dolist (load load-history)
-         (when (or (string= elc-file (car load))
-                   (string= el-file (car load)))
-           (throw 'loaded nil))) t))))
-
-(defun ergoemacs-component-describe (component)
-  "Display the full documentation of COMPONENT (a symbol or string)."
-  (interactive (ergoemacs-component--prompt))
-  (let* ((component (and component
-                         (or (and (stringp component) component)
-                             (and (symbolp component) (symbol-name 
component)))))
-         (comp (ergoemacs-component-struct--lookup-hash (or component "")))
-         (plist (ergoemacs-component-struct-plist comp))
-         (file (plist-get plist :file))
-         (el-file (and file (concat (file-name-sans-extension file) ".el")))
-         tmp vers
-         lst)
-    (if (not comp)
-        (message "You did not specify a valid ergoemacs component %s" 
component)
-      (help-setup-xref (list #'ergoemacs-component-describe (or component ""))
-                       (called-interactively-p 'interactive))
-      (with-help-window (help-buffer)
-        (with-current-buffer standard-output
-          (insert (or component ""))
-          ;; Use " is " instead of a colon so that
-          ;; it is easier to get out the function name using forward-sexp.
-          (insert " is an `ergoemacs-mode' component")
-          (when (and el-file (file-readable-p el-file))
-            (insert " defined in `")
-            (insert (file-name-nondirectory el-file))
-            (when (looking-back "`\\(.*\\)" nil)
-              (help-xref-button 1 'ergoemacs-component-def component))
-            (insert "'."))
-          (insert "\n\n")
-          (insert "Documentation:\n")
-          (insert (plist-get plist :description))
-          (insert "\n\n")
-          (insert (format "Cached instead of loaded: %s\n" (or (and 
(ergoemacs-component-cached-p component) "Yes") "No")))
-
-          (insert "\nKnown component properties:\n")
-          (dolist (prop ergoemacs-theme-component-properties)
-            (when (setq tmp (plist-get plist prop))
-              (insert (format "  %s -- %s\n" prop tmp))))
-          (insert "\n")
-          (insert (format "Plist: %s\n" plist))
-          
-          (insert (format "Base Layout: %s\n" 
(ergoemacs-component-struct-layout comp)))
-          (when (looking-back ": \\(.*\\)\n" nil)
-            (help-xref-button 1 'ergoemacs-layout-help (match-string 1)))
-          (insert (format "Relative To: %s\n" 
(ergoemacs-component-struct-relative-to comp)))
-          (when (looking-back ": \\(.*\\)\n" nil)
-            (help-xref-button 1 'ergoemacs-layout-help (match-string 1)))
-          (insert (format "Variable Modifiers: %s\n" 
(ergoemacs-component-struct-variable-modifiers comp)))
-          (insert (format "Variable Prefixes: %s\n"
-                          (mapconcat
-                           (lambda(x) (ergoemacs-key-description x))
-                           (ergoemacs-component-struct-variable-prefixes comp) 
", ")))
-
-          (when (setq tmp (ergoemacs-component-struct-unbind comp))
-            (insert (format "Unbound keys: %s\n"
-                            (mapconcat
-                             (lambda(x) (ergoemacs-key-description x)) tmp ", 
"))))
-
-          (when (setq tmp (ergoemacs-component-struct-undefined comp))
-            (insert (format "Masked emacs keys: %s\n"
-                            (mapconcat
-                             (lambda(x) (ergoemacs-key-description x)) tmp ", 
"))))
-
-          ;; FIXME: Describe major-mode / minor-mode differences
-          
-          ;; FIXME: Describe what keys are deferred, and what they would
-          ;; possibly bind to...
-
-          (if (not (setq vers (ergoemacs-component-struct-versions comp)))
-              (setq lst `(("Specified Keymap" ,(ergoemacs-component-struct-map 
comp))
-                          (,(format "Translated Keymap (%s)" 
ergoemacs-keyboard-layout) ,(ergoemacs-component-struct--get comp 
ergoemacs-keyboard-layout))))
-            (insert (format "Versions: %s, %s\n" ergoemacs-mode-version
-                            (mapconcat
-                             (lambda(x) x) vers ", ")))
-            
-            (setq lst `((,(format "Specified Keymap (%s)" (or 
(ergoemacs-theme--get-version) ergoemacs-mode-version))
-                         ,(ergoemacs-component-struct-map comp))
-                        ,@(mapcar
-                           (lambda(ver)
-                             (unless (string= ver 
(ergoemacs-theme--get-version))
-                               ;; (ergoemacs-component-struct--get 
(ergoemacs-component-struct--lookup-hash 'search  "5.7.5"))
-                               `(,(format "Specified keymap for Version %s" 
ver)
-                                 ,(ergoemacs-component-struct-map 
(ergoemacs-component-struct--lookup-hash component ver)))))
-                           vers)
-                        (,(format "Translated Keymap (%s; %s)" 
ergoemacs-keyboard-layout (or (ergoemacs-theme--get-version) 
ergoemacs-mode-version))
-                         ,(ergoemacs-component-struct--get comp 
ergoemacs-keyboard-layout))
-                        ,@(mapcar
-                           (lambda(ver)
-                             (unless (string= ver 
(ergoemacs-theme--get-version))
-                               `(,(format "Translated keymap for Version %s" 
ver)
-                                 ,(ergoemacs-component-struct--get 
(ergoemacs-component-struct--lookup-hash component ver) 
ergoemacs-keyboard-layout))))
-                           vers)
-                        )))
-          
-          (dolist (elt lst)
-            (unless (or (not elt) (ergoemacs (nth 1 elt) :empty-p))
-              (insert "\n")
-              (insert (nth 0 elt))
-              (insert ":\n")
-              (insert (make-string 78 ?-))
-              (ergoemacs-key-description--keymap (nth 1 elt) t)
-              (insert "\n")))
-          (with-current-buffer standard-output
-            ;; Return the text we displayed.
-            (buffer-string)))))))
-
-(defalias 'describe-ergoemacs-component 'ergoemacs-component-describe)
-
-(defun ergoemacs-component--diminish-on (plist &optional dim type)
-  "Apply `diminish' to PLIST for theme component.
-
-The :dimininish tag can be of the form:
-
-- t -- Removes the package name (PLIST :package-name) from the
-  minor mode display list.
-
-- minor-mode symbol -- Removes the symbol from the minor mode
-  display list.
-
-- string -- Replace the minor mode symbol with a string.
-
-- (string1 string2) -- Unicode (string1) and terminal (string2)
-  displays.  The display is determined by
-  `ergoemacs-key-description--unicode-char'.
-
-- (minor-mode-symbol) -- Suppress minor mode symbol
-
-- (minor-mode-symbol string) -- Replace minor mode symbol
-  modeline indicator with string
-
-- (minor-mode-symbol string1 string2) -- Replace
-  minor-mode-symbol indicator with unicode (string1) or
-  terminal (string2) indicators.  The display is determined by
-  `ergoemacs-key-description--unicode-char'.
-
-- List of minor mode symbols, or list specifications that include
-  the minor- mode symbol, so that multiple minor modes may be
-   processed by a single :diminish specifciation.
-
-DIM is the replacement for the PLIST :diminish, this is used in
-recursive calls to `ergoemacs-component--diminish-on' to process
-lists.  It can also be the symbol name of the package.
-uu
-When TYPE is non-nil, the function turns off the diminish
-modifications with `diminish-undo'"
-  (ignore-errors (ergoemacs-component-struct--ensure 'diminish))
-  (require 'diminish nil t)
-  (if (not (featurep 'diminish))
-      (message "Error installing diminish package.")
-    (let ((diminish-symbol (or (plist-get plist :package-name)
-                               (plist-get plist :name)
-                               plist))
-          (dim (or dim (plist-get plist :diminish))))
-      (when (and diminish-symbol (stringp diminish-symbol))
-        (setq diminish-symbol (intern diminish-symbol)))
-
-      (cond
-       ((not dim))
-       ;; :diminish t
-       ((eq t dim)
-        (cond
-         (type (diminish-undo diminish-symbol))
-         ((ignore-errors (and (commandp diminish-symbol t) (not 
(ergoemacs-autoloadp diminish-symbol))
-                              (diminish diminish-symbol)))
-          )
-         (t (eval-after-load diminish-symbol
-              `(diminish ',diminish-symbol)))))
-       ;; :diminish mode
-       ((symbolp dim)
-        (cond
-         (type (diminish-undo dim))
-         ((ignore-errors (and (commandp diminish-symbol t) (not 
(ergoemacs-autoloadp diminish-symbol))
-                              (diminish dim))))
-         (t (eval-after-load diminish-symbol
-              `(diminish ',dim)))))
-
-       ;; :diminish " g"
-       ((stringp dim)
-        (cond
-         (type (diminish-undo diminish-symbol))
-         ((ignore-errors (and (commandp diminish-symbol t) (not 
(ergoemacs-autoloadp diminish-symbol))
-                              (diminish diminish-symbol dim))))
-         (t (eval-after-load diminish-symbol
-              `(diminish ',diminish-symbol ,dim)))))
-       ((and (consp dim)
-             (= 1 (length dim))
-             (symbolp (nth 0 dim)))
-        (cond
-         (type (diminish-undo (nth 0 dim)))
-         ((ignore-errors (and (commandp (nth 0 dim) t) (not 
(ergoemacs-autoloadp (nth 0 dim)))
-                              (diminish (nth 0 dim) dim))))
-         (t (eval-after-load diminish-symbol
-              `(diminish ',(nth 0 dim))))))
-       
-       ;; :diminish (" " " g")
-       ((and (consp dim)
-             (= 2 (length dim))
-             (stringp (nth 0 dim))
-             (stringp (nth 1 dim)))
-        (cond
-         (type (diminish-undo diminish-symbol))
-         ((ignore-errors (and (commandp diminish-symbol t) (not 
(ergoemacs-autoloadp diminish-symbol))
-                              (diminish diminish-symbol (ergoemacs :unicode 
(nth 0 dim) (nth 1 dim))))))
-         (t (eval-after-load diminish-symbol
-              `(ignore-errors
-                 (diminish ',diminish-symbol
-                           ,(ergoemacs :unicode (nth 0 dim) (nth 1 dim))))))))
-       ;;:diminish (" 🌈" " ⓡ" " r")
-       ((and (consp dim)
-             (= 3 (length dim))
-             (stringp (nth 0 dim))
-             (stringp (nth 1 dim))
-             (stringp (nth 3 dim)))
-        (cond
-         (type (diminish-undo diminish-symbol))
-         ((ignore-errors (and (commandp diminish-symbol t) (not 
(ergoemacs-autoloadp diminish-symbol))
-                              (diminish diminish-symbol (ergoemacs :unicode 
(nth 0 dim) (ergoemacs :unicode (nth 1 dim) (nth 2 dim)))))))
-         (t (eval-after-load diminish-symbol
-              `(ignore-errors
-                 (diminish ',diminish-symbol
-                           ,(ergoemacs :unicode (nth 0 dim) (ergoemacs 
:unicode (nth 1 dim) (nth 2 dim)))))))))
-       ;; :diminish (mode " " " g")
-       ((and (consp dim)
-             (= 3 (length dim))
-             (symbolp (nth 0 dim))
-             (stringp (nth 1 dim))
-             (stringp (nth 2 dim)))
-        (cond
-         (type (diminish-undo (nth 0 dim)))
-         ((ignore-errors (and (commandp (nth 0 dim) t) (not 
(ergoemacs-autoloadp (nth 0 dim)))
-                              (diminish (nth 0 dim) (ergoemacs :unicode (nth 1 
dim) (nth 2 dim))))))
-         (t (eval-after-load diminish-symbol
-              `(ignore-errors
-                 (diminish ',(nth 0 dim)
-                           ,(ergoemacs :unicode (nth 1 dim) (nth 2 dim))))))))
-       ;; :diminish (rainbow-mode " 🌈" " ⓡ" " r")
-       ((and (consp dim)
-             (= 4 (length dim))
-             (symbolp (nth 0 dim))
-             (stringp (nth 1 dim))
-             (stringp (nth 2 dim))
-             (stringp (nth 3 dim)))
-        (cond
-         (type (diminish-undo (nth 0 dim)))
-         ((ignore-errors (and (commandp (nth 0 dim) t) (not 
(ergoemacs-autoloadp (nth 0 dim)))
-                              (diminish (nth 0 dim) (ergoemacs :unicode (nth 1 
dim) (ergoemacs :unicode (nth 2 dim) (nth 3 dim)))))))
-         (t (eval-after-load diminish-symbol
-              `(ignore-errors
-                 (diminish ',(nth 0 dim)
-                           ,(ergoemacs :unicode (nth 1 dim) (ergoemacs 
:unicode (nth 2 dim) (nth 3 dim)))))))))
-       ;; :diminish (mode " ")
-       ((and (consp dim)
-             (= 2 (length dim))
-             (symbolp (nth 0 dim))
-             (stringp (nth 1 dim)))
-        (cond
-         (type (diminish-undo (nth 0 dim)))
-         ((ignore-errors (and (commandp (nth 0 dim) t) (not 
(ergoemacs-autoloadp (nth 0 dim)))
-                              (diminish (nth 0 dim) (nth 1 dim)))))
-         (t (eval-after-load diminish-symbol
-              `(diminish ',(nth 0 dim) ,(nth 1 dim))))))
-       ((consp dim)
-        (dolist (elt dim)
-          (ergoemacs-component--diminish-on plist elt type)))))))
-
-(defun ergoemacs-component--diminish-off (plist)
-  "Remove `diminish' top PLIST for theme component.
-Wrapper for `ergoemacs-component--diminish-on'."
-  (ergoemacs-component--diminish-on plist nil t))
-
-(provide 'ergoemacs-component)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; ergoemacs-component.el ends here
-;; Local Variables:
-;; coding: utf-8-emacs
-;; End:
diff --git a/ergoemacs-debug.el b/ergoemacs-debug.el
index 83c9062..e2949d2 100644
--- a/ergoemacs-debug.el
+++ b/ergoemacs-debug.el
@@ -28,9 +28,7 @@
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ;; 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 
-;;; Code:
-;; (require 'guide-key nil t)
+
 (require 'cl-lib)
 
 (eval-when-compile
diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el
index 258c8be..f50662e 100644
--- a/ergoemacs-functions.el
+++ b/ergoemacs-functions.el
@@ -38,12 +38,10 @@
 (defvar apropos-do-all)
 (defvar cua--last-killed-rectangle)
 (defvar dirtrack-list)
-(defvar ergoemacs-command-loop--modal-stack)
 (defvar ergoemacs-dir)
 (defvar ergoemacs-keyboard-layout)
 (defvar ergoemacs-mode)
 (defvar ergoemacs-single-command-keys)
-(defvar ergoemacs-theme)
 (defvar helm-buffer)
 (defvar helm-ff-default-directory)
 (defvar helm-ff-last-expanded)
@@ -63,11 +61,9 @@
 (declare-function cua-set-rectangle-mark "cua-rect")
 (declare-function dired-get-marked-files "dired")
 
-(declare-function ergoemacs-map-- "ergoemacs-map")
 (declare-function ergoemacs-mode "ergoemacs-mode")
 (declare-function ergoemacs-map-properties--original 
"ergoemacs-map-properties")
 
-(declare-function ergoemacs-command-loop--modal-pop "ergoemacs-command-loop")
 (declare-function ergoemacs-theme-describe "ergoemacs-theme-engine")
 (declare-function ergoemacs-key-description "ergoemacs-key-description")
 
@@ -94,6 +90,12 @@
 
 (declare-function undo-tree-mode "undo-tree")
 
+(declare-function flyspell-auto-correct-previous-word "fylspell")
+(declare-function w32-shell-execute "compat")
+(declare-function w32-long-file-name "compat")
+(declare-function term-paste "term")
+(declare-function calc-yank "calc-yank")
+
 (defcustom ergoemacs-isearch-backward-char-to-edit nil
   "Backward char will edit isearch."
   :type 'boolean
@@ -104,20 +106,15 @@
   '(delete-backward-char delete-char kill-word backward-kill-word)
   "Defines deletion functions that ergoemacs is aware of.")
 
-(defcustom ergoemacs-ctl-c-or-ctl-x-delay 0.2
-  "Delay before sending Cut or Copy.
-This is applied when using Ctrl+c and Ctrl+x."
-  :type '(choice (number :tag "Inhibit delay")
-                 (const :tag "No delay" nil))
-  :group 'ergoemacs-mode)
-
-(defcustom ergoemacs-handle-ctl-c-or-ctl-x 'both
-  "Type of Copy and Paste handling for `ergoemacs-mode'."
-  :type '(choice
-          (const :tag "C-c/C-x only copy/cut" only-copy-cut)
-          (const :tag "C-c/C-x only Emacs C-c and C-x" only-C-c-and-C-x)
-          (const :tag "C-c/C-x copy/paste when region active, Emacs C-c/C-x 
otherwise." both))
-  :group 'ergoemacs-mode)
+;;;###autoload
+(defun ergoemacs-undo ()
+  "Run `undo'.  If in calc-mode, run `calc-undo'"
+  (interactive)
+  (if (eq major-mode 'calc-mode)
+      (calc-undo 1)
+    (undo)
+    )
+  )
 
 (defvar ergoemacs-revert-buffer 0)
 (defun ergoemacs-revert-buffer ()
@@ -147,7 +144,7 @@ The backup is determined by `find-backup-file-name'"
       (call-interactively bind))
      ((and (not (eq last-command 'ergoemacs-revert-buffer))
            (buffer-modified-p (current-buffer)))
-      (ergoemacs :remap 'revert-buffer)
+      (revert-buffer)
       (goto-char opt))
      ((and backup-buffer
            (or (and (not (eq last-command 'ergoemacs-revert-buffer))
@@ -282,10 +279,6 @@ The PROCESS is the process where the clean environment is 
run."
         (ergoemacs-load (or ergoemacs-run-clean
                             " --load=\"ergoemacs-mode\" 
--load=\"ergoemacs-test\"  --eval \"(progn (require 'elp) (setq debug-on-error 
t) (elp-instrument-package (symbol-name 'ergoemacs-)) (ergoemacs-mode 1) 
(run-with-idle-timer 0.1 nil 'elp-results))\""))
         cmd process rm-batch)
-    (when ergoemacs-keyboard-layout
-      (setenv "ERGOEMACS_KEYBOARD_LAYOUT" ergoemacs-keyboard-layout))
-    (when ergoemacs-theme
-      (setenv "ERGOEMACS_THEME" ergoemacs-theme))
     (cond
      ((with-current-buffer (get-buffer-create "*ergoemacs-clean*")
         (not ergoemacs-terminal))
@@ -375,15 +368,6 @@ If TERMINAL is non-nil, run the terminal version"
   (end-of-line)
   (newline-and-indent))
 
-(defun ergoemacs-print-buffer-confirm ()
-  "Print current buffer, but ask for confirmation first.
-If `pr-interface' is available, use that function instead."
-  (interactive)
-  (if (fboundp 'pr-interface)
-      (call-interactively 'pr-interface)
-    (when (y-or-n-p "Print current buffer? ")
-      (print-buffer))))
-
 (defun ergoemacs-call-keyword-completion ()
   "Call the command that has keyboard shortcut M-TAB."
   (interactive)
@@ -431,7 +415,7 @@ Pass prefix ARG to the respective copy functions."
     (kill-ring-save
      (save-excursion
        (let ((pt (point)))
-         (ergoemacs :remap 'move-beginning-of-line)
+         (call-interactively 'move-beginning-of-line)
          (when (= pt (point))
            (call-interactively 'move-beginning-of-line)))
        (when (not (bolp))
@@ -439,7 +423,7 @@ Pass prefix ARG to the respective copy functions."
        (point))
      (save-excursion
        (let ((pt (point)))
-         (ergoemacs :remap 'move-end-of-line)
+         (call-interactively 'move-end-of-line)
          (when (= pt (point))
            (call-interactively 'move-end-of-line)))
        (re-search-forward "\\=\n" nil t) ;; Include newline
@@ -476,19 +460,41 @@ The ARG is passed to the respective function for any 
prefixes."
     (cua-cut-region arg)
     (deactivate-mark))
    ((region-active-p) ;; In case something else is bound to C-w.
-    (ergoemacs :remap 'kill-region)
+    (call-interactively 'kill-region)
     (deactivate-mark))
    (t
     (ignore-errors
       (let ((pt (point)))
-        (ergoemacs :remap 'move-beginning-of-line)
+        (call-interactively 'move-beginning-of-line)
         (when (= pt (point))
           (call-interactively 'move-beginning-of-line))))
     (when (not (bolp))
       (beginning-of-line))
     ;; Keep prefix args.
     (let ((kill-whole-line t))
-      (ergoemacs :remap 'kill-line)))))
+      (kill-line)))))
+
+;; When editing a search in isearch, it uses the
+;; minibuffer-local-isearch-map keymap, which get overridden by the
+;; global emulation keymap.  So we make our own version of
+;; isearch-forward and isearch-backward to handle that.
+;;;###autoload
+(defun ergoemacs-isearch-forward ()
+  (interactive)
+  (if (eq (current-local-map) minibuffer-local-isearch-map)
+      (isearch-forward-exit-minibuffer)
+    (isearch-forward)
+    )
+  )
+
+;;;###autoload
+(defun ergoemacs-isearch-backward ()
+  (interactive)
+  (if (eq (current-local-map) minibuffer-local-isearch-map)
+      (isearch-reverse-exit-minibuffer)
+    (isearch-backward)
+    )
+  )
 
 ;;; CURSOR MOVEMENT
 (defun ergoemacs-forward-open-bracket (&optional number)
@@ -657,22 +663,12 @@ This behavior can be turned off with
   (interactive)
   (let ((ma (region-active-p)))
     (if current-prefix-arg
-        (let ((pt (point)))
-          ;; (setq prefix-arg current-prefix-arg)
-          (ergoemacs :remap 'end-of-buffer)
-          (when (= pt (point))
-            (call-interactively 'end-of-buffer)))
+        (call-interactively 'end-of-buffer)
       (cond
        ((and ergoemacs-repeatable-beginning-or-end-of-buffer (bobp))
-        (let ((pt (point)))
-          (ergoemacs :remap 'end-of-buffer)
-          (when (= pt (point))
-            (call-interactively 'end-of-buffer))))
+        (call-interactively 'end-of-buffer))
        (t
-        (let ((pt (point)))
-          (ergoemacs :remap 'beginning-of-buffer)
-          (when (= pt (point))
-            (call-interactively 'beginning-of-buffer))))))
+        (call-interactively 'beginning-of-buffer))))
     (when (and (not ma) (region-active-p))
       (deactivate-mark))))
 
@@ -694,24 +690,12 @@ This will not honor `shift-select-mode'."
   (interactive)
   (let ((ma (region-active-p)))
     (if current-prefix-arg
-        (let ((pt (point)))
-          ;; (setq prefix-arg current-prefix-arg)
-          (ergoemacs :remap 'end-of-buffer)
-          (when (= pt (point))
-            (call-interactively 'end-of-buffer)))
+        (call-interactively 'end-of-buffer)
       (cond
        ((and ergoemacs-repeatable-beginning-or-end-of-buffer (eobp))
-        (let ((pt (point)))
-          (ergoemacs :remap
-                     'beginning-of-buffer)
-          (when (= pt (point))
-            (call-interactively 'beginning-of-buffer))))
+        (call-interactively 'beginning-of-buffer))
        (t
-        (let ((pt (point)))
-          (ergoemacs :remap
-                     'end-of-buffer)
-          (when (= pt (point))
-            (call-interactively 'end-of-buffer))))))
+        (call-interactively 'end-of-buffer))))
     (when (and (not ma) (region-active-p))
       (deactivate-mark))))
 
@@ -815,7 +799,7 @@ the prefix arguments of `beginning-of-buffer',
                (equal current-prefix-arg '(4)))
            (ignore-errors
              (setq this-command 'scroll-other-window-down)
-             (ergoemacs :remap 'scroll-other-window-down)
+             (scroll-other-window-down)
              t)) nil
     (if (and ergoemacs-beginning-or-end-of-line-and-what
              (or (not ergoemacs-use-beginning-or-end-of-line-only)
@@ -826,8 +810,7 @@ the prefix arguments of `beginning-of-buffer',
           (cond
            ((eq ergoemacs-beginning-or-end-of-line-and-what 'buffer)
             (let ((pt (point)))
-              (ergoemacs :remap
-                         'beginning-of-buffer)
+              (beginning-of-buffer)
               (when (= pt (point))
                 (call-interactively 'beginning-of-buffer)))
             (setq this-command 'beginning-of-buffer))
@@ -836,8 +819,7 @@ the prefix arguments of `beginning-of-buffer',
             (setq this-command 'ergoemacs-backward-block))
            ((eq ergoemacs-beginning-or-end-of-line-and-what 'page)
             (let ((pt (point)))
-              (ergoemacs :remap
-                         'scroll-down-command)
+              (scroll-down-command)
               (when (= pt (point))
                 (call-interactively 'scroll-down-command)))
             (setq this-command 'scroll-down-command)))
@@ -852,16 +834,14 @@ the prefix arguments of `beginning-of-buffer',
           ;; (setq prefix-arg nil)
           (setq current-prefix-arg nil)
           (let ((pt (point)))
-            (ergoemacs :remap
-                       'move-beginning-of-line)
+            (call-interactively 'move-beginning-of-line)
             (when (= pt (point))
               (call-interactively 'move-beginning-of-line)))
           (push (point) pts)
           (when (and (not (bolp)) (not (bobp)))
             (backward-char 1)
             (let ((pt (point)))
-              (ergoemacs :remap
-                         'move-beginning-of-line)
+              (call-interactively 'move-beginning-of-line)
               (when (= pt (point))
                 (call-interactively 'move-beginning-of-line)))
             (push (point) pts)))
@@ -885,8 +865,7 @@ the prefix arguments of `beginning-of-buffer',
         (cond
          ((not pts)
           (let ((pt (point)))
-            (ergoemacs :remap
-                       'move-beginning-of-line)
+            (call-interactively 'move-beginning-of-line)
             (when (= pt (point))
               (call-interactively 'move-beginning-of-line))))
          (t
@@ -964,7 +943,7 @@ the prefix arguments of `end-of-buffer',
                (equal current-prefix-arg '(4)))
            (ignore-errors
              (setq this-command 'scroll-other-window)
-             (ergoemacs :remap 'scroll-other-window)
+             (scroll-other-window)
              t)) nil
     (if (and ergoemacs-beginning-or-end-of-line-and-what
              (or (not ergoemacs-use-beginning-or-end-of-line-only)
@@ -981,8 +960,7 @@ the prefix arguments of `end-of-buffer',
           (cond
            ((eq ergoemacs-beginning-or-end-of-line-and-what 'buffer)
             (let ((pt (point)))
-              (ergoemacs :remap
-                         'end-of-buffer)
+              (end-of-buffer)
               (when (= pt (point))
                 (call-interactively 'end-of-buffer)))
             (setq this-command 'end-of-buffer))
@@ -991,8 +969,7 @@ the prefix arguments of `end-of-buffer',
             (setq this-command 'ergoemacs-forward-block))
            ((eq ergoemacs-beginning-or-end-of-line-and-what 'page)
             (let ((pt (point)))
-              (ergoemacs :remap
-                         'scroll-up-command)
+              (scroll-up-command)
               (when (= pt (point))
                 (call-interactively 'scroll-up-command)))
             (setq this-command 'scroll-up-command)
@@ -1008,8 +985,7 @@ the prefix arguments of `end-of-buffer',
           (push (point) pts))
         (save-excursion
           (let ((pt (point)))
-            (ergoemacs :remap
-                       'move-end-of-line)
+            (call-interactively 'move-end-of-line)
             (when (= pt (point))
               (call-interactively 'move-end-of-line)))
           (push (point) pts)
@@ -1018,8 +994,7 @@ the prefix arguments of `end-of-buffer',
           (when (and (not (eolp)) (not (eobp)))
             (forward-char 1)
             (let ((pt (point)))
-              (ergoemacs :remap
-                         'move-end-of-line)
+              (call-interactively 'move-end-of-line)
               (when (= pt (point))
                 (call-interactively 'move-end-of-line)))
             (push (point) pts)))
@@ -1040,8 +1015,7 @@ the prefix arguments of `end-of-buffer',
         (cond
          ((not pts)
           (let ((pt (point)))
-            (ergoemacs :remap
-                       'move-end-of-line)
+            (call-interactively 'move-end-of-line)
             (when (= pt (point))
               (call-interactively 'move-end-of-line)))
           (setq this-command 'move-end-of-line))
@@ -1122,26 +1096,18 @@ Subsequent calls expands the selection to larger 
semantic unit."
 
 (defun ergoemacs-kill-line-backward (&optional number)
   "Kill text between the beginning of the line to the cursor position.
-If there's no text, delete the previous line ending.
-Use `ergoemacs-remap' in case kill line was remapped."
+If there's no text, delete the previous line ending."
   (interactive "p")
   (if (and (= number 1) (looking-back "\n" nil))
       (delete-char -1)
     (setq current-prefix-arg (- 1 number))
-    (ergoemacs :remap 'kill-line)))
-
-(defun ergoemacs-move-cursor-next-pane ()
-  "Move cursor to the next pane.
-Use `ergoemacs-remap' for maximum mode compatibility."
-  (interactive)
-  (ergoemacs :remap 'other-window))
+    (kill-line)))
 
 (defun ergoemacs-move-cursor-previous-pane (&optional number)
-  "Move cursor to the previous pane.
-Use `ergoemacs-shortcut-interal' for maximum mode compatibility."
+  "Move cursor to the previous pane."
   (interactive "p")
   (setq current-prefix-arg (if number (- 0 number) -1))
-  (ergoemacs :remap 'other-window))
+  (call-interactively 'other-window))
 
 (defun ergoemacs-unfill-paragraph ()
   "Replace newline char in current paragraph by space.
@@ -1150,7 +1116,7 @@ See also: `ergoemacs-compact-uncompact-block'"
   (interactive)
   (let ((fill-column 90002000))
     (setq current-prefix-arg nil);; Fill paragraph is bound it M-q.
-    (ergoemacs :remap 'fill-paragraph)))
+    (fill-paragraph)))
 
 (defun ergoemacs-unfill-region (start end)
   "Replace newline char in region by space.
@@ -1166,25 +1132,26 @@ This command is similar to a toggle of `fill-paragraph'.
 When there is a text selection, act on the region."
   (interactive)
   ;; This command symbol has a property “'stateIsCompact-p”.
-  (let (current-state-is-compact (big-fill-column-val 4333999) 
(deactivate-mark nil))
-    
-    (save-excursion
-      ;; Determine whether the text is currently compact.
-      (setq current-state-is-compact
-            (if (eq last-command this-command)
-                (get this-command 'state-is-compact-p)
-              (if (> (- (line-end-position) (line-beginning-position)) 
fill-column) t nil) ) )
-      
-      (if (region-active-p)
-          (if current-state-is-compact
-              (fill-region (region-beginning) (region-end))
-            (let ((fill-column big-fill-column-val))
-              (fill-region (region-beginning) (region-end))) )
+  (let (current-state-is-compact
+        (big-fill-column-val 4333999)
+        (deactivate-mark nil))
+    (setq current-state-is-compact
+          (if (> (- (line-end-position) (line-beginning-position)) fill-column)
+              t
+            nil
+            )
+          )
+    (if (region-active-p)
         (if current-state-is-compact
-            (ergoemacs :remap 'fill-paragraph)
+            (fill-region (region-beginning) (region-end))
           (let ((fill-column big-fill-column-val))
-            (ergoemacs :remap 'fill-paragraph))))
-      (put this-command 'stateIsCompact-p (if current-state-is-compact nil 
t)))))
+            (fill-region (region-beginning) (region-end))) )
+      (if current-state-is-compact
+          (fill-paragraph)
+        (let ((fill-column big-fill-column-val))
+          (fill-paragraph))))
+    )
+  )
 
 (defun ergoemacs-top-join-line ()
   "Join the current line with the line beneath it."
@@ -1396,7 +1363,7 @@ the last misspelled word with
         (setq p1 (car bds) p2 (cdr bds)))))
     (if (not (and p1 p2))
         (when ergoemacs-toggle-letter-case-and-spell
-          (ergoemacs :remap 'flyspell-auto-correct-previous-word))
+          (flyspell-auto-correct-previous-word))
       (when (not (eq last-command this-command))
         (save-excursion
           (goto-char p1)
@@ -1556,10 +1523,18 @@ Emacs buffers are those whose name starts with *."
     (funcall (and initial-major-mode))
     (setq buffer-offer-save t)))
 
+(defun ergoemacs-make-frame-command ()
+  "Create a new frame.  This is a thin wrapper so that menus will
+show the ergoemacs key binding rather than the traditional
+binding."
+  (interactive)
+  (make-frame-command)
+  )
+
 (defun ergoemacs-delete-frame ()
   "Deletes frame or closes emacs (with prompt)."
   (interactive)
-  (unless (ignore-errors (ergoemacs :remap 'delete-frame))
+  (unless (ignore-errors (delete-frame))
     (when (yes-or-no-p "Do you wish to Close Emacs? ")
       ;; Bound to C-x C-c
       (save-buffers-kill-terminal))))
@@ -1636,26 +1611,6 @@ by `ergoemacs-maximum-number-of-files-to-open'.
     (when (> (length ergoemacs-recently-closed-buffers) 
ergoemacs-recently-closed-buffers-max)
       (setq ergoemacs-recently-closed-buffers (butlast 
ergoemacs-recently-closed-buffers 1)))))
 
-(defun ergoemacs-redo ()
-  "Redo using either `redo' or `undo-tree-redo'.
-Installs `undo-tree' if not present."
-  (interactive "*")
-  (require 'undo-tree nil t)
-  (cond
-   ((fboundp 'redo)
-    (call-interactively 'redo))
-   ((fboundp 'undo-tree-redo)
-    (call-interactively 'undo-tree-redo))
-   (t
-    (if (not (yes-or-no-p "Redo command not found, install undo-tree for 
redo?"))
-        (error "Redo not found, need undo-tree or redo commands present.")
-      (package-refresh-contents) ;;available in gnu elpa.
-      (package-initialize)
-      (package-install 'undo-tree)
-      (require 'undo-tree)
-      (undo-tree-mode 1)
-      (call-interactively 'undo-tree-redo)))))
-
 (defun ergoemacs-keyboard-quit ()
   "Quit the current command/process.
 Similar to `keyboard-quit', with the following changes:
@@ -1665,9 +1620,6 @@ Similar to `keyboard-quit', with the following changes:
 • When a region is active, (see `region-active-p') deactivate the
   region with the function `deactivate-mark'.
 
-• When `ergoemacs-mode' is in a modal command mode, exit that
-  command mode.
-
 • When \"C-g\" is bound to something other than ergoemacs /
   standard quit commands, run that command.
 
@@ -1684,8 +1636,6 @@ Similar to `keyboard-quit', with the following changes:
       (setq saved-region-selection nil)
       (let (select-active-regions)
         (deactivate-mark)))
-     (ergoemacs-command-loop--modal-stack
-      (ergoemacs-command-loop--modal-pop))
      ((and (setq bind (key-binding [7])) ;; C-g
            (not (memq bind '(ergoemacs-keyboard-quit minibuffer-keyboard-quit 
keyboard-quit))))
       (call-interactively bind))
@@ -1799,99 +1749,6 @@ true; otherwise it is an emacs buffer."
   (interactive)
   (text-scale-increase 0))
 
-;;; helm-mode functions
-
-;;; This comes from https://github.com/emacs-helm/helm/pull/327, but
-;;; was reverted so it is added back here.
-(defcustom ergoemacs-helm-ff-ido-style-backspace t
-  "Use backspace to navigate with `helm-find-files'.
-You will have to restart Emacs or reeval `helm-find-files-map'
-and `helm-read-file-map' for this to take effect."
-  :group 'ergoemacs-mode
-  :type '(choice
-          (const :tag "Do not use ido-style backspace")
-          (const :tag "Use ido-style backspace" t)))
-
-(defun ergoemacs-helm-ff-backspace ()
-  "Call backsapce or `helm-find-files-down-one-level'.
-If sitting at the end of a file directory, backspace goes up one
-level, like in `ido-find-file'. "
-  (interactive)
-  (let (backspace)
-    (looking-back "^.*" nil)
-    (cond
-     ((and ergoemacs-helm-ff-ido-style-backspace
-           (looking-back "[/\\]" nil))
-      (call-interactively
-       (key-binding (kbd "<left>"))))
-     (t
-      (setq backspace (lookup-key
-                       (current-global-map)
-                       (read-kbd-macro "DEL")))
-      (call-interactively backspace)))))
-
-
-;;; This comes from https://github.com/emacs-helm/helm/issues/340
-(defcustom ergoemacs-helm-ido-style-return t
-  "Allows ido-style return in `helm-mode'"
-  :type 'boolean
-  :group 'ergoemacs-mode)
-
-(defun ergoemacs-helm-ff-expand-dir (candidate)
-  "Allows return to expand a directory like in `ido-find-file'.
-This requires `ergoemacs-mode' to be non-nil and
-`ergoemacs-helm-ido-style-return' to be non-nil."
-  (let* ((follow (and (boundp 'helm-follow-mode)
-                     (buffer-local-value
-                      'helm-follow-mode
-                      (get-buffer-create helm-buffer))))
-         (insert-in-minibuffer
-          #'(lambda (fname)
-              (with-selected-window (minibuffer-window)
-                (unless follow
-                  (delete-minibuffer-contents)
-                  (set-text-properties 0 (length fname)
-                                       nil fname)
-                  (insert fname))))))
-    (if (and ergoemacs-helm-ido-style-return ergoemacs-mode
-             (file-directory-p candidate))
-        (progn
-          (when (string= (helm-basename candidate) "..")
-            (setq helm-ff-last-expanded helm-ff-default-directory))
-          (funcall insert-in-minibuffer (file-name-as-directory
-                                         (expand-file-name candidate))))
-      (helm-exit-minibuffer))))
-
-(defun ergoemacs-helm-ff-persistent-expand-dir ()
-  "Makes `eroemacs-helm-ff-expand-dir' the default action for
-expanding helm-files."
-  (interactive)
-  (helm-attrset 'expand-dir 'ergoemacs-helm-ff-expand-dir)
-  (helm-execute-persistent-action 'expand-dir))
-
-
-(defun ergoemacs-helm-ff-dired-dir (candidate)
-  "Determines if a persistent action is called on directories.
-When `ergoemacs-mode' is enabled with
- `ergoemacs-helm-ido-style-return' non-nil then:
-- `helm-execute-persistent-action' is called on files.
-- `helm-exit-minibuffer' is called on directories.
-
-Otherwise `helm-execute-persistent-action' is called.
-"
-  (interactive)
-  (if (and ergoemacs-helm-ido-style-return ergoemacs-mode
-           (file-directory-p candidate))
-      (helm-exit-minibuffer)
-    (helm-execute-persistent-action)))
-
-(defun ergoemacs-helm-ff-execute-dired-dir ()
-  "Allow <M-return> to execute dired on directories in `helm-mode'.
-This requires `ergoemacs-mode' to be enabled with 
-`ergoemacs-helm-ido-style-return' to be non-nil."
-  (interactive)
-  (helm-attrset 'dired-dir 'ergoemacs-helm-ff-dired-dir)
-  (helm-execute-persistent-action 'dired-dir))
 
 ;; (define-key helm-find-files-map (kbd "<M-return>")
 ;;   'ergoemacs-helm-ff-execute-dired-dir)
@@ -1945,8 +1802,7 @@ initial pair in the unread command events."
         (setq last-input-event tmp)
         (setq prefix-arg current-prefix-arg)
         (setq unread-command-events (append (listify-key-sequence tmp) 
unread-command-events))
-        ;;(ergoemacs-defer-post-command-hook)
-        (ergoemacs :reset-prefix))
+        (prefix-command-preserve-state))
     (if (region-active-p)
         (let ((p1 (region-beginning))
               (p2 (region-end)))
@@ -2080,8 +1936,8 @@ When in `browse-kill-ring-mode', cycle backward through 
the key ring.
          (not (eq last-command 'yank)))
     (browse-kill-ring))
    (ergoemacs-smart-paste
-    (ergoemacs :remap 'yank))
-   (t (ergoemacs :remap 'yank-pop))))
+    (yank))
+   (t (yank-pop))))
 
 (put 'ergoemacs-paste 'delete-selection 'yank)
 ;;;###autoload
@@ -2093,10 +1949,16 @@ This is `browse-kill-ring' if `ergoemacs-smart-paste' 
equals 'browse-kill-ring a
 
 When in `browse-kill-ring-mode', cycle forward through the key ring.
 
-This does the same thing in `iseach-mode' using `isearch-yank-pop' and  
`isearch-yank-kill'
+This does the same thing in `isearch-mode' using `isearch-yank-pop' and  
`isearch-yank-kill'
+
+If in `term-mode', run `term-paste'.
 "
   (interactive)
   (cond
+   ((eq major-mode 'term-mode)
+    (term-paste))
+   ((eq major-mode 'calc-mode)
+    (calc-yank nil))
    ((and isearch-mode ergoemacs-smart-paste (eq last-command 
'isearch-yank-kill))
     (isearch-yank-pop)
     (setq this-command 'isearch-yank-pop))
@@ -2114,9 +1976,9 @@ This does the same thing in `iseach-mode' using 
`isearch-yank-pop' and  `isearch
     ;; Add unread command events another "paste"
     (setq unread-command-events (append (listify-key-sequence 
(this-single-command-keys)) unread-command-events)))
    ((and ergoemacs-smart-paste (eq last-command 'yank))
-    (ergoemacs :remap 'yank-pop))
+    (yank-pop))
    (t
-    (ergoemacs :remap 'yank))))
+    (yank))))
 
 (put 'ergoemacs-org-yank 'delete-selection 'yank)
 
@@ -2349,12 +2211,6 @@ If arg is a negative prefix, copy file path only"
   :type 'string
   :group 'ergoemacs-mode)
 
-;;; Unaccent region taken and modified from Drew Adam's unaccent.el
-
-(require 'strings nil t) ;; (no error if not found): region-description
-
-;;;;;;;;;;;;;;;;;;;;;;;;
-
 
 (defvar ergoemacs-reverse-iso-chars-alist
   '(;; Trema/umlaut (äëïöü) (ÄËÏÖÜ)
@@ -2440,8 +2296,6 @@ Guillemet -> quote, degree -> @, s-zed -> ss, upside-down 
?! -> ?!."
       (setq nbn (generate-new-buffer-name nbn))
       (rename-buffer nbn))))
 
-;; (add-hook 'dirtrack-directory-change-hook 
'ergoemacs-shell-here-directory-change-hook)
-
 (defun ergoemacs-shell-here-hook ()
   "Hook for `ergoemacs-shell-here'.
 Sends shell prompt string to process, then turns on
@@ -2467,8 +2321,6 @@ Sends shell prompt string to process, then turns on
         (shell-dirtrack-mode -1)
         (dirtrack-mode 1))))))
 
-;; (add-hook 'shell-mode-hook 'ergoemacs-shell-here-hook)
-
 (defun ergoemacs-shell-here (&optional shell-program buffer-prefix)
   "Runs/switches to a shell process in the current directory."
   (interactive)
@@ -2492,8 +2344,6 @@ Sends shell prompt string to process, then turns on
        (ergoemacs-shell-here nil "MSYS"))
     (error "Need to specify `ergoemacs-msys'.")))
 
-;; (add-hook 'eshell-post-command-hook 
'ergoemacs-shell-here-directory-change-hook)
-
 (defun ergoemacs-eshell-here ()
   "Run/switch to an `eshell' process in the current directory"
   (interactive)
@@ -2730,7 +2580,7 @@ With a prefix argument like \\[universial-argument] in an
 (defun ergoemacs-describe-current-theme ()
   "Describe the current theme."
   (interactive)
-  (ergoemacs-theme-describe (or ergoemacs-theme "standard")))
+  (ergoemacs-theme-describe))
 
 ;; Ergoemacs Test suite
 (unless (fboundp 'ergoemacs-test)
@@ -2745,7 +2595,7 @@ With a prefix argument like \\[universial-argument] in an
         key-seq2)
     (unwind-protect
         (progn
-          (setq overriding-terminal-local-map (ergoemacs :original  
global-map))
+          (setq overriding-terminal-local-map  global-map)
           (setq key-seq (read-key-sequence "Old Emacs Command: ")
                 cmd (key-binding key-seq)
                 overriding-terminal-local-map nil
diff --git a/ergoemacs-key-description.el b/ergoemacs-key-description.el
index 41ebad3..1ba401c 100644
--- a/ergoemacs-key-description.el
+++ b/ergoemacs-key-description.el
@@ -52,13 +52,11 @@
 (defvar ergoemacs-display-unicode-characters)
 (defvar ergoemacs-display-capitalize-keys)
 (defvar ergoemacs-display-key-use-face)
-(defvar ergoemacs-display-small-symbols-for-key-modifiers)
-(defvar ergoemacs-display-use-unicode-brackets-around-keys)
+(defvar ergoemacs-display-small-symbols-for-key-modifiers nil)
+(defvar ergoemacs-display-use-unicode-brackets-around-keys nil)
 (defvar ergoemacs-display-without-brackets nil
   "Display the key without brackets.")
 
-(declare-function ergoemacs-timing-- "ergoemacs-mode")
-
 (declare-function ergoemacs-translate--escape-to-meta "ergoemacs-translate")
 (declare-function ergoemacs-translate--event-modifiers "ergoemacs-translate")
 (declare-function ergoemacs-translate--event-basic-type "ergoemacs-translate")
@@ -72,8 +70,6 @@
 
 (declare-function ergoemacs-map--cache-- "ergoemacs-map")
 
-(declare-function ergoemacs-component--help-link "ergoemacs-component")
-
 (declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
 (declare-function ergoemacs-advice--real-substitute-command-keys "C")
 
@@ -157,33 +153,31 @@ MOD ar the modifiers applied to the key."
      ((eq key 32)
       (setq ret "Space"))
      ((eq key 127)
-      (setq ret (format "%sBackspace" (ergoemacs :unicode-or-alt "←" ""))))
+      (setq ret "←Backspace"))
      ((eq key 'escape)
       (setq ret "Esc"))
      ((eq key 'tab)
-      (setq ret (format "Tab%s"
-                        (ergoemacs :unicode-or-alt "↹" ""))))
+      (setq ret "Tab↹"))
      ((eq key 'return)
-      (setq ret (format "Enter%s"
-                        (ergoemacs :unicode-or-alt "↵" ""))))
+      (setq ret "Enter↵"))
      ((memq key '(apps menu))
-      (setq ret (ergoemacs :unicode-or-alt "▤" "Menu")))
+      (setq ret "▤"))
      ((eq key 'left)
-      (setq ret (ergoemacs :unicode-or-alt "←" "left")))
+      (setq ret "←"))
      ((eq key 'right)
-      (setq ret (ergoemacs :unicode-or-alt "→" "right")))
+      (setq ret "→"))
      ((eq key 'up)
-      (setq ret (ergoemacs :unicode-or-alt "↑" "up")))
+      (setq ret "↑"))
      ((eq key 'down)
-      (setq ret (ergoemacs :unicode-or-alt "↓" "down")))
+      (setq ret "↓"))
      ((eq key 'prior)
       (setq ret "PgUp"))
      ((eq key 'next)
       (setq ret "PgDn"))
      ((eq key 'remap)
-      (setq ret (ergoemacs :unicode-or-alt "➩" "remap")))
+      (setq ret "➩"))
      ((eq key 'ergoemacs-timeout)
-      (setq ret (ergoemacs :unicode-or-alt "⌚" "ergoemacs-timeout")))
+      (setq ret "⌚"))
      ((integerp key)
       (setq ret (or (and (or (and (eq ergoemacs-display-capitalize-keys 
'with-modifiers)
                                   mod)
@@ -216,55 +210,47 @@ MOD ar the modifiers applied to the key."
                     (eq mac-command-modifier 'meta))
                (and (boundp 'ns-command-modifier)
                     (eq ns-command-modifier 'meta))))
-      (setq ret (format "%s"
-                        (ergoemacs :unicode-or-alt "⌘" "+"))))
+      (setq ret "⌘"))
      ((and (eq mod 'meta)
            (eq system-type 'darwin)
            (or (and (boundp 'mac-command-modifier)
                     (eq mac-command-modifier 'meta))
                (and (boundp 'ns-command-modifier)
                     (eq ns-command-modifier 'meta))))
-      (setq ret (format "%sCmd+"
-                        (ergoemacs :unicode-or-alt "⌘" "+"))))
+      (setq ret "⌘Cmd+"))
      ((and (eq mod 'meta)
            (eq system-type 'darwin)
            (or (and (boundp 'mac-alternate-modifier)
                     (eq mac-alternate-modifier 'meta))
                (and (boundp 'ns-alternate-modifier)
                     (eq ns-alternate-modifier 'meta))))
-      (setq ret (format "%sOpt+" (ergoemacs :unicode-or-alt "⌥" "+"))))
+      (setq ret "⌥Opt+"))
      ((and (eq mod 'meta) ergoemacs-display-small-symbols-for-key-modifiers
            (eq system-type 'darwin)
            (or (and (boundp 'mac-alternate-modifier)
                     (eq mac-alternate-modifier 'meta))
                (and (boundp 'ns-alternate-modifier)
                     (eq ns-alternate-modifier 'meta))))
-      (setq ret (format "%s" (ergoemacs :unicode-or-alt "⌥" "+"))))
+      (setq ret "⌥"))
      ((and ergoemacs-display-small-symbols-for-key-modifiers (eq mod 'shift))
-      (setq ret (ergoemacs :unicode-or-alt "⇧" "+")))
+      (setq ret "⇧"))
      ((and ergoemacs-display-small-symbols-for-key-modifiers (eq mod 'meta))
-      (setq ret (ergoemacs :unicode-or-alt "♦" "!")))
+      (setq ret "♦"))
      ((and (or (eq system-type 'darwin) 
ergoemacs-display-small-symbols-for-key-modifiers)
            (memq mod '(control ergoemacs-control)))
       (setq ret "^"))
      ((eq mod 'shift)
-      (setq ret (format "%sShift+"
-                        (ergoemacs :unicode-or-alt "⇧" ""))))
+      (setq ret "⇧Shift+"))
      ((memq mod '(control ergoemacs-control))
-      (setq ret (format "%sCtrl+"
-                        (or (and (eq 'windows-nt system-type)
-                                 (ergoemacs :unicode "✲" ""))
-                            (and (eq 'gnu/linux system-type)
-                                 (ergoemacs :unicode "⎈" ""))
-                            ""))))
+      (setq ret "Ctrl+"))
      ((eq mod 'meta)
       (setq ret "Alt+"))
      ((and (eq mod 'super) ergoemacs-display-small-symbols-for-key-modifiers
            (eq system-type 'windows-nt))
-      (setq ret (ergoemacs :unicode-or-alt "⊞" "#")))
+      (setq ret "⊞"))
      ((and (eq mod 'super)
            (eq system-type 'windows-nt))
-      (setq ret (format "%sWin+" (ergoemacs :unicode-or-alt "⊞" "#"))))
+      (setq ret "⊞Win+"))
      (t
       (setq ret (format "%s+" mod))
       (when ergoemacs-display-key-use-face
@@ -337,13 +323,13 @@ KBD is the keyboard code.  LAYOUT is the layout that is 
used."
              (setq mod tmp))
             (setq tmp (format "%s%s%s%s"
                               (or (and (or ergoemacs-display-without-brackets 
ergoemacs-display-key-use-face) "")
-                                  (and 
ergoemacs-display-use-unicode-brackets-around-keys (ergoemacs :unicode-or-alt 
"【" "["))
+                                  (and 
ergoemacs-display-use-unicode-brackets-around-keys "【")
                                   "[")
                               (mapconcat #'ergoemacs-key-description--modifier
                                          mod "")
                               (ergoemacs-key-description--key ev mod)
                               (or (and (or ergoemacs-display-without-brackets 
ergoemacs-display-key-use-face) "")
-                                  (and 
ergoemacs-display-use-unicode-brackets-around-keys (ergoemacs :unicode-or-alt 
"】" "]"))
+                                  (and 
ergoemacs-display-use-unicode-brackets-around-keys "】")
                                   "]")))
             (when (and ergoemacs-display-small-symbols-for-key-modifiers 
ergoemacs-display-key-use-face)
               (add-text-properties 0 (length tmp)
@@ -412,7 +398,7 @@ KBD is the keyboard code.  LAYOUT is the layout that is 
used."
     (ergoemacs-key-description item))
    ((listp item)
     (cond
-     ((eq (car item) 'lambda) (cons nil (ergoemacs :unicode-or-alt "λ" 
"lambda")))
+     ((eq (car item) 'lambda) (cons nil "λ" ))
      ((eq (car item) 'closure) (cons nil "#<closure>"))
      ((eq (car item) 'keymap) (cons nil "#<keymap>"))
      (t (format "%s" item))))
@@ -420,7 +406,7 @@ KBD is the keyboard code.  LAYOUT is the layout that is 
used."
     (if (ignore-errors (commandp item t))
         (cons 'help-function (format "%s" item))
       (cons nil (format "%s" item))))
-   (t (cons nil (format"#<byte compiled %s>" (ergoemacs :unicode-or-alt "λ" 
"lambda"))))))
+   (t (cons nil (format"#<byte compiled %s>" "λ")))))
 
 (defun ergoemacs-key-description--keymap-blame (key map)
   "Find the source of KEY in MAP."
@@ -460,12 +446,6 @@ KBD is the keyboard code.  LAYOUT is the layout that is 
used."
       (setq ret (cons 'ergoemacs-component-help (nth 1 ret)))))
     ret))
 
-(defun ergoemacs-key-description--setup-xrefs ()
-  "Setup cross refecnes in help buffer."
-  (ergoemacs-component--help-link))
-
-(add-hook 'temp-buffer-show-hook 'ergoemacs-key-description--setup-xrefs)
-
 (defun ergoemacs-key-description--keymap-item (&optional elt keymap help)
   "Get keymap description for ELT based on KEYMAP.
 
@@ -509,21 +489,20 @@ When HELP is non-nil, insert and add help cross-refences."
   (let ((map (or (and (symbolp map) (symbol-value map))
                  (and (consp map) (eq (car map) 'keymap) map)))
         ret)
-    (ergoemacs-timing describe-keymap
-      (setq ret
-            (ergoemacs-cache (intern (format "describe-keymap-ret%s" 
(mapconcat (lambda(x) (md5 (format "%s" x))) (ergoemacs  map :key-hash) "_")))
-              (ergoemacs-map-keymap
-               (lambda (cur-key item)
-                 (unless (eq item 'ergoemacs-prefix)
-                   (cond
-                    ((consp cur-key))
-                    ((memq (elt cur-key 0) ergoemacs-describe-keymap--ignore))
-                    ((consp item))
-                    ((not item))
-                    (t
-                     (push (cons cur-key item) ret)))))
-               map)
-              ret)))
+    (setq ret
+          (ergoemacs-cache (intern (format "describe-keymap-ret%s" (mapconcat 
(lambda(x) (md5 (format "%s" x))) (ergoemacs  map :key-hash) "_")))
+            (ergoemacs-map-keymap
+             (lambda (cur-key item)
+               (unless (eq item 'ergoemacs-prefix)
+                 (cond
+                  ((consp cur-key))
+                  ((memq (elt cur-key 0) ergoemacs-describe-keymap--ignore))
+                  ((consp item))
+                  ((not item))
+                  (t
+                   (push (cons cur-key item) ret)))))
+             map)
+            ret))
     (setq ret (append (list nil t) (sort ret (lambda(e1 e2) (ergoemacs 
:key-lessp (car e1) (car e2))))))
     (if help
         (insert (ergoemacs-cache (intern (format "describe-keymap-help%s" 
(mapconcat (lambda(x) (md5 (format "%s" x))) (ergoemacs  map :key-hash) "_")))
diff --git a/ergoemacs-layouts.el b/ergoemacs-layouts.el
index 3ddd324..44e12e5 100644
--- a/ergoemacs-layouts.el
+++ b/ergoemacs-layouts.el
@@ -96,7 +96,6 @@
     "" ">"  "W" "X" "C" "V" "B" "N" "?" "." "/" "+" "" "" "")
   "Belgian AZERTY.")
 
-
 (defvar ergoemacs-layout-colemak
   '("" "`" "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "-" "=" ""
     "" ""  "q" "w" "f" "p" "g" "j" "l" "u" "y" ";" "[" "]" "\\"
@@ -259,7 +258,6 @@
     "" "|"  ":" "Q" "J" "K" "X" "B" "M" "W" "V" "Z" "" "" "")
   "UK Dvorak layout.")
 
-
 (defvar ergoemacs-layout-it
   '("" "\\" "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "'" "¡" ""
     "" ""  "q" "w" "e" "r" "t" "y" "u" "i" "o" "p" "è" "+" ""
@@ -321,7 +319,6 @@
     "" "»"  "Y" "Ç" "J" "B" "K" "Q" "V" "G" "F" "Z" "" "" "")
   "PT Nativo layout URL 
`http://xahlee.info/kbd/pt-nativo_keyboard_layout.html'.")
 
-
 (defvar ergoemacs-layout-sw
   '("" "½" "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "+" "’" ""
     "" ""  "q" "w" "e" "r" "t" "y" "u" "i" "o" "p" "å" "\"" ""
@@ -371,7 +368,6 @@
   "US Workman layout.  URL `http://www.workmanlayout.com/blog/'.")
 
 (defvaralias 'ergoemacs-layout-jcuken 'ergoemacs-layout-ru)
-
 (defvar ergoemacs-layout-ru
   '("" "" "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "-" "=" "\\"
     "" ""  "й" "ц" "у" "к" "е" "н" "г" "ш" "щ" "з" "х" "ъ" "" 
@@ -394,7 +390,6 @@
 (declare-function ergoemacs-translate-layout "ergoemacs-translate")
 (declare-function ergoemacs-translate--svg-layout "ergoemacs-translate")
 (declare-function ergoemacs-translate--png-layout "ergoemacs-translate")
-(declare-function ergoemacs-component--prompt "ergoemacs-component")
 (declare-function quail-insert-kbd-layout "quail")
 
 (defun ergoemacs-layouts--current (&optional layout)
@@ -411,30 +406,6 @@ If LAYOUT is unspecified, use `ergoemacs-keyboard-layout'."
                 `(const :tag ,elt :value ,elt))
               (sort (ergoemacs-layouts--list t) 'string<))))
 
-(defun ergoemacs-layouts--menu ()
-  "Gets the keymap entry for ergoemacs-layouts."
-  `(ergoemacs-keyboard-layout
-    menu-item "Keyboard Layouts"
-    (keymap
-     ,@(mapcar
-        (lambda(lay)
-          (let* ((variable (intern (concat "ergoemacs-layout-" lay)))
-                 (alias (condition-case nil
-                            (indirect-variable variable)
-                          (error variable)))
-                 (is-alias nil)
-                 (doc nil))
-            (setq doc (or (documentation-property variable 
'variable-documentation)
-                          (progn
-                            (setq is-alias t)
-                            (documentation-property alias 
'variable-documentation))))
-            `(,variable
-              menu-item ,(concat lay " - " doc)
-              (lambda() (interactive)
-                (ergoemacs-set-layout ,lay))
-              :button (:radio . (string= ergoemacs-keyboard-layout ,lay)))))
-        (sort (ergoemacs-layouts--list) 'string<)))))
-
 (defun ergoemacs-layouts--custom-documentation (&optional lays ini)
   "Get a documentation list of all known layouts.
 
@@ -460,13 +431,11 @@ file."
            (concat "\"" lay "\" (" doc ")" (if is-alias ", alias" "")))))
      lays "\n")))
 
-(defvar ergoemacs-layouts--no-aliases nil)
 (defvar ergoemacs-layouts--aliases nil)
 
 (defun ergoemacs-layouts--reset ()
   "Reset Layout information."
   (interactive)
-  (setq ergoemacs-layouts--no-aliases nil)
   (setq ergoemacs-layouts--aliases nil))
 
 (defun ergoemacs-layouts--list (&optional aliases ob)
@@ -475,9 +444,6 @@ file."
 When ALIASES is non-nil, list aliases and actuval variables.
 
 OB is the object array."
-  (if (and ergoemacs-layouts--no-aliases
-           (not aliases))
-      ergoemacs-layouts--no-aliases
     (if (and ergoemacs-layouts--aliases
              aliases)
         ergoemacs-layouts--aliases
@@ -495,8 +461,8 @@ OB is the object array."
          ob)
         (if aliases
             (setq ergoemacs-layouts--aliases nil)
-          (setq ergoemacs-layouts--no-aliases nil))
-        ret))))
+          )
+        ret)))
 
 (defun ergoemacs-layout (layout)
   "Set the ergoemacs layout to LAYOUT."
@@ -556,8 +522,6 @@ Otherwise, `ergoemacs-mode' will try to adjust based on 
your layout."
   (add-hook 'ergoemacs-init-hook #'ergoemacs-layout--update-quail))
 
 
-(defalias 'ergoemacs-layout 'ergoemacs-set-layout)
-
 (define-button-type 'ergoemacs-layout-help
   :supertype 'help-xref
   'help-function #'ergoemacs-layout-describe
@@ -573,13 +537,29 @@ expression matching the base layout."
         (f2 "Base Layout: \\(%s\\)"))
     (format (cond
              (base f2)
-             (t f1)) (regexp-opt (ergoemacs-layouts--list) t))))
+             (t f1))
+            (regexp-opt (ergoemacs-layouts--list) t))))
+
+(defun ergoemacs-layout--prompt ()
+  "Prompt for component or theme (when THEME-INSTEAD is non-nil)."
+  (let ((c ergoemacs-keyboard-layout)
+        (enable-recursive-minibuffers t)
+        val)
+    (setq val (completing-read (if (or (symbolp c) (stringp c))
+                                   (format
+                                    "Describe ergoemacs layout (default %s): "
+                                    c)
+                                 "Describe ergoemacs layout: ")
+                               (ergoemacs-layouts--list)
+                               nil t nil nil
+                               (format "%s" c)))
+    (list (or (and (equal val "") (format "%s" c)) val))))
 
 (defun ergoemacs-layout-describe (&optional layout)
   "Display the full documentation of an `ergoemacs-mode' LAYOUT.
 
 LAYOUT can be either a symbol or string."
-  (interactive (ergoemacs-component--prompt :layout))
+  (interactive (ergoemacs-layout--prompt))
   (let* ((layout (or (and layout
                           (or (and (stringp layout) layout)
                               (and (symbolp layout) (symbol-name layout))))
diff --git a/ergoemacs-lib.el b/ergoemacs-lib.el
index 398b8c9..c23aad2 100644
--- a/ergoemacs-lib.el
+++ b/ergoemacs-lib.el
@@ -31,12 +31,10 @@
 (eval-when-compile
   (require 'ergoemacs-macros))
 
-(defvar powerline-default-separator-dir)
 (defvar mode-icons-show-mode-name)
 (defvar mode-icons-read-only-space)
 (defvar mode-icons-cached-mode-name)
 (defvar mode-icons-eol-text)
-(defvar ergoemacs-theme)
 (defvar ergoemacs-excluded-major-modes)
 (defvar ergoemacs-keyboard-layout)
 (defvar ergoemacs-keymap)
@@ -44,13 +42,7 @@
 (defvar ergoemacs-mode-names)
 (defvar ergoemacs-require)
 (defvar ergoemacs-theme-hash)
-(defvar ergoemacs-timing-hash)
-(defvar ergoemacs-component-struct--apply-ensure-p)
 
-(defvar package-archives)
-
-(defvar tabbar-mode)
-(defvar ergoemacs-handle-ctl-c-or-ctl-x)
 (defvar ergoemacs-dir)
 
 
@@ -59,14 +51,10 @@
 (declare-function ergoemacs-previous-emacs-buffer "ergoemacs-functions")
 (declare-function ergoemacs-previous-user-buffer "ergoemacs-functions")
 
-(declare-function powerline-current-separator "powerline")
-(declare-function powerline-selected-window-active "powerline")
-
 (declare-function mode-icons-get-mode-icon "mode-icons")
 
 (declare-function ergoemacs-autoloadp "ergoemacs-macros")
 (declare-function ergoemacs-mode-reset "ergoemacs-mode")
-(declare-function ergoemacs-theme--list "ergoemacs-theme-engine")
 (declare-function ergoemacs-theme-option-on "ergoemacs-theme-engine")
 
 (declare-function ergoemacs-key-description--menu "ergoemacs-key-description")
@@ -75,13 +63,6 @@
 (declare-function ergoemacs-translate--ahk-ini "ergoemacs-translate")
 (declare-function ergoemacs-command-loop--spinner-display 
"ergoemacs-command-loop")
 
-(declare-function ergoemacs-component-find-definition "ergoemacs-component")
-(declare-function ergoemacs-component-find-1 "ergoemacs-component")
-
-(declare-function tabbar-install-faces "tabbar-ruler")
-(declare-function tabbar-mode "tabbar")
-
-
 (defun ergoemacs-setcdr (var val &optional default)
   "Use `setcdr' on VAL to VAL.
 If VAL is a symbol, use `ergoemacs-sv' to determine the value.
@@ -92,206 +73,6 @@ If DEFAULT is non-nil set the default value, instead of the 
symbol value."
     (if (not var) nil
       (setcdr var val))))
 
-(defvar ergoemacs-set-ignore-customize nil
-  "List of variables that should not be saved by customize.")
-
-;;;###autoload
-(defun ergoemacs-set (variable value &optional defer force)
-  "Sets VARIABLE to VALUE without disturbing customize or setq.
-
-If the user changed the value with either `setq' or `customize',
-then respect the varaible.
-
-If FORCE is true, set it even if it changed.
-
-Whe changed return t, otherwise return nil."
-  ;; (message "set:%s %s %s %s" variable value defer force)
-  (let* ((minor-mode-p (and (string= "mode" (substring (symbol-name variable) 
-4))
-                            (commandp variable t)))
-         (new-value (or (and (not minor-mode-p) value)
-                        (and (integerp value) (< 0 value) value)
-                        (and (not (integerp value)) value))) ; Otherwise 
negative integers are the same as nil
-         (last-value (ignore-errors (ergoemacs-sv variable)))
-         ret)
-    (when (and minor-mode-p (not last-value))
-      (setq last-value -1))
-    (cond
-     ((and minor-mode-p (functionp variable))
-      (unless (and defer (ergoemacs-autoloadp variable))
-        (unless (get variable :ergoemacs-save-value)
-          (put variable :ergoemacs-save-value (if new-value nil 1)))
-        (ergoemacs :spinner :new "Call (%s %s)" variable new-value)
-        ;; (message "(%s %s) #1" variable new-value)
-        (funcall variable new-value)
-        (ergoemacs :spinner :new "Done (%s %s)" variable new-value)
-        (put variable :ergoemacs-set-value (ergoemacs-sv variable))
-        (cl-pushnew variable ergoemacs-set-ignore-customize)
-        (setq ret t)))
-     ((not (equal last-value value))
-      (cond
-       ((and minor-mode-p (not new-value) (functionp variable))
-        (unless (and defer (ergoemacs-autoloadp variable))
-          ;; (message "(%s -1) #2" variable)
-          (ergoemacs :spinner :new "Call (%s -1)" variable)
-          (funcall variable -1)
-          (ergoemacs :spinner :new "Done (%s -1)" variable)
-          (unless (get variable :ergoemacs-save-value)
-            (put variable :ergoemacs-save-value (ergoemacs-sv variable)))
-          (put variable :ergoemacs-set-value (ergoemacs-sv variable))
-          (cl-pushnew variable ergoemacs-set-ignore-customize)
-          (setq ret t)))
-       ((and minor-mode-p new-value (functionp variable))
-        (unless (and defer (ergoemacs-autoloadp variable))
-          ;; (message "(%s %s) #3" variable new-value)
-          (ergoemacs :spinner :new "Call (%s %s)" variable new-value)
-          (funcall variable new-value)
-          (ergoemacs :spinner :new "Done (%s %s)" variable new-value)
-          (unless (get variable :ergoemacs-save-value)
-            (put variable :ergoemacs-save-value (ergoemacs-sv variable)))
-          (put variable :ergoemacs-set-value (ergoemacs-sv variable))
-          (cl-pushnew variable ergoemacs-set-ignore-customize)
-          (setq ret t)))
-       ((and (ergoemacs :custom-p variable)
-             (not minor-mode-p)
-             (or force (not (get variable 'save-value))))
-        ;; (message "%s->%s #1" variable new-value)
-        (unless (get variable :ergoemacs-save-value)
-          (put variable :ergoemacs-save-value (ergoemacs-sv variable)))
-        (set variable new-value)
-        ;; Don't save ergoemacs-mode intilization
-        (put variable :ergoemacs-set-value (ergoemacs-sv variable))
-        (cl-pushnew variable ergoemacs-set-ignore-customize)
-        (setq ret t))
-       ((or force (not minor-mode-p)
-            (equal (ergoemacs-sv variable) (default-value variable)))
-        ;; (message "%s->%s #1" variable new-value)
-        (unless (get variable :ergoemacs-save-value)
-          (put variable :ergoemacs-save-value (ergoemacs-sv variable)))
-        (set variable new-value)
-        (set-default variable new-value)
-        (unless (get variable :ergoemacs-save-value)
-          (put variable :ergoemacs-save-value (ergoemacs-sv variable)))
-        (put variable :ergoemacs-set-value (ergoemacs-sv variable))
-        (cl-pushnew variable ergoemacs-set-ignore-customize)
-        (setq ret t))
-       (t
-        ;; (ergoemacs-warn "%s changed outside ergoemacs-mode, respecting." 
variable)
-        (setq ret t))))
-     (t
-      ;; (message "%s was not changed by ergoemacs-mode, since it has the same 
value.\n\tlast-value: %s\n\tnew-value: %s" variable
-      ;;          last-value new-value)
-      ))
-    ret))
-
-;;;###autoload
-(defun ergoemacs-save (variable value)
-  "Set VARIABLE to VALUE and tell customize it needs to be saved."
-  (if (not (ergoemacs :custom-p variable))
-      (set variable value)
-    (customize-set-variable variable value)
-    (customize-mark-as-set variable)))
-
-(defun ergoemacs-reset (variable)
-  "Sets VARIABLE to VALUE without disturbing customize or setq."
-  (let* ((minor-mode-p (and (string= "mode" (substring (symbol-name variable) 
-4))
-                            (commandp variable t)))
-         (value (get variable :ergoemacs-save-value))
-         (new-value (or (and (not minor-mode-p) value)
-                        (and (integerp value) (< 0 value) value)
-                        (and (not (integerp value)) value)
-                        ;; Otherwise negative integers are the same as nil
-                        )))
-    (put variable :ergoemacs-save-value nil)
-    (if (and minor-mode-p (not (boundp variable)))
-        (funcall variable new-value)
-      (if (ergoemacs :custom-p variable)
-          (progn
-            ;; (customize-mark-to-save variable)
-            (if (and minor-mode-p (not new-value))
-                (funcall variable -1)
-              (set variable new-value)
-              (set-default variable new-value)))
-        (set variable new-value)
-        (set-default variable new-value)
-        (put variable :ergoemacs-set-value (ergoemacs-sv variable))
-        (cl-pushnew variable ergoemacs-set-ignore-customize)
-        (when minor-mode-p ;; Change minor mode
-          (if new-value
-              (funcall variable new-value)
-            (funcall variable -1)))))))
-
-(defun ergoemacs-remove (option &optional theme type keep)
-  "Removes an OPTION on ergoemacs themes.
-
-Calls `ergoemacs-require' with TYPE defaulting to 'off and
-remove defaulting to t.
-
-KEEP can change remove to nil."
-  (ergoemacs-require option theme (or type 'off) (if keep nil t)))
-
-(defvar ergoemacs-require--ini-p nil)
-(defun ergoemacs-require--ini-p ()
-  (setq ergoemacs-require--ini-p t))
-(add-hook 'ergoemacs-mode-after-startup-run-load-hooks 
#'ergoemacs-require--ini-p)
-
-(defun ergoemacs-require (option &optional theme type remove)
-  "Requires an OPTION on ergoemacs themes.
-
-THEME can be a single theme or list of themes to apply the option
-to.  If unspecified, it is all themes.
-
-TYPE can be 'on, where the option will be turned on by default
-but shown as something at can be toggled in the ergoemacs-mode
-menu.
-
-TYPE can also be 'required-hidden, where the option is turned on,
-and it dosen't show up on the ergoemacs-mode menu.
-
-TYPE can also be 'off, where the option will be included in the
-theme, but assumed to be disabled by default.
-
-When TYPE is nil, assume the type is 'required-hidden
-
-REMOVE represents when you would remove the OPTION from the
-ergoemacs THEME."
-  (setq ergoemacs-component-struct--apply-ensure-p t)
-  (unless (member (list option theme type remove) ergoemacs-require)
-    (push (list option theme type remove) ergoemacs-require))
-  (if ergoemacs-require--ini-p
-      (if (consp option)
-          (dolist (new-option option)
-            (let (ergoemacs-mode)
-              (ergoemacs-require new-option theme type)))
-        (let ((option-sym
-               (or (and option (stringp option) (intern option)) option)))
-          (dolist (theme (or (and theme (or (and (consp theme) theme) (list 
theme)))
-                             (ergoemacs-theme--list)))
-            (let ((theme-plist (ergoemacs-gethash (if (and theme (stringp 
theme)) theme
-                                                    (symbol-name theme))
-                                                  ergoemacs-theme-hash))
-                  comp on off)
-              (setq comp (plist-get theme-plist :components)
-                    on (plist-get theme-plist :optional-on)
-                    off (plist-get theme-plist :optional-off))
-              (setq comp (delq option-sym comp)
-                    on (delq option-sym on)
-                    off (delq option-sym off))
-              (cond
-               (remove) ;; Don't do anything.
-               ((or (not type) (memq type '(required-hidden :required-hidden)))
-                (push option-sym comp))
-               ((memq type '(off :off))
-                (push option-sym off))
-               ((memq type '(on :on))
-                (push option-sym on)))
-              (setq theme-plist (plist-put theme-plist :components comp))
-              (setq theme-plist (plist-put theme-plist :optional-on on))
-              (setq theme-plist (plist-put theme-plist :optional-off off))
-              (puthash (if (and theme (stringp theme)) theme (symbol-name 
theme)) theme-plist
-                       ergoemacs-theme-hash)))))
-    (unless (eq ergoemacs-require--ini-p :ini)
-      (ergoemacs-theme-option-on option t))))
-
 (defvar ergoemacs-xah-emacs-lisp-tutorial-url
   "http://ergoemacs.org/emacs/elisp.html";)
 
@@ -413,147 +194,12 @@ All other modes are assumed to be minor modes or 
unimportant.
              (separator1 menu-item "--")
              (package menu-item  "Manage Packages" list-packages))))
 
-(defun ergoemacs-menu-tabbar-toggle ()
-  "Enables/Disables (and installs if not present) a tab-bar for emacs."
-  (interactive)
-  (require 'package nil t)
-  (if (not (fboundp 'tabbar-mode))
-      (let ((package-archives '(("melpa" . "http://melpa.org/packages/";))))
-        (require 'tabbar-ruler nil t)
-        (if (fboundp 'tabbar-install-faces)
-            (tabbar-install-faces)
-          (when (fboundp 'package-install)
-            (package-refresh-contents)
-            (package-initialize)
-            (package-install 'tabbar-ruler)
-            (require 'tabbar-ruler nil t)
-            (tabbar-install-faces))))
-    (if (not (featurep 'tabbar-ruler))
-        (require 'tabbar-ruler nil t)
-      (if tabbar-mode
-          (tabbar-mode -1)
-        (tabbar-mode 1)))))
-
-(defun ergoemacs-menu--filter-key-shortcut (cmd &optional keymap)
-  "Figures out ergoemacs-mode menu's preferred key-binding for CMD."
-  (cond
-   ((not cmd))
-   ((and (memq ergoemacs-handle-ctl-c-or-ctl-x '(only-copy-cut both))
-         (eq cmd 'ergoemacs-cut-line-or-region)) 
(ergoemacs-key-description--menu (kbd "C-x")) )
-   ((and (memq ergoemacs-handle-ctl-c-or-ctl-x '(only-copy-cut both))
-         (eq cmd 'ergoemacs-copy-line-or-region)) 
(ergoemacs-key-description--menu (kbd "C-c")))
-   (t
-    ;;; FIXME: faster startup by creating component alists
-    ;; SLOW: 2-seconds
-    (let ((key (where-is-internal cmd (or keymap ergoemacs-keymap) 'meta nil 
t)))
-      (when (memq (elt key 0) '(menu-bar remap again redo cut copy paste help 
open find ergoemacs-remap execute))
-        (setq key nil))
-      (and key (ergoemacs-key-description--menu key)))
-    ;; (let ((key (ergoemacs-gethash cmd (ergoemacs (ergoemacs :global-map) 
:where-is))))
-    ;;   (when key
-    ;;     (setq key (nth 0 key)))
-    ;;   (when (memq (elt key 0) '(menu-bar remap again redo cut copy paste 
help open find ergoemacs-remap execute))
-    ;;     (setq key nil))
-    ;;   (or (and key (ergoemacs-key-description--menu key)) ""))
-    )))
-
-
-(defun ergoemacs-menu--filter-key-menu-item (item &optional keymap)
-  "Key menu item."
-  (if (and (>= (safe-length item) 4)
-           (symbolp (car item))
-           (eq (cadr item) 'menu-item)
-           (and (cl-caddr item) (stringp (cl-caddr item)))
-           (symbolp (cl-cadddr item))
-           (not (ergoemacs-keymapp (cl-cadddr item))))
-      ;; Look if this item already has a :keys property
-      (if (catch 'found-keys
-            (dolist (i item)
-              (when (eq i :keys)
-                (throw 'found-keys t))) nil) nil
-        (ergoemacs-menu--filter-key-shortcut (cl-cadddr item) keymap))
-    nil))
-
-;;;###autoload
-(defun ergoemacs-menu--filter (menu &optional fn keymap)
-  "Put `ergoemacs-mode' key bindings on menus."
-  (let ((menu (or (and (not fn) menu)
-                  (funcall fn menu)))
-        tmp tmp2)
-    ;; (when fn
-    ;;   (message "%s:\n\t%s" fn menu))
-    (if (not (ergoemacs-keymapp menu) )
-        (progn
-          (when menu
-            (message "Invalid menu in ergoemacs-menu--filter %s" menu))
-          menu)
-      (when (symbolp menu)
-        (setq menu (ergoemacs-sv menu)))
-      ;; For each element in the menu
-      (ergoemacs-setcdr
-       menu
-       (mapcar
-        (lambda (item)
-          (let (key)
-            (cond
-             ;; ((ergoemacs-keymapp item)
-             ;;  (ergoemacs-menu--filter item)
-             ;;  (message "1:%s..." (substring (format "%s" item) 0 (min 
(length (format "%s" item)) 60)))
-             ;;  item)
-             ((and (ergoemacs-keymapp keymap) (ergoemacs-keymapp (cdr (cdr 
item))))
-              ;; JIT processing
-              `(,(nth 0 item) menu-item ,(nth 1 item) ,(cdr (cdr item))
-                :filter (lambda(bind) (ergoemacs-menu--filter bind nil 
',keymap))))
-             ((ergoemacs-keymapp (cdr (cdr item)))
-              ;; JIT processing
-              `(,(nth 0 item) menu-item ,(nth 1 item) ,(cdr (cdr item))
-                :filter ergoemacs-menu--filter))
-             ((ergoemacs-keymapp (car (cdr (cdr (cdr item)))))
-              ;; (message "3:%s..." (substring (format "%s" item) 0 (min 
(length (format "%s" item)) 60)))
-              (if (setq tmp (plist-get item :filter))
-                  (mapcar
-                   (lambda(elt)
-                     (cond
-                      ((eq elt :filter)
-                       (setq tmp2 t)
-                       :filter)
-                      ((not tmp2)
-                       elt)
-                      ((eq elt 'ergoemacs-menu--filter)
-                       (setq tmp2 nil)
-                       'ergoemacs-menu--filter)
-                      ((ignore-errors
-                         (and (consp elt)
-                              (eq (nth 0 elt) 'lambda)
-                              (eq (nth 0 (nth 2 elt)) 
'ergoemacs-menu--filter)))
-                       (setq tmp2 nil)
-                       elt)
-                      (t
-                       (setq tmp2 nil)
-                       `(lambda(bind) (ergoemacs-menu--filter bind ',tmp 
',keymap)))))
-                   item)
-                `(,@item :filter ergoemacs-menu--filter)))
-             ((setq key (ergoemacs-menu--filter-key-menu-item item keymap))
-              (append item (cons :keys (cons key nil))))
-             (t item))))
-        (cdr menu))))
-    menu))
-
-;;;###autoload
-(defun ergoemacs-set-layout (layout)
-  "Set `ergoemacs-keyboard-layout' to LAYOUT and reset `ergoemacs-mode'.
-The reset is done with `ergoemacs-mode-reset'."
-  (setq ergoemacs-keyboard-layout layout)
-  (ergoemacs-mode-reset))
-
 ;;;###autoload
 (defun ergoemacs-gen-ahk (&optional all)
   "Generates autohotkey for all layouts and themes"
   (interactive)
   (if (called-interactively-p 'any)
       (progn
-       (setenv "ERGOEMACS_KEYBOARD_LAYOUT" ergoemacs-keyboard-layout)
-       (setenv "ERGOEMACS_THEME" ergoemacs-theme)
         (shell-command (format "%s -Q --batch -l %s/ergoemacs-mode --eval 
\"(ergoemacs-gen-ahk %s)\" &"
                                (ergoemacs-emacs-exe)
                                ergoemacs-dir (if current-prefix-arg "t" 
"nil"))))
@@ -569,7 +215,7 @@ The reset is done with `ergoemacs-mode-reset'."
       (setq file-temp (expand-file-name "ergoemacs.ini" extra-dir))
       (with-temp-file file-temp
         (set-buffer-file-coding-system 'utf-8)
-        (insert (ergoemacs-translate--ahk-ini all all)))
+        (insert (ergoemacs-translate--ahk-ini all)))
       (setq file-temp (expand-file-name "ergoemacs.ahk" extra-dir))
       (with-temp-file file-temp
         (set-buffer-file-coding-system 'utf-8)
@@ -599,244 +245,6 @@ to the `warn' function."
 (defvar ergoemacs-mx-len nil)
 
 
-(defvar ergoemacs-timing-results-buffer "*Ergoemacs Profiling Results*"
-  "Buffer name for outputting profiling results.")
-
-(defun ergoemacs-timing-sort-by-call-count (vec1 vec2)
-  "Sort by highest call count.  See `sort'."
-  (>= (aref vec1 0) (aref vec2 0)))
-
-(defun ergoemacs-timing-sort-by-total-time (vec1 vec2)
-  "Sort by highest total time spent in function. See `sort'."
-  (>= (aref vec1 1) (aref vec2 1)))
-
-(defun ergoemacs-timing-sort-by-average-time (vec1 vec2)
-  "Sort by highest average time spent in function. See `sort'."
-  (>= (aref vec1 2) (aref vec2 2)))
-
-
-(defcustom ergoemacs-timing-sort-by-function
-  'ergoemacs-timing-sort-by-total-time
-  "Non-nil specifies ELP results sorting function.
-These functions are currently available:
-
-  `ergoemacs-timing-sort-by-call-count'   -- sort by the highest call count
-  `ergoemacs-timing-sort-by-total-time'   -- sort by the highest total time
-  `ergoemacs-timing-sort-by-average-time' -- sort by the highest average times
-
-You can write your own sort function.  It should adhere to the
-interface specified by the PREDICATE argument for `sort'.  Each
-\"element of LIST\" is really a 4 element vector where element 0
-is the call count, element 1 is the total time spent in the
-function, element 2 is the average time spent in the function,
-and element 3 is the symbol's name string."
-  :type 'function
-  :group 'ergoemacs-mode)
-
-(defsubst ergoemacs-timing-pack-number (number width)
-  "Pack the NUMBER string into WIDTH characters, watching out for
-very small or large numbers"
-  (if (<= (length number) width)
-      number
-    ;; check for very large or small numbers
-    (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number)
-        (concat (substring
-                 (match-string 1 number)
-                 0
-                 (- width (match-end 2) (- (match-beginning 2)) 3))
-                "..."
-                (match-string 2 number))
-      (substring number 0 width))))
-
-(defun ergoemacs-timing-results-jump-to-component (&optional event)
-  "Jump to component linked to the current button.
-EVENT is used when this is calledf rom a mouse event."
-  (interactive (list last-nonmenu-event))
-  (if event (posn-set-point (event-end event)))
-  (ergoemacs-component-find-definition
-   (get-text-property (point) 'ergoemacs-component)))
-
-(defvar ergoemacs-timing-component-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map [mouse-1] 'ergoemacs-timing-results-jump-to-component)
-    (define-key map [follow-link] 'mouse-face)
-    (define-key map "\C-m" 'ergoemacs-timing-results-jump-to-component)
-    map)
-  "Keymap used on the component maps.")
-
-(defcustom ergoemacs-timing-find-regexp
-  (concat"^\\s-*(ergoemacs-timing" find-function-space-re "%s\\(\\s-\\|$\\)")
-  "The regexp used by `ergoemacs-timing-find-no-select' to search for a timing 
definition.
-Note it must contain a `%s' at the place where `format' should
-insert the face name."
-  :type 'regexp
-  :group 'find-function
-  :version "22.1")
-
-(unless (assoc 'ergoemacs-timing find-function-regexp-alist)
-  (push (cons 'ergoemacs-timing 'ergoemacs-timing-find-regexp) 
find-function-regexp-alist))
-
-(defun ergoemacs-timing-find-no-select (timing-definition file)
-  "Find TIMING-DEFINITION in FILE.
-This uses `find-function-search-for-symbol'."
-  (let* ((el-file (and file (concat (file-name-sans-extension file) ".el")))
-         (sym (intern (format "%s" timing-definition))))
-    (find-function-search-for-symbol sym 'ergoemacs-timing el-file)))
-
-(defun ergoemacs-timing-results-jump (&optional event)
-  "Jump to timing item linked to the current button.
-EVENT is used when this is called from a mouse event."
-  (interactive (list last-nonmenu-event))
-  (if event (posn-set-point (event-end event)))
-  (let ((file (get-text-property (point) 'ergoemacs-timing-file))
-        (symbol (get-text-property (point) 'ergoemacs-timing-symbol)))
-    (when file
-      (ergoemacs-component-find-1
-       symbol 'ergoemacs-timing 'switch-to-buffer
-       (save-excursion
-         (ergoemacs-timing-find-no-select symbol file))))))
-
-(defvar ergoemacs-timing-jump-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map [mouse-1] 'ergoemacs-timing-results-jump)
-    (define-key map [follow-link] 'mouse-face)
-    (define-key map "\C-m" 'ergoemacs-timing-results-jump)
-    map)
-  "Jump to a timing definition.")
-
-(defun ergoemacs-timing-output-result--sym (symname &optional file)
-  "Insert SYMNAME with appropriate links."
-  (let ((sym (format "%s" symname)))
-    (unless (catch 'found
-              (dolist (lst '(("initialize-\\(.*\\)\\'" "Initialize ")
-                             ("ensure-\\(.*\\)\\'" "Ensure ")
-                             ("create-component-\\(.*\\)\\'" "Create Component 
")
-                             ("translate-keymap-\\(.*\\)\\'" "Translate Keymap 
")))
-                (when (string-match (nth 0 lst) sym)
-                  (insert (nth 1 lst)
-                          (propertize (match-string 1 sym)
-                                      'ergoemacs-component (intern 
(match-string 1 sym))
-                                      'keymap ergoemacs-timing-component-map
-                                      'mouse-face 'highlight
-                                      'face 'link
-                                      'help-echo "mouse-1 or RET jumps to 
definition"))
-                  (throw 'found t)))
-              nil)
-      (if file
-         (insert (propertize sym
-                             'ergoemacs-timing-symbol (intern sym)
-                             'ergoemacs-timing-file file
-                             'keymap ergoemacs-timing-jump-map
-                             'mouse-face 'highlight
-                             'face 'link
-                             'help-echo "mouse-1 or RET jumps to definition"))
-       (insert sym)))))
-
-(defun ergoemacs-timing-output-result (resultvec)
-  "Output the RESULTVEC into the results buffer. RESULTVEC is a 4
-or more element vector where aref 0 is the call count, aref 1 is
-the total time spent in the function, aref 2 is the average time
-spent in the function, aref 3 is the minimum time spent on the
-function, aref 4 is the maximum time spend on the function, and
-aref 3 is the symbol's string name. All other elements in the
-vector are ignored."
-  (let* ((cc (aref resultvec 0))
-         (tt (aref resultvec 1))
-         (at (aref resultvec 2))
-         (mn (aref resultvec 3))
-         (mx (aref resultvec 4))
-         (symname (aref resultvec 5))
-         (file (aref resultvec 6))
-         callcnt totaltime avetime mntime mxtime)
-    (setq callcnt (number-to-string cc)
-          totaltime (number-to-string tt)
-          avetime (number-to-string at)
-          mntime (number-to-string mn)
-          mxtime (number-to-string mx))
-    ;; possibly prune the results
-    (ergoemacs-timing-output-result--sym symname file)
-    (insert-char 32 (+ ergoemacs-field-len (- (length symname)) 2))
-    ;; print stuff out, formatting it nicely
-    (insert callcnt)
-    (insert-char 32 (+ ergoemacs-cc-len (- (length callcnt)) 2))
-    (let ((ttstr (ergoemacs-timing-pack-number totaltime ergoemacs-et-len))
-          (atstr (ergoemacs-timing-pack-number avetime ergoemacs-at-len))
-          (mnstr (ergoemacs-timing-pack-number mntime ergoemacs-mn-len))
-          (mxstr (ergoemacs-timing-pack-number mxtime ergoemacs-mx-len)))
-      (insert ttstr)
-      (insert-char 32 (+ ergoemacs-et-len (- (length ttstr)) 2))
-      (insert atstr)
-      (insert-char 32 (+ ergoemacs-at-len (- (length atstr)) 2))
-      (insert mnstr)
-      (insert-char 32 (+ ergoemacs-mn-len (- (length mnstr)) 2))
-      (insert mxstr))
-    (insert "\n")))
-
-(defun ergoemacs-timing-results ()
-  "Display current ergoemacs-mode  profiling results.
-Based on `elp-results'."
-  (interactive)
-  (let ((curbuf (current-buffer))
-        (resultsbuf (get-buffer-create ergoemacs-timing-results-buffer)))
-    (set-buffer resultsbuf)
-    (erase-buffer)
-    ;; get the length of the longest function name being profiled
-    (let* ((longest 0)
-           (title "What")
-           (titlelen (length title))
-           (ergoemacs-field-len titlelen)
-           (cc-header "Count")
-           (ergoemacs-cc-len    (length cc-header))
-           (et-header "Elapsed")
-           (ergoemacs-et-len    (length et-header))
-           (at-header "Average")
-           (ergoemacs-at-len    (length at-header))
-           (mn-header "Min")
-           (ergoemacs-mn-len    (length mn-header))
-           (mx-header "Max")
-           (ergoemacs-mx-len    (length mx-header))
-           (resvec '()))
-      (maphash
-       (lambda(key item)
-         (let* ((symname (format "%s" key))
-                (cc (aref item 0))
-                (tt (aref item 1))
-                (mn (aref item 2))
-                (mx (aref item 3))
-                (file (aref item 4)))
-           (setq longest (max longest (length symname)))
-           (push (vector cc tt (if (zerop cc) 0.0
-                                 (/ (float tt) (float cc)))
-                         mn mx symname file)
-                 resvec)))
-       ergoemacs-timing-hash)
-      (setq ergoemacs-field-len (max titlelen longest))
-      (let ((column 0))
-        (setq header-line-format
-              (mapconcat
-               (lambda (title)
-                 (prog1
-                     (concat
-                      (propertize " "
-                                  'display (list 'space :align-to column)
-                                  'face 'fixed-pitch)
-                      title)
-                   (setq column (+ column 2
-                                   (if (= column 0)
-                                       ergoemacs-field-len
-                                     (length title))))))
-               (list title cc-header et-header at-header
-                     mn-header mx-header) "")))
-      ;; if sorting is enabled, then sort the results list. in either
-      ;; case, call ergoemacs-timing-output-result to output the result in the
-      ;; buffer
-      (if ergoemacs-timing-sort-by-function
-          (setq resvec (sort resvec ergoemacs-timing-sort-by-function)))
-      (mapc #'ergoemacs-timing-output-result resvec))
-    ;; now pop up results buffer
-    (set-buffer curbuf)
-    (pop-to-buffer resultsbuf)
-    (goto-char (point-min))))
 
 (provide 'ergoemacs-lib)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el
index 1305dba..cae95e4 100644
--- a/ergoemacs-macros.el
+++ b/ergoemacs-macros.el
@@ -51,551 +51,6 @@ If SYMBOL is void, return nil"
        (ignore-errors (default-value ,symbol))
      (ignore-errors (symbol-value ,symbol))))
 
-;; This shouldn't be called at run-time; This fixes the byte-compile warning.
-(fset 'ergoemacs-theme-component--parse
-      #'(lambda(keys-and-body &optional skip-first)
-          "Parse KEYS-AND-BODY, optionally skipping the name and
-documentation with SKIP-FIRST.
-
-Uses `ergoemacs-theme-component--parse-keys-and-body' and
-  `ergoemacs-theme-component--parse-remaining'."
-          (ergoemacs-theme-component--parse-keys-and-body
-           keys-and-body
-           'ergoemacs-theme-component--parse-remaining
-           skip-first)))
-
-(fset 'ergoemacs-theme-component--parse-key-str
-      #'(lambda (str)
-          "Wraps C-i, C-m and C-[ in <>."
-          (cond
-           ((not (stringp str)) str)
-           ((string-match-p "^\\(?:M-\\|S-\\)*C-\\(?:M-\\|S-\\)*[im[]$" str) 
(concat "<" str ">"))
-           (t str))))
-
-(fset 'ergoemacs-theme-component--parse-key
-      #'(lambda  (item)
-          "Changes `kbd' and `read-kbd-macro' on C-i, C-m, and C-[ to allow 
calling on GUI."
-          (cond
-           ((not (consp item)) item)
-           ((eq (nth 0 item) 'kbd)
-            (list 'kbd (ergoemacs-theme-component--parse-key-str (nth 1 
item))))
-           ((eq (nth 0 item) 'read-kbd-macro)
-            (list 'read-kbd-macro (ergoemacs-theme-component--parse-key-str 
(nth 1 item)) (nth 2 item)))
-           (t item))))
-
-(fset 'ergoemacs-theme-component--parse-fun
-      #'(lambda (fun)
-          "Determine how FUN should be used with 
`ergoemacs-component-struct--define-key'."
-          (let (tmp)
-            (or (and (ergoemacs-keymapp (ergoemacs-sv fun)) `(quote ,fun))
-                (ignore-errors
-                  (and (consp fun)
-                       (stringp (nth 0 fun))
-                       (symbolp (nth 1 fun))
-                       (eq (nth 1 fun) :emacs)
-                       (setq tmp (lookup-key global-map (read-kbd-macro (nth 0 
fun))))
-                       (commandp tmp)
-                       `(quote ,tmp)))
-                (ignore-errors
-                  (and (consp fun)
-                       (eq 'quote (nth 0 fun))
-                       (consp (nth 1 fun))
-                       (stringp (nth 0 (nth 1 fun)))
-                       (symbolp (nth 1 (nth 1 fun)))
-                       (eq (nth 1 (nth 1 fun)) :emacs)
-                       (setq tmp (lookup-key global-map (read-kbd-macro (nth 0 
(nth 1 fun)))))
-                       (commandp tmp)
-                       `(quote ,tmp)))
-                (ignore-errors
-                  (and (consp fun)
-                       (stringp (nth 0 fun))
-                       (symbolp (nth 1 fun))
-                       `(quote ,fun)))
-                fun))))
-
-;;;###autoload
-(defun ergoemacs-theme-component--parse-remaining (remaining)
-  "Parse the REMAINING list, and convert:
-
-- `define-key' is converted to
-  `ergoemacs-component-struct--define-key' and keymaps are quoted.
-
-- `global-set-key' is converted to
-  `ergoemacs-component-struct--define-key' with keymap equal to
-  `global-map'.
-
-- `bind-key' is converted to
-  `ergoemacs-component-struct--define-key'.
-
-- `global-unset-key' is converted to
-  `ergoemacs-component-struct--define-key' with keymap equal to
-  `global-map' and function definition is nil.
-
-- `global-reset-key' is converted
-  `ergoemacs-component-struct--define-key'
-
-- `setq' and `set' is converted to
-  `ergoemacs-component-struct--set'
-
-- `add-hook' and `remove-hook' is converted to
-  `ergoemacs-component-struct--set'
-
-- Mode initialization like (delete-selection-mode 1)
-  or (delete-selection) is converted to
-  `ergoemacs-component-struct--set'
-
-- Allows :version statement expansion to
-  `ergoemacs-component-struct--new-version'
-
-- Adds with-hook syntax or (when -hook) or (when -mode) using
-  `ergoemacs-component-struct--with-hook'
-
-Since `ergoemacs-mode' tries to distinguish return, escape, and
-tab from their ASCII equivalents In the GUI, the following Emacs
-keyboard codes are converted to keys that `ergoemacs-mode' can
-distinguish from the ASCII equivalents:
-
-- C-i (TAB) is changed to <C-i>
-
-- C-m (RET) is changed to <C-m>
-
-- C-[ (ESC)  is changed to <C-]>"
-  (let* ((last-was-version nil)
-         (remaining
-          (mapcar
-           (lambda(elt)
-             (cond
-              (last-was-version
-               (setq last-was-version nil)
-               (if (stringp elt)
-                   `(ergoemacs-component-struct--new-version ,elt)
-                 `(ergoemacs-component-struct--new-version ,(symbol-name 
elt))))
-              ((ignore-errors (eq elt ':version))
-               (setq last-was-version t)
-               nil)
-              ((ignore-errors (eq (nth 0 elt) 'global-reset-key))
-               `(ergoemacs-component-struct--define-key 'global-map 
,(ergoemacs-theme-component--parse-key (nth 1 elt)) nil))
-              ((ignore-errors (eq (nth 0 elt) 'global-unset-key))
-               `(ergoemacs-component-struct--define-key 'global-map 
,(ergoemacs-theme-component--parse-key (nth 1 elt)) nil))
-              ((ignore-errors (eq (nth 0 elt) 'set))
-               ;; Currently doesn't support (setq a b c d ), but it should.
-               `(ergoemacs-component-struct--set ,(nth 1 elt) '(lambda() ,(nth 
2 elt))))
-              ((ignore-errors (eq (nth 0 elt) 'add-hook))
-               `(ergoemacs-component-struct--set ,(nth 1 elt) ,(nth 2 elt)
-                                                 (list t ,(nth 3 elt) ,(nth 4 
elt))))
-              ((ignore-errors (eq (nth 0 elt) 'remove-hook))
-               `(ergoemacs-component-struct--set ,(nth 1 elt) ,(nth 2 elt)
-                                                 (list nil nil ,(nth 3 elt))))
-              ((ignore-errors (memq (nth 0 elt) '(setq setq-default)))
-               ;; in the theme component `setq' is equivalent to
-               ;; `seq-default' since the component uses `set' and 
`set-default'
-               (let ((tmp-elt elt)
-                     (ret '()))
-                 (pop tmp-elt)
-                 (while (and (= 0 (mod (length tmp-elt) 2)) (< 0 (length 
tmp-elt)))
-                   (push `(ergoemacs-component-struct--set (quote ,(pop 
tmp-elt)) '(lambda() ,(pop tmp-elt))) ret))
-                 (push 'progn ret)
-                 ret))
-              ((ignore-errors (string-match "-mode$" (symbol-name (nth 0 
elt))))
-               `(ergoemacs-component-struct--set (quote ,(nth 0 elt)) 
'(lambda() ,(nth 1 elt))))
-              ((ignore-errors (eq (nth 0 elt) 'global-set-key))
-               `(ergoemacs-component-struct--define-key 'global-map 
,(ergoemacs-theme-component--parse-key (nth 1 elt))
-                                                        
,(ergoemacs-theme-component--parse-fun (nth 2 elt))))
-              
-              ;; (bind-key "C-c x" 'my-ctrl-c-x-command)
-              ((ignore-errors (and (eq (nth 0 elt) 'bind-key)
-                                   (= (length elt) 3)))
-               `(ergoemacs-component-struct--define-key 'global-map (kbd 
,(ergoemacs-theme-component--parse-key-str (nth 1 elt)))
-                                                        
,(ergoemacs-theme-component--parse-fun (nth 2 elt))))
-
-              ;; (bind-key "C-c x" 'my-ctrl-c-x-command some-other-map)
-              ((ignore-errors (and (eq (nth 0 elt) 'bind-key)
-                                   (= (length elt) 4)))
-               `(ergoemacs-component-struct--define-key (quote ,(nth 3 elt)) 
(kbd ,(ergoemacs-theme-component--parse-key-str (nth 1 elt)))
-                                                        
,(ergoemacs-theme-component--parse-fun (nth 2 elt))))
-              
-              ((ignore-errors (eq (nth 0 elt) 'define-key))
-               (if (equal (nth 1 elt) '(current-global-map))
-                   `(ergoemacs-component-struct--define-key 'global-map 
,(ergoemacs-theme-component--parse-key (nth 2 elt))
-                                                            
,(ergoemacs-theme-component--parse-fun (nth 3 elt)))
-                 `(ergoemacs-component-struct--define-key (quote ,(nth 1 elt)) 
,(ergoemacs-theme-component--parse-key (nth 2 elt))
-                                                          
,(ergoemacs-theme-component--parse-fun (nth 3 elt)))))
-              ((or (ignore-errors (eq (nth 0 elt) 'with-hook))
-                   (and (ignore-errors (eq (nth 0 elt) 'when))
-                        (ignore-errors (string-match 
"\\(-hook\\|-mode\\|^mark-active\\)$" (symbol-name (nth 1 elt))))))
-               (let ((tmp (ergoemacs-theme-component--parse (cdr (cdr elt)) 
t)))
-                 `(ergoemacs-component-struct--with-hook
-                   ',(nth 1 elt) ',(nth 0 tmp)
-                   '(lambda () ,@(nth 1 tmp)))))
-              ((ignore-errors (memq (nth 0 elt) '(dolist when unless if)))
-               `(,(car elt) ,(car (cdr elt)) ,@(macroexpand-all 
(ergoemacs-theme-component--parse-remaining (cdr (cdr elt))))))
-              ((ignore-errors (memq (nth 0 elt) '(ergoemacs-advice defadvice)))
-               (macroexpand-all elt))
-              (t `(ergoemacs-component-struct--deferred ',elt))))
-           remaining)))
-    remaining))
-
-;;;###autoload
-(defmacro ergoemacs-component (&rest body-and-plist)
-  "A component of an ergoemacs-theme.
-
-This places BODY-AND-PLIST in the `ergoemacs-theme-component'
-macro."
-  (declare (doc-string 2)
-           (indent 2))
-  (macroexpand-all `(ergoemacs-theme-component ,@body-and-plist)))
-
-
-(defvar ergoemacs-theme-component-properties
-  '(:bind
-    :bind-keymap
-    :bind*
-    :bind-keymap*
-    :commands
-    :mode
-    :interpreter
-    :defer
-    :demand
-    :diminish
-    :ensure
-    :package-name
-    :ergoemacs-require
-    :no-load
-    :no-require
-    :just-first-keys
-    :variable-modifiers
-    :variable-prefixes
-    :layout)
-  "List of ergoemacs-theme-component properties.")
-;;;###autoload
-(defmacro ergoemacs-theme-component (&rest body-and-plist)
-  "A component of an ergoemacs-theme.
-
-This macro parses BODY-AND-PLIST to Emacs code to generate an
-`erogemacs-mode' theme component.
-
-This accepts the following keywords:
-
-:bind -- What keys to bind.  This is compatible with use-package
-    definitions.  That is it can take a command like:
-
-    :bind (\"C-.\" . ace-jump-mode)
-
-    or list of commands
-
-    :bind ((\"M-o l\" . highlight-lines-matching-regexp)
-           (\"M-o r\" . highlight-regexp)
-           (\"M-o w\" . highlight-phrase))
-
-    This list of commands can just be a list without the extra
-    parentheses for each command:
-
-    :bind (\"M-o l\" . highlight-lines-matching-regexp
-           \"M-o r\" . highlight-regexp
-           \"M-o w\" . highlight-phrase)
-
-
-    Note that these keys may change based on keyboard layouts,
-    and also these keys can accept special ergoemacs-commands and
-    keymaps (unlike use-package).
-
-    When package-name is non-nil, create autoloads for undefined commands.
-
-    Default: nil
-
-:bind-keymap -- A keymap to bind.  Similar to :bind but used for
-    keymaps.  This is processed before :bind keywords.  While
-    this is necessary for use-package, it is not necessary for
-    `ergoemacs-mode'.  However, this keyword is provided for convenience. 
-
-    Default: nil
-
-:bind* -- Keys to bind above minor modes (in
-  `ergoemacs-override-keymap').
-
-   Default: nil
-
-:bind-keymap* -- Keymap to bind above minor modes (in
-   `ergoemacs-override-keymap').
-
-    Default: nil
-
-:commands -- List of commands to create autoloads for.  This can
-    take a command like:
-
-    :commands ace-jump-mode
-
-    Or
-
-    :commands (isearch-moccur isearch-all)
-
-    When :package-name is non-nil, this will create autoloads for
-    the commands.
-
-:defer -- Should this package's loading be deferred?
-    When using :commands :bind :bind* :bind-keymap :bind-keymap*
-   :mode or :interperter, defer is implied.  When :package-name
-   is nil, this dosen't do anything.
-
-:demand -- Prevent deferred loading in all cases
-
-:diminish -- Diminish this mode.  It can be of the following forms:
-
-    :diminish t -- Assumes that :package-name is diminshed
-    :diminish package-name -- Diminshes package-name
-    :diminish (package-name \" New Description\")
-    :diminish (package-name \" unicode\" \" str\")
-
-    For more information, see `ergoemacs-component--diminish-on'.
-
-    By default this is nil.
-
-:mode -- Modes to be added to `auto-mode-alist'. This can be a string such as:
-
-(ergoemacs-package ruby-mode
-    :mode \"\\\\.rb\\\\'\")
-
-or a list 
-
-(ergoemacs-package ruby-mode
-    :mode (\"\\\\.rb\\\\'\" . ruby-mode))
-
-or a list of modes:
-
-(ergoemacs-package ess-site
-    :ensure ess
-    :mode ((\"\\\\.R\\\\'\" . R.mode)
-           (\"\\\\.[Ss][Aa][Ss]\\\\'\" . SAS-mode)))
-
-Borrowed from `use-package'.
-
-:ensure -- If the package should be installed by `package' if not present.
-
-This can be t to install the :package-name symbol.  Otherwise
-it can be a list of symbols or single symbol.
-
-:package-name -- Name of package to load.  When non-nil any key
-defition to a single command will create an autoload for that
-command.
-
-Default: nil
-
-:no-load / :no-require -- Don't load/require the package-name.
-
-:ergoemacs-require -- when non-nil, this ergoemacs-component is
-required with `ergoemacs-require'. By default this is disabled
-
-:just-first-keys -- Keys where a fixed amount of the key is based
-on variable keyboard placement, then the rest of the key is
-based on letter.  For example with the apps component, the
-just first keys are defined to be [apps ?h], which means the
-[apps h] will be defined based on finger placement, but the
-keys afterward would be based on letter.
-
-By default this is defined as nil, meaning no special keys
-like this occur.
-
-:just-first-keys (list [apps ?h] [menu ?h])
-Defaults to nil
-
-:variable-modifiers -- Modifiers that are considierd variable.
-These modifiers have keys change among various keyboard
-layouts.  That is keys are bound based on finger placement
-among various keyboard layouts.
-
-Defaults to '(meta)
-
-:variable-prefixes -- Keyboard prefixes that are considiered
-variable.  After these keys are pressed, the keyboard layout
-dictates the keys.  That is, keys are bound based on finger
-placement among various keyboard layouts.
-
-Defaults to '([apps] [menu] [27])
-
-:layout -- Layout that the key bindings are based on.
-
-Defaults to us (QWERTY)
-
-Please do not use the following tags, since they are parsed based
-on the definition:
-
-:name -- Component Name
-
-:description -- Component Description
-
-:file -- File where the component was defined."
-  (declare (doc-string 2)
-           (indent 2))
-  (let ((kb (make-symbol "body-and-plist")))
-    (setq kb (ergoemacs-theme-component--parse body-and-plist))
-    `(let ((plist ',(nth 0 kb))
-           (fun '(lambda () ,@(nth 1 kb))))
-       (unless (boundp 'ergoemacs-component-hash)
-         (defvar ergoemacs-component-hash (make-hash-table :test 'equal)
-           "Hash of ergoemacs theme components"))
-       (defvar ergoemacs-mode-reset)
-       (setq ergoemacs-mode-reset t)
-       (puthash ,(plist-get (nth 0 kb) :name)
-                `(lambda() ,(plist-get plist :description)
-                  (ergoemacs-component-struct--create-component
-                   ',plist ',fun ,(or load-file-name buffer-file-name)))
-                ergoemacs-component-hash)
-       ,(when (plist-get (nth 0 kb) :ergoemacs-require)
-          `(ergoemacs-require ',(intern (plist-get (nth 0 kb) :name)))))))
-
-(defmacro ergoemacs-package (name &rest keys-and-body)
-  "Defines a required package named NAME.
-
-KEYS-AND-BODY will be processed by
-`ergoemacs-theme-component--parse-keys-and-body'.
-
-The documentation of the supported keys are in
-`ergoemacs-theme-component'.
-
-The NAME will be assumed to be the :package-name keyword.
-
-By default, this package also set the :ergoemacs-require to t,
-requiring the ergoemacs theme component immediately.  To turn off
-this feature, you can specify :ergoemacs-require nil in the body
-of the `ergoemacs-package' macro.  Another option is to use
-`ergoemacs-autoload', which is the same as `ergoemacs-package'
-with :ergoemacs-require set to nil."
-  (declare (indent 2))
-  (let ((kb (make-symbol "body-and-plist"))
-        (plist (make-symbol "plist"))
-        (body (make-symbol "body"))
-        (doc (make-symbol "doc")))
-    (setq kb (ergoemacs-theme-component--parse-keys-and-body keys-and-body  
nil t)
-          plist (nth 0 kb)
-          body (nth 1 kb))
-    (when (equal (car body) '())
-      (setq body (cdr body)))
-    (setq doc (if (stringp (car body)) (pop body) (symbol-name name)))
-    (unless (memq :ergoemacs-require plist) ;; Its a required theme component.
-      (setq plist (plist-put plist :ergoemacs-require name)))
-    (unless (plist-get plist :package-name)
-      (setq plist (plist-put plist :package-name name)))
-    (macroexpand-all
-     `(ergoemacs-theme-component ,name ()
-        ,doc
-        ,@plist
-        ;; (require ',name)
-        ,@body))))
-
-(defmacro ergoemacs-autoload (name &rest keys-and-body)
-  "Defines a required package named NAME.
-
-KEYS-AND-BODY will be processed by
-`ergoemacs-theme-component--parse-keys-and-body'.
-
-The documentation of the supported keys are in
-`ergoemacs-theme-component'.
-
-The NAME will be assumed to be the :package-name keyword.
-
-By default, this package also set the :ergoemacs-require to nil,
-deferring the ergoemacs theme component until it is required by
-the user by either `ergoemacs-require' or turning it on/off in an
-ergoemacs-mode theme.  To turn off this feature, you can
-specify :ergoemacs-require t in the body of the
-`ergoemacs-autoload' macro.  Another option is to use
-`ergoemacs-package', which is the same as `ergoemacs-autoload'
-with :ergoemacs-require set to t."
-  (declare (indent 2))
-  (let ((kb (make-symbol "body-and-plist"))
-        (plist (make-symbol "plist"))
-        (body (make-symbol "body"))
-        (doc (make-symbol "doc")))
-    (setq kb (ergoemacs-theme-component--parse-keys-and-body keys-and-body  
nil t)
-          plist (nth 0 kb)
-          body (nth 1 kb))
-    (when (equal (car body) '())
-      (setq body (cdr body)))
-    (setq doc (if (stringp (car body)) (pop body) (symbol-name name)))
-    (unless (plist-get plist :package-name)
-      (setq plist (plist-put plist :package-name name)))
-    (macroexpand-all
-     `(ergoemacs-theme-component ,name ()
-        ,doc
-        ,@plist
-        ,@body))))
-
-;;;###autoload
-(defmacro ergoemacs-test-layout (&rest keys-and-body)
-  (let ((kb (make-symbol "body-and-plist"))
-        (plist (make-symbol "plist"))
-        (body (make-symbol "body")))
-    (setq kb (ergoemacs-theme-component--parse-keys-and-body keys-and-body  
nil t)
-          plist (nth 0 kb)
-          body (nth 1 kb))
-    (macroexpand-all
-     `(let ((old-ergoemacs-theme (ergoemacs :current-theme))
-            (old-type ergoemacs-command-loop-type)
-            (old-paste interprogram-paste-function)
-            (old-cut interprogram-cut-function)
-            ;; (old-kill kill-ring)
-            ;; (old-pointer kill-ring-yank-pointer)
-            (old-version (ergoemacs :current-version))
-            (macro
-             ,(if (plist-get plist :macro)
-                  `(edmacro-parse-keys ,(plist-get plist :macro) t)))
-            (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-            (reset-ergoemacs nil))
-        (setq ergoemacs-theme ,(plist-get plist ':current-theme)
-              ergoemacs-keyboard-layout ,(or (plist-get plist ':layout) "us")
-              ergoemacs-command-loop-type nil
-              interprogram-paste-function nil
-              interprogram-cut-function nil
-              ;; kill-ring nil
-              ;; kill-ring-yank-pointer nil
-              
-              ;; Make sure the copy functions don't think the last
-              ;; command was a copy.
-              last-command 'ergoemacs-test)
-        (ergoemacs-theme-set-version ,(or (plist-get plist ':version) nil))
-        (unless (and (equal old-ergoemacs-theme ergoemacs-theme)
-                     (equal old-ergoemacs-keyboard-layout 
ergoemacs-keyboard-layout)
-                     (equal old-version (ergoemacs :current-vresion)))
-          (setq reset-ergoemacs t)
-          (ergoemacs-mode-reset))
-        
-        ,(if (plist-get plist :cua)
-             `(cua-mode 1))
-        (unwind-protect
-            (progn
-              ,@body)
-          (setq ergoemacs-command-loop-type old-type
-                ergoemacs-theme old-ergoemacs-theme
-                ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout
-                interprogram-paste-function old-paste
-                interprogram-cut-function old-cut
-                ;; kill-ring old-kill
-                ;; kill-ring-yank-pointer old-pointer
-                )
-          (ergoemacs-theme-set-version old-version)
-          (when reset-ergoemacs
-            (ergoemacs-mode-reset)))))))
-
-(defvar ergoemacs-theme-components--modified-plist nil
-  "Modified plist.")
-
-(fset 'ergoemacs-theme-component--add-ensure
-      #'(lambda (plist pkg)
-          "Add PKG to the :ensure keyword."
-          (let ((cur-ensure (plist-get plist :ensure))
-                (cur-pkg (intern (format "%s" (plist-get plist 
:package-name)))))
-            (cond
-             ((eq cur-ensure t)
-              (setq ergoemacs-theme-components--modified-plist
-                    (plist-put plist :ensure (list pkg cur-pkg))))
-             ((not cur-ensure)
-              (setq ergoemacs-theme-components--modified-plist
-                    (plist-put plist :ensure pkg)))
-             ((not (memq pkg cur-ensure))
-              (push pkg cur-ensure)
-              (setq ergoemacs-theme-components--modified-plist
-                    (plist-put plist :ensure cur-ensure)))))))
-
 (fset 'ergoemacs-theme-component--parse-keys-and-body
       #'(lambda (keys-and-body &optional parse-function  skip-first)
           "Split KEYS-AND-BODY into keyword-and-value pairs and the remaining 
body.
@@ -646,126 +101,6 @@ additional parsing routines defined by PARSE-FUNCTION."
             (list plist remaining))))
 
 ;;;###autoload
-(defmacro ergoemacs-theme (&rest body-and-plist)
-  "Define an ergoemacs-theme.
-
-This macro parses BODY-AND-PLIST into an `ergoemacs-mode' theme.
-
-- :components -- list of components that this theme uses.  These
-  can't be seen or toggled.
-
-- :optional-on -- list of components that are optional and are on
-  by default
-
-- :optional-off -- list of components that are optional and off
-  by default
-
-- :options-menu -- Menu options list
-
-- :silent -- If this theme is \"silent\", i.e. doesn't show up in
-  the Themes menu.
-
-- :based-on -- what `ergoemacs-mode' theme this is based on.
-
-The rest of the body is an `ergoemacs-theme-component' named
- THEME-NAME-theme."
-  (declare (doc-string 2)
-           (indent 2))
-  (let ((kb (make-symbol "body-and-plist"))
-        (tmp (make-symbol "tmp"))
-        (based-on (make-symbol "based-on")))
-    (setq kb (ergoemacs-theme-component--parse-keys-and-body body-and-plist))
-    (setq tmp (eval (plist-get (nth 0 kb) :components)))
-    (push (intern (concat (plist-get (nth 0 kb) :name) "-theme")) tmp)
-    (setq tmp (plist-put (nth 0 kb) :components tmp))
-    (setq based-on (plist-get (nth 0 kb) :based-on))
-    ;; (message "First Based-On: %s" based-on)
-    (setq based-on (or (and (stringp based-on) based-on)
-                       (and (symbolp based-on) (symbol-name based-on))
-                       (and (eq (car based-on) 'quote) (symbol-name (car (cdr 
based-on))))
-                       nil))
-    ;; (message "Last Based-On: %s" based-on)
-    (dolist (comp '(:optional-on :optional-off :options-menu))
-      (setq tmp (plist-put (nth 0 kb) comp
-                           (eval (plist-get (nth 0 kb) comp)))))
-    (macroexpand-all
-     `(let* ((based-on (ergoemacs-gethash ,based-on ergoemacs-theme-hash))
-             (curr-plist ',tmp)
-             (opt-on (plist-get curr-plist ':optional-on))
-             (opt-off (plist-get curr-plist ':optional-off))
-             (comp (plist-get curr-plist ':components))
-             (themes (ergoemacs-gethash "defined-themes" ergoemacs-theme-hash))
-             (silent (ergoemacs-gethash "silent-themes" ergoemacs-theme-hash))
-             (included (append opt-on opt-off comp))
-             (file (or load-file-name (buffer-file-name)))
-             (mod (list file (and (stringp file) (nth 5 (file-attributes 
file))))))
-        (when (not (boundp 'ergoemacs--component-file-mod-time-list))
-          (setq ergoemacs--component-file-mod-time-list nil))
-        (push ,(plist-get (nth 0 kb) :name) themes)
-        (push ,(plist-get (nth 0 kb) :name) silent)
-        (setq curr-plist (plist-put curr-plist :file file))
-        (unless (member mod ergoemacs--component-file-mod-time-list)
-          (push mod ergoemacs--component-file-mod-time-list))
-        (if (not based-on)
-            (puthash ,(plist-get (nth 0 kb) ':name) curr-plist 
ergoemacs-theme-hash)
-          (dolist (type '(:optional-on :optional-off :components))
-            (dolist (comp (plist-get based-on type))
-              (unless (memq comp included)
-                (setq curr-plist
-                      (plist-put curr-plist type
-                                 (append (plist-get curr-plist type)
-                                         (list comp)))))))
-          (when (and (not (plist-get curr-plist :options-menu))
-                     (plist-get based-on :options-menu))
-            (setq curr-plist
-                  (plist-put curr-plist :options-menu
-                             (plist-get based-on :options-menu))))
-          (puthash ,(plist-get (nth 0 kb) :name) curr-plist
-                   ergoemacs-theme-hash))
-        (if ,(plist-get (nth 0 kb) :silent)
-            (puthash "silent-themes" silent ergoemacs-theme-hash)
-          (puthash "defined-themes" themes ergoemacs-theme-hash))
-        (ergoemacs-theme-component ,(intern (concat (plist-get (nth 0 kb) 
:name) "-theme")) ()
-          ,(format "Generated theme component for %s theme" (plist-get (nth 0 
kb) :name))
-          ,@(nth 1 kb))))))
-
-;;;###autoload
-(defmacro ergoemacs-deftheme (name desc based-on &rest differences)
-  "Create theme layout for `ergoemacs-mode' key-bindings.
-
-This is compatibility layer.
-
-- NAME is the theme name.
-
-- DESC is the theme description
-
-- BASED-ON is the base name theme that the new theme is based on.
-
-- DIFFERENCES are the differences from the layout based on the
-  functions.  These are based on the following functions:
-
-- `ergoemacs-key' = defines/replaces variable key with function
-  by (ergoemacs-key QWERTY-KEY FUNCTION DESCRIPTION ONLY-FIRST)
-
-- `ergoemacs-fixed-key' = defines/replace fixed key with function
-   by (ergoemacs-fixed-key KEY FUNCTION DESCRIPTION)."
-  (declare (indent 1))
-  (macroexpand-all
-   `(let (silent pl tmp)
-      (setq pl (ergoemacs-gethash (or ,based-on "standard") 
ergoemacs-theme-hash))
-      (plist-put pl ':name ,(symbol-name name))
-      (setq tmp (plist-get pl ':components))
-      (push (intern (concat ,(symbol-name name) "-theme")) tmp)
-      (setq tmp (plist-put pl ':components tmp))
-      (setq silent (ergoemacs-gethash "silent-themes" ergoemacs-theme-hash))
-      (push ,(symbol-name name) silent)
-      (puthash "silent-themes" silent ergoemacs-theme-hash)
-      (puthash ,(symbol-name name) tmp ergoemacs-theme-hash)
-      (ergoemacs-theme-component ,(intern (concat (symbol-name name) 
"-theme")) ()
-        ,(or desc (format "Generated theme component for %s theme" 
(symbol-name name)))
-        ,@differences))))
-
-;;;###autoload
 (defmacro ergoemacs-save-buffer-state (&rest body)
   "Eval BODY,
 then restore the buffer state under the assumption that no significant
@@ -842,8 +177,6 @@ functions.")
 
 When arg1 can be a property.  The following properties are supported:
 - :layout - returns the current (or specified by PROPERTY) keyboard layout.
-- :remap - Use `ergoemacs-mode' to remap to an appropriate function.
-- :md5 -- returns an md5 of the currently enabled `ergoemacs-mode' options.
 - :map-list,  :composed-p, :composed-list, :key-hash :empty-p calls 
ergoemacs-map-properties-- equivalent functions.
 
 "
@@ -852,39 +185,7 @@ When arg1 can be a property.  The following properties are 
supported:
         (arg3 (nth 2 args))
         (arg4 (nth 3 args)))
     (cond
-     ((eq arg1 :w32-long-file-name)
-      (if (fboundp 'w32-long-file-name)
-          `(w32-long-file-name ,@(cdr args))
-        `nil))
-     ((eq arg1 :w32-shell-open-files)
-      (if (fboundp 'w32-shell-execute)
-          `(dolist (f-path ,@(cdr args))
-             (w32-shell-execute
-              "open" (replace-regexp-in-string "/" "\\" f-path t t)))
-        `nil))
-     ((eq arg1 :w32-shell-execute)
-      (if (fboundp 'w32-shell-execute)
-          `(w32-shell-execute ,@(cdr args))
-        `nil))
-     ((eq arg1 :reset-prefix)
-      (if (<= 25 emacs-major-version)
-         `(prefix-command-preserve-state)
-       `(reset-this-command-lengths)))
-     ((eq arg1 :set-selection)
-      (if (<= 25 emacs-major-version)
-          `(gui-set-selection ,@(cdr args))
-        `(x-set-selection ,@(cdr args))))
-     ((eq arg1 :width)
-      `(ergoemacs-mode--eval-width ,arg2))
-     ((and arg1 (symbolp arg1) (eq arg1 :mode-if) arg2)
-      `(ergoemacs-mode-line--if ,arg2 ,arg3 ,arg4))
-     ((and arg1 (symbolp arg1) (memq arg1 '(:sep :separator)))
-      `(ergoemacs-mode-line--sep ,@(cdr args)))
-     ((and arg1 (symbolp arg1) (memq arg1 '(:sep-right :separator-right)))
-      `(ergoemacs-mode-line--sep 'right ,@(cdr args)))
-     ((and arg1 (symbolp arg1) (memq arg1 '(:sep-left :separator-left)))
-      `(ergoemacs-mode-line--sep 'left ,@(cdr args)))
-     ((eq arg1 :custom-p) (symbolp arg2)
+     ((and arg1 (symbolp arg1) (eq arg1 :custom-p) (symbolp arg2))
       (if (fboundp 'custom-variable-p)
           `(custom-variable-p ,arg2)
         `(user-variable-p ,arg2)))
@@ -900,39 +201,14 @@ When arg1 can be a property.  The following properties 
are supported:
       `(ergoemacs-map-properties--before-ergoemacs))
      ((eq arg1 :user-after) (not arg2) (not arg3)
       `(ergoemacs-map-properties--before-ergoemacs t))
-     ((eq arg1 :modal-p)
-      `(ergoemacs-command-loop--modal-p))
      ((and arg1 (symbolp arg1) (eq arg1 :combine) arg2 arg3)
       `(ergoemacs-command-loop--combine ,arg2 ,arg3))
-     ((and arg1 (symbolp arg1) (memq arg1 '(:unicode-or-alt :unicode)))
-      `(ergoemacs-key-description--unicode-char ,@(cdr args)))
      ((and arg1 (symbolp arg1) (eq arg1 :modifier-desc)
            arg2)
       `(mapconcat #'ergoemacs-key-description--modifier ,arg2 ""))
-     ((eq arg1 :current-version)
-      `(ergoemacs-theme--get-version))
-     ((eq arg1 :current-theme)
-      `(or (and ergoemacs-theme (stringp ergoemacs-theme) ergoemacs-theme)
-           (and ergoemacs-theme (symbolp ergoemacs-theme) (symbol-name 
ergoemacs-theme))
-           "standard"))
      ((and arg1 (symbolp arg1)
            (memq arg1 ergoemacs--map-properties-list))
       `(,(intern (format "ergoemacs-map-properties--%s" (substring 
(symbol-name arg1) 1))) ,@(cdr args)))
-
-     ((and arg1 arg2 (eq arg2 :new-command) arg3)
-      ;; (ergoemacs arg1 :new-command 'next-line)
-      `(ergoemacs-map-properties--new-command ,arg1 ,arg3))
-     ((and arg1 (symbolp arg1)
-           (eq arg1 :global-map))
-      `(ergoemacs-map-properties--original (or ergoemacs-saved-global-map 
global-map)))
-     ((and arg1 (symbolp arg1)
-           (eq arg1 :revert-global-map))
-      `(ergoemacs-map-properties--original (or ergoemacs-saved-global-map 
global-map) :setcdr))
-     ((and arg1 (symbolp arg1)
-           (eq arg1 :remap) arg2)
-      `(progn
-         (setq this-command (or (key-binding (vector 'ergoemacs-remap ,arg2) t 
nil (point)) ,arg2))
-         (call-interactively (or (key-binding (vector 'ergoemacs-remap ,arg2) 
t nil (point)) ,arg2))))
      ((and arg1 (symbolp arg1)
            (eq arg1 :layout))
       `(ergoemacs-layouts--current ,arg2))
@@ -968,13 +244,45 @@ When arg1 can be a property.  The following properties 
are supported:
       `(ergoemacs-map--minor-mode-overriding-map-alist ,arg2))
      ((and (not arg3) (eq arg1 'minor-mode-map-alist))
       `(ergoemacs-map--minor-mode-map-alist ,arg2))
-     (t
-      `(ergoemacs-map-- ,arg1)))))
+     )
+    )
+  )
+
+(defmacro ergoemacs-cache (item &rest body)
+  "Either read ITEM's cache or evaluate BODY, cache ITEM and return value."
+  (declare (indent 1))
+  (or (and (symbolp item)
+           (macroexpand-all
+            `(progn
+               (or (ergoemacs-map--cache-- ',item)
+                   (ergoemacs-map--cache--
+                    ',item (progn ,@body))))))
+      (macroexpand-all
+       `(let ((--hash-key ,item))
+          (or (ergoemacs-map--cache-- --hash-key)
+              (ergoemacs-map--cache-- --hash-key (progn ,@body)))))))
+
+(defmacro ergoemacs-no-specials (&rest body)
+  "Revert some `ergoemacs-mode' function  s to their C defintions in BODY."
+  `(cl-letf (((symbol-function 'read-key-sequence) 
#'ergoemacs--real-read-key-sequence)
+            ((symbol-function 'describe-key) #'ergoemacs--real-describe-key))
+     ,@body))
+
+(defmacro ergoemacs-autoloadp (object)
+  "Non-nil if OBJECT is an autoload."
+  (cond
+   ((fboundp #'autoloadp) `(autoloadp ,object))
+   (t `(eq 'autoload (car-safe ,object)))))
+
+(defmacro ergoemacs-buffer-narrowed-p ()
+  "Return non-nil if the current buffer is narrowed."
+  (cond
+   ((fboundp #'buffer-narrowed-p) `(buffer-narrowed-p))
+   (t `(/= (- (point-max) (point-min)) (buffer-size)))))
 
 ;;;###autoload
 (defmacro ergoemacs-translation (&rest body-and-plist)
   "Defines an `ergoemacs-mode' translation.
-
 :text -- Text to display while completing this translation
 :keymap -- Local Keymap for translation
 :keymap-modal -- Modal keymap for overrides.
@@ -990,7 +298,6 @@ The following arguments allow the keyboard presses to be 
translated:
  - :control-shift
  - :meta-control-shift
  - :unchorded (no modifiers)
-
 This also creates functions:
 - ergoemacs-translate--NAME-universal-argument
 - ergoemacs-translate--NAME-digit-argument
@@ -1006,7 +313,6 @@ This also creates functions:
                        (ergoemacs-translate--create :key ,(intern (concat ":" 
(plist-get (nth 0 kb) ':name)))
                                                     ,@(nth 0 kb))) 
ergoemacs-translation-hash))))
 
-;;;###autoload
 (defmacro ergoemacs-advice (function args &rest body-and-plist)
   "Defines an `ergoemacs-mode' advice.
 
@@ -1058,59 +364,13 @@ When :type is :replace that replaces a function (like 
`define-key')"
                                `(push ',function 
ergoemacs-advice--permanent-replace-functions)
                              `(push ',function 
ergoemacs-advice--temp-replace-functions))))))))
 
-(defmacro ergoemacs-cache (item &rest body)
-  "Either read ITEM's cache or evaluate BODY, cache ITEM and return value."
-  (declare (indent 1))
-  (or (and (symbolp item)
-           (macroexpand-all
-            `(progn
-               (or (ergoemacs-map--cache-- ',item)
-                   (ergoemacs-map--cache--
-                    ',item (progn ,@body))))))
-      (macroexpand-all
-       `(let ((--hash-key ,item))
-          (or (ergoemacs-map--cache-- --hash-key)
-              (ergoemacs-map--cache-- --hash-key (progn ,@body)))))))
-
-(defmacro ergoemacs-cache-p (item)
-  "Does ITEM cache exist?"
-  (or (and (symbolp item)
-           (macroexpand-all
-            `(ergoemacs-map-cache--exists-p ',item)))
-      (macroexpand-all
-       `(let ((--hash-key ,item))
-          (ergoemacs-map-cache--exists-p --hash-key)))))
-
-(defmacro ergoemacs-timing (key &rest body)
-  "Save the timing using KEY for BODY."
-  (declare (indent 1))
-  (if (listp key)
-      `(ergoemacs-timing-- ,key (lambda() ,@body))
-    `(ergoemacs-timing-- ',key (lambda() ,@body))))
 
-(defmacro ergoemacs-no-specials (&rest body)
-  "Revert some `ergoemacs-mode' functions to their C defintions in BODY."
-  `(cl-letf (((symbol-function 'read-key-sequence) 
#'ergoemacs--real-read-key-sequence)
-            ((symbol-function 'describe-key) #'ergoemacs--real-describe-key))
-     ,@body))
-
-(defmacro ergoemacs-specials (&rest body)
-  "Use `ergoemacs-mode' special functions in BODY."
-  `(cl-letf (((symbol-function 'read-key-sequence) 
#'ergoemacs-command-loop--read-key-sequence)
-            ((symbol-function 'key-description) #'ergoemacs-key-description))
-     ,@body))
-
-(defmacro ergoemacs-autoloadp (object)
-  "Non-nil if OBJECT is an autoload."
-  (cond
-   ((fboundp #'autoloadp) `(autoloadp ,object))
-   (t `(eq 'autoload (car-safe ,object)))))
-
-(defmacro ergoemacs-buffer-narrowed-p ()
-  "Return non-nil if the current buffer is narrowed."
-  (cond
-   ((fboundp #'buffer-narrowed-p) `(buffer-narrowed-p))
-   (t `(/= (- (point-max) (point-min)) (buffer-size)))))
+(defmacro ergoemacs-save-key-state (keymap-symbol &rest body)
+  "Save keys in KEYMAP-SYMBOL, eval BODY."
+  `(progn
+     (ergoemacs-mode--save-map ,keymap-symbol)
+     ,@body
+     (ergoemacs-mode--save-map ,keymap-symbol t)))
 
 (provide 'ergoemacs-macros)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/ergoemacs-map-properties.el b/ergoemacs-map-properties.el
index bee84a5..6a2cc69 100644
--- a/ergoemacs-map-properties.el
+++ b/ergoemacs-map-properties.el
@@ -35,1166 +35,6 @@
 (eval-when-compile
   (require 'ergoemacs-macros))
 
-(require 'package)
-
-(defvar ergoemacs-translate--parent-map)
-(defvar ergoemacs-translate--modal-parent-map)
-(defvar ergoemacs--gzip)
-(defvar ergoemacs-map-keymap--load-autoloads-p)
-(defvar ergoemacs--original-local-map)
-(defvar ergoemacs--system)
-(defvar ergoemacs-breadcrumb-hash)
-(defvar ergoemacs-dir)
-(defvar ergoemacs-directories-where-keys-from-hook-are-deferred)
-(defvar ergoemacs-functions-that-always-override-ergoemacs-mode)
-(defvar ergoemacs-hooks-that-always-override-ergoemacs-mode)
-(defvar ergoemacs-ignore-prev-global)
-(defvar ergoemacs-map--breadcrumb)
-(defvar ergoemacs-map-properties--after-ergoemacs)
-(defvar ergoemacs-map-properties--before-ergoemacs)
-(defvar ergoemacs-map-properties--get-or-generate-map-key)
-(defvar ergoemacs-map-properties--indirect-keymaps)
-(defvar ergoemacs-map-properties--key-struct)
-(defvar ergoemacs-map-properties--plist-hash)
-(defvar ergoemacs-mode--fast-p)
-(defvar ergoemacs-remap-ignore)
-(defvar ergoemacs-saved-global-map)
-(defvar ergoemacs-map-properties--label-atoms-maps)
-(defvar icicle-search-key-prefix)
-(defvar icicle-search-map)
-
-(declare-function ergoemacs-command-loop--spinner-display 
"ergoemacs-command-loop")
-(declare-function ergoemacs-timing-- "ergoemacs-mode")
-
-(declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
-(declare-function ergoemacs-emacs-exe "ergoemacs-functions")
-(declare-function ergoemacs-setcdr "ergoemacs-lib")
-(declare-function ergoemacs-warn "ergoemacs-lib")
-
-(declare-function ergoemacs-translate--define-key "ergoemacs-translate")
-(declare-function ergoemacs-translate--escape-to-meta "ergoemacs-translate")
-(declare-function ergoemacs-key-description "ergoemacs-key-description")
-
-(declare-function icicle-remap "icicles-opt")
-
-(defun ergoemacs-map-properties--keymap-value (keymap)
-  "Return the keymap value of KEYMAP.
-KEYMAP can be a symbol, keymap or ergoemacs-mode keymap"
-  (let (tmp)
-    (or (and (integerp keymap) keymap)
-        (and (listp keymap) (ergoemacs-keymapp keymap) keymap)
-        (and (symbolp keymap) (ergoemacs-keymapp (setq tmp (symbol-value 
keymap))) tmp)
-        (and (symbolp keymap) (ergoemacs-keymapp (setq tmp (symbol-function 
keymap))) tmp)
-        ;; (ignore-errors (and (setq tmp (ergoemacs-gethash keymap 
ergoemacs-map-properties--plist-hash))
-        ;;                     (setq tmp (ergoemacs-gethash :map-list tmp))
-        ;;                     (symbol-value (car tmp))))
-        ;; (ignore-errors (and (setq tmp (plist-get keymap :map-list)) 
(symbol-value (nth 0 tmp))))
-        )))
-
-(defun ergoemacs-map-properties--composed-p (keymap)
-  "Determine if the KEYMAP is a composed keymap."
-  (and (ergoemacs-keymapp keymap)
-       (ignore-errors (eq 'keymap (car keymap)))
-       (ignore-errors (eq 'keymap (cl-caadr keymap)))))
-
-;; FIXME: Write test or function
-(defun ergoemacs-map-properties--all-sparse-p (keymap)
-  "Determines if all components of a KEYMAP are sparse keymaps.
-This does not include submaps, which may also be a full keymap."
-  (if (not (ergoemacs-keymapp keymap)) t
-    (let ((ret t)
-          (kv (ergoemacs-map-properties--keymap-value keymap)))
-      (cond
-       ((ergoemacs-map-properties--composed-p kv)
-        (setq ret
-              (catch 'found-full
-                (dolist (map (ergoemacs keymap :composed-list))
-                  (when (ergoemacs-keymapp map)
-                    (unless (ergoemacs-map-properties--all-sparse-p map)
-                      (throw 'found-full nil)))) t)))
-       (t
-        (setq ret (not (ignore-errors (char-table-p (nth 1 kv)))))))
-      (when ret
-        (setq ret (ergoemacs-map-properties--all-sparse-p (keymap-parent 
keymap))))
-      ret)))
-
-(defun ergoemacs-map-properties--composed-list (keymap &optional melt label)
-  "Return the list of maps in a composed KEYMAP.
-If there are no maps, return nil.
-
-When MELT is true, combine all the keymaps (with the exception of
-the parent-map).
-
-When LABEL is non-nil, label the keymap."
-  (if (not (ergoemacs-map-properties--composed-p keymap)) nil
-    (let ((parent (keymap-parent keymap))
-          ret)
-      (unwind-protect
-          (progn
-            (when parent
-              (set-keymap-parent keymap nil))
-            (dolist (map (reverse (cdr keymap)))
-              (when label
-                (ergoemacs :label map))
-              (if (consp map)
-                  (if melt
-                      (setq ret (append (cdr map) ret))
-                    (push (cons (car map) (cdr map)) ret))
-                (push map ret))))
-        (when parent
-          (set-keymap-parent keymap parent))
-        (when melt
-          (setq ret (append '(keymap) ret))))
-      ret)))
-
-(defun ergoemacs-map-properties--composed (keymap &optional force)
-  "Return a list of `ergoemacs-mode' map-keys for the composed KEYMAP list.
-
-When FORCE is non-nil, force the abiity to get map-keys by assigning them."
-  (let ((composed-list (ergoemacs-map-properties--composed-list keymap nil 
force)))
-    (and composed-list
-         (catch 'not-bound
-           (mapcar
-            (lambda(comp)
-              (when (ergoemacs-keymapp comp)
-                (let ((ret (ergoemacs-map-properties--key-struct comp)))
-                  (when (and (not force) (not ret))
-                    (throw 'not-bound nil))
-                  ret))) composed-list)))))
-
-
-(defun ergoemacs-map-properties--key-struct (keymap &optional force)
-  "Return the maps linked to the current KEYMAP.
-
-This only works if the KEYMAP is  an `ergoemacs-mode' map.
-
-:map-key is the key of the current map.
-
-:composed is a list of the `ergoemacs-map-properties--key-struct'
-  of each of the composed maps.
-
-:parent is the `ergoemacs-map-properties--key-struct' of the
-  current map.
-
-This will return the keymap structure prior to `ergoemacs-mode' modifications.
-
-When FORCE is non-nil, make sure the keymaps have `ergoemacs-mode' labels."
-  ;;|-----------+------------+--------------+--------------|
-  ;;| Condition | Call Count | Elapsed Time | Average Time |
-  ;;|-----------+------------+--------------+--------------|
-  ;;| Pre Hash  |     237982 | 100.52800000 | 0.0004224185 |
-  ;;| Post Hash |     150045 | 40.600999999 | 0.0002705921 |
-  ;;|-----------+------------+--------------+--------------|
-  (let* ((keymap (ergoemacs-map-properties--keymap-value keymap))
-         (map-key (ergoemacs keymap :map-key))
-         (composed (ergoemacs-map-properties--composed keymap force))
-         parent
-         (hash-key (or (and (not composed) (integerp map-key) map-key)
-                       (and composed (not (consp map-key)) (cdr keymap))))
-         (ret (or (and (consp map-key) (car map-key))
-                  (and hash-key (ergoemacs-gethash hash-key 
ergoemacs-map-properties--key-struct)))))
-    (unless ret
-      (when (and force (not (or map-key composed)))
-        (ergoemacs :label keymap)
-        (setq map-key (ergoemacs keymap :map-key)
-              composed (ergoemacs-map-properties--composed keymap)
-              parent (ergoemacs-map-properties--parent keymap)))
-      (when map-key
-        (setq ret (plist-put ret :map-key map-key)))
-      (when composed
-        (setq ret (plist-put ret :composed composed)))
-      (when (or map-key composed)
-        (setq parent (ergoemacs-map-properties--parent keymap t))
-        (when parent
-          (setq ret (plist-put ret :parent parent))))
-      (puthash hash-key ret ergoemacs-map-properties--key-struct))
-    ret))
-
-
-(defun ergoemacs-map-properties--key-hash (keymap &optional force)
-  "Return the maps linked to the current KEYMAP.
-
-This only works if the KEYMAP is an `ergoemacs-mode' map.
-
-When FORCE is non-nil, make sure every map has an
-`ergoemacs-mode' keymap identifier installed in it.
-
-:map-key is the key of the current map.
-
-:composed is a list of the `ergoemacs-map-properties--key-struct'
-          of each of the composed maps.
-
-:parent is the `ergoemacs-map-properties--key-struct' of the current map.
-
-This will return the keymap structure prior to `ergoemacs-mode' modifications."
-  ;;|-----------+------------+--------------+--------------|
-  ;;| Condition | Call Count | Elapsed Time | Average Time |
-  ;;|-----------+------------+--------------+--------------|
-  ;;| Pre Hash  |     237982 | 100.52800000 | 0.0004224185 |
-  ;;| Post Hash |     150045 | 40.600999999 | 0.0002705921 |
-  ;;| Hash Key  |      76379 | 15.183000000 | 0.0001987850 |
-  ;;|-----------+------------+--------------+--------------|
-  (cond
-   ((integerp keymap) (list keymap))
-   ((ergoemacs-keymapp keymap)
-    (let* ((keymap (ergoemacs-map-properties--keymap-value keymap))
-           (map-key (ergoemacs keymap :map-key))
-           (composed (ergoemacs-map-properties--composed-list keymap force))
-           (parent (and composed (keymap-parent keymap)))
-           (ret (or (and (consp map-key) (car map-key))
-                    (and composed
-                         (append
-                          (mapcar
-                           (lambda(map)
-                             (ergoemacs map :map-key))
-                           composed)
-                          (list (and parent (ergoemacs parent :map-key)))))
-                    (and (integerp map-key) (list map-key)))))
-      ret))))
-
-(defun ergoemacs-map-properties--default-global-file (&optional other)
-  "What is the global key hash file.
-
-When OTHER is non-nil, get the OTHER file instead of the global
-file."
-  (let* ((file (expand-file-name (format "ergoemacs-%s-%s.el%s" (or other 
"global") ergoemacs--system (or (and ergoemacs--gzip ".gz") ""))
-                                 ergoemacs-dir))
-         (extras (expand-file-name "ergoemacs-extras" user-emacs-directory))
-         (file2 (expand-file-name (format "ergoemacs-%s-%s.el%s" (or other 
"global") ergoemacs--system (or (and ergoemacs--gzip ".gz") ""))
-                                  extras)))
-    (if (not (file-exists-p extras))
-        (make-directory extras t))
-    (or
-     (and (file-readable-p file2) file2)
-     (and (file-readable-p file) file)
-     (and (file-writable-p file) file)
-     file2)))
-
-(defvar ergoemacs-map-properties--const-keymaps nil
-  "Variable listing constant keymaps.")
-
-(defun ergoemacs-map-properties--map-regexp (&optional at-end)
-  "Generate a regular expression of all known maps.
-When AT-END is non-nil, replace the end of the regular expression
-with this string.  Otherwise, it is assumed to be \"$\".r"
-  (concat (regexp-opt (mapcar (lambda(x) (symbol-name x)) 
ergoemacs-map-properties--label-atoms-maps) 'symbols) (or (and at-end "$") "")))
-
-(defun ergoemacs-map-properties--default-global-gen ()
-  "Generate hash for default Emacs maps."
-  ;; (setq ergoemacs-map-properties--plist-hash (make-hash-table :test 'equal))
-  (ergoemacs global-map :label most-negative-fixnum) ;; Should be 
`most-negative-fixnum'
-  (push 'global-map ergoemacs-map-properties--label-atoms-maps)
-  (ergoemacs-map-properties--label-atoms)
-  (with-temp-file (ergoemacs-map-properties--default-global-file)
-    (let ((print-level nil)
-          (print-length nil)
-          (where-is-hash (make-hash-table))
-          tmp
-          keys)
-      (goto-char (point-min))
-      (insert ";; -*- coding: utf-8-emacs -*-\n")
-      (insert "(defvar ergoemacs-map-properties--plist-hash)(declare-function 
ergoemacs-map-properties--label \"ergoemacs-map-properties\")(declare-function 
ergoemacs-command-loop--spinner-display \"ergoemacs-command-loop\")")
-      (ergoemacs-map-keymap
-       (lambda (key item)
-         (cond
-          ((vectorp key)
-           (push key keys)
-           (if (setq tmp (ergoemacs-gethash item where-is-hash))
-               (push key tmp)
-             (puthash item (list key) where-is-hash)))))
-       global-map)
-      (ergoemacs :label global-map)
-      (ergoemacs :keys global-map) ;; Should calculate :where-is and :lookup 
from original map
-      
-      (insert "(setq ergoemacs-map-properties--plist-hash '")
-      (prin1 ergoemacs-map-properties--plist-hash (current-buffer))
-      (goto-char (point-max))
-      (insert ")")
-
-      (insert "(setq ergoemacs-breadcrumb-hash '")
-      (prin1 ergoemacs-breadcrumb-hash (current-buffer))
-      (goto-char (point-max))
-      (insert ")")
-      
-      (insert "(setq ergoemacs-map-properties--label-atoms-maps '")
-      (prin1 ergoemacs-map-properties--label-atoms-maps (current-buffer))
-      (goto-char (point-max))
-      (insert ")")
-      
-      (insert "(setq ergoemacs-map-properties--get-or-generate-map-key "
-             (number-to-string 
ergoemacs-map-properties--get-or-generate-map-key) ")")
-      (message "global-map-list %s" (ergoemacs global-map :map-list))
-      (message "minibuffer-local-map %s" (ergoemacs minibuffer-local-map 
:map-list))
-      (message "European: %s" (ergoemacs describe-european-environment-map 
:map-list))
-      (message "Completed generating default keys file."))))
-
-(defun ergoemacs-map-properties--label-echo (keymap-symbol map id)
-  "When KEYMAP-SYMBOL is bound, label MAP to ID.
-
-Also let the user know that the labeling was performed."
-  (when (boundp keymap-symbol)
-    (ergoemacs :spinner '("🎫→%s" "Label→%s" "Label->%s") keymap-symbol)
-    (if (ergoemacs map :installed-p)
-        (ergoemacs :label (ergoemacs map :original) id)
-      (if (ergoemacs map :composed-p)
-          (ergoemacs-warn "%s was not labeled to %s since it was a composed 
keymap.")
-        (ergoemacs :label (ergoemacs map :original) id)))))
-
-
-(defvar ergoemacs-map-properties--global-submap-p nil
-  "Submap that was found.
-The submap is found by the `ergoemacs-map-properties--global-submap-p' 
function.")
-
-(defun ergoemacs-map-properties--global-submap-p (key)
-  "Determine if KEY is defining a global submap.
-If so, return the a vector with the key relative to the submap.
-The submap value is stored in the variable 
`ergoemacs-map-properties--global-submap-p'."
-  (let* ((key (or (ergoemacs-translate--escape-to-meta key) key))
-        (len (length key))
-        cur-map
-        (i 1))
-    (catch 'found-submap
-      (while (<= i len)
-       (setq cur-map (lookup-key (ergoemacs :global-map) (substring key 0 i))
-             cur-map (or (and (symbolp cur-map) (boundp cur-map) (symbol-value 
cur-map))
-                         (and (symbolp cur-map) (fboundp cur-map) 
(symbol-function cur-map))
-                         cur-map))
-       (when (and (ergoemacs-keymapp cur-map)
-                  (integerp (ergoemacs cur-map :map-key)))
-         (setq ergoemacs-map-properties--global-submap-p cur-map)
-         (throw 'found-submap (substring key i)))
-       (setq i (1+ i))) nil)))
-
-(defun ergoemacs-map-properties--before-ergoemacs (&optional after)
-  "Get a keymap of keys that changed before or after loading ergoemacs.
-
-By default this gives a keymap of keys changed before
-ergoemacs-mode loaded.
-
-When AFTER is non-nil, this is a list of keys that changed after
-`ergoemacs-mode' loaded."
-  (or (and (not after) ergoemacs-map-properties--before-ergoemacs)
-      (and after ergoemacs-map-properties--after-ergoemacs)
-      (let ((hash-table (ergoemacs-gethash :extract-lookup (ergoemacs-gethash 
(list :map-key most-negative-fixnum) ergoemacs-map-properties--plist-hash)))
-            (original-global-map (ergoemacs :global-map))
-            (before-map (make-sparse-keymap))
-            tmp)
-        (ergoemacs-timing before-ergoemacs
-          (unwind-protect
-              (progn
-                (setq ergoemacs-map-keymap--load-autoloads-p nil)
-                (ergoemacs-map-keymap
-                 (lambda (cur-key item)
-                   (unless (or (consp cur-key) (eq item 'ergoemacs-prefix))
-                     (setq tmp (ergoemacs-gethash cur-key hash-table cur-key))
-                     (cond
-                      ;; bach mode doesn't save menu-bar or tool-bar 
information
-                      ((memq (elt cur-key 0) '(menu-bar tool-bar iconify-frame 
make-frame-visible)))
-                      ;; batch mode also doesn't save mouse-events
-                      ((memq (event-basic-type (elt cur-key 0)) '(mouse-1 
mouse-2 mouse-3 mouse-4 mouse-4)))
-                      ;; M-O is bound to facemenu keymap by default, except in
-                      ;; terminal/batch mode
-                      ((and (>= (length cur-key) 2)
-                            (eq (elt cur-key 0) 27)
-                            (eq (elt cur-key 1) 111)
-                            (eq (lookup-key original-global-map [27 111]) 
'facemenu-keymap)))
-                      ((eq 'ergoemacs-labeled (elt cur-key (- (length cur-key) 
1))))
-                      ((and (symbolp item) (string-match-p "clipboard" 
(symbol-name item))))
-                      ((and (equal [27 115 104 102] cur-key) (eq item 
'hi-lock-find-patterns)))
-                     ;; If this is bound to another keymap, assume it doesn't 
affect user maps.
-                     ;; For example the M-s keymap, or M-g keymaps.
-                     ((ergoemacs-map-properties--global-submap-p cur-key))
-                      ((and tmp (not (equal tmp item))
-                            (or (not after)
-                                (not (and 
ergoemacs-map-properties--before-ergoemacs
-                                          (eq item (lookup-key 
ergoemacs-map-properties--before-ergoemacs cur-key))))))
-                      (ergoemacs :define-key before-map cur-key item))
-                      ((and (not tmp)
-                            (or (not after)
-                                (not (and 
ergoemacs-map-properties--before-ergoemacs
-                                          (lookup-key 
ergoemacs-map-properties--before-ergoemacs cur-key)))))
-                      (ergoemacs :define-key before-map cur-key tmp)))))
-                 original-global-map t))
-            (setq ergoemacs-map-keymap--load-autoloads-p t)))
-        (if after
-            (progn
-              (setq ergoemacs-map-properties--after-ergoemacs before-map)
-              (ergoemacs before-map :label)
-             (ergoemacs :map-list before-map 
'ergoemacs-map-properties--after-ergoemacs))
-          (setq ergoemacs-map-properties--before-ergoemacs before-map)
-          (ergoemacs before-map :label)
-         (ergoemacs :map-list before-map 
'ergoemacs-map-properties--before-ergoemacs))
-        before-map)))
-
-(defvar ergoemacs-map-properties--protect-local nil)
-(defun ergoemacs-map-properties--protect-local (hook fn)
-  "Protect a local map's modification.
-
-Save information about what HOOK is running function FN."
-  (let ((fn (or (and (symbolp fn) fn) 'lambda)))
-    (if (not hook)
-        (setq ergoemacs-map-properties--protect-local nil)
-      (setq ergoemacs-map-properties--protect-local (list hook fn)))))
-
-
-(defvar ergoemacs-map-properties--modify-run-mode-hooks-excluded
-  '(font-lock-mode-hook emojify-emojify-mode-line mu4e-update-mail-and-index
-    change-major-mode-hook after-change-major-mode-hook)
-  "List of hooks where keymaps should not be modified.")
-
-(defun ergoemacs-map-properties--modify-run-mode-hooks-p (hook)
-  "Should the HOOK be modified?
-This tests if HOOK is:
-- bound with `boundp'
-- matches mode-hook
-- Is not in `ergoemacs-map-properties--modify-run-mode-hooks-excluded'"
-  (and (boundp hook)
-       (string-match-p "mode-hook\\'" (symbol-name hook))
-       (not (memq hook 
ergoemacs-map-properties--modify-run-mode-hooks-excluded))))
-
-(defun ergoemacs-map-properties--modify-run-mode-hooks (&rest hooks)
-  "Modify HOOKS to run `ergoemacs-map-properties--protect-local' before hook."
-  (let (tmp hook-value)
-    (dolist (hook (or (and (consp hooks) hooks) (list hooks)))
-      (if (consp hook)
-          (dolist (lhook hook)
-           (ergoemacs-map-properties--modify-run-mode-hooks lhook))
-        (when (and hook (ergoemacs-map-properties--modify-run-mode-hooks-p 
hook))
-          (set hook
-               (cond
-                ((and (setq hook-value (symbol-value hook))
-                      (consp hook-value))
-                 (mapcar
-                  (lambda(fn)
-                    (if (or (eq fn t) (and (setq tmp (documentation fn))
-                                           (stringp tmp)
-                                           (string-match-p  "^Ergoemacs 
protect local" tmp)))
-                        fn
-                      `(lambda() "Ergoemacs protect local"
-                         (ergoemacs-map-properties--protect-local ',hook ',fn)
-                         (funcall ',fn))))
-                  hook-value))
-                (t ;; For now do nothing
-                 hook-value))))))))
-
-
-(defun ergoemacs-map-properties--reset-run-mode-hooks (&rest hooks)
-  "Reset HOOKS as if `ergoemacs-map-properties--modify-run-mode-hooks' wasn't 
run."
-  (let (tmp hook-value)
-    (dolist (hook (or (and (consp hooks) hooks) (list hooks)))
-      (if (consp hook)
-          (dolist (lhook hook)
-            (ergoemacs-map-properties--reset-run-mode-hooks lhook))
-        (when (and hook
-                  (boundp hook)
-                  (string-match-p "mode-hook" (symbol-name hook))
-                  (ergoemacs-map-properties--modify-run-mode-hooks-p hook))
-          (set hook
-               (cond
-                ((and (setq hook-value (symbol-value hook))
-                      (consp hook))
-                 (mapcar
-                  (lambda(fn)
-                    (if (or (eq fn t) (and (setq tmp (documentation fn))
-                                           (stringp tmp)
-                                           (string-match-p  "^Ergoemacs 
protect local" tmp)
-                                           (setq tmp (ignore-errors (car (cdr 
(nth 1 (nth 4 fn))))))))
-                        tmp
-                      fn))
-                  hook-value))
-                (t ;; For now don't touch these.
-                 hook-value))))))))
-
-
-(defvar ergoemacs-map-properties--hook-map-hash (make-hash-table :test 'equal)
-  "Hash table of user hook maps that `ergoemacs-mode' saves.")
-
-(defun ergoemacs-map-properties--hook-define-key (keymap key def)
-  "Save hook-defined keys on separate keymaps.
-
-The KEYMAP is the keymap where keys are going to be defined.
-
-The KEY is the key that is being defined.
-
-The DEF is the key definition.
-
-These keymaps are saved in `ergoemacs-map-properties--hook-map-hash'."
-  (ergoemacs keymap :label)
-  (let* ((kbd key)
-         (key (ergoemacs keymap :map-key))
-         key2 tmp map)
-    (when (integerp key)
-      (setq key2 key
-            tmp (ergoemacs-gethash key2 
ergoemacs-map-properties--hook-map-hash)
-            map (ergoemacs-gethash
-                 (setq key `(,(ergoemacs keymap :key-hash) 
,@ergoemacs-map-properties--protect-local))
-                 ergoemacs-map-properties--hook-map-hash))
-      (push key tmp)
-      (puthash key2 tmp ergoemacs-map-properties--hook-map-hash)
-      (unless map
-        (puthash key (make-sparse-keymap) 
ergoemacs-map-properties--hook-map-hash)
-        (setq map (ergoemacs-gethash key 
ergoemacs-map-properties--hook-map-hash))
-        (ergoemacs map :label `(hook-map 
,@ergoemacs-map-properties--protect-local)))
-      (unwind-protect
-          (progn
-            (setq tmp ergoemacs-map-properties--protect-local
-                  ergoemacs-map-properties--protect-local nil)
-            (ergoemacs :define-key map kbd def))
-        (setq ergoemacs-map-properties--protect-local nil)))))
-
-(defun ergoemacs-map-properties--override-maps (keymap)
-  "Return a list of overriding maps based on hooks run for KEYMAP."
-  (ergoemacs keymap :label)
-  (let* ((key (ergoemacs keymap :map-key))
-         lst
-        new-map
-        standard
-         ret command condition)
-    (when (integerp key)
-      (setq lst (ergoemacs-gethash key 
ergoemacs-map-properties--hook-map-hash))
-      (dolist (map-key lst)
-       (when (ergoemacs map-key :override-map-p)
-          (push (ergoemacs-gethash map-key 
ergoemacs-map-properties--hook-map-hash) ret)))
-      (when (and (boundp 'icicle-mode-map)
-                (eq icicle-mode-map keymap))
-       (setq new-map (make-sparse-keymap))
-       (unless (equal icicle-search-key-prefix "\M-s\M-s")
-         (ergoemacs :define-key new-map icicle-search-key-prefix 
icicle-search-map))
-       (when (and (boundp 'icicle-top-level-key-bindings) (custom-variable-p 
'icicle-top-level-key-bindings))
-         (setq standard (eval (car (get 'icicle-top-level-key-bindings 
'standard-value)) t))
-         ;; After determine if anything has changed...
-         ;; Lifted partially from icicles
-         (dolist (key-def  icicle-top-level-key-bindings)
-           (unless (member key-def standard)
-             (setq key        (car key-def)
-                   command    (cadr key-def)
-                   condition  (car (cddr key-def)))
-             (when (eval condition t)
-               (if (symbolp key)
-                   (icicle-remap key command new-map (current-global-map))
-                 (ergoemacs :define-key new-map key command))))))
-       (unless (ergoemacs new-map :empty-p)
-         (push new-map ret))))
-    ret))
-
-(defun ergoemacs-map-properties--deferred-maps (keymap)
-  "Return a list of overriding maps based on hooks run based on KEYMAP."
-  (let* ((key (ergoemacs keymap :map-key))
-         lst
-         ret)
-    (when (integerp key)
-      (setq lst (ergoemacs-gethash key 
ergoemacs-map-properties--hook-map-hash))
-      (dolist (map-key lst)
-        (when (not (ergoemacs map-key :override-map-p))
-          (push (ergoemacs-gethash map-key 
ergoemacs-map-properties--hook-map-hash) ret))))
-    ret))
-
-
-(defvar ergoemacs-map-properties--override-map-hash (make-hash-table)
-  "Hash Table of defined/undefined keys.")
-
-(defvar ergoemacs-map-properties--deferred-hooks-directory-regexp
-  (concat "\\`" (regexp-opt (append package-directory-list
-                                    (list package-user-dir)
-                                    (list (file-name-directory (locate-library 
"abbrev")))
-                                    
ergoemacs-directories-where-keys-from-hook-are-deferred) t))
-  "Regular experssion of libraries where maps are deferred.")
-
-(defun ergoemacs-map-properties--override-map-p (keymap)
-  "Determine if KEYMAP should override `ergoemacs-mode' keys."
-  (let ((key (or (and (ergoemacs-keymapp keymap) (ergoemacs keymap :map-key)) 
keymap))
-        tmp)
-    (and (consp key)
-         (or (eq (car key) 'hook-map)
-             (and (consp (car key)) (integerp (car (car key)))))
-         (or (memq (nth 1 key) 
ergoemacs-hooks-that-always-override-ergoemacs-mode)
-             (memq (nth 2 key) 
ergoemacs-functions-that-always-override-ergoemacs-mode)
-             (progn
-               (setq tmp (ergoemacs-gethash (nth 2 key) 
ergoemacs-map-properties--override-map-hash))
-               (if tmp
-                   (if (eq tmp :override-p) t nil)
-                 (if (not (functionp (nth 2 key))) nil
-                   (if (and (setq tmp (find-lisp-object-file-name (nth 2 key) 
(symbol-function (nth 2 key))))
-                           (stringp tmp)
-                           (string-match-p 
ergoemacs-map-properties--deferred-hooks-directory-regexp tmp))
-                       (progn
-                         (puthash (nth 2 key) :deferred-p 
ergoemacs-map-properties--override-map-hash)
-                         nil)
-                     (puthash (nth 2 key) :override-p 
ergoemacs-map-properties--override-map-hash)
-                     t))))))))
-(defun ergoemacs-map-properties--protect-global-map ()
-  "Protect global map by adding a user-key layer to it."
-  (when (and (or (not noninteractive) (file-readable-p 
(ergoemacs-map-properties--default-global-file)))
-             (integerp (ergoemacs global-map :map-key)))
-    (let ((user-map (ergoemacs global-map :user)))
-      (ergoemacs :user-before)
-      (setq global-map (make-composed-keymap user-map global-map)))))
-
-(defvar ergoemacs-map-properties--known-maps nil
-  "A list of known, but unlabeled maps.")
-
-(defun ergoemacs-map-properties--get-original-global-map ()
-  "Load/Create the default global map information."
-  (if ergoemacs-mode--fast-p
-      (progn
-       (setq ergoemacs-map-properties--known-maps 
ergoemacs-map-properties--label-atoms-maps)
-       (ergoemacs-map-properties--label-known))
-      ;; (ergoemacs-map-properties--label-atoms)
-    (ergoemacs-timing get-original-global-map
-      ;; (ergoemacs-map-properties--label-atoms)
-      (if (file-readable-p (ergoemacs-map-properties--default-global-file))
-          (progn
-           (load (ergoemacs-map-properties--default-global-file))
-           (setq ergoemacs-map-properties--known-maps 
ergoemacs-map-properties--label-atoms-maps)
-           (message "Breadcrumb %s" (ergoemacs-gethash 
'describe-european-environment-map ergoemacs-breadcrumb-hash))
-           (ergoemacs-map-properties--label-known)
-            (ergoemacs-map-properties--protect-global-map))
-        (if noninteractive
-            (ergoemacs-warn "Could not find global map information")
-          (ergoemacs-timing ergoemacs-create-global
-            (let* ((emacs-exe (ergoemacs-emacs-exe))
-                   (default-directory (expand-file-name (file-name-directory 
(locate-library "ergoemacs-mode"))))
-                   (cmd (format "%s -L %s --batch --load \"ergoemacs-mode\" -Q 
--eval \"(progn (ergoemacs-map-properties--default-global-gen) (kill-emacs))\"" 
emacs-exe default-directory)))
-              (message "%s" (shell-command-to-string cmd))
-              (ergoemacs-map-properties--get-original-global-map))))))))
-
-(add-hook 'ergoemacs-mode-intialize-hook 
'ergoemacs-map-properties--get-original-global-map)
-
-(defun ergoemacs-map-properties--map-fixed-plist (keymap)
-  "Determines if this is an `ergoemacs-mode' KEYMAP.
-Returns a plist of fixed keymap properties (not changed by
-composing or parent/child relationships)"
-  (if (not (ergoemacs-keymapp keymap) ) nil
-    (if (ignore-errors (symbol-function keymap))
-        (progn (ergoemacs-gethash keymap 
ergoemacs-map-properties--indirect-keymaps))
-      (let ((ret (or
-                  (ignore-errors ;; (keymap #char-table "Label" 
(ergoemacs-map-marker) (ergoemacs-map-list))
-                    (and (char-table-p (car (cdr keymap)))
-                         (stringp (car (cdr (cdr keymap))))
-                         (eq (car (car (cdr (cdr (cdr keymap))))) 
'ergoemacs-labeled)
-                         (funcall (cdr (car (cdr (cdr (cdr keymap))))))))
-                  (ignore-errors ;; (keymap #char-table (ergoemacs-map-marker) 
(ergoemacs-map-list))
-                    (and (char-table-p (car (cdr keymap)))
-                         (eq (car (car (cdr (cdr keymap)))) 'ergoemacs-labeled)
-                         (funcall (cdr (car (cdr (cdr keymap)))))))
-                  (ignore-errors ;; (keymap "label" (ergoemacs-map-marker) 
(ergoemacs-map-list))
-                    (and (stringp (car (cdr keymap)))
-                         (eq (car (car (cdr (cdr keymap)))) 'ergoemacs-labeled)
-                         (funcall (cdr (car (cdr (cdr keymap)))))))
-                  (ignore-errors ;;(keymap  (ergoemacs-map-marker) 
(ergoemacs-map-list))
-                    (and (eq (car (car (cdr keymap))) 'ergoemacs-labeled)
-                         (funcall (cdr (car (cdr keymap))))))))
-            (map keymap) parent)
-        (unless ret
-          (unwind-protect
-              (progn
-                (when (char-table-p (car (cdr map)))
-                  ;; Drop any full keymap labels
-                  (setq map `(keymap ,@(cdr (cdr map)))))
-                (setq parent (keymap-parent map))
-                (ignore-errors (set-keymap-parent map nil))
-                (setq ret (lookup-key map [ergoemacs-labeled]))
-                (when ret
-                  (setq ret (ignore-errors (funcall ret)))))
-            (ignore-errors (set-keymap-parent map parent))))
-        (if ret ret
-          ;; Now get properties for constant/indirect keymaps
-          (catch 'found-map
-            (dolist (map ergoemacs-map-properties--const-keymaps)
-              (when (eq (cdr map) (cdr keymap))
-                (setq ret (car map))
-                (throw 'found-map t))))
-          ret)))))
-
-(defun ergoemacs-map-properties--get (keymap property)
-  "Get ergoemacs-mode KEYMAP PROPERTY."
-  (let ((ret (ergoemacs-map-properties--map-fixed-plist keymap)) tmp)
-    (unless (and ergoemacs-map-properties--plist-hash (hash-table-p 
ergoemacs-map-properties--plist-hash))
-      (setq ergoemacs-map-properties--plist-hash (make-hash-table :test 
'equal)))
-    (setq tmp (ergoemacs-gethash (ergoemacs-map-properties--key-struct keymap) 
ergoemacs-map-properties--plist-hash))
-    (if (not (and tmp (hash-table-p tmp)))
-       (setq ret nil)
-      (setq ret (ergoemacs-gethash property tmp)))
-    ret))
-
-(defun ergoemacs-map-properties--put (keymap property value)
-  "Set ergoemacs-mode KEYMAP PROPERTY to VALUE."
-  (prog1 value
-    (if (eq property :label)
-        (ergoemacs :label keymap value)
-      (let ((keymap (ergoemacs-map-properties--keymap-value keymap)))
-        (cond
-         ((not (ergoemacs-keymapp keymap))
-          (error "Trying to put keymap property on non-keymap %s" keymap))
-         ((eq property :full)
-          (ergoemacs-warn "Cannot set the keymap property :full"))
-         (t (let ((ret (ergoemacs-map-properties--map-fixed-plist keymap)) tmp)
-              (if (and ret (eq property :map-key))
-                  (progn
-                    (setq ret (plist-put ret property value))
-                    (ergoemacs :label keymap value))
-                (unless (and ergoemacs-map-properties--plist-hash 
(hash-table-p ergoemacs-map-properties--plist-hash))
-                  (setq ergoemacs-map-properties--plist-hash (make-hash-table 
:test 'equal)))
-                (setq tmp (ergoemacs-gethash 
(ergoemacs-map-properties--key-struct keymap) 
ergoemacs-map-properties--plist-hash))
-                (unless (and tmp (hash-table-p tmp))
-                  (setq tmp (make-hash-table)))
-                (puthash property value tmp)
-                (puthash (ergoemacs-map-properties--key-struct keymap) tmp 
ergoemacs-map-properties--plist-hash)))))))))
-
-(defun ergoemacs-map-properties--parent (keymap &optional force)
-  "Return a `ergoemacs-mode' map-key for the parent of KEYMAP.
-
-When FORCE is non-nil make sure it has a map key."
-  (if (not (ergoemacs-keymapp keymap)) nil
-    (let ((parent (keymap-parent keymap)))
-      (and parent (ergoemacs-map-properties--key-struct parent force)))))
-
-(defun ergoemacs-map-properties--map-list (keymap &optional add-map)
-  "Get the list of maps bound to KEYMAP.
-KEYMAP can be a keymap or integer indicating the keympap id.
-The optional ADD-MAP argument adds maps to the map-list.  It can be a symbol 
or list of symbols to add."
-  (let (tmp)
-    (cond
-     ((ergoemacs-keymapp keymap)
-      (ergoemacs-map-properties--map-list (ergoemacs (ergoemacs keymap 
:original) :key) add-map))
-     ((and (integerp keymap) (not add-map))
-      ;; (message "Key%s->%s" keymap (ergoemacs-gethash keymap 
ergoemacs-map-properties--plist-hash))
-      (ergoemacs-gethash keymap ergoemacs-map-properties--plist-hash))
-     ((and (integerp keymap) (symbolp add-map))
-      (setq tmp (ergoemacs-gethash keymap 
ergoemacs-map-properties--plist-hash))
-      (cl-pushnew add-map tmp)
-      (cl-pushnew add-map ergoemacs-map-properties--label-atoms-maps)
-      (puthash add-map keymap ergoemacs-breadcrumb-hash)
-      (puthash keymap add-map ergoemacs-breadcrumb-hash)
-      (puthash keymap tmp ergoemacs-map-properties--plist-hash)
-      (ergoemacs-map-properties--map-list keymap))
-     ((and (integerp keymap) (consp add-map))
-      (setq tmp (ergoemacs-gethash keymap 
ergoemacs-map-properties--plist-hash))
-      (dolist (map add-map)
-       (when (symbolp map)
-         (cl-pushnew map ergoemacs-map-properties--label-atoms-maps)
-         (cl-pushnew map tmp)
-         (puthash map keymap ergoemacs-breadcrumb-hash)
-          (puthash keymap map ergoemacs-breadcrumb-hash)
-          ))
-      (puthash keymap tmp ergoemacs-map-properties--plist-hash)
-      (ergoemacs-map-properties--map-list keymap))
-     (t nil))))
-
-(defvar ergoemacs-map-properties--get-or-generate-map-name nil)
-
-(defun ergoemacs-map-properties--label-map (map &optional label-empty-p)
-  "Label MAP.
-When LABEL-EMPTY-P is non-nil, also label empty maps."
-  (let* (sv)
-    (cond
-     ((get map :ergoemacs-labeled)
-      t) ;; Already labeled
-     ((not (setq sv (ergoemacs-sv map t)))
-      nil) ;; Nil
-     ((not (ergoemacs-keymapp sv)) ;; Not a keymap
-      (put map :ergoemacs-labeled t)
-      t)
-     ((eq sv global-map)
-      (put map :ergoemacs-labeled t))
-     ((and (not label-empty-p)
-          (or (equal sv (make-sparse-keymap)) ;; Empty
-              (equal sv (make-keymap))))
-      nil)
-     ((ergoemacs sv :installed-p) ;; Already modified.
-      (put map :ergoemacs-labeled t)
-      (ergoemacs :map-list sv map))
-     ;; ((ergoemacs sv :composed-p) ;; Already modified.
-     ;;  (ergoemacs-warn "Composed map %s not labeled." map))
-     (t ;;Label
-      (setq ergoemacs-map-properties--get-or-generate-map-name map)
-      (ergoemacs :label sv)
-      (ergoemacs :map-list sv map)
-      (put map :ergoemacs-labeled t)
-      t))))
-
-(defun ergoemacs-map-properties--label-atoms ()
-  "Label all the bound keymaps."
-  (mapatoms #'ergoemacs-map-properties--label-map))
-
-;; Startup and load functions
-;;(add-hook 'ergoemacs-mode-after-init-emacs 
'ergoemacs-map-properties--label-unlabeled)
-;;(add-hook 'ergoemacs-mode-after-load-hook 
'ergoemacs-map-properties--label-unlabeled)
-
-(defun ergoemacs-map-properties--label-known ()
-  "Label known maps."
-  (dolist (map (let (tmp) (dolist (map ergoemacs-map-properties--known-maps) 
(push map tmp)) tmp))
-    (when (and (boundp map) (ergoemacs-keymapp map))
-      (setq ergoemacs-map-properties--get-or-generate-map-name map)
-      (ergoemacs :label map))))
-
-(defun ergoemacs-map-properties--linked-map (keymap &optional drop)
-  "For KEYMAP get linked maps.
-When DROP is non-nil, drop any found maps from 
`ergoemacs-map-properties--known-maps'."
-  (let (map-list known)
-    (when (and (ergoemacs-keymapp keymap)
-              (not (ergoemacs :empty-p keymap)))
-      (dolist (map ergoemacs-map-properties--known-maps)
-       (if (and (boundp map)
-                (eq (ergoemacs-sv map) keymap))
-           (push map map-list)
-         (when drop
-           (push map known))))
-      (when drop
-        (setq ergoemacs-map-properties--known-maps known)))
-    map-list))
-
-(defvar ergoemacs-map-properties--breadcrumb nil)
-
-(defun ergoemacs-map-properties--get-or-generate-map-key (keymap)
-  "Gets the key for the KEYMAP."
-  (let ((ret (ergoemacs-map-properties--map-fixed-plist 
(ergoemacs-map-properties--keymap-value keymap)))
-       map-list last-map tmp)
-    (cond
-     ((and ret (setq ret (plist-get ret :map-key))) ret)
-     ;; Special Keymaps
-     ((eq keymap global-map) most-negative-fixnum)
-     ((eq keymap ergoemacs-translate--parent-map) (- most-positive-fixnum 1))
-     ((eq keymap ergoemacs-translate--modal-parent-map) (- 
most-positive-fixnum 2))
-     ;; Other keymaps
-     (t
-      (setq map-list (ergoemacs-map-properties--linked-map keymap t)
-           last-map (or ergoemacs-map-properties--get-or-generate-map-name 
(car map-list)))
-      (when ergoemacs-map-properties--get-or-generate-map-name
-       (dolist (map ergoemacs-map-properties--known-maps)
-         (unless (eq map ergoemacs-map-properties--get-or-generate-map-name)
-           (push map tmp)))
-       (setq ergoemacs-map-properties--known-maps tmp
-             ergoemacs-map-properties--get-or-generate-map-name nil))
-      (when (and ergoemacs-map-properties--breadcrumb (not (string= "" 
ergoemacs-map-properties--breadcrumb))
-                (or (not ergoemacs-map--breadcrumb) (string= "" 
ergoemacs-map--breadcrumb)))
-       (setq ergoemacs-map--breadcrumb ergoemacs-map-properties--breadcrumb))
-      (cond
-       ((and last-map (setq ret (ergoemacs-gethash last-map 
ergoemacs-breadcrumb-hash)))
-       ;; Found id from bound map.
-       (ergoemacs :spinner '("🎫→%s (Restore)" "Label→%s (Restore)" "Label->%s 
(Restore)") last-map)
-       ret)
-       (last-map
-       ;; Generate and save.
-       (setq ergoemacs-map-properties--get-or-generate-map-key
-             (+ 1 ergoemacs-map-properties--get-or-generate-map-key))
-       (ergoemacs :spinner :new '("🎫→%s (Save)" "Label→%s (Save)" "Label->%s 
(Save)") last-map)
-       (dolist (map map-list)
-         (ergoemacs :map-list 
ergoemacs-map-properties--get-or-generate-map-key map))
-       ergoemacs-map-properties--get-or-generate-map-key)
-       ((and ergoemacs-map--breadcrumb
-            (not (string= "" ergoemacs-map--breadcrumb))
-            (not (setq ret (ergoemacs-gethash (intern 
ergoemacs-map--breadcrumb) ergoemacs-breadcrumb-hash))))
-       ;; Not found in breadcrumb hash, but breadcrumb is specified.
-       ;; Generate and save.
-       (setq ergoemacs-map-properties--get-or-generate-map-key
-             (+ 1 ergoemacs-map-properties--get-or-generate-map-key))
-       (puthash (intern ergoemacs-map--breadcrumb) 
ergoemacs-map-properties--get-or-generate-map-key ergoemacs-breadcrumb-hash)
-       (puthash ergoemacs-map-properties--get-or-generate-map-key (intern 
ergoemacs-map--breadcrumb) ergoemacs-breadcrumb-hash)
-       (ergoemacs :spinner :new '("🎫→%s (Save)" "Label→%s (Save)" "Label->%s 
(Save)") ergoemacs-map--breadcrumb)
-       (setq ergoemacs-map--breadcrumb "")
-       ergoemacs-map-properties--get-or-generate-map-key)
-       (ret
-       ;; Found in breadcrumb hash.
-       (ergoemacs :spinner '("🎫→%s (Restore)" "Label→%s (Restore)" "Label->%s 
(Restore)") ergoemacs-map--breadcrumb)
-       (setq ergoemacs-map--breadcrumb "")
-       ret)
-       (t
-       ;; (ergoemacs-warn "Labeling untraceable map...%s" keymap)
-       (setq ergoemacs-map-properties--get-or-generate-map-key
-             (+ 1 ergoemacs-map-properties--get-or-generate-map-key))
-       ;; (setq map-list (format "New Map %s->%s" 
ergoemacs-map-properties--get-or-generate-map-key keymap)
-       ;;       map-list (substring map-list 0 (min (length map-list) 80)))
-       ;; (message "%s" map-list)
-       ergoemacs-map-properties--get-or-generate-map-key))))))
-
-(defun ergoemacs-map-properties--label (keymap &optional map-key struct-in)
-  "Label an `ergoemacs-mode' touched KEYMAP.
-MAP-KEY is the identifier of the map name.
-STRUCT is the keymap structure for the current map."
-  (unless (not (ergoemacs-keymapp keymap))
-    (cond
-     ((ergoemacs-map-properties--composed-p keymap)
-      (cond
-       (map-key
-       (error "Will not label a composed map's members to %s" map-key))
-       (t
-       (let* ((breadcrumb-base ergoemacs-map--breadcrumb)
-              (comp (plist-get (or struct-in (ergoemacs-gethash map-key 
ergoemacs-map-properties--key-struct))  :composed))
-              (comp-list (ergoemacs-map-properties--composed-list keymap))
-              from-prop-p
-              (i 0))
-         (unless (= (length comp) (length comp-list))
-           (setq comp nil))
-         (when (and ergoemacs-map-properties--breadcrumb
-                    (not (string= ergoemacs-map-properties--breadcrumb ""))
-                    (or (not breadcrumb-base) (string= "" breadcrumb-base)))
-           (setq breadcrumb-base ergoemacs-map-properties--breadcrumb
-                 from-prop-p t
-                 ergoemacs-map-properties--breadcrumb nil))
-         (dolist (map comp-list)
-           (when (and breadcrumb-base (not (string= breadcrumb-base "")))
-             (setq ergoemacs-map--breadcrumb (concat breadcrumb-base "-" 
(number-to-string i))
-                   i (+ 1 i)))
-           (if comp
-               (ergoemacs :label map nil (pop comp))
-             (ergoemacs :label map)))
-         (if from-prop-p
-             (setq ergoemacs-map-properties--breadcrumb breadcrumb-base)
-           (setq ergoemacs-map--breadcrumb breadcrumb-base))))))
-     (t
-      (let* ((map keymap)
-            (map-key (or map-key
-                         (plist-get struct-in :map-key)
-                         (ergoemacs-map-properties--get-or-generate-map-key 
map)))
-            char-table
-            indirect-p
-            old-plist
-            (breadcrumb-base ergoemacs-map--breadcrumb)
-            (parent (keymap-parent map))
-            label tmp1 tmp2)
-       (unwind-protect
-           (progn
-             (ignore-errors (set-keymap-parent map nil))
-             (if (ergoemacs-keymapp (symbol-function keymap))
-                 (setq indirect-p t ; Indirect keymap
-                       old-plist (ergoemacs-gethash keymap 
ergoemacs-map-properties--indirect-keymaps))
-               (setq old-plist (lookup-key map [ergoemacs-labeled]))
-               (if (eq (car map) 'keymap)
-                   (setq map (cdr map))
-                 (setq map (list map)))
-               (when (ignore-errors (char-table-p (car map)))
-                 (setq char-table (pop map)))
-               (when (stringp (car map))
-                 (setq label (pop map)))
-               ;; Drop prior `ergoemacs-mode' labels
-               (setq tmp1 '()
-                     tmp2 nil)
-               (when old-plist
-                 (setq old-plist (ignore-errors (funcall old-plist)))
-                 (while (not (and (consp tmp2)
-                                  (eq (car tmp2) 'ergoemacs-labeled)))
-                   (setq tmp2 (pop map))
-                   (unless (and (consp tmp2) (equal 'ergoemacs-labeled (car 
tmp2)))
-                     (push tmp2 tmp1)))
-                 (while tmp1
-                   (push (pop tmp1) map))))
-             (setq old-plist (list :map-key map-key))
-             (unless indirect-p
-               (push (cons 'ergoemacs-labeled
-                           `(lambda() (interactive) ',old-plist)) map))
-             (unless indirect-p
-               (when label
-                 (push label map))
-               (when char-table
-                 (push char-table map))
-               (push 'keymap map)))
-          (when parent
-           (set-keymap-parent map parent)
-           (setq ergoemacs-map--breadcrumb breadcrumb-base)))
-       (if indirect-p
-           (puthash keymap old-plist 
ergoemacs-map-properties--indirect-keymaps)
-         (unless (ignore-errors (ergoemacs-setcdr keymap (cdr map)))
-           (cl-pushnew (cons old-plist (cdr keymap)) 
ergoemacs-map-properties--const-keymaps)))
-       map)))))
-
-(defun ergoemacs-map-properties--empty-p (keymap &optional labeled-is-keymap-p)
-  "Determines if a KEYMAP is empty.
-
-When LABELED-IS-KEYMAP-P is non-nil, ergoemacs-mode labeled
-keymaps without any additional keys are not considered empty.
-Otherwise, erogemacs-mode labeled keymaps without any additional
-keys are considered empty."
-  (catch 'found-key
-    (ergoemacs-timing empty-p
-      (ergoemacs-map-keymap
-       (lambda (cur-key item)
-         (unless (and (not labeled-is-keymap-p) (equal cur-key 
[ergoemacs-labeled]))
-           (if (consp cur-key)
-               (throw 'found-key nil)
-             (unless (eq item 'ergoemacs-prefix)
-               (when item
-                 (throw 'found-key nil))))))
-       keymap)) t))
-
-;;ergoemacs-map-properties--label
-
-
-(defvar ergoemacs-map-properties--user-map-hash (make-hash-table :test 'equal)
-  "Hash table of the user maps that `ergoemacs-mode' saves.")
-
-(defun ergoemacs-map-properties--user (keymap)
-  "Gets the user KEYMAP with `ergoemacs-mode' identifiers installed.
-KEYMAP can be an `ergoemacs-map-properties--key-struct' of the keymap as well."
-  (let ((key (ergoemacs keymap :map-key))
-        original map)
-    (cond
-     ((not key)
-      (ergoemacs :label keymap)
-      (setq key (ergoemacs keymap :map-key))
-      (puthash key (make-sparse-keymap) 
ergoemacs-map-properties--user-map-hash)
-      (setq map (ergoemacs-gethash key 
ergoemacs-map-properties--user-map-hash))
-      (ergoemacs map :label (list (ergoemacs keymap :key-hash) 'user)))
-     ((not (integerp key))
-      (setq original (ergoemacs keymap :original)
-            key (ergoemacs original :map-key))
-      (if (integerp key)
-          (setq map (ergoemacs original :user))
-        (setq map (ergoemacs-gethash key 
ergoemacs-map-properties--user-map-hash))
-        (unless map
-          (puthash key (make-sparse-keymap) 
ergoemacs-map-properties--user-map-hash)
-          (setq map (ergoemacs-gethash key 
ergoemacs-map-properties--user-map-hash))
-          (ergoemacs map :label (list key 'user)))))
-     (t
-      (setq map (ergoemacs-gethash (setq key (ergoemacs keymap :key-hash)) 
ergoemacs-map-properties--user-map-hash))
-      (unless map
-        (puthash key (make-sparse-keymap) 
ergoemacs-map-properties--user-map-hash)
-        (setq map (ergoemacs-gethash key 
ergoemacs-map-properties--user-map-hash))
-        (ergoemacs map :label (list (ergoemacs keymap :key-hash) 'user)))))
-    map))
-
-(defun ergoemacs-map-properties--calculate-keys-and-where-is-hash (keymap)
-  "Calculates :where-is and :keys properties for KEYMAP."
-  (let ((where-is-hash (make-hash-table))
-        (lookup-hash (make-hash-table :test 'equal))
-        keys tmp)
-    (ergoemacs-timing where-is-hash
-      (ergoemacs-map-keymap
-       (lambda (key item)
-         (unless (and (vectorp key) (eq (elt key (- (length key) 1)) 
'ergoemacs-labeled))
-           (cond
-            ((and (vectorp key)
-                  (commandp item t))
-             (push key keys)
-             (if (setq tmp (ergoemacs-gethash item where-is-hash))
-                 (push key tmp)
-               (puthash item (list key) where-is-hash))
-             (puthash key item lookup-hash)))))
-       keymap))
-    (ergoemacs keymap :extract-keys keys)
-    (ergoemacs keymap :extract-where-is where-is-hash)
-    (ergoemacs keymap :extract-lookup lookup-hash)))
-
-(defun ergoemacs-map-properties--keys (keymap)
-  "Extract :keys property for KEYMAP."
-  (let ((ret (ergoemacs keymap :extract-keys)))
-    (unless ret
-      (ergoemacs-map-properties--calculate-keys-and-where-is-hash keymap)
-      (setq ret (ergoemacs keymap :extract-keys)))
-    ret))
-
-(defun ergoemacs-map-properties--where-is (keymap)
-  "Extract :where-is property for KEYMAP."
-  (let ((ret (ergoemacs keymap :extract-where-is)))
-    (unless ret
-      (ergoemacs-map-properties--calculate-keys-and-where-is-hash keymap)
-      (setq ret (ergoemacs keymap :extract-where-is)))
-    ret))
-
-(defun ergoemacs-map-properties--lookup (keymap)
-  "Extract :lookup property for KEYMAP."
-  (let ((ret (ergoemacs keymap :extract-lookup)))
-    (unless ret
-      (ergoemacs-map-properties--calculate-keys-and-where-is-hash keymap)
-      (setq ret (ergoemacs keymap :extract-lookup)))
-    ret))
-
-(defun ergoemacs-map-properties--new-command (keymap command &optional 
relative-map)
-  "In KEYMAP, get the COMMAND equivalent binding relative to the RELATIVE-MAP."
-  (and command keymap
-       (let* (ret
-              (hash-table (ergoemacs (or relative-map 
ergoemacs-saved-global-map global-map) :where-is))
-              (cmd-list (ergoemacs-gethash command hash-table)))
-         (if (not cmd-list) nil
-           (catch 'found-new
-             (dolist (key cmd-list)
-               (when (and (setq ret (lookup-key keymap key t))
-                          (or (and (commandp ret t) (not (memq ret 
ergoemacs-remap-ignore)))
-                              (and (integerp ret) (setq ret nil))))
-                 (throw 'found-new t))
-               (setq ret nil)) t) ret))))
-
-(defun ergoemacs-map-properties--revert-original (keymap &rest type)
-  "Revert KEYMAP.
-
-This is the same as calling `ergoemacs-map-properties--original'
-with the TYPE set to :setcdr.
-
-You may specify TYPE to be :flatten to return a flattend copy of
-the original instead."
-  (ergoemacs-map-properties--original keymap (or type :setcdr)))
-(defun ergoemacs-map-properties--original (keymap &optional type)
-  "Get original KEYMAP.
-
-When TYPE is :flatten, the return keymap is not composed and has
-no parents.
-
-When TYPE is :setcdr, the function modifies any submaps so they
-are original keymaps as well as modifying KEYMAP to be the
-original keymap.
-
-When TYPE is nil, return the original keymap, but any sub keymaps
-are not original, and the keymap may be composed or have a parent
-keymap."
-  (if (not (ergoemacs-keymapp keymap)) nil
-    (let ((ret keymap))
-      (while (and (or (and (not (ergoemacs ret :map-key))
-                           ;; Apply label if needed.
-                           (ergoemacs ret :label)) t)
-                  (not (integerp (ergoemacs ret :map-key)))
-                  (setq ret (keymap-parent ret)))
-        t)
-      (cond
-       ((eq type :flatten)
-        (ergoemacs-timing flatten-original
-          (ergoemacs-map-keymap nil ret t)))
-       ((eq type :submaps)
-        (ergoemacs-setcdr (cdr ret)
-                          (cdr (ergoemacs-timing flatten-setcdr
-                                 (ergoemacs-map-keymap nil ret :setcdr))))
-        ret)
-       (t ret)))))
-
-(defun ergoemacs-map-properties--original-user (keymap)
-  "Gets the original KEYMAP with the user protecting layer."
-  (make-composed-keymap (ergoemacs keymap :user) (ergoemacs keymap :original)))
-
-(defun ergoemacs-map-properties--installed-p (keymap)
-  "Is `ergoemacs-mode' installed in KEYMAP?
-Values returned are:
-  :protected-p -- An ergoemacs user keymap is installed on top
-  :cond-p -- This is a conditional map (usually found in 
`minor-mode-map-alist')
-  t -- `ergoemacs-mode' has been installed.
-  nil -- `ergoemacs-mode' has not modified this map."
-  (when (and keymap (ergoemacs-keymapp keymap))
-    (let* ((parent (keymap-parent keymap))
-           (key (and parent (ergoemacs keymap :map-key)))
-           (ret (and (consp key)
-                     (or (and (eq (nth 1 key) 'user) :protected-p)
-                         (and (eq (nth 1 key) 'cond-map) :cond-p)))))
-      (cond
-       ((eq ret :cond-p) ret)
-       ((not ret) nil)
-       ((and (setq key (ergoemacs parent :map-key)) (not (consp key))) ret)
-       ((eq (nth 1 key) 'ergoemacs-unbound) t)
-       ((and (ergoemacs parent :composed-p) (consp key)) t)
-       (t ret)))))
-
-
-(defun ergoemacs-map-properties--sequence (key)
-  "Return key sequence list from KEY.
-This sequence is compatible with `listify-key-sequence'."
-  (let (input)
-    (cond
-     ((not key)) ;; Not specified.
-     ((vectorp key) ;; Actual key sequence
-      (setq input (listify-key-sequence key)))
-     ((consp key) ;; Listified key sequence
-      (setq input key))
-     ((stringp key) ;; Kbd code
-      (setq input (listify-key-sequence (read-kbd-macro key t)))))
-    input))
-
 (defun ergoemacs-map-properties--movement-p (command)
   "Determines if COMMAND is a movement command.
 This is done by checking if this is a command that supports shift
@@ -1207,7 +47,6 @@ selection or cua-mode's movement."
       ;; Put 'CUA movement command if it wasn't there.
       (when (and tmp (symbolp command))
         (put command 'CUA 'move)))))
-
 (defun ergoemacs-map-properties--key-lessp (key1 key2)
   "Compares KEY1 and KEY2, and determines if KEY1 is \"less than\" key2.
 Used for sorting keys in displays."
@@ -1280,77 +119,6 @@ Used for sorting keys in displays."
         (< e1 e2))
        (t t))))))
 
-
-(defvar ergoemacs-map-properties--use-local-unbind-list '(isearch-mode-map)
-  "List of maps that will unbind ergoemacs-mode keys instead of using them 
directly.")
-
-(defun ergoemacs-map-properties--use-local-unbind-list-p (keymap)
-  "Determine if ergoemacs-mode keys should be unbound in KEYMAP.
-Looks in `ergoemacs-use-local-unbind-list' to determine what maps
-will unbind ergoemacs keys.
-
- This is useful in supporting isearch in Emacs 24.4+."
-  (when (ergoemacs-keymapp keymap)
-    
-    (let ((local-unbind-list-p (ergoemacs keymap :use-local-unbind-list-key)))
-      (cond
-       ((eq local-unbind-list-p 'no) nil)
-       (local-unbind-list-p local-unbind-list-p)
-       (ergoemacs-map-properties--use-local-unbind-list
-        (let ((map-list (ergoemacs keymap :map-list)))
-          (prog1 (catch 'found-use-local
-                   (dolist (map map-list)
-                     (when (memq map 
ergoemacs-map-properties--use-local-unbind-list)
-                       (setq local-unbind-list-p t)
-                       (throw 'found-use-local t)))
-                   (setq local-unbind-list-p 'no)
-                   nil)
-            (ergoemacs keymap :use-local-unbind-list-key 
local-unbind-list-p))))
-       (t nil)))))
-
-(defvar ergoemacs-map-properties--set-map-list '(isearch-mode-map)
-  "`ergoemacs-mode' modified maps.
-
-This is a list of maps that  `ergoemacs-mode' modifies directly.")
-
-(defun ergoemacs-map-properties--set-map-p (keymap)
-  "Determines if `ergoemacs-mode' should assign the original KEYMAP.
-
-Tyically `ergoemacs-mode' dosen't modify maps, but if this
-function returns non-nil, `ergoemacs-mode' does modify the
-keymaps and sets them to the original symbol in the object array.
-
- This is useful in supporting isearch in Emacs 24.4+."
-  (when (ergoemacs-keymapp keymap)
-
-    (let ((set-map-p (ergoemacs keymap :use-set-map-key)))
-      (cond
-       ((eq set-map-p 'no) nil)
-       (set-map-p set-map-p)
-       (ergoemacs-map-properties--set-map-list
-        (let ((map-list (ergoemacs keymap :map-list)))
-          (prog1 (catch 'found-use-local
-                   (dolist (map map-list)
-                     (when (memq map ergoemacs-map-properties--set-map-list)
-                       (setq set-map-p t)
-                       (throw 'found-use-local t)))
-                   (setq set-map-p 'no)
-                   nil)
-            (ergoemacs keymap :use-set-map-key set-map-p))))
-       (t nil)))))
-
-(defvar ergoemacs-map-properties--major-modes-that-modify-global-keymap
-  '(calc-mode calc-trail-mode calc-edit-mode)
-  "List of major modes that modify the global map.")
-
-(defvar ergoemacs-map-properties--ignore-global-changes-p nil
-  "When set, `ergoemacs-mode' may ignore changes in the `global-map'.")
-
-(defun ergoemacs-map-properties--ignore-global-changes-p ()
-  "Determines if `ergoemacs-mode' can ignore any change in the `global-map'."
-  (or ergoemacs-map-properties--ignore-global-changes-p
-      (memq major-mode 
ergoemacs-map-properties--major-modes-that-modify-global-keymap)))
-
 (provide 'ergoemacs-map-properties)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; ergoemacs-map-properties.el ends here
diff --git a/ergoemacs-map.el b/ergoemacs-map.el
index 1d48b59..3771b50 100644
--- a/ergoemacs-map.el
+++ b/ergoemacs-map.el
@@ -49,11 +49,9 @@
 (defvar ergoemacs-map--cache-save)
 (defvar ergoemacs-map--hash)
 (defvar ergoemacs-map-properties--plist-hash)
-(defvar ergoemacs-menu-keymap)
 (defvar ergoemacs-mode)
 (defvar ergoemacs-modify-transient-maps)
 (defvar ergoemacs-saved-global-map)
-(defvar ergoemacs-theme)
 (defvar ergoemacs-translation-hash)
 (defvar ergoemacs-user-keymap)
 (defvar ess-language)
@@ -63,28 +61,17 @@
 (defvar term-raw-map)
 
 
-(declare-function ergoemacs-timing-- "ergoemacs-mode")
-
-(declare-function ergoemacs-menu--filter "ergoemacs-lib")
 (declare-function ergoemacs-warn "ergoemacs-lib")
 (declare-function ergoemacs-setcdr "ergoemacs-lib")
 
-(declare-function ergoemacs-command-loop--modal "ergoemacs-command-loop")
 (declare-function ergoemacs-command-loop--spinner-display 
"ergoemacs-command-loop")
 
-(declare-function ergoemacs-component-struct--create-hooks 
"ergoemacs-component")
 (declare-function ergoemacs-component-struct--get "ergoemacs-component")
 (declare-function ergoemacs-component-struct--lookup-hash 
"ergoemacs-component")
 (declare-function ergoemacs-component-struct--lookup-list 
"ergoemacs-component")
 (declare-function ergoemacs-component-struct--minor-mode-map-alist 
"ergoemacs-component")
-(declare-function ergoemacs-component-struct--rm-hooks "ergoemacs-component")
-(declare-function ergoemacs-component-struct--translated-list 
"ergoemacs-component")
-
-(declare-function ergoemacs-command-loop--minibuffer-supported-p 
"ergoemacs-command-loop")
 
-(declare-function ergoemacs-theme--get-version "ergoemacs-theme-engine")
 (declare-function ergoemacs-theme-components "ergoemacs-theme-engine")
-(declare-function ergoemacs-theme--menu "ergoemacs-theme-engine")
 
 (declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
 
@@ -94,7 +81,6 @@
 (declare-function ergoemacs-map-properties--deferred-maps 
"ergoemacs-map-properties")
 (declare-function ergoemacs-map-properties--empty-p "ergoemacs-map-properties")
 (declare-function ergoemacs-map-properties--get-or-generate-map-key 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--ignore-global-changes-p 
"ergoemacs-map-properties")
 (declare-function ergoemacs-map-properties--installed-p 
"ergoemacs-map-properties")
 (declare-function ergoemacs-map-properties--key-hash 
"ergoemacs-map-properties")
 (declare-function ergoemacs-map-properties--keymap-value 
"ergoemacs-map-properties")
@@ -136,7 +122,7 @@
 When SYMBOL is a string/symbol generate a hash-key based on the symbol/string."
   (or (and symbol ergoemacs-map--hashkey
            (intern (format "%s-%s" symbol ergoemacs-map--hashkey)))
-      (let* ((val (format "%s" (append (list ergoemacs-keyboard-layout 
(ergoemacs :current-version)) (ergoemacs-theme-components))))
+      (let* ((val (format "%s" (append (list ergoemacs-keyboard-layout nil) 
(ergoemacs-theme-components))))
              (md5 (md5 val)))
         (setq ergoemacs-map--hashkey (intern md5)))))
 
@@ -310,17 +296,9 @@ done in `ergoemacs-map--alist'."
     ret))
 
 (defvar ergoemacs-menu-order)
-(defvar ergoemacs-map--undefined-keys nil
-  "List of undefined keys for the global map.")
-
 
 (defvar ergoemacs-map--cache--last-breadcrumb "")
 
-(defun ergoemacs-map-cache--exists-p (what)
-  "Does the hashkey WHAT exist?"
-  (let ((key (ergoemacs-map--hashkey what)))
-    (ergoemacs-gethash key ergoemacs-map--hash)))
-
 (defun ergoemacs-map--cache-- (what &optional save)
   "Get WHAT cache.  If SAVE is non-nil, save cache to WHAT."
   (or (and (not what) save
@@ -345,26 +323,6 @@ done in `ergoemacs-map--alist'."
           (puthash key (copy-tree val t) ergoemacs-map--hash))
         val)))
 
-(defvar ergoemacs-map--lookup-keymap-key-volitile-maps
-  '()
-  "Keymaps that are always calculated when they are the `current-local-map'.")
-
-(defun ergoemacs-map--lookup-keymap-key (lookup-keymap)
-  "Calculates the cache key based on LOOKUP-KEYMAP."
-  (let ((lookup-key (or (and (not (string= "" ergoemacs-map--breadcrumb)) 
ergoemacs-map--breadcrumb)
-                        (ergoemacs lookup-keymap :map-list)))
-        mode-hook)
-    (setq lookup-key (or (and (stringp lookup-key) (intern lookup-key))
-                         (and (consp lookup-key) (car lookup-key))))
-    (when (and lookup-key (eq (current-local-map) lookup-keymap))
-      (if (memq lookup-key ergoemacs-map--lookup-keymap-key-volitile-maps)
-          (setq lookup-key nil)
-        (if (minibufferp)
-            (setq lookup-key (intern (format "%s-%s" lookup-key (md5 (format 
"%s" minibuffer-setup-hook)))))
-          (when (and (setq mode-hook (intern (format "%s-hook" major-mode))) 
(boundp mode-hook))
-            (setq lookup-key (intern (format "%s-%s" lookup-key (md5 (format 
"%s" (symbol-value mode-hook))))))))))
-    lookup-key))
-
 (defvar ergoemacs-map--unbound-keys nil
   "Unbound keys.")
 
@@ -378,747 +336,17 @@ done in `ergoemacs-map--alist'."
 (defvar ergoemacs-map-- (make-hash-table :test 'equal))
 (defvar ergoemacs-map--lookup-hash (make-hash-table :test 'equal))
 
-(defun ergoemacs-map--composed-list (lookup-keymap lookup-key only-modify-p 
use-local-unbind-list-p)
-  "Calculate majority of keys for LOOKUP-KEYMAP.
-
-It takes the following arguments:
-
-- LOOKUP-KEY - key for the caching of keymaps.
-
-- LOOKUP-KEYMP -- keymap for any ergoemacs-mode equivalent
-  binding lookups.
-
-- ONLY-MODIFY-P -- When the keymap should only be modified,
-  lookups should not be performed.
-
-- USE-LOCAL-UNBIND-LIST-P -- When `ergoemacs-mode' equivalent
-  keys should be locally unbound.  This is useful for
-  `isearch-mode-map' keymap in Emacs 24.4+."
-  (when (ergoemacs-keymapp lookup-keymap)
-    (unless (ergoemacs lookup-keymap :installed-p)
-      (let ((ret (make-sparse-keymap))
-            tmp composed-list local-unbind-list bound-keys i key2)
-        (ergoemacs-cache (and lookup-key (intern (format "%s-%s-composed-key" 
lookup-key
-                                                         (ergoemacs 
lookup-keymap :map-key))))
-          (unless only-modify-p
-            (ergoemacs-timing lookup-keymap
-              (ergoemacs-map-keymap
-               (lambda(key item)
-                 (unless (or (eq item 'ergoemacs-prefix)
-                             (consp key)
-                             (memq item ergoemacs-remap-ignore))
-                   (let ((key (vconcat key)))
-                     ;; What are the keys that are changed.
-                     (when (setq tmp (ergoemacs-gethash key 
ergoemacs-map--lookup-hash))
-                       (dolist (new-key tmp)
-                         ;; (if (and (boundp 'isearch-mode-map) (eq 
lookup-keymap isearch-mode-map))
-                         ;;     (message "Define %s->%s" (key-description 
new-key) item))
-                         ;; Don't use (ergoemacs :define-key), since list 
contains all variants.
-                         (ergoemacs :define-key ret new-key item)
-                         (push new-key bound-keys)))
-                     ;; Keys where `ergoemacs-mode' dominates
-                     (setq i (length key))
-                     (when (and (catch 'found-key
-                                  (while (> i 0)
-                                    (when (setq tmp (ergoemacs-gethash (setq 
key2 (substring key 0 i)) ergoemacs-map--))
-                                      (throw 'found-key t))
-                                    (setq i (- i 1))) nil)
-                                (not (member key2 bound-keys))
-                                (not (member key2 
ergoemacs-map--unbound-keys)))
-                       (if (not use-local-unbind-list-p)
-                           (ergoemacs :define-key ret key2 tmp)
-                         (ergoemacs :apply-key key2
-                                    (lambda (trans-key)
-                                      (unless (member trans-key 
local-unbind-list)
-                                        (push trans-key local-unbind-list))))))
-                     ;; Define ergoemacs-mode remapping
-                     ;; lookups.
-                     (when (setq tmp (ergoemacs-gethash key (ergoemacs 
global-map :lookup)))
-                       (ergoemacs :define-key ret (vector 'ergoemacs-remap 
tmp) item)))))
-               lookup-keymap))
-            (ergoemacs ret :label (list (ergoemacs lookup-keymap :key-hash) 
'ergoemacs-mode (intern ergoemacs-keyboard-layout))))
-          (setq tmp (ergoemacs-component-struct--lookup-list lookup-keymap) 
composed-list (or (and ret (or (and tmp (append tmp (list ret))) (list ret))) 
tmp))
-          (list composed-list local-unbind-list ret))))))
-
-(defun ergoemacs-map--puthash (key new &optional table)
-  "Associate KEY with a list including NEW in TABLE."
-  (let* ((hash (or table ergoemacs-map--lookup-hash))
-         (lst (ergoemacs-gethash key hash)))
-    (if lst
-        (unless (member new lst)
-          (push new lst))
-      (setq lst (list new)))
-    (puthash key lst hash)))
-
-(defun ergoemacs-map--remhash (key new &optional table)
-  "For the KEY containing NEW, remove that NEW and update TABLE.
-
-If NEW is the only item in the list, remove it from the hash
-TABLE."
-  (let* ((hash (or table ergoemacs-map--lookup-hash))
-         (lst (ergoemacs-gethash key hash))
-         new-lst)
-    (when lst
-      (dolist (elt (reverse new-lst))
-        (unless (equal new elt)
-          (push elt new-lst)))
-      (if new-lst
-          (puthash key lst hash)
-        (remhash key hash)))))
-
-(defun ergoemacs-map--get-struct-map (struct-map cur-layout &optional 
lookup-keymap)
-  "For component STRUCT-MAP, get the ergoemacs keymap.
-
-When STRUCT-MAP is not a `ergoemacs-component-struct' object,
-return nil.  Otherwise, return the keymap based on the STRUCT-MAP
-component.
-
-The keyboard layout that is being calculated is CUR-LAYOUT.
-
-When LOOKUP-KEYMAP is nil, the returned map is relative to the
-global keymap.  Otherwise, it is relative to LOOKUP-KEYMAP."
-  (if (not (ergoemacs-component-struct-p struct-map)) nil
-    (let (ret
-         (cur-layout (or cur-layout ergoemacs-keyboard-layout)))
-      (cond
-       ((and (not lookup-keymap)
-             (string= cur-layout (ergoemacs-component-struct-layout 
struct-map)))
-        (setq ret (ergoemacs-component-struct-map struct-map)))
-       ((and (not lookup-keymap)
-             (setq ret (ergoemacs-gethash
-                        (list nil (intern cur-layout))
-                        (ergoemacs-component-struct-calculated-layouts 
struct-map))))
-        ret)
-       ((not lookup-keymap)
-        ;; Overall layout hasn't been calculated.
-        (setq ret (ergoemacs-component-struct--get struct-map cur-layout nil)))
-       (t
-        (error "Cant calculate/lookup keymap")))
-      ret)))
-
-(defun ergoemacs-map--get-unbind-list (component-list)
-  "Get the list of unbound keys based on COMPONENT-LIST.
-
-COMPONENT-LIST is a list of `ergoemacs-component-struct' items
-that will be applied.
-
-This is cached based on the current theme & theme options by
-`ergoemacs-cache'."
-  (if (not (consp component-list)) nil
-    (let (unbind-list)
-      (ergoemacs-cache unbind-list
-       (dolist (cur-map component-list)
-         (setq unbind-list
-               (append unbind-list
-                       (ergoemacs-component-struct--translated-list
-                        cur-map (ergoemacs-component-struct-unbind cur-map)))))
-       unbind-list))))
-
-(defun ergoemacs-map--get-undefined-map (component-list)
-  "Get a keymap of the ergoemacs-mode unbound keys based on COMPONENT-LIST.
-
-COMPONENT-LIST is a list of `ergoemacs-component-struct' items
-that will be applied.
-
-This updates the variable `ergoemacs-map--undefined-keys', and
-then defines each key in the `ergoemacs-map--undefined-keys'
-vector on the new keymap to be `ergoemacs-map-undefind'."
-  (let ((ret (make-sparse-keymap)))
-    (dolist (cur-map component-list)
-      (dolist (undefined-key (ergoemacs-component-struct-undefined cur-map))
-        (unless (member undefined-key ergoemacs-map--undefined-keys)
-          (push undefined-key ergoemacs-map--undefined-keys))))
-    (dolist (i ergoemacs-map--undefined-keys)
-      (define-key ret i #'ergoemacs-map-undefined))
-    (ergoemacs ret :label (list (ergoemacs (ergoemacs :global-map) :key-hash) 
'ergoemacs-undefined (intern ergoemacs-keyboard-layout)))
-    ret))
-
-(defun ergoemacs-map--global-component-keys-lists (component-list 
menu-bar-list composed-keymap-list &optional layout)
-  "Get ergoemacs keys from COMPONENT-LIST.
-
-This puts menu bar components in MENU-BAR-LIST, and other keymaps
-in COMPOSED-KEYMAP-LIST.
-
-The LAYOUT represents the keybaord layout that will be translated."
-  (let (tmp tmp2)
-    (push (lookup-key (ergoemacs :global-map) [menu-bar]) menu-bar-list)
-    (dolist (cur-map (reverse component-list))
-      (when cur-map
-       (setq tmp (ergoemacs-map--get-struct-map cur-map layout))
-       (unless (ergoemacs tmp :empty-p)
-          (cond
-           ((setq tmp2 (lookup-key tmp [menu-bar-list]))
-            (push (copy-keymap tmp2) menu-bar-list)
-            (setq tmp2 (make-sparse-keymap))
-            (map-keymap
-             (lambda (event item)
-               (unless (eq event 'menu-bar-list)
-                 (define-key tmp2 (vector event) item)))
-             tmp)
-            (unless (ergoemacs tmp2 :empty-p)
-              (push tmp2 composed-keymap-list)))
-           (t (push tmp composed-keymap-list))))))
-    (vector menu-bar-list composed-keymap-list)))
-
-(defun ergoemacs-map--setup-global-ergoemacs-hash (keymap-list unbind-list)
-  "Setup `ergoemacs-map--' cache based on KEYMAP-LIST, repsecting UNBIND-LIST."
-  (let (tmp)
-    (ergoemacs-timing setup-ergoemacs-hash
-      (dolist (ret keymap-list)
-       (ergoemacs-map-keymap
-        (lambda(key item)
-          (unless (or (eq item 'ergoemacs-prefix)
-                      (ignore-errors (eq (aref key 0) 'ergoemacs-labeled))
-                      (gethash key ergoemacs-map--)
-                      (member key unbind-list))
-            (when (setq tmp (ergoemacs-gethash item (ergoemacs global-map 
:where-is)))
-              (dolist (old-key tmp)
-                (ergoemacs :apply-key old-key
-                           (lambda(trans-old-key)
-                             (ergoemacs :apply-key key
-                                        (lambda(trans-new-key)
-                                          (unless (or (gethash trans-new-key 
ergoemacs-map--)
-                                                      (member trans-new-key 
unbind-list))
-                                            (puthash trans-new-key item 
ergoemacs-map--)
-                                            (ergoemacs-map--puthash 
trans-old-key trans-new-key))))))))
-            (ergoemacs :apply-key key #'puthash item ergoemacs-map--)))
-        ret)))))
-
-(defun ergoemacs-map--get-global-menu-map (menu-bar-list)
-  "Get the global menu-bar from MENU-BAR-LIST."
-  (let ((tmp (make-composed-keymap menu-bar-list))
-       (i 0)
-       alst)
-    (dolist (menu ergoemacs-menu-order)
-      (push (list menu i) alst)
-      (setq i (+ i 1)))
-    (setq tmp (sort tmp (lambda(elt1 elt2)
-                          (let ((i1 (or (and (eq elt1 'keymap) -1) (assq (car 
elt1) alst)))
-                                (i2 (or (and (eq elt2 'keymap) -1) (assq (car 
elt2) alst))))
-                            (if i1
-                                (setq i1 (or (and (integerp i1) i1) (nth 1 
i1)))
-                              (setq i1 (length ergoemacs-menu-order)))
-                            (if i2
-                                (setq i2 (or (and (integerp i2) i2) (nth 1 
i2)) )
-                              (setq i2 (length ergoemacs-menu-order)))
-                            (< i1 i2)))))
-    tmp))
-
-(defun ergoemacs-map--get-global-unbound-keymap (unbind-list)
-  "Create a keymap for UNBIND-LIST to unbind keys."
-  (let ((ret (make-sparse-keymap)))
-    (dolist (key unbind-list)
-      (define-key ret key nil))
-    (ergoemacs ret :label (list (ergoemacs (ergoemacs :global-map) :key-hash) 
'ergoemacs-unbound (intern ergoemacs-keyboard-layout)))
-    ret))
-
-
-(defun ergoemacs-map--get-global-map (component-list unbind-list layout 
lookup-key)
-  "Get the global map.
-
-- COMPONENT-LIST is the list of ergoemacs components to apply.
-
-- UNBIND-LIST is the keys that `ergoemacs-mode' has unbound.
-
-- LAYOUT represents the keyboard layout to be calculated
-
-- LOOKUP-KEY represents the symbol to cache the calculated
-  results."
-  ;; The `undefined-key' layer
-  (let (tmp
-       ret
-       menu-bar
-       parent
-       composed-list
-       tmp2)
-    (setq tmp (ergoemacs-cache global-menu
-                (push (ergoemacs-map--get-undefined-map component-list) 
composed-list)
-                (setq tmp (ergoemacs-map--global-component-keys-lists 
component-list menu-bar composed-list layout)
-                      menu-bar (elt tmp 0)
-                      composed-list (elt tmp 1))
-                (ergoemacs-map--setup-global-ergoemacs-hash composed-list 
unbind-list)
-                ;; The real `global-map'
-                (setq tmp (ergoemacs-map--get-global-menu-map menu-bar)
-                      ;; The keys that will be unbound
-                      ret (ergoemacs-map--get-global-unbound-keymap 
unbind-list))
-                
-                tmp))
-    (setq parent (copy-keymap (ergoemacs :global-map))
-         composed-list (ergoemacs-cache global-composed-list composed-list)
-         ret (ergoemacs-cache global-ret ret)
-         ergoemacs-map-- (ergoemacs-cache ergoemacs-map-- ergoemacs-map--)
-         ergoemacs-map--lookup-hash (ergoemacs-cache 
ergoemacs-map--lookup-hash ergoemacs-map--lookup-hash)
-         ergoemacs-map--undefined-keys (ergoemacs-cache undefined-keys 
ergoemacs-map--undefined-keys))
-    (define-key parent [menu-bar] tmp)
-    (set-keymap-parent ret (make-composed-keymap composed-list parent))
-    ;; Save hash
-    (puthash lookup-key ret ergoemacs-map--hash)
-    (puthash (ergoemacs-map--hashkey 'ergoemacs-map--lookup-hash) 
ergoemacs-map--lookup-hash ergoemacs-map--hash)
-    (puthash (ergoemacs-map--hashkey 'ergoemacs-map--undefined-keys) 
ergoemacs-map--undefined-keys ergoemacs-map--hash)
-    
-    ;; Get the protecting user keys
-    (setq tmp2 (list))
-    (unless ergoemacs-ignore-prev-global
-      (setq tmp (ergoemacs :user-before))
-      (unless (ergoemacs tmp :empty-p)
-       (push tmp tmp2)))
-    (setq tmp (ergoemacs :user-after))
-    (unless (ergoemacs tmp :empty-p)
-      (push tmp tmp2))
-    (setq tmp (ergoemacs parent :user))
-    (when tmp
-      (push tmp tmp2))
-    (push ergoemacs-user-keymap tmp2)
-    (define-key ret [ergoemacs-ignore] 'ergoemacs-command-loop--ignore)
-    (setq ret (make-composed-keymap tmp2 ret))
-    ret))
-
-(defun ergoemacs-map--adjust-remaps-for-overrides (hook-overrides 
composed-list keymap &optional deferred-p)
-  "Use HOOK-OVERRIDES to adjust COMPOSED-LIST and KEYMAP.
-
-A new list of keymaps will be returned with any [ergoemacs-remap]
-keys calculated.
-
-When DEFERRED-P is non-nil, the returned keymap list will have
-new overriding keymaps are appended, otherwise the overriding
-keymaps are prepended"
-  (if (not hook-overrides) composed-list
-    ;; Need to fix 'ergoemacs-remaps as well.
-    ;; This is done here because hooks can change, and the
-    ;; cached map would be invalid.
-    (let ((tmp (ergoemacs global-map :keys))
-          (tmp2 (make-sparse-keymap))
-          (tmp3 (make-composed-keymap hook-overrides)))
-      (ergoemacs tmp2 :label '(fix-hook-remaps))
-      (ergoemacs-timing calculate-ergoemacs-remap
-       (ergoemacs-map-keymap
-        (lambda(key item)
-          (unless (or (eq item 'ergoemacs-prefix)
-                      (consp key))
-            (let ((key (vconcat key)))
-              (when (member key tmp)
-                (define-key keymap (vector 'ergoemacs-remap (ergoemacs-gethash 
key (ergoemacs global-map :lookup))) nil)))))
-        tmp3))
-      (unless (ergoemacs tmp2 :empty-p)
-       (push tmp2 hook-overrides))
-      (if deferred-p
-         (append composed-list hook-overrides)
-       (append hook-overrides composed-list)))))
-
-(defun ergoemacs-map--unbound-passthrough (hook-overrides hook-deferred 
unbind-list local-unbind-list)
-  "Create a keymap of the keys that should be visible to Emacs.
-
-- HOOK-OVERRIDES -- overriding keys from hooks.
-
-- HOOK-DEFERRED -- Keys defined in hooks that will can be
-  overriden by `ergoemacs-mode'.
-
-- UNBIND-LIST -- List of unbound keys.
-
-- LOCAL-UNBIND-LIST - List of locally unbound keys."
-  (let ((unbound-passthrough (make-sparse-keymap))
-       tmp tmp3)
-    (when (or hook-overrides hook-deferred)
-      (setq tmp3 (make-composed-keymap (append hook-overrides hook-deferred))
-            tmp (append unbind-list ergoemacs-map--unbound-keys 
local-unbind-list))
-      (ergoemacs-timing calc-passthrough
-        (ergoemacs-map-keymap
-         (lambda (key item)
-           (unless (or (eq item 'ergoemacs-prefix)
-                       (consp key))
-             (let ((key (vconcat key)))
-               (when (member key tmp)
-                 (define-key unbound-passthrough key item)))))
-         tmp3))
-      (ergoemacs unbound-passthrough :label '(unbound-passthrough)))
-    unbound-passthrough))
-
-(defun ergoemacs-map--unbound-keymap (lookup-key lookup-keymap unbind-list 
local-unbind-list)
-  "Create unbound keymap.
-
-This is cached with LOOKUP-KEY.
-
-The LOOKUP-KEYMAP is the keymap that will be modified.
-
-The UNBIND-LIST and LOCAL-UNBIND-LIST are the keys that will be
-unbound."
-  (let ((ret (make-sparse-keymap))
-       tmp tmp2 tmp3)
-    (ergoemacs-cache (and lookup-key (intern (format "%s-unbound-keymap" 
lookup-key)))
-      ;; Remove keys from lookup-keymap
-      (unless lookup-keymap
-       (setq tmp2 nil)
-       (maphash
-        (lambda(key item)
-          (dolist (key2 item)
-            (when (member key2 (append unbind-list ergoemacs-map--unbound-keys 
local-unbind-list))
-              (push key tmp2)
-              (when (setq tmp3 (ergoemacs-translate--escape-to-meta key))
-                (push tmp3 tmp2))
-              (when (setq tmp3 (ergoemacs-translate--meta-to-escape key))
-                (push tmp3 tmp2)))))
-        ergoemacs-map--lookup-hash)
-       (dolist (key tmp2)
-         (remhash key ergoemacs-map--lookup-hash)))
-      (dolist (key (append unbind-list ergoemacs-map--unbound-keys 
local-unbind-list))
-       (unless (equal key [ergoemacs-labeled])
-         (when (not lookup-keymap)
-           (remhash key ergoemacs-map--)
-           (when (setq tmp (ergoemacs-translate--escape-to-meta key))
-             (remhash key ergoemacs-map--lookup-hash)))
-         (if (not lookup-keymap)
-             (define-key ret key nil)
-           (setq tmp (lookup-key lookup-keymap key))
-           (if (or (not tmp) (integerp tmp))
-               (define-key ret key nil)
-             (if (member key local-unbind-list)
-                 (define-key ret key nil)
-               (define-key ret key tmp))))))
-      (ergoemacs ret :label (list (ergoemacs lookup-keymap :key-hash) 
'ergoemacs-unbound (intern ergoemacs-keyboard-layout)))
-      ret)))
-
-(defun ergoemacs-map--set-maps (lookup-keymap final-keymap)
-  "Set maps.
-
-LOOKUP-KEYMAP is the lookup-keymap where the keymaps may be set.
-
-FINAL-KEYMAP is the `ergoemacs-mode' modified keymap."
-  (let (tmp)
-    (when (ergoemacs lookup-keymap :set-map-p)
-      (dolist (map (ergoemacs lookup-keymap :map-list))
-       (when (eq lookup-keymap overriding-local-map)
-         (setq overriding-local-map final-keymap))
-       (when (eq lookup-keymap overriding-terminal-local-map)
-         (setq overriding-terminal-local-map final-keymap))
-       (when (eq (default-value map) lookup-keymap)
-         (ergoemacs :spinner '("⌨→%s (default)" "ergoemacs→%s (default)" 
"ergoemacs->%s (default)") map)
-         (set-default map final-keymap))
-       (when (eq (symbol-value map) lookup-keymap)
-         (ergoemacs :spinner '("⌨→%s (local)" "ergoemacs→%s (local)" 
"ergoemacs->%s (local)") map)
-         (set map final-keymap))
-       (when (setq tmp (assoc map ergoemacs-map--mirrored-maps))
-         (dolist (mirror (cdr tmp))
-           (when (and mirror (boundp mirror))
-             (ergoemacs :spinner '("⌨→%s (mirror %s)" "ergoemacs→%s (mirror 
%s)" "ergoemacs->%s (mirror %s)") map mirror)
-             (set mirror final-keymap)
-             (push mirror ergoemacs-map--modified-maps))))
-       (push map ergoemacs-map--modified-maps)))))
-
-(defun ergoemacs-map--lookup-map (keymap unbind-list)
-  "Change KEYMAP to insert `ergoemacs-mode' keys.
-UNBIND-LIST is the list of keys that `ergoemacs-mode'."
-  (ergoemacs keymap :label)
-  (let* ((lookup-keymap (ergoemacs keymap :original))
-         (use-local-unbind-list-p (ergoemacs lookup-keymap 
:use-local-unbind-list-p))
-         (only-modify-p (ergoemacs lookup-keymap :only-local-modifications-p))
-         (lookup-key (ergoemacs-map--lookup-keymap-key lookup-keymap))
-         (composed-list (ergoemacs-map--composed-list lookup-keymap lookup-key 
only-modify-p use-local-unbind-list-p))
-         (ret (nth 2 composed-list))
-        (local-unbind-list (nth 1 composed-list))
-        (composed-list (nth 0 composed-list))
-        (parent lookup-keymap)
-        (hook-overrides (ergoemacs lookup-keymap :override-maps))
-        (hook-deferred (ergoemacs lookup-keymap :deferred-maps))
-        unbound-passthrough tmp)
-    (setq composed-list (ergoemacs-map--adjust-remaps-for-overrides 
hook-overrides composed-list ret)
-         composed-list (ergoemacs-map--adjust-remaps-for-overrides 
hook-deferred composed-list ret t)
-         unbound-passthrough (ergoemacs-map--unbound-passthrough 
hook-overrides hook-deferred unbind-list local-unbind-list))
-    (cond
-     ((and only-modify-p composed-list)
-      ;; Get the protecting user keys
-      (setq ret (make-composed-keymap composed-list parent)
-            tmp (ergoemacs parent :user))
-      (when tmp
-        (setq ret (make-composed-keymap tmp ret)))
-      ret)
-     ((and only-modify-p (not composed-list))
-      (setq ret parent))
-     (t
-      ;; The keys that will be unbound
-      (setq ret (ergoemacs-map--unbound-keymap lookup-key lookup-keymap 
unbind-list local-unbind-list))
-      (set-keymap-parent ret (make-composed-keymap composed-list parent))
-      ;; Put the unbound keys that are passed through the
-      ;; `ergoemacs-mode' layer of keys.
-      (unless (ergoemacs unbound-passthrough :empty-p)
-        (setq ret (make-composed-keymap unbound-passthrough ret)))
-      ;; Get the protecting user keys
-      (setq tmp (ergoemacs parent :user))
-      (when tmp
-        (setq ret (make-composed-keymap tmp ret)))
-      ;; Set the overall map values too...
-      (when (ergoemacs lookup-keymap :set-map-p)
-        (dolist (map (ergoemacs lookup-keymap :map-list))
-          (when (eq lookup-keymap overriding-local-map)
-            (setq overriding-local-map ret))
-          (when (eq lookup-keymap overriding-terminal-local-map)
-            (setq overriding-terminal-local-map ret))
-          (when (eq (default-value map) lookup-keymap)
-            (ergoemacs :spinner '("⌨→%s (default)" "ergoemacs→%s (default)" 
"ergoemacs->%s (default)") map)
-            (set-default map ret))
-          (when (eq (symbol-value map) lookup-keymap)
-            (ergoemacs :spinner '("⌨→%s (local)" "ergoemacs→%s (local)" 
"ergoemacs->%s (local)") map)
-            (set map ret))
-          (when (setq tmp (assoc map ergoemacs-map--mirrored-maps))
-            (dolist (mirror (cdr tmp))
-              (when (and mirror (boundp mirror))
-                (ergoemacs :spinner '("⌨→%s (mirror %s)" "ergoemacs→%s (mirror 
%s)" "ergoemacs->%s (mirror %s)") map mirror)
-                (set mirror ret)
-                (push mirror ergoemacs-map--modified-maps))))
-          (push map ergoemacs-map--modified-maps)))))
-    ret))
-
-(defun ergoemacs-map-- (&optional lookup-keymap layout struct-map)
-  "Get map looking up changed keys in LOOKUP-KEYMAP based on LAYOUT.
-
-STRUCT-MAP can be a `ergoemacs-component-struct', or a string/symbol of
-a calculated or uncalcuated component in
-`ergoemacs-component-hash'
-
-STRUCT-MAP can also be a list of `ergoemacs-component-struct' values
-or string/symbols that are in `ergoemacs-component-hash'
-
-If missing, STRUCT-MAP represents the current theme compenents, from
-`ergoemacs-theme-components'
-
-LAYOUT represents the layout that is used.
-
-LOOKUP-KEYMAP represents what should be calculated/looked up.
-
-If LOOKUP-KEYMAP is a keymap, lookup the ergoemacs-mode
-modifications to that keymap."
-  (let* ((cur-layout (or layout ergoemacs-keyboard-layout))
-         lookup-key
-         (struct-map (ergoemacs-component-struct--lookup-hash (or struct-map 
(ergoemacs-theme-components))))
-         unbind-list
-         ret
-         (lookup-keymap (or (and lookup-keymap (symbolp lookup-keymap)
-                                (ergoemacs-sv lookup-keymap))
-                           lookup-keymap)))
-    (cond
-     ((memq 'add-keymap-witness lookup-keymap) ;; Don't translate complete 
tranisent maps.
-      lookup-keymap)
-     ((and lookup-keymap (symbolp lookup-keymap) (ergoemacs-gethash 
lookup-keymap ergoemacs-translation-hash))
-      (ergoemacs-command-loop--modal lookup-keymap))
-     ((consp (ergoemacs lookup-keymap :map-key)) ;; Ignore already installed.
-      lookup-keymap)
-     ((and lookup-keymap (ergoemacs lookup-keymap :dont-modify-p))
-      lookup-keymap)
-     ((and (consp struct-map) ;; Don't do anything with blank keymaps.
-           lookup-keymap
-          ;; Blank keymaps are also unlabeled by `ergoemacs-mode', so
-          ;; make sure to use :empty-p t
-          (ergoemacs lookup-keymap :empty-p t))
-      lookup-keymap)
-     ((and (consp struct-map)
-           (progn
-             (setq unbind-list (ergoemacs-map--get-unbind-list struct-map)) t))
-      (cond
-       ((not lookup-keymap)
-       (ergoemacs-map--get-global-map struct-map unbind-list cur-layout 
lookup-key))
-       ;; Now create the keymap for a specified `lookup-keymap'
-       (lookup-keymap
-       (ergoemacs-map--lookup-map lookup-keymap unbind-list))))
-     ;; Component keymap
-     ((setq ret (ergoemacs-map--get-struct-map struct-map cur-layout 
lookup-keymap))
-      ret)
-     (t
-      (ergoemacs-warn "Component struct-map isn't a proper argument for 
`ergoemacs-map'")
-      (ergoemacs-warn "\tLookup:%s" lookup-keymap)
-      (ergoemacs-warn "\tLayout:%s" layout)
-      (ergoemacs-warn "\tMap:%s" struct-map)
-      lookup-keymap))))
-
-(defun ergoemacs-map--temporary-map-properties (map)
-  "Test if MAP is a transient map that `ergoemacs-mode' does not touch.
-
-This occurs when the keymap is not known to `ergoemacs-mode' and
-it is not a composed keymap.
-
-If it is a tranisent map, assign the :dont-modify-p property to t."
-  (setq ergoemacs-map--breadcrumb "transient-maps")
-  (ergoemacs map :label)
-  ;;ergoemacs-modify-transient-maps
-  (if (eq (ergoemacs-gethash 'transient-maps ergoemacs-breadcrumb-hash)
-         (ergoemacs (ergoemacs :original map) :key))
-      (ergoemacs map :dont-modify-p t)
-    (ergoemacs-setcdr (cdr map) (cdr (ergoemacs (ergoemacs :original map))))))
-
-
-(defvar ergoemacs-map--modify-active-last-overriding-terminal-local-map nil)
-(defvar ergoemacs-map--modify-active-last-overriding-local-map nil)
-(defvar ergoemacs-map--modify-active-last-char-map nil)
-(defvar ergoemacs-map--modify-active-last-local-map nil)
-(defvar ergoemacs-map--saved-global-map nil)
-(defvar ergoemacs-map--last-global-map nil)
 (defvar ergoemacs-read-from-minibuffer-map nil
   "If non-nil, keymap that is being read by the minibuffer.")
-(defun ergoemacs-map--modify-active (&optional ini)
-  "Modifies Active maps.
-
-When INI is non-nil, add conditional maps to `minor-mode-map-alist'."
-  (when ergoemacs-mode
-    (let ((char-map (get-char-property-and-overlay (point) 'keymap))
-         (local-map (get-text-property (point) 'local-map))
-         (current-local-map (current-local-map))
-         tmp)
-      (when (and overriding-terminal-local-map
-                (not (eq overriding-terminal-local-map 
ergoemacs-map--modify-active-last-overriding-terminal-local-map))
-                (not (ergoemacs overriding-terminal-local-map :installed-p))
-                (not (memq 'add-keymap-witness overriding-terminal-local-map)))
-       ;; (ergoemacs-map--temporary-map-properties 
overriding-terminal-local-map)
-       (setq overriding-terminal-local-map (ergoemacs 
overriding-terminal-local-map)))
-      
-      (when (and overriding-local-map
-                (not (eq overriding-local-map 
ergoemacs-map--modify-active-last-overriding-local-map))
-                (not (ergoemacs overriding-local-map :installed-p)))
-       ;; (ergoemacs-map--temporary-map-properties overriding-local-map)
-       (setq overriding-local-map (ergoemacs overriding-local-map)))
-
-      (ergoemacs-save-buffer-state
-       (when (and char-map (symbolp char-map))
-        (setq char-map (ergoemacs-sv char-map)))
-       (when (and (listp char-map)
-                 (car char-map)
-                 (not (eq (car char-map) 
ergoemacs-map--modify-active-last-char-map))
-                 (not (ergoemacs (car char-map) :installed-p)))
-        (cond
-         ((cdr char-map)
-          ;; Overlay
-          (overlay-put (cdr char-map) 'keymap (ergoemacs (car char-map))))
-         (t ;; Text Property
-          (put-text-property (previous-single-char-property-change (point) 
'keymap)
-                             (next-single-char-property-change (point) 'keymap)
-                             'keymap
-                             (ergoemacs (car char-map))))))
-       (when (and local-map (symbolp local-map))
-        (setq local-map (ergoemacs-sv local-map)))
-       (when (and local-map
-                 (not (eq local-map 
ergoemacs-map--modify-active-last-local-map))
-                 (not (ergoemacs local-map :installed-p)))
-        (put-text-property (previous-single-char-property-change (point) 
'local-map)
-                           (next-single-char-property-change (point) 
'local-map)
-                           'local-map (ergoemacs local-map)))
-       ;; Save before any changes happen (ie in calc)
-       (when (and (not ergoemacs-map--saved-global-map)
-                 (ergoemacs :ignore-global-changes-p))
-        (setq ergoemacs-map--saved-global-map (copy-keymap global-map)))
-       ;; Restore outside of modes that change the global map (calc)
-       (when (and ergoemacs-map--saved-global-map
-                 (not (ergoemacs :ignore-global-changes-p)))
-        (setq global-map (copy-keymap ergoemacs-map--saved-global-map)
-              ergoemacs-map--saved-global-map nil)
-        (use-global-map global-map))
-       (when (and (setq tmp (current-global-map))
-                 (ergoemacs-keymapp tmp)
-                 (not (eq tmp global-map))
-                 (or (not ergoemacs-map--last-global-map)
-                     (not (eq ergoemacs-map--last-global-map tmp)))
-                 (not (ergoemacs tmp :installed-p)))
-        (use-global-map (ergoemacs tmp))
-        (setq ergoemacs-map--last-global-map (current-global-map)))
-       (when (and current-local-map (not (ergoemacs current-local-map 
:installed-p))
-                 (not (minibufferp)))
-        (setq ergoemacs-map--breadcrumb (format "%s" major-mode))
-        (when (eq major-mode 'ess-mode)
-          (setq ergoemacs-map--breadcrumb (format "ess-mode-%s" ess-language)))
-         ;; term-mode has a term-raw-map that it checks against
-         ;; current-local-map to see if it is in line-mode or
-         ;; char-mode.  So we have to modify both term-raw-map and
-         ;; current-local-map to be able to switch.
-         (if (not (eq major-mode 'term-mode))
-            (use-local-map (ergoemacs current-local-map))
-           (progn
-             (use-local-map (ergoemacs term-raw-map))))
-        (setq ergoemacs-map--breadcrumb ""))
-       (when (and (minibufferp) ergoemacs-read-from-minibuffer-map)
-         ;; Preserve bindings for space, such as when completing a filename
-         (if (and (equal (key-binding " ") 'self-insert-command))
-             (use-local-map (list 'keymap
-                                  '(32 . self-insert-command) ;; space==32
-                                  (ergoemacs 
ergoemacs-read-from-minibuffer-map)))
-           (use-local-map (ergoemacs ergoemacs-read-from-minibuffer-map)))
-        (setq ergoemacs-read-from-minibuffer-map nil
-              ergoemacs-map--breadcrumb ""))
-       ;; Run deferred "hooks"
-       (when (and (minibufferp) 
ergoemacs-component-struct--composed-hook-minibuffer)
-        (dolist (elt (reverse 
ergoemacs-component-struct--composed-hook-minibuffer))
-          (when (equal (ergoemacs (symbol-value elt) :map-key)
-                       (ergoemacs ergoemacs-read-from-minibuffer-map :map-key))
-            (use-local-map (make-composed-keymap (cdr elt) 
(current-local-map))))
-          (ergoemacs-save-buffer-state
-           (set (make-local-variable (car elt)) (make-composed-keymap (cdr 
elt) (symbol-value (car elt))))))
-        (setq ergoemacs-component-struct--composed-hook-minibuffer nil)))
-      (setq ergoemacs-map--modify-active-last-overriding-terminal-local-map 
overriding-terminal-local-map
-           ergoemacs-map--modify-active-last-overriding-local-map 
overriding-local-map
-           ergoemacs-map--modify-active-last-char-map char-map
-           ergoemacs-map--modify-active-last-local-map local-map)
-      (ergoemacs-map--emulation-mode-map-alists)
-      (ergoemacs-map--minor-mode-map-alist ini)
-      (ergoemacs-map--minor-mode-overriding-map-alist))))
-
-
 (defvar ergoemacs-map--quit-map nil
   "Keymap of quit keys for local keymap.")
 
 (defun ergoemacs-map--install ()
   "Install `ergoemacs-mode' into the appropriate keymaps."
   (interactive)
-  (ergoemacs-map--hashkey)
-  (ergoemacs-mode-line)
-  (define-key ergoemacs-menu-keymap [menu-bar ergoemacs-mode]
-    `("ErgoEmacs" . ,(ergoemacs-theme--menu (ergoemacs :current-theme))))
-
-  (let ((x (assq 'ergoemacs-mode minor-mode-map-alist)))
-    (while x
-      (setq minor-mode-map-alist (delq x minor-mode-map-alist))
-      ;; Multiple menus sometimes happen because of multiple
-      ;; ergoemacs-mode variables in minor-mode-map-alist
-      (setq x (assq 'ergoemacs-mode minor-mode-map-alist)))
-    (push (cons 'ergoemacs-mode ergoemacs-menu-keymap) minor-mode-map-alist))
-  
-  (setq ergoemacs-map-- (make-hash-table :test 'equal)
-        ergoemacs-map--lookup-hash (make-hash-table :test 'equal)
-        ergoemacs-keymap (ergoemacs)
-        ergoemacs-map--alist (make-hash-table)
-        ergoemacs-map--alists (make-hash-table)
-        ergoemacs-map--alist-t (make-hash-table)
-        ergoemacs-map--alist-t-o (make-hash-table)
-        ergoemacs-map--quit-map (make-sparse-keymap)
-        ergoemacs-saved-global-map global-map
-        global-map ergoemacs-keymap)
-  (use-global-map global-map)
-  ;; Setup the quit map
-  (dolist (key (where-is-internal 'keyboard-quit))
-    (when (= 1 (length key))
-      (define-key ergoemacs-map--quit-map key 'keyboard-quit)))
-  (ergoemacs ergoemacs-map--quit-map :label '(ergoemacs-quit))
-  
-  ;; Put `ergoemacs-mode' style key shortcuts instead of emacs
-  ;; style shortcuts (They need to place the correct shortucts)
-  (ergoemacs-menu--filter (lookup-key ergoemacs-keymap [menu-bar]))
-  (ergoemacs-map--modify-active t)
-  (ergoemacs-component-struct--create-hooks)
-  (add-hook 'ergoemacs-post-command-hook #'ergoemacs-map--modify-active))
-
-(add-hook 'ergoemacs-mode-startup-hook #'ergoemacs-map--install)
+  (ergoemacs-mode-line))
 
 (defvar ergoemacs-mode)
-(defun ergoemacs-map--remove ()
-  "Remove `ergoemacs-mode' keybindings."
-  (interactive)
-  ;; Restore menu-bar
-  ;; Not needed; Global map isn't modified...
-  (let (ergoemacs-mode)
-    (setq ergoemacs-map--alist (make-hash-table)
-          ergoemacs-map--alists (make-hash-table)
-          global-map (ergoemacs :revert-global-map)
-          ergoemacs-saved-global-map  nil)
-    (use-global-map global-map)
-    (ergoemacs-map--modify-active t)
-    (ergoemacs-component-struct--rm-hooks)
-    (dolist (map ergoemacs-map--modified-maps)
-      (ergoemacs :spinner '("rm ⌨→%s" "rm ergoemacs→%s" "rm ergoemacs->%s") 
map)
-      (set map (ergoemacs (ergoemacs-sv map) :revert-original)))))
 
 (defvar ergoemacs-map-undefined-remaps
   '((kill-buffer . ergoemacs-close-current-buffer))
@@ -1141,8 +369,6 @@ runs the same command, tell the user."
      (t
       (message "%s is disabled!" key)))))
 
-(add-hook 'ergoemacs-mode-shutdown-hook #'ergoemacs-map--remove)
-
 (autoload 'ergoemacs (expand-file-name "ergoemacs-macros.el" ergoemacs-dir) 
nil t)
 (provide 'ergoemacs-map)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index 38e0307..8568e7f 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -9,7 +9,7 @@
 ;; Created: August 01 2007
 ;; Keywords: convenience
 ;; Version: 5.16.10.12
-;; Package-Requires: ((emacs "24.1") (undo-tree "0.6.5") (cl-lib "0.5"))
+;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
 ;; URL: https://github.com/ergoemacs/ergoemacs-mode
 
 ;; ErgoEmacs is free software: you can redistribute it and/or modify
@@ -49,73 +49,23 @@
 (eval-when-compile
   (require 'ergoemacs-macros))
 
-(require 'easymenu)
-(require 'undo-tree nil t)
 (provide 'ergoemacs-mode)
-(require 'package)
 (require 'kmacro)
 
 (require 'printing)
 (pr-update-menus)
 
-(add-to-list 'package-archives '("melpa-stable" . 
"http://stable.melpa.org/packages/";))
-(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/";))
-(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/";))
-
-(defvar ergoemacs--system (replace-regexp-in-string "[^0-9A-Za-z]+" "-" 
(concat emacs-version "-" system-configuration)))
-
-(when (and (string= package-user-dir (locate-user-emacs-file "elpa"))
-           (not (file-exists-p (locate-user-emacs-file "elpa"))))
-  (setq package-user-dir (locate-user-emacs-file (format "elpa-%s" 
ergoemacs--system))))
-
-(defvar cl-struct-ergoemacs-component-struct-tags)
-(defvar ergoemacs-component-struct--refresh-variables)
 (defvar ergoemacs-keyboard-layout)
-(defvar ergoemacs-map--hashkey)
-(defvar ergoemacs-require--ini-p)
-(defvar ergoemacs-require)
-(defvar pcache-directory)
-(defvar ergoemacs-component-struct--apply-ensure-p)
-
-(require 'package)
 
 (declare-function ergoemacs-key-description--unicode-char 
"ergoemacs-key-description")
-
-(declare-function ergoemacs-require "ergoemacs-lib")
-(declare-function ergoemacs-layouts--custom-documentation "ergoemacs-layouts")
-
 (declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
-;; (declare-function ergoemacs-map-properties--create-label-function 
"ergoemacs-map-properties")
-(declare-function ergoemacs-map-properties--put "ergoemacs-map-properties")
-
-(declare-function ergoemacs-theme--custom-documentation 
"ergoemacs-theme-engine")
-(declare-function ergoemacs-theme--customization-type "ergoemacs-theme-engine")
-(declare-function ergoemacs-theme-components "ergoemacs-theme-engine")
-
 (declare-function ergoemacs-translate--meta-to-escape "ergoemacs-translate")
-
 (declare-function ergoemacs-layouts--customization-type "ergoemacs-layouts")
 
-(declare-function ergoemacs-map-properties--label "ergoemacs-map-properties")
-(declare-function ergoemacs-map-- "ergoemacs-map")
-
-(declare-function persistent-soft-fetch "persistent-soft")
-(declare-function persistent-soft-flush "persistent-soft")
-(declare-function persistent-soft-location-destroy "persistent-flush")
-(declare-function persistent-soft-store "persistent-soft")
-
-(declare-function pcache-clear "pcache")
-(declare-function pcache-repository "pcache")
-
 
 ;; Fundamental ergoemacs functions
 
 
-;; (unless (featurep 'ergoemacs-map)
-;;   (load "ergoemacs-map"))
-
-
-
 ;; Ergoemacs-keybindings version
 (defconst ergoemacs-mode-version "5.14.7.3"
   "Ergoemacs-keybindings minor mode version number.")
@@ -129,56 +79,40 @@ Added beginning-of-buffer Alt+n (QWERTY notation) and 
end-of-buffer Alt+Shift+n"
   :group 'convenience
   :group 'emulations)
 
-(defcustom ergoemacs-theme (if (and (boundp 'ergoemacs-variant) 
ergoemacs-variant)
-                               ergoemacs-variant
-                             (if (and (boundp 'ergoemacs-theme) 
ergoemacs-theme)
-                                 ergoemacs-theme
-                               (if (getenv "ERGOEMACS_THEME")
-                                   (getenv "ERGOEMACS_THEME")
-                                 nil)))
+(defcustom ergoemacs-display-key-use-face t
+  "Use a button face for keys."
+  :type 'boolean
+  :initialize #'custom-initialize-default
+  :group 'ergoemacs-display)
+
+(defcustom ergoemacs-theme nil
   "Ergoemacs Keyboard Layout Themes."
   :type '(choice
           (const :tag "Standard" :value nil)
           (choice (symbol :tag "Other (symbol)")
                   (string :tag "Other (string)")))
-  :set 'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-mode)
 
-;;; ergoemacs-keymap
-
 (defvar ergoemacs-keymap (make-sparse-keymap)
-  "ErgoEmacs minor mode keymap.  This replaces `global-map'.")
-
-(defvar ergoemacs-saved-global-map nil
-  "Saved global map.")
-
-(defvar ergoemacs-menu-keymap (make-sparse-keymap)
-  "ErgoEmacs minor-mode menu keymap.")
+  "ErgoEmacs minor mode keymap.")
 
-(defvar ergoemacs-global-changed-keymap (make-sparse-keymap)
-  "This keymap shows the global keys that were changed before `ergoemacs-mode' 
loaded.")
+(defvar ergoemacs-translate--parent-map (make-sparse-keymap)
+  "Parent keymap for sparse translation")
 
-(defvar ergoemacs-map--breadcrumb ""
-  "Breadcrumb that is used to figure out what map is being modified.")
-
-(defcustom ergoemacs-keyboard-layout (or (getenv "ERGOEMACS_KEYBOARD_LAYOUT") 
"us")
-  (concat "Specifies which keyboard layout to use.
-  This is a mirror of the environment variable ERGOEMACS_KEYBOARD_LAYOUT.")
+(defcustom ergoemacs-keyboard-layout "us"
+  (concat "Specifies which keyboard layout to use.")
   :type 'sexp
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-mode)
 
 (defcustom ergoemacs-keyboard-mirror nil
   "Specifies which keyboard layout to mirror."
   :type 'sexp
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-mode)
 
 
-(defvar ergoemacs-theme)
 (defcustom ergoemacs-mode-line t
   "Determines when the ergoemacs-mode modeline indicator is shown."
   :type '(choice
@@ -204,19 +138,12 @@ The TEXT will be what the mode-line is set to be."
                       (if (not (eq 'ergoemacs-mode (nth 0 x)))
                           x
                         `(ergoemacs-mode ,(if (or (not ergoemacs-mode-line) 
(eq ergoemacs-mode-line 'no-layout)) ""
-                                            (concat
-                                             (if (string= "standard" 
(ergoemacs :current-theme))
-                                                 " ErgoEmacs"
-                                               (concat " Ergo"
-                                                       (upcase (substring 
(ergoemacs :current-theme) 0 1))
-                                                       (substring (ergoemacs 
:current-theme) 1)))
-                                             "[" ergoemacs-keyboard-layout 
"]")))))
+                                            (concat " ErgoEmacs"
+                                                    "[" 
ergoemacs-keyboard-layout "]")))))
                     minor-mode-alist)))))
 
-(require 'lookup-word-on-internet nil "NOERROR")
-
 (defconst ergoemacs-font-lock-keywords
-  
'(("(\\(ergoemacs\\(?:-theme-component\\|-theme\\|-component\\|-require\\|-remove\\|-advice\\|-translation\\|-cache\\|-timing\\|-package\\|-autoload\\)\\)\\_>[
 \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
+  '(("(\\(ergoemacs\\(?:-translation\\)\\)\\_>[ 
\t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
      (1 font-lock-keyword-face)
      (2 font-lock-constant-face nil t))))
 
@@ -224,61 +151,86 @@ The TEXT will be what the mode-line is set to be."
 
 
 
-(defcustom ergoemacs-hooks-that-always-override-ergoemacs-mode '()
-  "List of hooks that when defining keys override `ergoemacs-mode' keys."
-  :type '(repeat
-          (symbol :tag "Hook"))
-  :group 'ergoemacs-mode)
+(defvar ergoemacs-mode-startup-hook nil
+  "Hook for starting `ergoemacs-mode'.")
 
-(defcustom ergoemacs-functions-that-always-override-ergoemacs-mode '(lambda)
-  "List of overriding functions run from a hook.
+(defvar ergoemacs-mode-shutdown-hook nil
+  "Hook for shutting down `ergoemacs-mode'.")
 
-When defining keys these functions override
-`ergoemacs-mode'.  `lambda' is a special undefined function"
-  :type '(repeat
-          (symbol :tag "Function"))
-  :group 'ergoemacs-mode)
+(defvar ergoemacs-mode-intialize-hook nil
+  "Hook for initializing `ergoemacs-mode'.")
 
-(defcustom ergoemacs-directories-where-keys-from-hook-are-deferred '()
-  "Directories where `ergoemacs-mode' defers hooks that gerenate key changes."
-  :type '(repeat
-          (directory :tag "Deferred Directory: "))
-  :group 'ergoemacs-mode)
+(defvar ergoemacs-mode-init-hook nil
+  "Hook for running after Emacs loads.")
 
+(defvar ergoemacs-mode-after-load-hook nil
+  "Hook for running after a library loads.")
 
-(defgroup ergoemacs-themes nil
-  "Default Ergoemacs Layout"
-  :group 'ergoemacs-mode)
+(defvar ergoemacs-pre-command-hook nil)
+(defun ergoemacs-pre-command-hook ()
+  "Run `ergoemacs-mode' pre command hooks."
+  (when ergoemacs-mode
+    (run-hooks 'ergoemacs-pre-command-hook)))
 
-(defcustom ergoemacs-theme-options
-  '()
-  "List of theme options."
-  :type '(repeat
-          (list
-           (sexp :tag "Theme Component")
-           (choice
-            (const :tag "Force Off" off)
-            (const :tag "Force On" on)
-            (const :tag "Let theme decide" nil))))
-  :group 'ergoemacs-themes)
-
-(defcustom ergoemacs-theme-version
-  '()
-  "Each themes set version."
-  :type '(repeat
-          (list
-           (string :tag "Theme Component")
-           (choice
-            (const :tag "Latest Version" nil)
-            (string :tag "Version"))))
-  :group 'ergoemacs-theme)
+(defvar ergoemacs-post-command-hook nil)
+(defun ergoemacs-post-command-hook ()
+  "Run `ergoemacs-mode' post command hooks."
+  (when ergoemacs-mode
+    (run-hooks 'ergoemacs-post-command-hook)))
+
+(defvar ergoemacs-after-load-functions nil)
+(defun ergoemacs-after-load-functions (absoulte-file-name)
+  "Run `ergoemacs-mode' after load functions.
+
+ABSOULTE-FILE-NAME is the file name that will be passed to the
+variable `ergoemacs-after-load-functions'."
+  (run-hook-with-args 'ergoemacs-after-load-functions absoulte-file-name))
 
 (defvar ergoemacs-mode--default-frame-alist nil
   "List that saves default frame parameters.")
 
+(defvar ergoemacs-mode--save-keymaps-list '()
+  "List of emacs saved to restore if needed.")
+
+(defvar ergoemacs-mode--save-keymaps (make-hash-table)
+  "Saved keymaps for `ergoemacs-mode'")
+
+
+(defun ergoemacs-mode--save-map (symbol-map &optional is-ergoemacs)
+  "Save the keymap SYMBOL-MAP in the hash `ergoemacs-mode--save-keymaps'.
+
+IS-ERGOEMACS is true when the `ergoemacs-mode' keybindings are installed."
+  (let (hash-symbol
+        (map (symbol-value symbol-map)))
+    (if is-ergoemacs
+        (setq hash-symbol (concat (symbol-name symbol-map) "-ergoemacs-"
+                                  (or ergoemacs-theme "")))
+      (add-to-list 'ergoemacs-mode--save-keymaps-list symbol-map)
+      (setq hash-symbol (symbol-name symbol-map)))
+    (setq hash-symbol (intern hash-symbol))
+    (unless (gethash hash-symbol ergoemacs-mode--save-keymaps)
+      (puthash hash-symbol (copy-keymap map)
+               ergoemacs-mode--save-keymaps))))
+
+
+
+(defun ergoemacs-mode--get-map (symbol-map &optional is-ergoemacs)
+  "Get the keymap SYMBOL-MAP in the hash `ergoemacs-mode--save-keymaps'.
+
+IS-ERGOEMACS is true when the `ergoemacs-mode' keybindings are installed."
+  (let (hash-symbol)
+    (if is-ergoemacs
+        (setq hash-symbol (concat (symbol-name symbol-map) "-ergoemacs-"
+                                  (or ergoemacs-theme "")))
+      (setq hash-symbol (symbol-name symbol-map)))
+    (setq hash-symbol (intern hash-symbol))
+    (gethash hash-symbol ergoemacs-mode--save-keymaps)))
+
+(defun ergoemacs-mode--restore-maps (&optional is-ergoemacs)
+  "Restore normal or ergoemacs keymaps (when IS-ERGOEMACS is non-nil)."
+  (dolist (k ergoemacs-mode--save-keymaps-list)
+    (set k (ergoemacs-mode--get-map k is-ergoemacs))))
 
-(defvar ergoemacs-mode--start-p nil
-  "Determines if `ergoemacs-mode' will start.")
 ;; ErgoEmacs minor mode
 ;;;###autoload
 (define-minor-mode ergoemacs-mode
@@ -297,298 +249,69 @@ The `execute-extended-command' is now 
\\[execute-extended-command].
   :lighter " ErgoEmacs"
   :global t
   :group 'ergoemacs-mode
-  :keymap ergoemacs-menu-keymap
-  :after-hook (if (and (not noninteractive)
-                       (not ergoemacs-mode--start-p))
-                  (if ergoemacs-mode
-                      (message "Ergoemacs will be started.")
-                    (message "Ergoemacs startup canceled."))
-                (setq ergoemacs-map--hashkey nil)
-                (unless ergoemacs-require--ini-p
-                  (setq ergoemacs-require--ini-p :ini)
-                  (when ergoemacs-require
-                    (dolist (elt ergoemacs-require)
-                      (apply #'ergoemacs-require elt))))
-                (let ((refresh-p 
ergoemacs-component-struct--refresh-variables))
-                  (if ergoemacs-mode
-                      (progn
-                        (setq ergoemacs-mode--default-frame-alist nil)
-                        (dolist (elt (reverse default-frame-alist))
-                          (push elt ergoemacs-mode--default-frame-alist))
-                        (run-hooks 'ergoemacs-mode-startup-hook)
-                        (add-hook 'pre-command-hook 
#'ergoemacs-pre-command-hook)
-                        (add-hook 'post-command-hook 
#'ergoemacs-post-command-hook)
-                        (add-hook 'after-load-functions 
#'ergoemacs-after-load-functions)
-                        (setq ergoemacs-require--ini-p t
-                              ergoemacs-component-struct--apply-ensure-p t)
-                       (ergoemacs-setup-override-keymap)                       
-                        (if refresh-p
-                            (message "Ergoemacs-mode keys refreshed (%s:%s)"
-                                     ergoemacs-keyboard-layout (or 
ergoemacs-theme "standard"))
-                          (message "Ergoemacs-mode turned ON (%s:%s)." 
ergoemacs-keyboard-layout (or ergoemacs-theme "standard"))))
-                    (modify-all-frames-parameters 
ergoemacs-mode--default-frame-alist)
-                    (unless (assoc 'cursor-type 
ergoemacs-mode--default-frame-alist)
-                      (modify-all-frames-parameters (list (cons 'cursor-type 
'box))))
-                    (setq ergoemacs-mode--default-frame-alist nil
-                          ergoemacs-component-struct--apply-ensure-p t)
-                    (run-hooks 'ergoemacs-mode-shutdown-hook)
-                    (remove-hook 'post-command-hook 
#'ergoemacs-post-command-hook)
-                    (remove-hook 'pre-command-hook 
#'ergoemacs-pre-command-hook)
-                    (remove-hook 'after-load-functions 
#'ergoemacs-after-load-functions)
-                    (unless refresh-p
-                      (message "Ergoemacs-mode turned OFF."))))))
-
-(defvar ergoemacs--gzip (executable-find "gzip")
-  "Gzip location.")
-
-(defun ergoemacs-mode--pcache-repository ()
-  "Return the `ergoemacs-mode' pcache repository name."
-  (format "ergoemacs-mode-%s%s" ergoemacs--system
-          (or (and ergoemacs--gzip ".gz") "")))
-
-(defvar ergoemacs-mode--fast-p nil
-  "Is `ergoemacs-mode' running from the cache?")
-
-(defun ergoemacs-mode--setup-hash-tables--setq (store-p &rest args)
-  "Setup hash tables.
-STORE-P tells if the hash table should be stored.
-ARGS ar the set arguments."
-  (let (sym val found-p)
-    (dolist (a args)
-      (cond
-       ((and (symbolp a) (not store-p)) ;; Fetch
-        (setq sym a)
-        (when (featurep 'persistent-soft)
-          (setq val (persistent-soft-fetch sym 
(ergoemacs-mode--pcache-repository)))
-          (when val
-            (setq found-p t)
-            (set sym val)
-            (when (and (eq sym 'ergoemacs-component-hash)
-                       (hash-table-p val))
-              (setq ergoemacs-mode--fast-p t)))))
-       ((symbolp a) ;; Store
-        (setq sym a)
-        (when (featurep 'persistent-soft)
-          (persistent-soft-store sym (symbol-value sym) 
(ergoemacs-mode--pcache-repository))))
-       ((and (not found-p) (not store-p) (not (symbol-value sym)))
-        ;; Setup empty symbol.
-        ;; (message "Empty %s->%s" sym a)
-        (set sym a)
-        (setq found-p nil))
-       (t
-        (setq found-p nil))))))
-
-(defvar ergoemacs-component-hash nil
-  "Hash of ergoemacs-components.")
-
-(defvar ergoemacs-map--hash nil
-  "Hash of calculated maps.")
-
-(defvar ergoemacs-map-properties--indirect-keymaps nil
-  "Variable listing indirect keymaps.")
-
-(defvar ergoemacs-map-properties--key-struct nil
-  "Key struct hash table.")
-
-(defvar ergoemacs-map-properties--plist-hash nil)
-
-(defvar ergoemacs-theme-hash nil
-  "Hash of `ergoemacs-mode' themes.")
-
-(defvar ergoemacs-translate--event-hash nil
+  (setq ergoemacs-mode--start-p t)
+  (if ergoemacs-mode
+      (progn
+        ;; Save frame parameters
+        (run-hooks 'ergoemacs-mode-startup-hook)
+        (add-hook 'pre-command-hook #'ergoemacs-pre-command-hook)
+        (add-hook 'post-command-hook #'ergoemacs-post-command-hook)
+        (add-hook 'after-load-functions #'ergoemacs-after-load-functions)
+
+        (setq ergoemacs-mode--default-frame-alist nil)
+        (dolist (elt (reverse default-frame-alist))
+          (push elt ergoemacs-mode--default-frame-alist))
+        (ergoemacs-mode--restore-maps t)
+        ;; Setup the global keys that can be overriden
+        (cond
+         ((string-equal ergoemacs-theme "reduction")
+          (ergoemacs-install-reduction-theme))
+         (t (ergoemacs-install-standard-theme)))
+        (ergoemacs-command-loop--setup-quit-key)
+        ;; Make the ErgoEmacs menu
+        (ergoemacs-map--install)
+        ;; Setup the main keys
+        (cond
+         ((string-equal ergoemacs-theme "reduction")
+          (ergoemacs-setup-override-keymap))
+         (t (ergoemacs-setup-override-keymap)))
+        (setq ergoemacs-require--ini-p t)
+        ;;(define-key key-translation-map (kbd "<apps>") (kbd "<menu>"))
+        ;;(global-unset-key (kbd "<apps>"))
+        ;;(global-unset-key (kbd "<menu>"))
+        ;;(define-key ergoemacs-translate--parent-map [apps] 
'ergoemacs-command-loop--swap-translation)
+        ;;(define-key ergoemacs-translate--parent-map [menu] 
'ergoemacs-command-loop--swap-translation)
+        (when ergoemacs-mode-turn-on-cua-mode
+          (cua-mode 1))
+        (message "Ergoemacs-mode turned ON (%s)." ergoemacs-keyboard-layout))
+    ;; Turn off
+    ;; Restore frame parameters
+    (modify-all-frames-parameters ergoemacs-mode--default-frame-alist)
+    (setq ergoemacs-mode--default-frame-alist nil)
+
+    (ergoemacs-command-loop--redefine-quit-key)
+    (run-hooks 'ergoemacs-mode-shutdown-hook)
+    (remove-hook 'post-command-hook #'ergoemacs-post-command-hook)
+    (remove-hook 'pre-command-hook #'ergoemacs-pre-command-hook)
+    (remove-hook 'after-load-functions #'ergoemacs-after-load-functions)
+    (when ergoemacs-mode-turn-on-cua-mode
+      (cua-mode 0))
+    (ergoemacs-mode--restore-maps)
+    (message "Ergoemacs-mode turned OFF.")))
+
+(defvar ergoemacs-translate--event-hash (make-hash-table)
   "Event modifiers not covered by standard Emacs.")
 
-(defvar ergoemacs-translate--hash nil
+(defvar ergoemacs-translate--hash (make-hash-table)
   "Hash table of keyboard translations.
 This is structured by valid keyboard layouts for
 `ergoemacs-keyboard-layout'.")
 
-(defvar ergoemacs-translation-hash nil
+(defvar ergoemacs-translation-hash (make-hash-table)
   "Hash table of translations, structured by translatin type.")
 
-;; (defvar ergoemacs-map-properties--create-label-function nil)
-
-(defvar ergoemacs-map-properties--get-or-generate-map-key most-negative-fixnum)
-
-(defvar ergoemacs-breadcrumb-hash nil
-  "Hash table of map breadcrumbs.")
-
-(defvar ergoemacs-map-properties--before-ergoemacs nil
-  "Keymap describing changes before `ergoemacs-mode' loads.")
-
-(defvar ergoemacs-map-properties--after-ergoemacs nil
-  "Keymap describing changes before `ergoemacs-mode' loads.")
-
-(defvar ergoemacs-require nil
-  "List of required theme components.")
-
-(defvar ergoemacs-map-properties--label-atoms-maps nil
-  "Known bound keymaps.")
-
-(defvar ergoemacs-timing-hash nil
-  "Hash table of `ergoemacs-mode' timing.")
-
-(defvar ergoemacs-timing--locations
-  '((ensure . "ergoemacs-component.el")
-    (remove-global-map-map-keymap . "ergoemacs-component.el")
-    (remove-local-keymap-map-keymap . "ergoemacs-component.el")
-    (translate-keymap . "ergoemacs-component.el")
-    (describe-keymap . "ergoemacs-key-description.el")
-    (before-ergoemacs . "ergoemacs-map-properties.el")
-    (get-original-global-map . "ergoemacs-map-properties.el")
-    ;; (ergoemacs-map-properties--create-label-function . 
"ergoemacs-map-properties.el")
-    (ergoemacs-create-global . "ergoemacs-map-properties.el")
-    (empty-p . "ergoemacs-map-properties.el")
-    (where-is-hash . "ergoemacs-map-properties.el")
-    (flatten-original . "ergoemacs-map-properties.el")
-    (lookup-keymap . "ergoemacs-map.el")
-    (calculate-ergoemacs-remap . "ergoemacs-map.el")
-    (calc-remaps . "ergoemacs-map.el")
-    (calc-passthrough . "ergoemacs-map.el")
-    (ergoemacs-mode-after-init-emacs . "ergoemacs-mode.el")
-    (setup-ergoemacs-hash . "ergoemacs-mode.el"))
-  "Alist of known timing functions.")
-
-(defun ergoemacs-timing-- (key function)
-  "Save timing information for KEY by calling FUNCTION."
-  (let* ((entry-time (current-time))
-         (ret (funcall function))
-         val time file)
-    (if (not ergoemacs-timing-hash)
-        (setq ergoemacs-timing-hash (make-hash-table))
-      (if (not (setq val (gethash key ergoemacs-timing-hash)))
-          (puthash key (vector 1 (setq val (float-time (time-subtract 
(current-time) entry-time)))
-                               val val (or (and (setq file (assoc key 
ergoemacs-timing--locations)) (expand-file-name (cdr file) ergoemacs-dir))
-                                          load-file-name buffer-file-name)) 
ergoemacs-timing-hash)
-        (cl-incf (aref val 0))
-        (cl-incf (aref val 1) (setq time (float-time (time-subtract 
(current-time) entry-time))))
-        (setf (aref val 2) (min time (aref val 2)))
-        (setf (aref val 3) (max time (aref val 3)))
-        (puthash key val ergoemacs-timing-hash)))
-    ret))
-
-(defvar ergoemacs--component-file-mod-time-list nil)
-(defun ergoemacs--emacs-state ()
-  "Return MD5 represting current Emacs state."
-  (let* ((state (format "%s %s %s %s %s" ergoemacs--system features 
package-alist load-path ergoemacs--component-file-mod-time-list))
-         (md5 (md5 state)))
-    ;; (message "%s->%s" md5 state)
-    md5))
-
-(defvar ergoemacs--start-emacs-state (ergoemacs--emacs-state))
-(defvar ergoemacs--last-start-emacs-state nil)
-
-(defvar ergoemacs--start-emacs-state-2 nil)
-(defvar ergoemacs--last-start-emacs-state-2 nil)
-
-
-(require 'persistent-soft nil t)
-
-(defvar ergoemacs-map--cache-save nil)
-
-(defun ergoemacs-mode-clear-cache (&optional no-message)
-  "Clear the cache for next ergoemacs-mode load.
-NO-MESSAGE doesn't tell anything about clearing the cache."
-  (interactive)
-  (setq ergoemacs-map--cache-save :remove)
-  (ergoemacs-map--cache-save)
-  
-  (let ((extras (expand-file-name "ergoemacs-extras" user-emacs-directory)))
-    (if (not (file-exists-p extras))
-        (make-directory extras t))
-    (dolist (ext '("svg" "png"))
-      (dolist (file (file-expand-wildcards (expand-file-name (concat "*." ext) 
(expand-file-name "bindings" extras))))
-       (delete-file file)
-       (message "Remove %s, since keys may have changed." file))))
-
-  (unless no-message
-    (message "Clear cache for next startup.")))
-
-(defun ergoemacs-map--cache-save (&optional remove)
-  "Save ergoemacs cache for startup.
-REMOVE removes the cache insead of saving it."
-  (cond
-   ((and (featurep 'persistent-soft)
-         (featurep 'pcache)
-         (or remove (eq ergoemacs-map--cache-save :remove)))
-    (pcache-clear (pcache-repository (ergoemacs-mode--pcache-repository)))
-    (persistent-soft-location-destroy (ergoemacs-mode--pcache-repository)))
-   ((or remove (eq ergoemacs-map--cache-save :remove)))
-   (ergoemacs-map--cache-save
-    (ergoemacs-mode--setup-hash-tables t)
-    (setq ergoemacs-map--cache-save nil))))
-
-(add-hook 'kill-emacs-hook 'ergoemacs-map--cache-save)
-
-
-(defun ergoemacs-mode--setup-hash-tables (&optional store-p)
-  "Load hash-tables using `persistent-soft' when available.
-When STORE-P is non-nil, save the tables."
-  (ergoemacs-timing setup-hash-tables
-    ;; (when store-p
-    ;;   (setq ergoemacs-map-properties--create-label-function 
(ergoemacs-map-properties--create-label-function)))
-    (unless store-p
-      (ergoemacs-mode--setup-hash-tables--setq
-       nil
-       'ergoemacs--last-start-emacs-state nil)
-      ;; Check if system state has expired the cache.
-      (unless (equal ergoemacs--last-start-emacs-state 
ergoemacs--start-emacs-state)
-        (ergoemacs-mode-clear-cache t)
-        (message "Cache reset before loading.")
-        (setq ergoemacs-map--cache-save t)
-        (setq ergoemacs--last-start-emacs-state ergoemacs--start-emacs-state)
-        (ergoemacs-mode--setup-hash-tables--setq
-         t
-         'ergoemacs--last-start-emacs-state ergoemacs--last-start-emacs-state)
-        (ergoemacs-mode--setup-hash-tables--setq nil 'ergoemacs-require nil)))
-    (ergoemacs-mode--setup-hash-tables--setq
-     store-p
-     'ergoemacs-require nil
-     'ergoemacs-component-hash (make-hash-table :test 'equal)
-     'ergoemacs-map--hash (make-hash-table :test 'equal)
-     'ergoemacs-map-properties--indirect-keymaps (make-hash-table)
-     'ergoemacs-map-properties--key-struct (make-hash-table)
-     'ergoemacs-map-properties--plist-hash (make-hash-table :test 'equal)
-     'ergoemacs-theme-hash (make-hash-table :test 'equal)
-     'ergoemacs-translate--event-hash (make-hash-table)
-     'ergoemacs-translate--hash (make-hash-table)
-     'ergoemacs-translation-hash (make-hash-table)
-     'ergoemacs-breadcrumb-hash (make-hash-table)
-     ;; 'ergoemacs-map-properties--create-label-function nil
-     'ergoemacs-map-properties--get-or-generate-map-key most-negative-fixnum
-     'ergoemacs-map-properties--before-ergoemacs nil
-     'ergoemacs-map-properties--label-atoms-maps nil
-     ;;'ergoemacs-map-- (make-hash-table :test 'equal))
-     ;;'ergoemacs-map--alist (make-hash-table)
-     ;;'ergoemacs-map--alists (make-hash-table)
-     ;;'ergoemacs-map-properties--user-map-hash (make-hash-table :test 'equal)
-     ;;'ergoemacs-translate--keymap-hash (make-hash-table)
-     )
-    (when (and store-p (featurep 'persistent-soft))
-      (persistent-soft-flush (ergoemacs-mode--pcache-repository))
-      (with-temp-buffer
-        (insert-file-contents (concat pcache-directory 
(ergoemacs-mode--pcache-repository)))
-        (persistent-soft-location-destroy (ergoemacs-mode--pcache-repository))
-        (goto-char (point-min))
-        (while (re-search-forward "
+$" nil t)
-          (replace-match ""))
-        (goto-char (point-min))
-        ;; Add utf-8-emacs coding to the top.
-        (insert ";; -*- coding: utf-8-emacs -*-\n")
-        (goto-char (point-max))
-        ;; Update timestamp.
-        (when (re-search-backward ":timestamp +[0-9.]+" nil t)
-          (replace-match (format ":timestamp %s" (float-time (current-time)))))
-        (write-region (point-min) (point-max)
-                      (concat pcache-directory 
(ergoemacs-mode--pcache-repository))
-                      nil 1)))))
-
-(ergoemacs-mode--setup-hash-tables)
-
 (dolist (pkg '(ergoemacs-command-loop
                ergoemacs-advice
-               ergoemacs-component
-               ergoemacs-debug
                ergoemacs-functions
                ergoemacs-key-description
                ergoemacs-layouts
@@ -599,27 +322,18 @@ When STORE-P is non-nil, save the tables."
                ergoemacs-theme-engine
                ergoemacs-translate
                ergoemacs-macros
-               ;; ergoemacs-themes
-               ))
+               ergoemacs-calculate-bindings
+               ergoemacs-themes))
   (unless (featurep pkg)
-    (ergoemacs-timing (intern (format "load-%s" pkg))
-      (load (symbol-name pkg)))))
+    (load (symbol-name pkg))))
 
 (require 'unicode-fonts nil t)
-;; (when (featurep 'unicode-fonts)
-;;   (require 'persistent-soft nil t)
-;;   (when (featurep 'persistent-soft)
-;;     (unicode-fonts-setup)))
-
-
 (defcustom ergoemacs-use-unicode-symbols nil
-  ;; (and (featurep 'persistent-soft)
-  ;;      (featurep 'unicode-fonts))
   "Use unicode symbols in display."
   :type 'boolean
   :group 'ergoemacs-mode)
 
-(defcustom ergoemacs-command-loop-spinners
+(defvar ergoemacs-command-loop-spinners
   '((standard ("|" "/" "-" "\\"))
     (arrows ("←" "↖" "↑" "↗" "→" "↘" "↓" "↙"))
     (bar-vertical ("▁" "▃" "▄" "▅" "▆" "▇" "█" "▇" "▆" "▅" "▄" "▃"))
@@ -631,9 +345,12 @@ When STORE-P is non-nil, save the tables."
     (dots ("⣾" "⣽" "⣻" "⢿" "⡿" "⣟" "⣯" "⣷"))
     (dot ("⠁" "⠂" "⠄" "⡀" "⢀" "⠠" "⠐" "⠈"))
     (fish (">))'>" " >))'>" "  >))'>" "   >))'>" "    >))'>" "   <'((<" "  
<'((<" " <'((<")))
-  "Spinners for long commands with `ergoemacs-command-loop'."
-  :type 'sexp 
-  :group 'ergoemacs-command-loop)
+  "Spinners for long commands with `ergoemacs-command-loop'.")
+
+(defcustom ergoemacs-mode-turn-on-cua-mode t
+  "Turn on cua mode when starting `ergoemacs-mode'."
+  :type 'boolean
+  :group 'ergoemacs-mode)
 
 (defcustom ergoemacs-command-loop-spinner (or (and 
ergoemacs-use-unicode-symbols 'dots) 'standard)
   "What spinner to use for long commands with `ergoemacs-command-loop'."
@@ -653,85 +370,55 @@ When STORE-P is non-nil, save the tables."
 
 (require 'cus-edit)
 
-(defvar ergoemacs-mode-startup-hook nil
-  "Hook for starting `ergoemacs-mode'.")
-
-(defvar ergoemacs-mode-shutdown-hook nil
-  "Hook for shutting down `ergoemacs-mode'.")
-
 (defvar ergoemacs-mode-intialize-hook nil
   "Hook for initializing `ergoemacs-mode'.")
 
 (defvar ergoemacs-mode-init-hook nil
   "Hook for running after Emacs loads.")
 
-(defvar ergoemacs-mode-after-load-hook nil
-  "Hook for running after a library loads.")
-
-(defvar ergoemacs-pre-command-hook nil)
-(defun ergoemacs-pre-command-hook ()
-  "Run `ergoemacs-mode' pre command hooks."
-  (when ergoemacs-mode
-    (run-hooks 'ergoemacs-pre-command-hook)))
-
-(defvar ergoemacs-post-command-hook nil)
-(defun ergoemacs-post-command-hook ()
-  "Run `ergoemacs-mode' post command hooks."
-  (when ergoemacs-mode
-    (run-hooks 'ergoemacs-post-command-hook)))
-
-(defvar ergoemacs-after-load-functions nil)
-(defun ergoemacs-after-load-functions (absoulte-file-name)
-  "Run `ergoemacs-mode' after load functions.
-
-ABSOULTE-FILE-NAME is the file name that will be passed to the
-variable `ergoemacs-after-load-functions'."
-  (run-hook-with-args 'ergoemacs-after-load-functions absoulte-file-name))
-
-(defvar ergoemacs-mode-reset nil
-  "Does `ergoemacs-mode' need to be reset?")
-
-;;;###autoload
-(defun ergoemacs-mode-reset ()
-  "Reset `ergoemacs-mode' without toggling unnecessary variables."
-  (when (or ergoemacs-mode--start-p noninteractive)
-    (setq ergoemacs-component-struct--refresh-variables t)
-    (ergoemacs-mode -1)
-    (ergoemacs-mode 1)
-    (setq ergoemacs-mode-reset nil)))
-
-;;;###autoload
-(defun ergoemacs-set-default (symbol new-value)
-  "`ergoemacs-mode' equivalent to `set-default'.
-
-Will reload `ergoemacs-mode' after setting the values.
+(defvar ergoemacs-override-keymap (make-sparse-keymap)
+  "ErgoEmacs override keymap.  Modify this keymap to change the
+basic ergoemacs functionality.  For example, if you want M-t to
+transpose words instead of running completion, call
 
-SYMBOL is the symbol to set, NEW-VALUE is it's value."
-  (set-default symbol new-value)
-  (when (and (or (not (boundp 'ergoemacs-fixed-layout-tmp))
-                 (save-match-data (string-match "ergoemacs-redundant-keys-" 
(symbol-name symbol))))
-             (boundp 'ergoemacs-mode) ergoemacs-mode)
-    (ergoemacs-mode-reset)))
+  (ergoemacs-define-key ergoemacs-override-keymap (kbd \"M-t\") 
'transpose-words)
 
-(defvar ergoemacs-override-keymap (make-sparse-keymap)
-  "ErgoEmacs override keymap.")
+after initializing ergoemacs-mode.
+")
 
-(ergoemacs :label ergoemacs-override-keymap)
+(defvar ergoemacs-mark-active-keymap (let ((map (make-sparse-keymap)))
+                                       (define-key map (kbd "TAB") 
'indent-region))
+  "The keybinding that is active when the mark is active.")
 
 (defvar ergoemacs-override-alist nil
   "ErgoEmacs override keymaps.")
 
+(defvar ergoemacs-minor-alist nil
+  "ErgoEmacs minor mode keymap.")
+
+(declare-function ergoemacs-advice-undefined "ergoemacs-advice")
+
 (defun ergoemacs-setup-override-keymap ()
-  "Setup `ergoemacs-mode' overriding keymap `ergoemacs-override-keymap'."
-  (setq ergoemacs-override-alist `((ergoemacs-mode . ,(ergoemacs 
ergoemacs-override-keymap))))
-  (add-hook 'emulation-mode-map-alists 'ergoemacs-override-alist))
+  "Setup `ergoemacs-mode' keymaps."
+  (setq ergoemacs-override-alist `((ergoemacs-mode . ,ergoemacs-user-keymap)
+                                   (ergoemacs-mode . 
,ergoemacs-override-keymap)
+                                   (ergoemacs-mode . ,ergoemacs-keymap))
+        ergoemacs-minor-alist `((mark-active . ,ergoemacs-mark-active-keymap)))
+  (add-hook 'emulation-mode-map-alists ergoemacs-override-alist)
+  (add-hook 'minor-mode-map-alist ergoemacs-minor-alist)
+  (advice-add 'undefined :around #'ergoemacs-advice-undefined)
+  (advice-add 'substitute-command-keys :around 
#'ergoemacs-advice-substitute-command-keys)
+  (advice-add 'handle-shift-selection :before 
#'ergoemacs-advice-handle-shift-selection)
+  (advice-add 'read-key :before #'ergoemacs-advice-read-key))
 
 (defun ergoemacs-remove-override-keymap ()
-  "Remove `ergoemacs-mode' overriding keymap `ergoemacs-override-keymap'."
-  (remove-hook 'emulation-mode-map-alists 'ergoemacs-override-alist))
-
-;; (add-hook 'ergoemacs-mode-startup-hook 'ergoemacs-setup-override-keymap)
-;; (add-hook 'ergoemacs-mode-shudown-hook 'ergoemacs-setup-override-keymap)
+  "Remove `ergoemacs-mode' keymaps."
+  (remove-hook 'emulation-mode-map-alists 'ergoemacs-override-alist)
+  (remove-hook 'minor-mode-map-alist ergoemacs-minor-alist)
+  (advice-remove 'undefined #'ergoemacs-advice-undefined)
+  (advice-remove 'substitute-command-keys 
#'ergoemacs-advice-substitute-command-keys)
+  (advice-remove 'handle-shift-selection 
#'ergoemacs-advice-handle-shift-selection)
+  (advice-remove 'read-key #'ergoemacs-advice-read-key))
 
 
 ;;; Frequently used commands as aliases
@@ -787,105 +474,41 @@ not be useful.  However instead of using
   (dolist (x ergoemacs-aliases)
     (eval (macroexpand `(defalias ',(nth 0 x) ',(nth 1 x))) t)))
 
-(autoload 'ergoemacs-component "ergoemacs-macros")
-(autoload 'ergoemacs-theme-component "ergoemacs-macros")
-(autoload 'ergoemacs-theme "ergoemacs-macros")
 (autoload 'ergoemacs "ergoemacs-macros")
 
-(defcustom ergoemacs-keyboard-layout (or (getenv "ERGOEMACS_KEYBOARD_LAYOUT") 
"us")
+(defcustom ergoemacs-keyboard-layout "us"
   (concat "Specifies which keyboard layout to use.
-This is a mirror of the environment variable ERGOEMACS_KEYBOARD_LAYOUT.
 
 Valid values are:
 " (ergoemacs-layouts--custom-documentation)
 )
   :type (ergoemacs-layouts--customization-type)
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-mode)
 
 
-(defun ergoemacs-mode--update-theme-description ()
-  "Update theme description based on loaded themes."
-  (defcustom ergoemacs-theme (if (and (boundp 'ergoemacs-variant) 
ergoemacs-variant)
-                                 ergoemacs-variant
-                               (if (and (boundp 'ergoemacs-theme) 
ergoemacs-theme)
-                                   ergoemacs-theme
-                                 (if (getenv "ERGOEMACS_THEME")
-                                     (getenv "ERGOEMACS_THEME")
-                                   nil)))
-    (concat"Ergoemacs Keyboard Layout Themes.
-This is a mirror of the environment variable ERGOEMACS_THEME.
-
-Valid values are:
-"
-           (ergoemacs-theme--custom-documentation))
-    :type (ergoemacs-theme--customization-type)
-    :set 'ergoemacs-set-default
-    :initialize #'custom-initialize-default
-    :group 'ergoemacs-mode))
-
-(add-hook 'ergoemacs-mode-startup-hook 
#'ergoemacs-mode--update-theme-description)
-
-(defcustom ergoemacs-remap-ignore '(undo-tree-visualize)
-  "Functions to ignore in `ergoemacs-mode' remaps."
-  :type '(repeat (sexp :tag "Function"))
-  :set #'ergoemacs-set-default
-  :initialize #'custom-initialize-default
-  :group 'ergoemacs-mode)
-
-(defvar ergoemacs-map-properties--global-map-before-ergoemacs 
(ergoemacs-map-keymap nil global-map)
-  "A single keymap for the keys before `ergoemacs-mode' loads.")
-
-(defcustom ergoemacs-ignore-prev-global t
-  "Ignore global keys that were changed before `ergoemacs-mode' was loaded."
-  :type 'boolean
-  :set #'ergoemacs-set-default
-  :initialize #'custom-initialize-default
-  :group 'ergoemacs-mode)
-
 (defgroup ergoemacs-display nil
   "Display Options for `ergoemacs-mode'."
   :group 'ergoemacs-mode)
 
-(define-obsolete-variable-alias 'ergoemacs-use-unicode-char 
'ergoemacs-display-unicode-characters "Ergoemacs-v5.16")
-
-(defcustom ergoemacs-display-unicode-characters t
-  "Use unicode characters when available."
-  :type 'boolean
-  :set #'ergoemacs-set-default
-  :initialize #'custom-initialize-default
-  :group 'ergoemacs-display)
-
-(define-obsolete-variable-alias 'ergoemacs-use-ergoemacs-key-descriptions 
'ergoemacs-display-ergoemacs-key-descriptions)
-
 (defcustom ergoemacs-display-ergoemacs-key-descriptions t
   "Use ergoemacs key descriptions (Alt+)."
   :type 'boolean
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-display)
 
-(define-obsolete-variable-alias 'ergoemacs-use-unicode-brackets 
'ergoemacs-display-use-unicode-brackets-around-keys "Ergoemacs-v5.16")
-
 (defcustom ergoemacs-display-use-unicode-brackets-around-keys t
   "Use unicode brackets."
   :type 'boolean
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-display)
 
-(define-obsolete-variable-alias 'ergoemacs-use-small-symbols 
'ergoemacs-display-small-symbols-for-key-modifiers "Ergoemacs-v5.16")
-
 (defcustom ergoemacs-display-small-symbols-for-key-modifiers nil
   "Use small symbols to represent alt+ ctl+ on windows/linux."
   :type 'boolean
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-display)
 
-(define-obsolete-variable-alias 'ergoemacs-capitalize-keys 
'ergoemacs-display-capitalize-keys "Ergoemacs-v5.16")
-
 (defcustom ergoemacs-display-capitalize-keys 'with-modifiers
   "Capitalize keys like Ctrl+C.
 `ergoemacs-mode' should show Ctrl+Shift+C if you are pressing these keys."
@@ -893,69 +516,26 @@ Valid values are:
           (const :tag "Don't Capitalize Keys" nil)
           (const :tag "Capitalize Keys with modifiers" with-modifiers)
           (const :tag "Capitalize Keys" t))
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-display)
 
-(define-obsolete-variable-alias 'ergoemacs-pretty-key-use-face-p 
'ergoemacs-display-key-use-face "Ergoemacs-v5.16")
-
-(defcustom ergoemacs-display-key-use-face t
+(defcustom ergoemacs-display-key-use-face-p t
   "Use a button face for keys."
   :type 'boolean
-  :set #'ergoemacs-set-default
   :initialize #'custom-initialize-default
   :group 'ergoemacs-display)
 
 (defface ergoemacs-display-key-face
   '((t :inverse-video t :box (:line-width 1 :style released-button) :weight 
bold))
   "Button Face for an `ergoemacs-mode' pretty key."
-  ;; :set #'ergoemacs-set-default
-  ;; :initialize #'custom-initialize-default
   :group 'ergoemacs-display)
 
-(defcustom ergoemacs-excluded-major-modes
-  '(conf-colon-mode
-    conf-xdefaults-mode conf-space-mode conf-javaprop-mode
-    conf-ppd-mode mail-mode
-    ebrowse-tree-mode diff-mode fundamental-mode emacs-lisp-byte-code-mode
-    R-transcript-mode S-transcript-mode XLS-mode tar-mode
-    git-commit-mode git-rebase-mode image-mode
-    archive-mode ses-mode)
-  "List of major modes excluded from ergoemacs' Languages menu."
-  :type '(repeat (symbol :tag "Excluded Major Mode"))
-  :group 'ergoemacs-mode)
-;;; Menu options
-
-(defgroup ergoemacs-menus nil
-  "Options for `ergoemacs-command-loop'."
-  :group 'ergoemacs-mode)
-
-(defcustom ergoemacs-mode-names
-  '((conf-mode "Settings")
-    (ses-mode "Emacs Spreadsheet")
-    (m2-mode "Modula-2")
-    (snmpv2-mode "SNMPv2 MIBs")
-    (snmp-mode "SKMP MIBs"))
-  "Menu name for ergoemacs' Languages menu."
-  :type '(repeat
-          (list
-           (symbol :tag "Major Mode Name")
-           (text :tag "Alternative Description:")))
-  :group 'ergoemacs-menus)
-
-(defcustom ergoemacs-menu-order '(file edit search view languages options 
buffers help)
-  "Menu order for `ergoemacs-mode' global menus."
-  :type '(repeat (sexp :tag "Menu-bar key"))
-  :group 'ergoemacs-menus)
-
 ;;; Command loop options.
 (defgroup ergoemacs-command-loop nil
   "Options for `ergoemacs-command-loop'."
   :group 'ergoemacs-mode)
 
-(define-obsolete-variable-alias 'ergoemacs-read-blink 
'ergoemacs-command-loop-blink-character "Ergoemacs-v5.16")
-
-(defcustom ergoemacs-command-loop-blink-character (ergoemacs :unicode-or-alt 
"•" "·" "-")
+(defcustom ergoemacs-command-loop-blink-character "-"
   "Blink character."
   :type '(choice
           (string :tag "Cursor")
@@ -969,16 +549,9 @@ Valid values are:
   :type 'number
   :group 'ergoemacs-command-loop)
 
-(define-obsolete-variable-alias 'ergoemacs-read-swaps 
'ergoemacs-command-loop-swap-translation "Ergoemacs-v5.16")
-
 (defcustom ergoemacs-command-loop-swap-translation
   '(((:normal :normal) :unchorded-ctl)
-    ((:normal :unchorded-ctl) :ctl-to-alt)
-    ((:normal :unchorded-ctl) :normal)
-    ((:ctl-to-alt :ctl-to-alt) :unchorded-ctl)
-    ((:ctl-to-alt :unchorded-ctl) :ctl-to-alt)
-    ((:unchorded-ctl :unchorded-ctl) :ctl-to-alt)
-    ((:unchorded-ctl :ctl-to-alt) :unchorded-ctl))
+    ((:normal :unchorded-ctl) :normal))
   "How the translation will be swapped."
   :type '(repeat
           (list
@@ -996,12 +569,6 @@ Valid values are:
           (const :tag "No command loop support" nil))
   :group 'ergoemacs-comamnd-loop)
 
-(defcustom ergoemacs-command-loop-hide-shift-translations t
-  "Hide shift translations in the command loop help."
-  :type 'boolean
-  :group 'ergoemacs-command-loop)
-
-
 (defcustom ergoemacs-command-loop-echo-keystrokes 1
   "The amount of time before `ergoemacs-mode' displays keystrokes."
   :type 'number
@@ -1031,8 +598,6 @@ Valid values are:
   :type '(repeat string)
   :group 'ergoemacs-modal)
 
-(define-obsolete-variable-alias 'ergoemacs-default-cursor 
'ergoemacs-default-cursor-color "Ergoemacs-v5.16")
-
 (defcustom ergoemacs-default-cursor-color nil
   "Default cursor color.
 
@@ -1174,56 +739,6 @@ color.  Otherwise this will be nil A color string as 
passed to
 
 (defvar ergoemacs-modal-list '())
 (defvar ergoemacs-translate--translation-hash)
-(defvar ergoemacs-modal-ignored-keymap
-  (let ((ret (make-sparse-keymap))
-        (mods '(control meta shift hyper super alt))
-        tmp
-        key)
-    (dolist (char '("<f1>"
-                    "<f2>"
-                    "<f3>"
-                    "<f4>"
-                    "<f5>"
-                    "<f6>"
-                    "<f7>"
-                    "<f8>"
-                    "<f9>"
-                    "<f10>"
-                    "<f11>"
-                    "<f12>"
-                    "<apps>" "<menu>"
-                    "RET" "ESC" "DEL" "TAB"
-                    "<home>"
-                    "<next>"
-                    "<prior>"
-                    "<end>"
-                    "<insert>"
-                    "<deletechar>"))
-      (define-key ret (setq key (read-kbd-macro char t)) 
'ergoemacs-ignore-modal)
-      (setq key (elt key 0))
-      (dolist (mod1 mods)
-        (setq tmp (vector (event-convert-list (list mod1 key))))
-        (ignore-errors (define-key ret tmp 'ignore))
-        (when (setq tmp (ergoemacs-translate--meta-to-escape tmp))
-          (ignore-errors (define-key ret tmp 'ignore)))
-        (dolist (mod2 mods)
-          (setq tmp (vector (event-convert-list (list mod1 mod2 key))))
-          (ignore-errors (define-key ret tmp 'ignore))
-          (when (setq tmp (ergoemacs-translate--meta-to-escape tmp))
-            (ignore-errors (define-key ret tmp 'ignore)))
-          (dolist (mod3 mods)
-            (setq tmp (vector (event-convert-list (list mod1 mod2 mod3 key))))
-            (ignore-errors (define-key ret tmp 'ignore))
-            (when (setq tmp (ergoemacs-translate--meta-to-escape tmp))
-              (ignore-errors (define-key ret tmp 'ignore)))
-            (dolist (mod4 mods)
-              (setq tmp (vector (event-convert-list (list mod1 mod2 mod3 mod4 
key))))
-              (ignore-errors (define-key ret tmp 'ignore))
-              (when (setq tmp (ergoemacs-translate--meta-to-escape tmp))
-                (ignore-errors (define-key ret tmp 'ignore))))))))
-    ret)
-  "`ergoemacs-mode' keys to ignore the modal translation.
-Typically function keys")
 
 (defcustom ergoemacs-translate-keys nil
   "Try differnt key combinations to lookup unfound command.
@@ -1254,56 +769,11 @@ also perform `outline-next-visible-heading'"
   :group 'ergoemacs-mode)
 
 
-;; (define-obsolete-face-alias 'ergoemacs-key-description-kbd 
'ergoemacs-display-key-face "")
-
-;;; Options not supported now
-
-;; (defcustom ergoemacs-change-fixed-layout-to-variable-layout nil
-;;   "Change the fixed layout to variable layout keys.
-;; For example, on dvorak, change C-j to C-c (copy/command)."
-;;   :type 'boolean
-;;   :set 'ergoemacs-set-default
-;;   :initialize #'custom-initialize-default
-;;   :group 'ergoemacs-mode)
-
-(defun ergoemacs-mode-after-startup-run-load-hooks (&rest _ignore)
-  "Run `ergoemacs-mode-after-load-hook' after loading Emacs."
-  (run-hooks 'ergoemacs-mode-after-load-hook))
-
-(defvar ergoemacs-mode-started-p nil)
-(defun ergoemacs-mode-after-init-emacs ()
-  "Start `ergoemacs-mode' after loading Emacs."
-  (unless ergoemacs-mode--start-p
-    (ergoemacs-timing ergoemacs-mode-after-init-emacs
-      (setq ergoemacs-mode--start-p t)
-      (ergoemacs-mode ergoemacs-mode)
-      (run-hooks 'ergoemacs-mode-init-hook)
-      (add-hook 'after-load-functions 
#'ergoemacs-mode-after-startup-run-load-hooks))
-    (let* ((time1 ergoemacs--load-time)
-           (time2 (aref (gethash 'ergoemacs-mode-after-init-emacs 
ergoemacs-timing-hash) 1))
-           (time3 (+ time1 time2)))
-      (message "Started `ergoemacs-mode'. Total startup time %f (Load: %f, 
Initialize:%f%s)"
-               time3 time1 time2 (or (and ergoemacs-mode--fast-p ", cached") 
""))))
-  (setq ergoemacs-mode-started-p t))
-
-(if ergoemacs-mode--fast-p
-    (provide 'ergoemacs-themes)
-  (ergoemacs-timing ergoemacs-themes
-    (load "ergoemacs-themes")))
-
 (when ergoemacs-use-aliases
-  (ergoemacs-timing ergoemacs-load-aliases
-    (ergoemacs-load-aliases)))
-
-(ergoemacs-timing ergoemacs-mode-intialize-hook
-  (run-hooks 'ergoemacs-mode-intialize-hook))
+  (ergoemacs-load-aliases))
 
+(run-hooks 'ergoemacs-mode-intialize-hook)
 (setq ergoemacs--load-time (float-time (time-subtract (current-time) 
ergoemacs--load-time)))
-(puthash 'ergoemacs-load-time (vector 1 ergoemacs--load-time 
ergoemacs--load-time ergoemacs--load-time (or load-file-name buffer-file-name))
-         ergoemacs-timing-hash)
-
-(run-with-idle-timer 0.05 nil #'ergoemacs-mode-after-init-emacs)
-(add-hook 'emacs-startup-hook #'ergoemacs-mode-after-init-emacs)
 
 (provide 'ergoemacs-mode)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/ergoemacs-score.el b/ergoemacs-score.el
deleted file mode 100644
index f647926..0000000
--- a/ergoemacs-score.el
+++ /dev/null
@@ -1,439 +0,0 @@
-;;; ergoemacs-score.el --- Ergoemacs ergonomic score -*- lexical-binding: t -*-
-
-;; Copyright © 2013-2015  Free Software Foundation, Inc.
-
-;; Filename: ergoemacs-score.el
-;; Author: Matthew L. Fidler
-;; Maintainer: 
-;; 
-;;; Commentary: 
-;; 
-;;
-;; 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 
-;;; Change Log:
-;; 
-;; 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as
-;; published by the Free Software Foundation; either version 3, or
-;; (at your option) any later version.
-;; 
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;; General Public License for more details.
-;; 
-;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
-;; 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 
-;;; Code:
-(defvar ergoemacs-track-hand
-  '(0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
-      0 0 0 0 0 0 0 1 1 1 1 1 1 1 1)
-  "Based on ergoemcs-layouts, which hand is typing?
-0 represents left, 1 represents right.")
-
-(defvar ergoemacs-track-row
-  '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-      2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
-      3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
-      4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
-      1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-      2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
-      3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
-      4 4 4 4 4 4 4 4 4 4 4 4 4 4 4)
-  "Based on ergoemacs-layouts, what row is being used?
-1 = 1st row/number row
-2 = 2nd row
-3 = 3rd row/home row
-4 = 4th row")
-
-(defvar ergoemacs-track-finger
-  ' (0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7
-       0 0 0 1 2 3 3 4 4 5 6 7 7 7 7)
-    "Track the finger based on the ergoemacs-layout.
-0 = left pinky,
-1 = left ring
-2 = left middle
-3 = left pointer
-4 = right pointer
-5 = right middle
-6 = right ring
-7 = right pinky
-")
-
-;; These are taken from http://www.colemak.com/wiki/index.php?title=Compare
-(defvar ergoemacs-key-width 18.0
-  "Assumption of key width (in px)")
-
-(defvar ergoemacs-key-height 22.0
-  "Assumption of key height (in px)")
-
-(defvar ergoemacs-tab-key-width 28.0
-  "Assumption of key width (in px)")
-
-(defvar ergoemacs-lock-key-width 34.0
-  "Assumption of lock key width (in px)")
-
-(defvar ergoemacs-shift-key-width 26.0
-  "Assumption of shift key width (in px)")
-
-(defvar ergoemacs-return-key-width 36.0
-  "Assumption of return key width (in px)")
-
-(defvar ergoemacs-tab-key-width 28.0
-  "Assumption of tab key width (in px)")
-
-(defvar ergoemacs-key-width-m 0.010
-  "Default key width (in m)")
-
-(defvar ergoemacs-keyboard-coordinates-x nil
-  "Keyboard x-coordinates (in m)")
-
-(defvar ergoemacs-keyboard-coordinates-y nil
-  "Keyboard y-coordinates (in m)")
-
-(defun ergoemacs-calculate-keyboard-coordinates ()
-  "Calculates `ergoemacs-keyboard-coordinates-x' and
-`ergoemacs-keyboard-coordintes-y'"
-  (setq ergoemacs-keyboard-coordinates-x
-        (let ((i 0)
-              (last 0)
-              curr)
-          (mapcar
-           (lambda(_x)
-             (setq i (+ i 1))
-             (setq curr (+ last (/ ergoemacs-tab-key-width 2)))
-             (cond
-              ((or (= 17 i) (= 58 i))
-               (setq last ergoemacs-tab-key-width))
-              ((or (= 34 i) (= 75 i))
-               (setq last ergoemacs-lock-key-width))
-              ((or (= 41 i) (= 92 i))
-               (setq last ergoemacs-shift-key-width))
-              (t
-               (setq last (+ last ergoemacs-key-width))))
-             (* (/ ergoemacs-key-width-m ergoemacs-key-width) curr))
-           ergoemacs-track-finger)))
-  
-  (setq ergoemacs-keyboard-coordinates-y
-        (let ((i 0)
-              (last 0)
-              curr)
-          (mapcar
-           (lambda(_x)
-             (setq i (+ i 1))
-             (setq curr (+ last (/ ergoemacs-tab-key-width 2)))
-             (cond
-              ((= 58 i)
-               (setq last 0))
-              ((or (= 17 i) (= 34 i) (= 75 i)(= 41 i) (= 92 i))
-               (setq last (+ last ergoemacs-tab-key-width))))
-             (* (/ ergoemacs-key-width-m ergoemacs-key-width) curr))
-           ergoemacs-track-finger))))
-
-(ergoemacs-calculate-keyboard-coordinates)
-
-(defun ergoemacs-key-properties (key layout &optional curr-i)
-  "Key the KEY properties based on ergoemacs LAYOUT"
-  (let ((i 0)
-        (lay (intern-soft (format "ergoemacs-layout-%s" layout)))
-        wi xh yh xc yc
-        dx dy
-        ret)
-    (when lay
-      (if curr-i
-          (setq wi curr-i)
-        (dolist (x (ergoemacs-sv lay))
-          (when (string= key x)
-            (setq wi i))
-          (setq i (+ i 1))))
-      (setq i wi)
-      (setq xh (nth (if (<= (nth i ergoemacs-track-finger) 3)
-                        (+ 32 (nth i ergoemacs-track-finger))
-                      (+ 38 (- (nth i ergoemacs-track-finger) 4)))
-                    ergoemacs-keyboard-coordinates-x))
-      (setq yh (nth (if (<= (nth i ergoemacs-track-finger) 3)
-                        (+ 32 (nth i ergoemacs-track-finger))
-                      (+ 38 (- (nth i ergoemacs-track-finger) 4)))
-                    ergoemacs-keyboard-coordinates-y))
-      (setq xc (nth i ergoemacs-keyboard-coordinates-x))
-      (setq yc (nth i ergoemacs-keyboard-coordinates-y))
-      (setq dx (- xc xh))
-      (setq dy (- yc yh))
-      
-      (setq ret
-            `(:x ,xc
-                 :y ,yc
-                 :x-home ,xh
-                 :y-home ,yh
-                 :d-home ,(sqrt (+ (* dx dx) (* dy dy)))
-                 
-                 :hand ,(if (= 0 (nth i ergoemacs-track-hand))
-                            'left
-                          'right)
-
-                 :finger ,(cond
-                           ((or (= 0 (nth i ergoemacs-track-finger))
-                                (= 7 (nth i ergoemacs-track-finger)))
-                            'pinky)
-                           ((or (= 1 (nth i ergoemacs-track-finger))
-                                (= 6 (nth i ergoemacs-track-finger)))
-                            'ring)
-                           ((or (= 2 (nth i ergoemacs-track-finger))
-                                (= 5 (nth i ergoemacs-track-finger)))
-                            'middle)
-                           (t
-                            'pointer))
-
-                 :finger-n ,(nth i ergoemacs-track-finger)
-
-                 :row-n ,(nth i ergoemacs-track-row)
-
-                 :row ,(cond
-                        ((= 1 (nth i ergoemacs-track-row))
-                         'number)
-                        ((= 2 (nth i ergoemacs-track-row))
-                         'top)
-                        ((= 3 (nth i  ergoemacs-track-row))
-                         'home)
-                        ((= 4 (nth i ergoemacs-track-row))
-                         'bottom))))
-      ret)))
-
-(defvar ergoemacs-key-hash nil
-  "Key hash")
-
-(defvar ergoemacs-distance-hash nil
-  "Distance hash.")
-
-(setq ergoemacs-distance-hash (make-hash-table :test 'equal))
-
-(setq ergoemacs-key-hash (make-hash-table :test 'equal))
-
-(declare-function ergoemacs-get-layouts "ergoemacs-layouts.el")
-(dolist (layout (ergoemacs-get-layouts t))
-  (let ((lay (intern-soft (format "ergoemacs-layout-%s" layout))))
-    (when lay
-      (dolist (key (ergoemacs-sv lay))
-        (unless (string= key "")
-          (puthash (cons layout key)
-                   (ergoemacs-key-properties key layout)
-                   ergoemacs-key-hash))))))
-
-(defun ergoemacs-key-distance (key1 key2 &optional last-plist layout)
-  "Gets the key distance based on the layout.
-KEY1 is the first key pressed.
-KEY2 is the second key pressed.
-LAYOUT is the ergoemacs-layout used.
-LAST-PLIST is the last property list returned by this function or nil if 
nothing was returned previously."
-  (if layout
-      (let ((ret (ergoemacs-gethash (cons (cons key1 key2) (cons last-plist 
layout)) ergoemacs-key-hash)))
-        (if ret
-            ret
-          (let ((kp1 (ergoemacs-gethash (cons layout key1) ergoemacs-key-hash))
-                (kp2 (ergoemacs-gethash (cons layout key2) ergoemacs-key-hash))
-                kpl kpl1
-                (kp12 (ergoemacs-gethash (cons layout (cons key1 key2)) 
ergoemacs-key-hash))
-                dx dy)
-            
-            (when (and (not kp12) kp1 kp2
-                       (eq (plist-get kp1 :finger-n) (plist-get kp2 
:finger-n)))
-              (setq dx (- (plist-get kp1 :x) (plist-get kp2 :x)))
-              (setq dy (- (plist-get kp1 :y) (plist-get kp2 :y)))
-              (setq kp12 (sqrt (+ (* dx dx) (* dy dy))))
-              (puthash (cons layout (cons key1 key2)) kp12 ergoemacs-key-hash))
-            
-            (cond
-             ((and (not last-plist) (not kp1) (not kp2))
-              (setq ret `(:d 0 :dh 0
-                             :finger-n -10
-                             :key ,key2)))
-             ((and last-plist (not kp1) (not kp2))
-              (setq ret `(:d ,(plist-get last-plist :dh) :dh 0
-                             :finger-n -10
-                             :key ,key2)))
-             ((and (not last-plist) kp1 (not kp2))
-
-              ;; kp2 is not defined.  Assume space or no-length character.
-              (setq ret `(:d ,(* 2 (plist-get kp1 :d-home)) :dh 0
-                             :finger-n -10
-                             :key ,key2)))
-
-             ((and (not last-plist) (not kp1) kp2)
-              ;; kp1 is not defined.  Assume space or no-length character.
-              (setq ret `(:d ,(plist-get kp2 :d-home) :dh ,(plist-get kp2 
:d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-
-             ((and last-plist (not kp1) kp2)
-              ;; kp1 is not defined.  Assume space or no-length character.
-              (setq ret `(:d ,(+ (plist-get last-plist :dh)
-                                 (plist-get kp2 :d-home))
-                             :dh ,(plist-get kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-
-             ((and last-plist kp1 (not kp2)
-                   (eq (plist-get last-plist :finger-n) (plist-get kp1 
:finger-n)))
-              
-              ;; Last keypress was on the same finger as kp1.  kp2 is a reset.
-              (setq kpl (ergoemacs-gethash (cons layout (plist-get last-plist 
:key)) ergoemacs-key-hash))
-              (setq kpl1 (ergoemacs-gethash (cons layout (cons (plist-get 
last-plist :key) key1))
-                                  ergoemacs-key-hash))
-
-              (when (not kpl1)
-                (setq dx (- (plist-get kpl :x) (plist-get kp1 :x)))
-                (setq dy (- (plist-get kpl :y) (plist-get kp1 :y)))
-                (setq kpl1 (sqrt (+ (* dx dx) (* dy dy))))
-                (puthash (cons layout
-                               (cons (plist-get last-plist :key)
-                                     key1)) kp12 ergoemacs-key-hash))
-              (setq ret `(:d ,(+ kpl1 (plist-get kp1 :d-home)) :dh 0
-                             :finger-n -10
-                             :key ,key2)))
-             ((and last-plist kp1 (not kp2))
-              ;; last keypress was not on the same finger as kp1. kp2 is a
-              ;; reset
-              (setq ret `(:d ,(+ (plist-get last-plist :dh)
-                                 (* 2 (plist-get kp1 :d-home)))
-                             :dh 0
-                             :finger-n -10
-                             :key ,key2)))
-             ((and (not last-plist)
-                   (eq (plist-get kp1 :finger-n) (plist-get kp2 :finger-n)))
-
-              ;; Distance when key1 and key2 are on the same finger is:
-              ;; D(Home,Key1)+D(Key1,Key2)
-              ;; Residual is D(Key2, Home)
-              
-              (setq ret `(:d ,(+ (plist-get kp1 :d-home) kp12) :dh ,(plist-get 
kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-             ((not last-plist)
-
-              ;; Distance when key1 and key2 are on a different finger is:
-              ;; 2*D(Home,Key1)+D(Home,Key2)
-              ;; Residual is D(Key2,Home)
-              
-              (setq ret `(:d ,(+ (* 2 (plist-get kp1 :d-home))
-                                 (plist-get kp2 :d-home))
-                             :dh ,(plist-get kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-             
-             ((and (eq (plist-get last-plist :finger-n) (plist-get kp1 
:finger-n))
-                   (eq (plist-get last-plist :finger-n) (plist-get kp2 
:finger-n)))
-              
-              ;; The last finger called is the same as the current finger
-              ;; Key1 and Key 2 are on the same finger
-              ;; Distance is D(Last-Key,Key1)+D(Key1,Key2)
-              ;; Residual Distance is D(Key2,Home)
-              
-              (setq kpl (ergoemacs-gethash (cons layout (plist-get last-plist 
:key)) ergoemacs-key-hash))
-              (setq kpl1 (ergoemacs-gethash (cons layout (cons (plist-get 
last-plist :key) key1))
-                                  ergoemacs-key-hash))
-
-              (when (not kpl1)
-                (setq dx (- (plist-get kpl :x) (plist-get kp1 :x)))
-                (setq dy (- (plist-get kpl :y) (plist-get kp1 :y)))
-                (setq kpl1 (sqrt (+ (* dx dx) (* dy dy))))
-                (puthash (cons layout
-                               (cons (plist-get last-plist :key)
-                                     key1)) kp12 ergoemacs-key-hash))
-              
-              (setq ret `(:d ,(+ kpl1 kp12)
-                             :dh ,(plist-get kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-             ((and (eq (plist-get last-plist :finger-n) (plist-get kp1 
:finger-n)))
-              ;; The last finger is the same as kp1.  the kp1 finger is
-              ;; different from kp2.
-              ;;
-              ;; Distance is D(Last,kp1)+D(kp1,home)+D(kp2,home)
-              ;; Residual is D(kp2,home)
-              (setq kpl (ergoemacs-gethash (cons layout (plist-get last-plist 
:key)) ergoemacs-key-hash))
-              (setq kpl1 (ergoemacs-gethash (cons layout (cons (plist-get 
last-plist :key) key1))
-                                  ergoemacs-key-hash))
-
-              (when (not kpl1)
-                (setq dx (- (plist-get kpl :x) (plist-get kp1 :x)))
-                (setq dy (- (plist-get kpl :y) (plist-get kp1 :y)))
-                (setq kpl1 (sqrt (+ (* dx dx) (* dy dy))))
-                (puthash (cons layout
-                               (cons (plist-get last-plist :key)
-                                     key1)) kp12 ergoemacs-key-hash))
-
-              (setq ret `(:d ,(+ kpl1 (plist-get kp1 :d-home) (plist-get kp2 
:d-home))
-                             :dh ,(plist-get kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-             ((and
-               (not (eq (plist-get last-plist :finger-n) (plist-get kp1 
:finger-n)))
-               (eq (plist-get kp1 :finger-n) (plist-get kp2 :finger-n)))
-              ;; The last finger called not the same as kp1
-              ;; key1 and key2 are on the same finger.
-              ;; Distance is D(Last-Key,home)+D(Key1,Key2)
-              ;; Residual Distance is D(Key2,Home)
-              (setq ret `(:d ,(+ (plist-get last-plist :dh) kp12)
-                             :dh ,(plist-get kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))
-             (t
-              ;; The three fingers are on different hands or the last finger
-              ;; pressed and kp2 are on the same hand.  For this layout the
-              ;; distance is given by:
-              ;; d(Last,Home)+2*D(home,kp1)+D(home,kp2)
-              ;; Residual distance is D(kp2,home)
-              (setq ret `(:d ,(+ (plist-get last-plist :dh)
-                                 (* 2 (plist-get kp1 :d-home))
-                                 (plist-get kp2 :d-home))
-                             :dh ,(plist-get kp2 :d-home)
-                             :finger-n ,(plist-get kp2 :finger-n)
-                             :key ,key2)))))
-          (puthash (cons (cons key1 key2) (cons last-plist layout)) ret 
ergoemacs-key-hash)
-          ret))
-    (let (ret)
-      (setq ret
-            (mapcar
-             (lambda(lay)
-               (let (last-p
-                     (dist (ergoemacs-gethash lay ergoemacs-distance-hash 0))
-                     ret)
-                 (when last-plist
-                   (setq last-p (assoc lay last-plist))
-                   (when last-p
-                     (setq last-p (cadr last-p))))
-                 (setq ret (ergoemacs-key-distance key1 key2 last-p lay))
-                 (puthash lay (+ dist (plist-get ret :d)) 
ergoemacs-distance-hash)
-                 `(,lay ,ret)))
-             (ergoemacs-get-layouts)))
-      ret)))
-
-(defvar ergoemacs-last-distance-plist nil
-  "Last distance plist")
-
-(defvar ergoemacs-last-key-press nil)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; ergoemacs-score.el ends here
-;; Local Variables:
-;; coding: utf-8-emacs
-;; End:
diff --git a/ergoemacs-test.el b/ergoemacs-test.el
index 9298018..5d8591f 100644
--- a/ergoemacs-test.el
+++ b/ergoemacs-test.el
@@ -35,34 +35,21 @@
 (declare-function ergoemacs-translate--keymap "ergoemacs-translate")
 (declare-function ergoemacs-mode-reset "ergoemacs-mode")
 
-(declare-function icy-mode "icy-mode")
-
-(defvar ergoemacs-translate--parent-map)
 (defvar ergoemacs-map--)
 (defvar ergoemacs-layout-us)
 (defvar ergoemacs-keyboard-layout)
-(defvar ergoemacs-theme)
 (defvar ergoemacs-command-loop-type)
 (defvar ergoemacs-dir)
 (defvar ergoemacs-mode)
 (defvar dired-sort-map)
 (defvar dired-mode-map)
-(defvar cl-struct-ergoemacs-component-struct-tags)
-
-(declare-function ergoemacs-key-description "ergoemacs-key-description")
-
 
 (declare-function ergoemacs-translate--meta-to-escape "ergoemacs-translate")
 (declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
 
 (declare-function ergoemacs-mode "ergoemacs-mode")
 
-(declare-function ergoemacs-command-loop "ergoemacs-command-loop")
-(declare-function ergoemacs-command-loop--internal "ergoemacs-command-loop")
 (declare-function ergoemacs-command-loop--mouse-command-drop-first 
"ergoemacs-command-loop")
-(declare-function ergoemacs-command-loop--read-key-sequence 
"ergoemacs-command-loop")
-
-(declare-function ergoemacs-component-struct--lookup-hash 
"ergoemacs-compononent")
 
 (declare-function ergoemacs-copy-line-or-region "ergoemacs-functions")
 (declare-function ergoemacs-cut-line-or-region "ergoemacs-functions")
@@ -70,20 +57,8 @@
 (declare-function ergoemacs-eshell-here "ergoemacs-functions")
 (declare-function ergoemacs-paste "ergoemacs-functions")
 
-(declare-function ergoemacs-map-- "ergoemacs-map")
-(declare-function ergoemacs-map--modify-active "ergoemacs-map")
-
-(declare-function ergoemacs-require "ergoemacs-lib")
-
-(declare-function ergoemacs-theme--get-version "ergoemacs-theme")
-(declare-function ergoemacs-theme-set-version "ergoemacs-theme")
-
-(declare-function ergoemacs-translate--event-mods "ergoemacs-translate")
 (declare-function ergoemacs-translate--quail-to-ergoemacs 
"ergoemacs-translate")
 (declare-function ergoemacs-translate-layout "ergoemacs-translate")
-(declare-function ergoemacs-translate--get "ergoemacs-translate")
-(declare-function ergoemacs-unchorded-alt-modal "ergoemacs-translate")
-(declare-function ergoemacs-translate--event-modifiers "ergoemacs-translate")
 
 (require 'ert)
 (require 'elp)
@@ -100,13 +75,6 @@ reprehenderit in voluptate velit esse cillum dolore eu 
fugiat
 nulla pariatur. Excepteur sint occaecat cupidatat non proident,
 sunt in culpa qui officia deserunt mollit anim id est laborum.")
 
-(defun ergoemacs-test-require-input ()
-  "Run tests that require input."
-  (interactive)
-  (elp-instrument-package "ergoemacs-")
-  (ert '(and "ergoemacs-" (tag :require-input)))
-  (call-interactively 'elp-results))
-
 (defun ergoemacs-test-fast ()
   "Fast test of ergoemacs-mode (doesn't include keyboard startup issues)."
   (interactive)
@@ -128,13 +96,6 @@ sunt in culpa qui officia deserunt mollit anim id est 
laborum.")
   (ert '(and "ergoemacs-" (tag :map-keymap)))
   (call-interactively 'elp-results))
 
-(defun ergoemacs-test-copy ()
-  "Copy/Paste test for ergoemacs-mode."
-  (interactive)
-  (elp-instrument-package "ergoemacs-")
-  (ert '(and "ergoemacs-" (tag :copy)))
-  (call-interactively 'elp-results))
-
 (defun ergoemacs-test-calc ()
   "Test for calc."
   (interactive)
@@ -177,357 +138,29 @@ sunt in culpa qui officia deserunt mollit anim id est 
laborum.")
   (let ((ret t)
         (test))
     (elp-instrument-package "ergoemacs-")
-    (ert '(and "^ergoemacs-test-" (not (tag :require-input))))
+    (ert "^ergoemacs-test-")
     (call-interactively 'elp-results)))
 
-;; Test isearch
-
-(ert-deftest ergoemacs-test-isearch-C-f-backspace ()
-  "Test Backspace in `isearch-mode'"
-  :tags '(:search :interactive)
-  ;; Google Code Issue #145
-  (ergoemacs-test-layout
-   :layout "colemak"
-   :macro "C-f a r s C-f <backspace> M-n"
-   (save-excursion
-     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-     (delete-region (point-min) (point-max))
-     (insert "aars1\nars2\nars3\nars4")
-     (goto-char (point-min))
-     (execute-kbd-macro macro)
-     (when (looking-at ".*")
-       (should (string= "s1" (match-string 0))))
-     (kill-buffer (current-buffer)))))
-
-(ert-deftest ergoemacs-test-isearch-C-f ()
-  "C-f doesn't work in isearch-mode."
-  :tags '(:search :interactive)
-  ;; Google Code Issue #119
-  (ergoemacs-test-layout
-   :layout "colemak"
-   :cua t
-   :macro "C-f ars C-f C-f"
-   (save-excursion
-     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-     (delete-region (point-min) (point-max))
-     (insert "aars1\nars2\nars3\nars4")
-     (goto-char (point-min))
-     (execute-kbd-macro macro)
-     (when (looking-at ".*")
-       (should (string= "3" (match-string 0))))
-     (kill-buffer (current-buffer)))))
-
-(ert-deftest ergoemacs-test-isearch-exit-C-s ()
-  "Make sure C-s works outside of `ergoemacs-mode'. Issue #361."
-  :tags '(:search)
-  (ergoemacs-mode -1)
-  (should (eq (lookup-key isearch-mode-map (kbd "C-s")) 
'isearch-repeat-forward))
-  (should (eq (lookup-key isearch-mode-map (kbd "C-r")) 
'isearch-repeat-backward))
-  (save-excursion
-    (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-    (delete-region (point-min) (point-max))
-    (insert "aars1\nars2\nars3\nars4")
-    (goto-char (point-min))
-    (execute-kbd-macro (read-kbd-macro "C-s ars C-s C-s"))
-    (when (looking-at ".*")
-      (should (string= "3" (match-string 0))))
-    (kill-buffer (current-buffer)))
-  (ergoemacs-mode 1))
-
-(ert-deftest ergoemacs-test-isearch-in-eshell ()
-  "Test Issue #322."
-  :tags '(:search :calc)
-  (ergoemacs-test-layout
-   :layout "us"
-   (ergoemacs-eshell-here)
-   (should (eq 'isearch-forward (key-binding (kbd "C-f"))))
-   (should (eq 'isearch-forward (key-binding (kbd "M-y"))))
-   (kill-buffer (current-buffer))))
-
-(ert-deftest ergoemacs-test-isearch-works-with-region ()
-  "With vanilla Emacs, when mark is active and even some region is
-already selected, isearch-ing would expand or shrink selection.
-Currently ergoemacs-mode discards selection as soon as isearch key is
-pressed. Reproducible with ergoemacs-clean.
-Issue #186."
-  :tags '(:search)
-  (let ((ret t))
-    (ergoemacs-test-layout
-     :macro "C-f lab"
-     :layout "colemak"
-     :cua t
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-min))
-       (mark-word)
-       (execute-kbd-macro macro)
-       (setq ret mark-active)
-       (kill-buffer (current-buffer))))
-    (should (equal ret t))))
-
-(ert-deftest ergoemacs-test-isearch-exits-with-ergoemacs-movement-keys ()
-  "Tests if isearch exits the search with movement keys.
-Tests issue #347"
-  :tags '(:search)
-  (ergoemacs-test-layout
-   :macro "C-f ars M-e"
-   :layout "colemak"
-  (save-excursion
-    (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-    (delete-region (point-min) (point-max))
-    (insert "aars1\nars2\nars3\nars4")
-    (goto-char (point-min))
-    (execute-kbd-macro macro)
-    (should (not isearch-mode))
-    (when isearch-mode
-      (isearch-mode -1))
-    (kill-buffer (current-buffer)))))
-
-;; Not sure why; Fixed but test dosesn't work
-;; (ert-deftest ergoemacs-test-isearch-isearch-backward-repeats-backward ()
-;;   "Tests backward isearch remapping is correct."
-;;   :tags '(:search)
-;;   (ergoemacs-test-layout
-;;    :macro "M-j ars M-j M-i"
-;;    :layout "colemak"
-;;    :theme "reduction"
-;;    (save-excursion
-;;      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-;;      (delete-region (point-min) (point-max))
-;;      (insert "aars1\nars2\nars3\nars4")
-;;      (goto-char (point-max))
-;;      (execute-kbd-macro macro)
-;;      (should (looking-at "rs3")))))
-
-;;; Shift Selection
-(ert-deftest ergoemacs-test-shift-select-move-no-mark ()
-  "Tests another shifted selection"
-  :tags '(:shift-select)
-  (let ((ret t))
-    (ergoemacs-test-layout
-     :macro "M-H"
-     :layout "colemak"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (goto-char (point-min))
-       (insert ";;")
-       (execute-kbd-macro macro)
-       (setq ret (not mark-active)) ;;  Shouldn't be selected
-       (kill-buffer (current-buffer))))
-    (should (equal ret t))))
-
-(ert-deftest ergoemacs-test-shift-select-cua-move-keep-mark ()
-  "Test the shifted selection bug."
-  :tags '(:shift-select)
-  (let (ret)
-    (ergoemacs-test-layout
-     :macro "M-SPC M-h M-I"
-     :layout "colemak"
-     :cua t
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test-shifted-move*"))
-       (delete-region (point-min) (point-max))
-       (insert ";;;;")
-       (goto-char (point-min))
-       (execute-kbd-macro macro)
-       (setq ret mark-active) ;; Should be selected.
-       (kill-buffer (current-buffer))))
-    (should (equal ret t))))
-
-(ert-deftest ergoemacs-test-shift-select-reduction ()
-  "Test that shift selection works properly in reduction."
-  :tags '(:shift-select :calc :interactive)
-  (ergoemacs-test-layout
-   :theme "reduction"
-   :layout "colemak"
-   :macro "M-E M-E M-x"
-   (save-excursion
-     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-     (delete-region (point-min) (point-max))
-     (insert ergoemacs-test-lorem-ipsum)
-     (goto-char (point-min))
-     (execute-kbd-macro macro)
-     (should (= (point) (point-min)))
-     (kill-buffer (current-buffer)))))
-
-
-(ert-deftest ergoemacs-test-shift-select-subword ()
-  "Test for mark working with shift-selection of `subword-forward'."
-  :tags '(:shift-select)
-  (let (ret)
-    (ergoemacs-test-layout
-     :macro "M-Y M-x"
-     :theme "reduction"
-     :layout "colemak"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (subword-mode 1)
-       (goto-char (point-max))
-       (beginning-of-line)
-       (execute-kbd-macro macro)
-       (when (looking-at " in culpa qui")
-         (setq ret t))
-       (kill-buffer (current-buffer))))))
-
-;;; Copy/Paste
-
-
-(ert-deftest ergoemacs-test-copy-paste-issue-184 ()
-  "Issue #184; Not replace the \"selected all\" by paste."
-  :tags '(:copy :interactive)
-  (let ((ret t)
-        (ergoemacs-handle-ctl-c-or-ctl-x 'both))
-    (ergoemacs-test-layout
-     :macro "C-v"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-min))
-       (push-mark)
-       (end-of-line)
-       (ergoemacs-copy-line-or-region)
-       (push-mark (point))
-       (push-mark (point-max) nil t)
-       (goto-char (point-min))
-       ;; Make sure the `pre-command-hook' and `post-command-hook' is
-       ;; run by calling the macro.
-       (execute-kbd-macro macro) 
-       ;; (ergoemacs-paste)
-       (should (string= "Lorem ipsum dolor sit amet, consectetur adipisicing 
elit, sed\n"
-                        (buffer-string)))
-       (kill-buffer (current-buffer))))))
-
-(ert-deftest ergoemacs-test-copy-paste-issue-184-paste-should-clear-mark ()
-  "Issue #186.
-Selected mark would not be cleared after paste."
-  :tags '(:copy)
-  (ergoemacs-test-layout
-   (let ((ergoemacs-handle-ctl-c-or-ctl-x 'both))
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-min))
-       (push-mark)
-       (end-of-line)
-       (ergoemacs-copy-line-or-region)
-       (push-mark (point))
-       (push-mark (point-max) nil t)
-       (goto-char (point-min))
-       (ergoemacs-paste)
-       (should (or deactivate-mark (not mark-active)))
-       (kill-buffer (current-buffer))))))
-
-
 (ert-deftest ergoemacs-test-copy-paste-cut-line-or-region ()
   "Issue #68.
 kill-ring function name is used and such doesn't exist. It errs when
 not using cua or cutting line. I think kill-region is what is meant."
-  (ergoemacs-test-layout
-   (let ((old-c cua-mode)
-         (ret t))
-     (cua-mode -1)
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (condition-case _err
-           (ergoemacs-cut-line-or-region)
-         (error (setq ret nil)))
-       (kill-buffer (current-buffer)))
-     (when old-c
-       (cua-mode 1))
-     (should ret))))
-
-
-(ert-deftest ergoemacs-test-copy-paste-issue-130-cut ()
-  "Attempts to test Issue #130 -- Cut"
-  :tags '(:copy :interactive)
-  (ergoemacs-test-layout
-   (let ((ret t)
-         (ergoemacs-ctl-c-or-ctl-x-delay 0.1)
-         (ergoemacs-handle-ctl-c-or-ctl-x 'both))
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (push-mark (point))
-       (push-mark (point-max) nil t)
-       (goto-char (point-min))
-       (ergoemacs-command-loop--internal "C-x <ergoemacs-timeout>")
-       (setq ret (string= "" (buffer-string)))
-       (kill-buffer (current-buffer)))
-     (should ret))))
-
-(ert-deftest ergoemacs-test-copy-paste-issue-130-copy ()
-  "Attempts to test Issue #130 -- Copy"
-  :tags '(:copy :interactive)
-  (ergoemacs-test-layout
-   (let ((ergoemacs-ctl-c-or-ctl-x-delay 0.1)
-         (ergoemacs-handle-ctl-c-or-ctl-x 'both)
-         (txt "Text\n123"))
-     (with-temp-buffer
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert txt)
-       (push-mark (point))
-       (push-mark (point-max) nil t)
-       ;; (message "Region Active: %s" transient-mark-mode)
-       (setq last-command nil
-             this-command nil)
-       (goto-char (point-min))
-       (ergoemacs-command-loop--internal "C-c <ergoemacs-timeout>")
-       (goto-char (point-max))
-       (ergoemacs-paste)
-       (should (string= (concat txt txt)
-                        (buffer-string)))
-       (kill-buffer (current-buffer))))))
-
-(ert-deftest ergoemacs-test-copy-paste-apps-cut ()
-  "Tests <apps> x on QWERTY cutting a region, not just a line."
-  :tags '(:copy :interactive)
-  (let (ret)
-    (ergoemacs-test-layout
-     :macro (format "<%s> x"
-                    (if (eq system-type 'windows-nt)
-                        "apps" "menu"))
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (push-mark (point))
-       (push-mark (point-max) nil t)
-       (goto-char (point-min))
-       (ergoemacs-command-loop--internal macro)
-       (setq ret (string= "" (buffer-string)))
-       (kill-buffer (current-buffer))))
-    (should ret)))
-
-;; [1 apps 99 22]
-
-(ert-deftest ergoemacs-test-copy-paste-apps-copy ()
-  "Tests <apps> c on QWERTY copying a region, not just a line."
-  :tags '(:copy :interactive)
-  ;; :tags '(:interactive)
-  (ergoemacs-test-layout
-   :macro (format "C-a <%s> c C-v"
-                  (if (eq system-type 'windows-nt)
-                      "apps" "menu"))
-   (let ((test-string "1\n2\n3\n4"))
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert test-string)
-       (execute-kbd-macro macro)
-       (should (string= (concat test-string test-string)
-                        (buffer-string)))
-       (kill-buffer (current-buffer))))))
+  (let ((old-c cua-mode)
+        (ret t))
+    (cua-mode -1)
+    (save-excursion
+      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+      (delete-region (point-min) (point-max))
+      (insert ergoemacs-test-lorem-ipsum)
+      (condition-case _err
+          (ergoemacs-cut-line-or-region)
+        (error (setq ret nil)))
+      (kill-buffer (current-buffer)))
+    (when old-c
+      (cua-mode 1))
+    (should ret)
+    )
+  )
 
 ;;; Functionality Test
 
@@ -571,202 +204,21 @@ not using cua or cutting line. I think kill-region is 
what is meant."
 
 (ert-deftest ergoemacs-test-function-unbind-commands-active ()
   "Make sure the unbound keys work"
-  (should (eq 'ergoemacs-map-undefined (key-binding (read-kbd-macro "C-x 
C-s")))))
-
-(ert-deftest ergoemacs-test-function-M-e-only-one-char-issue-306 ()
-  "Tests Issue #306."
-  :tags '(:calc)
-  (let ((ergoemacs-test-fn t)
-        (ergoemacs-read-input-keys nil))
-    (ergoemacs-test-layout
-     :layout "us"
-     :theme "lvl2"
-     :macro "M-e"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (fundamental-mode)
-       (should (or (eq (key-binding (kbd "M-e")) 'backward-kill-word)
-                   (eq (key-binding (kbd "M-e"))
-                      (command-remapping 'backward-kill-word (point)))))
-       (setq ergoemacs-test-fn nil)
-       (goto-char (point-max))
-       (execute-kbd-macro macro)
-       (should (string= "Lorem ipsum dolor sit amet, consectetur adipisicing 
elit, sed
-do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
-enim ad minim veniam, quis nostrud exercitation ullamco laboris
-nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
-reprehenderit in voluptate velit esse cillum dolore eu fugiat
-nulla pariatur. Excepteur sint occaecat cupidatat non proident,
-sunt in culpa qui officia deserunt mollit anim id est " (buffer-string)))
-       (kill-buffer (current-buffer))))))
-
-
-(ert-deftest ergoemacs-test-function-issue-305-variables-set-to-nil ()
-  "Test Issue #305.
-When calling `ergoemacs-refresh' variable values should be preserved."
-  (ergoemacs-mode-reset)
-  (should (eq t shift-select-mode)))
-
-;;; Grep
-
-
-(ert-deftest ergoemacs-test-grep-issue-293 ()
-  "Test Issue #293.
-Unable to use M-ijkl in a grep buffer."
-  (ergoemacs-test-layout
-   :layout "colemak"
-   :macro "M-e M-e M-e M-i"
-   (save-excursion
-     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-     (delete-region (point-min) (point-max))
-     (insert "-*- mode: grep; default-directory: \"~src/ergoemacs-mode/\" -*-
-Grep started at Fri Aug 22 08:30:37
-grep -nH -e ergoemacs-mode ergoemacs-mode.el
-ergoemacs-mode.el:1:;;; ergoemacs-mode.el --- Emacs mode based on common 
modern interface and ergonomics. -*- lexical-binding: t -*-
-ergoemacs-mode.el:949:;;; ergoemacs-mode.el ends here
-Grep finished (matches found) at Fri Aug 22 08:30:37
-")
-     (grep-mode)
-     ;; (ergoemacs-map--modify-active)
-     (goto-char (point-min))
-     (execute-kbd-macro macro)
-     (should (string= (buffer-substring (point) (+ 16 (point)))
-                      "rgoemacs-mode.el"))
-     (kill-buffer (current-buffer)))))
+  (should (eq 'undefined (key-binding (read-kbd-macro "C-x C-s")))))
 
 ;;; Org-mode
 
-(ert-deftest ergoemacs-test-org-C-a ()
-  "Test beginning of line in standard ergoemacs-mode/org-mode."
-  (ergoemacs-test-layout
-   :layout "colemak"
-   :macro "M-m"
-   (let (ret)
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert "abc\n* TODO Fix org C-a issue")
-       (org-mode)
-       (goto-char (point-max))
-       (execute-kbd-macro macro)
-       (ignore-errors
-         (should (string= (buffer-substring (point) (point-at-eol))
-                          "Fix org C-a issue")))
-       (kill-buffer (current-buffer))))))
-
-(ert-deftest ergoemacs-test-org-respect-keys-issue-304 ()
-  "Tests Issue #304.
-`org-mode' should respect the keys used."
-  (let ((ergoemacs-test-fn t))
-    (ergoemacs-test-layout
-     :layout "us"
-     :theme "standard"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (org-mode)
-       (ergoemacs-map--modify-active)
-       (should (eq (key-binding (kbd "<M-right>")) 'ergoemacs-org-metaright))
-       (should (eq (key-binding (kbd "<M-left>")) 'ergoemacs-org-metaleft))
-       (should (eq (key-binding (kbd "<M-up>")) 'ergoemacs-org-metaup))
-       (should (eq (key-binding (kbd "<M-down>")) 'ergoemacs-org-metadown))
-       (kill-buffer (current-buffer))))))
-
-
 ;;; Calc
 
-(ert-deftest ergoemacs-test-calc-300 ()
-  "Test Calc undo"
-  :tags '(:calc :interactive)
-  (let ((ergoemacs-test-fn t))
-    (ergoemacs-test-layout
-     :theme "reduction"
-     :layout "colemak"
-     (call-interactively 'calc)
-     (unwind-protect
-         (should (eq (key-binding (kbd "C-z")) (or (command-remapping 
'calc-undo (point)) 'calc-undo)))
-       (call-interactively 'calc-quit)))))
-
-(ert-deftest ergoemacs-test-calc-fries-ergoemacs-mode ()
-  "After calc has entered some numbers, it fries ergoemacs-mode."
-  :tags '(:calc :interactive)
-  (let ((ergoemacs-test-fn t))
-    (ergoemacs-test-layout
-     :theme "reduction"
-     :layout "colemak"
-     (call-interactively 'calc)
-     (execute-kbd-macro "1 1 +")
-     (call-interactively 'calc-quit)
-     (should (eq (key-binding (kbd "M-u")) 'previous-line)))))
-
-;;; Modal
-
-(ert-deftest ergoemacs-test-modal-preserve-mark ()
-  "Issue #101.
-Test next and prior translation."
-  (with-temp-buffer
-    (insert ergoemacs-test-lorem-ipsum)
-    (goto-char (point-min))
-    (ergoemacs-translate--get :unchorded-alt) ;; Load translation
-    (ergoemacs-unchorded-alt-modal)
-    (set-mark (point))
-    (forward-char 3)
-    (ergoemacs-unchorded-alt-modal)
-    (should mark-active)))
-
-(ert-deftest ergoemacs-test-modal-alt-mode-horizontal-position ()
-  "Tests Issue #213"
-  (let (ret)
-    (ergoemacs-test-layout
-     :layout "colemak"
-     :macro "i u u"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-max))
-       (beginning-of-line)
-       (ergoemacs-translate--get :unchorded-alt)
-       (ergoemacs-unchorded-alt-modal)
-       (execute-kbd-macro macro)
-       (looking-at ".*? ")
-       (ignore-errors (should (string= (match-string 0) "eprehenderit ")))
-       (ergoemacs-unchorded-alt-modal)
-       (kill-buffer (current-buffer))))))
-
-
-
 ;;; Command Loop
 
-(ert-deftest ergoemacs-test-command-loop-apps-e-t-_ ()
-  "Test that colemak <apps> e t sends _.
-Should test for Issue #143."
-  (ergoemacs-test-layout
-   :theme "reduction"
-   :layout "colemak"
-   (save-excursion
-     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-     (delete-region (point-min) (point-max))
-     (with-timeout (0.5 nil)
-       (ergoemacs-command-loop--internal (format "<%s> e t"
-                                       (if (eq system-type 'windows-nt)
-                                           "apps" "menu"))))
-     (should (string= "_" (buffer-string)))
-     (kill-buffer (current-buffer)))))
-
-
 (ert-deftest ergoemacs-test-command-loop-C-x-8-! ()
   "Test that unicode translations work.
 See Issue #138."
   (save-excursion
-    (unless ergoemacs-mode
-      (ergoemacs-mode))
     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
     (delete-region (point-min) (point-max))
-    (ergoemacs-command-loop--internal "C-x 8 !")
+    (execute-kbd-macro (kbd "C-x 8 !"))
     (should (string= "¡" (buffer-string)))
     (kill-buffer (current-buffer))))
 
@@ -775,138 +227,11 @@ See Issue #138."
 See Issue #138."
   (save-excursion
     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-    (unless ergoemacs-mode
-      (ergoemacs-mode))
     (delete-region (point-min) (point-max))
-    (ergoemacs-command-loop--internal "C-x 8 \" A")
+    (execute-kbd-macro (kbd "C-x 8 \" A"))
     (should (string= "Ä" (buffer-string)))
     (kill-buffer (current-buffer))))
 
-(ert-deftest ergoemacs-test-command-loop-overlay-paren ()
-  "Test that overlays will send the appropriate parenthesis"
-  (let (ret
-        tmp (tmp-key (make-sparse-keymap)) overlays)
-    (ergoemacs-test-layout
-     :layout "colemak"
-     :macro (format "M-i <%s> e e"
-                    (if (eq system-type 'windows-nt)
-                        "apps" "menu"))
-     (define-key tmp-key [ergoemacs-test] 'ignore)
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-min))
-       ;; Put in dummy overlay
-       (while (re-search-forward "[A-Za-z]+" nil t)
-         (setq tmp (make-overlay (match-beginning 0) (match-end 0)))
-         (overlay-put tmp 'keymap tmp-key)
-         (push tmp overlays))
-       (goto-char (point-min))
-       (execute-kbd-macro macro)
-       (when (looking-at ")")
-         (setq ret t))
-       (dolist (x overlays)
-         (delete-overlay x))
-       (kill-buffer (current-buffer))))
-    (should (equal ret t))))
-
-(ert-deftest ergoemacs-test-command-loop-shortcut ()
-  "Test that shortcuts don't eat or duplicate key-strokes. (Issue #141)"
-  :tags '(:interactive)
-  (let (ret)
-    (ergoemacs-test-layout
-     :macro (format "<%s> e e M-u"
-                    (if (eq system-type 'windows-nt)
-                        "apps" "menu"))
-     :layout "colemak"
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-max))
-       (beginning-of-line)
-       (execute-kbd-macro macro)
-       (looking-at ".*")
-       (when (looking-at "ulla pariatur.")
-         (setq ret t))
-       (kill-buffer (current-buffer))))
-    (should (equal ret t))))
-
-(ert-deftest ergoemacs-test-command-loop-overlay ()
-  "Test for mark working with overlays.
-Should test issue #142"
-  :tags '(:interactive)
-  (let (ret
-        tmp (tmp-key (make-sparse-keymap))
-        overlays)
-    (ergoemacs-test-layout
-     :macro "M-SPC M-y M-x"
-     :layout "colemak"
-     (define-key tmp-key [ergoemacs-test] 'ignore)
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-min))
-       ;; Put in dummy overlay
-       (while (re-search-forward "[A-Za-z]+" nil t)
-         (setq tmp (make-overlay (match-beginning 0) (match-end 0)))
-         (overlay-put tmp 'keymap tmp-key)
-         (push tmp overlays))
-       (goto-char (point-max))
-       (beginning-of-line)
-       (execute-kbd-macro macro)
-       (when (looking-at " in culpa qui")
-         (setq ret t))
-       (dolist (x overlays)
-         (delete-overlay x))
-       (kill-buffer (current-buffer)))
-     (should (equal ret t)))))
-
-(ert-deftest ergoemacs-test-command-loop-reduction-M-o-works ()
-  "Test Ergoemacs M-o works correctly (Issue #171)."
-  ;; (let ((ergoemacs-test-fn t))
-  ;;   (ergoemacs-test-layout
-  ;;    :theme "reduction"
-  ;;    :layout "colemak"
-  ;;    (with-timeout (0.2 nil) (ergoemacs-read-key "M-o"))
-  ;;    (message "Test FN: %s" ergoemacs-test-fn)
-  ;;    (should (eq ergoemacs-test-fn (or (command-remapping 
'execute-extended-command (point)) 'execute-extended-command)))))
-  )
-
-(ert-deftest ergoemacs-test-terminal-M-O-fight ()
-  "Tests Issue #188"
-  (let ((old-map (copy-keymap input-decode-map))
-        (ret nil))
-    (ergoemacs-test-layout
-     (setq input-decode-map (make-sparse-keymap))
-     ;; Setup input decode map just like `xterm' for some common keys.
-     (define-key input-decode-map "\eOA" [up])
-     (define-key input-decode-map "\eOB" [down])
-     (define-key input-decode-map "\eOC" [right])
-     (define-key input-decode-map "\eOD" [left])
-     (define-key input-decode-map "\eOF" [end])
-     (define-key input-decode-map "\eOH" [home])
-     (save-excursion
-       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-       (delete-region (point-min) (point-max))
-       (insert ergoemacs-test-lorem-ipsum)
-       (goto-char (point-max))
-       (beginning-of-line)
-       (with-timeout (0.2 nil)
-         (ergoemacs-command-loop--internal "M-O A")) ; by looking at 
`ergoemacs-read-key' this seems to be translating correctly, but... it doesn't 
run in this context.
-       (message "Decode: %s" (lookup-key input-decode-map (kbd "M-O A")))
-       (setq ret (looking-at "nulla pariatur. Excepteur sint occaecat 
cupidatat non proident,"))
-       (kill-buffer (current-buffer)))
-     (setq input-decode-map (copy-keymap old-map)))
-    (should ret)))
-
-;;; Key inheritance 
-(ert-deftest ergoemacs-key-inheitance-alt-up-and-down ()
-  "Test M-up and M-down keys make sure they are moving lines"
-  (ergoemacs-require 'move-and-transpose-lines)
-  (ergoemacs-mode-reset)
-  (should (eq (key-binding [\M-up]) 'ergoemacs-move-text-up))
-  (should (eq (key-binding [\M-down]) 'ergoemacs-move-text-down)))
-
 ;;; Global map tests.
 (defun ergoemacs-test-global-key-set-before (&optional after key ergoemacs 
ignore-prev-global delete-def)
   "Test the global key set before ergoemacs-mode is loaded."
@@ -934,7 +259,6 @@ Should test issue #142"
           (insert (format "(global-set-key (kbd \"%s\") nil)" delete-def)))
         (insert sk))
       (insert (format "(add-to-list 'load-path \"%s\")" ergoemacs-dir))
-      (insert "(setq ergoemacs-theme nil)")
       (insert "(setq ergoemacs-keyboard-layout \"us\")")
       (unless ignore-prev-global
         (insert "(setq ergoemacs-ignore-prev-global nil)"))
@@ -962,297 +286,19 @@ Should test issue #142"
       (delete-file w-file))
     ret))
 
-(ert-deftest ergoemacs-test-global-key-set-before-1 ()
-  "Test global set key before ergoemacs-mode loads."
-  :tags '(:slow :interactive)
-  (should (equal (ergoemacs-test-global-key-set-before) t)))
-
-(ert-deftest ergoemacs-test-global-key-set-before-2 ()
-  "Test global set key before ergoemacs-mode loads (define-key)."
-  :tags '(:slow :interactive)
-  (should (equal (ergoemacs-test-global-key-set-before nil nil 'define-key) 
t)))
-
-(ert-deftest ergoemacs-test-global-key-set-after ()
-  "Test global set key after ergoemacs loads."
-  :tags '(:slow)
-  (should (equal (ergoemacs-test-global-key-set-before 'after) t)))
-
-(ert-deftest ergoemacs-test-global-key-set-after-2 ()
-  "Test global set key after ergoemacs loads (define-key)."
-  :tags '(:slow)
-  (should (equal (ergoemacs-test-global-key-set-before 'after nil 'define-key) 
t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-c-before ()
-  "Test setting <apps> m c before loading."
-  :tags '(:slow :interactive)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     nil
-     (if (eq system-type 'windows-nt)
-         "<apps> m c"
-       "<menu> m c") nil nil "<menu>") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-c-before-2 ()
-  "Test setting <apps> m c before loading (define-key)."
-  :tags '(:slow :interactive)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     nil
-     (if (eq system-type 'windows-nt)
-         "<apps> m c"
-       "<menu> m c") 'define-key nil "<menu>") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-m-semi-before ()
-  "Test setting M-; before loading."
-  :tags '(:slow :interactive)
-  (should (equal (ergoemacs-test-global-key-set-before nil "M-;") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-m-semi-after ()
-  "Test setting M-; before loading."
-  :tags '(:slow)
-  (should (equal (ergoemacs-test-global-key-set-before t "M-;") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-before ()
-  "Test setting <apps> before loading."
-  :tags '(:slow :interactive)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     nil
-     (if (eq system-type 'windows-nt)
-         "<apps>"
-       "<menu>")) t)))
-
-
-(ert-deftest ergoemacs-test-global-key-set-apps-before-2 ()
-  "Test setting <apps> before loading (define-key)."
-  :tags '(:slow :interactive)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     nil
-     (if (eq system-type 'windows-nt)
-         "<apps>"
-       "<menu>") 'define-key) t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-before ()
-  "Test setting <apps> m before loading."
-  :tags '(:slow :interactive)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     nil
-     (if (eq system-type 'windows-nt)
-         "<apps> m"
-       "<menu> m") nil nil "<menu>") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-before-2 ()
-  "Test setting <apps> m before loading (define-key)."
-  :tags '(:slow :interactive)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     nil
-     (if (eq system-type 'windows-nt)
-         "<apps> m"
-       "<menu> m") 'define-key nil "<menu>") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-after ()
-  "Test setting <apps> m after loading"
-  :tags '(:slow)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     'after
-     (if (eq system-type 'windows-nt)
-         "<apps> m"
-       "<menu> m") nil nil "<menu>") t)))
-
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-after-2 ()
-  "Test setting <apps> m after loading (define-key)"
-  :tags '(:slow)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     'after
-     (if (eq system-type 'windows-nt)
-         "<apps> m"
-       "<menu> m") 'define-key nil "<menu>") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-c-after ()
-  "Test setting <apps> m c after loading."
-  :tags '(:slow)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     'after
-     (if (eq system-type 'windows-nt)
-         "<apps> m c"
-       "<menu> m c") nil nil "<menu>") t)))
-
-(ert-deftest ergoemacs-test-global-key-set-apps-m-c-after-2 ()
-  "Test setting <apps> m c after loading (define-key)."
-  :tags '(:slow)
-  (should
-   (equal
-    (ergoemacs-test-global-key-set-before
-     'after
-     (if (eq system-type 'windows-nt)
-         "<apps> m c"
-       "<menu> m c") 'define-key nil "<menu>") t)))
-
-
 (ert-deftest ergoemacs-test-global-key-set-after-220 ()
   "Test global C-c b"
   :tags '(:slow)
   (should (equal (ergoemacs-test-global-key-set-before 'after "C-c b") t)))
 
-
-(ert-deftest ergoemacs-test-global-key-set-after-397 ()
-  "Test global C-SPC"
-  :tags '(:slow)
-  (should (equal (ergoemacs-test-global-key-set-before 'after "C-SPC") t)))
-
-(ert-deftest ergoemacs-test-397-test-3 ()
-  "Test M-s is switch pane."
-  :tags '(:slow)
-  (let* ((emacs-exe (ergoemacs-emacs-exe))
-         (w-file (expand-file-name "global-test" ergoemacs-dir))
-         (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-    (with-temp-file temp-file
-      (insert "(eval-when-compile (load (expand-file-name 
\"ergoemacs-macros\")) (require 'cl))"
-              (or (and (boundp 'wait-for-me)
-                       "(setq debug-on-error t debug-on-quit t)") "")
-             "(setq ergoemacs-theme nil)"
-             "(setq ergoemacs-keyboard-layout \"us\")"
-              "(ergoemacs-mode 1)\n"
-             "(global-set-key (kbd \"C-SPC\") 'set-mark-command)\n"
-              "(when (eq (key-binding (kbd \"M-s\")) 
'ergoemacs-move-cursor-next-pane)\n"
-              "(with-temp-file \"" w-file "\")\n"
-              "   (message \"Passed\")"
-              "  (insert \"Found\"))\n"
-              (or (and (boundp 'wait-for-me) "")
-                  "(kill-emacs)")))
-    (byte-compile-file temp-file)
-    (message "%s"
-             (shell-command-to-string
-              (format "%s %s -Q -L %s -l %s -l %s"
-                      emacs-exe (if (boundp 'wait-for-me) "-debug-init" 
"--batch")
-                      (expand-file-name (file-name-directory (locate-library 
"ergoemacs-mode")))
-                      (expand-file-name (file-name-sans-extension 
(locate-library "ergoemacs-mode")))
-                      temp-file)))
-    (should (file-exists-p w-file))
-    (when  (file-exists-p temp-file)
-      (delete-file temp-file))
-    (when  (file-exists-p (concat temp-file "c"))
-      (delete-file (concat temp-file "c")))
-    (when (file-exists-p w-file)
-      (delete-file w-file))))
-
 (defvar ergoemacs-component-hash)
-(ergoemacs-package icicles
-    :ensure t)
-
-(ert-deftest ergoemacs-test-397-test-4 ()
-  "Test M-s is switch pane."
-  :tags '(:slow :icicles :interactive)
-  (if (not (locate-library "icicles")) (should t)
-    (let* ((emacs-exe (ergoemacs-emacs-exe))
-           (w-file (expand-file-name "global-test" ergoemacs-dir))
-           (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-      (with-temp-file temp-file
-       (insert "(add-to-list 'load-path \"" (expand-file-name 
(file-name-directory (locate-library "ergoemacs-mode"))) "\")"
-               "(add-to-list 'load-path \"" (expand-file-name 
(file-name-directory (locate-library "icicles"))) "\")"
-               "(eval-when-compile (require 'ergoemacs-macros) (require 'cl))"
-               (or (and (boundp 'wait-for-me)
-                        "(setq debug-on-error t debug-on-quit t)") "")
-               "(setq ergoemacs-theme nil)"
-               "(setq ergoemacs-keyboard-layout \"us\")"
-               "(require 'icicles)\n"
-               "(require 'ergoemacs-mode)\n"
-               "(ergoemacs-mode 1)\n"
-               "(setq icicle-search-key-prefix (kbd \"C-f\"))\n"
-               "(icy-mode 1)\n"
-               "(when (eq (key-binding (kbd \"M-s\")) 
'ergoemacs-move-cursor-next-pane)\n"
-               "(with-temp-file \"" w-file "\")\n"
-               "   (message \"Passed\")"
-               "  (insert \"Found\"))\n"
-               (or (and (boundp 'wait-for-me) "")
-                    "(kill-emacs)")))
-      (byte-compile-file temp-file)
-      (message "%s"
-               (shell-command-to-string
-               (format "%s %s -Q -l %s"
-                       emacs-exe (if (boundp 'wait-for-me) "-debug-init" 
"--batch")                      
-                       temp-file)))
-      (should (file-exists-p w-file))
-      (when  (file-exists-p temp-file)
-       (delete-file temp-file))
-      (when  (file-exists-p (concat temp-file "c"))
-       (delete-file (concat temp-file "c")))
-      (when (file-exists-p w-file)
-       (delete-file w-file)))))
-
-(ert-deftest ergoemacs-test-397-test-2 ()
-  "Test that defining C-SPC after ergoemacs-mode loads will give 
`set-mark-command'."
-  :tags '(:slow)
-  (let* ((emacs-exe (ergoemacs-emacs-exe))
-         (w-file (expand-file-name "global-test" ergoemacs-dir))
-         (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-    (with-temp-file temp-file
-      (insert "(eval-when-compile (require 'ergoemacs-macros) (require 'cl))"
-              (or (and (boundp 'wait-for-me)
-                       "(setq debug-on-error t debug-on-quit t)") "")
-             "(setq ergoemacs-theme nil)"
-             "(setq ergoemacs-keyboard-layout \"us\")"
-              "(ergoemacs-mode 1)\n"
-             "(global-set-key (kbd \"C-SPC\") 'set-mark-command)\n"
-              "(when (eq (key-binding (kbd \"C-SPC\")) 'set-mark-command)\n"
-              ;; "           (eq (key-binding (kbd \"M-s\")) 
'ergoemacs-move-cursor-next-pane))\n"
-              "(with-temp-file \"" w-file "\")\n"
-              "   (message \"Passed\")"
-              "  (insert \"Found\"))\n"
-              (or (and (boundp 'wait-for-me) "")
-                  "(kill-emacs)")))
-    (byte-compile-file temp-file)
-    (message "%s"
-             (shell-command-to-string
-              (format "%s %s -Q -L %s -l %s -l %s"
-                      emacs-exe (if (boundp 'wait-for-me) "-debug-init" 
"--batch")
-                      (expand-file-name (file-name-directory (locate-library 
"ergoemacs-mode")))
-                      (expand-file-name (file-name-sans-extension 
(locate-library "ergoemacs-mode")))
-                      temp-file)))
-    (should (file-exists-p w-file))
-    (when  (file-exists-p temp-file)
-      (delete-file temp-file))
-    (when  (file-exists-p (concat temp-file "c"))
-      (delete-file (concat temp-file "c")))
-    (when (file-exists-p w-file)
-      (delete-file w-file))))
 
 (ert-deftest ergoemacs-test-global-key-set-apps-220-before ()
   "Test global C-c b"
   :tags '(:slow :interactive)
   (should (equal (ergoemacs-test-global-key-set-before nil "C-c b") t)))
 
-(ert-deftest ergoemacs-test-global-key-set-M-t-after ()
-  "Test global M-t"
-  :tags '(:slow)
-  (should (equal (ergoemacs-test-global-key-set-before 'after "M-t") t)))
-
-
-(ert-deftest ergoemacs-test-global-key-set-C-d-after ()
-  "Test global C-d"
-  :tags '(:slow)
-  (should (equal (ergoemacs-test-global-key-set-before 'after "C-d") t)))
 
-(ert-deftest ergoemacs-test-global-key-set-C-d-before ()
-  "Test global C-d"
-  :tags '(:slow :interactive)
-  (should (equal (ergoemacs-test-global-key-set-before nil "C-d") t)))
 
 (ert-deftest ergoemacs-test-issue-243 ()
   "Allow globally set keys like C-c C-c M-x to work globally while local 
commands like C-c C-c will work correctly. "
@@ -1263,7 +309,6 @@ Should test issue #142"
     (with-temp-file temp-file
       (insert "(condition-case err (progn ")
       (insert (format "(add-to-list 'load-path \"%s\")" ergoemacs-dir))
-      (insert "(setq ergoemacs-theme nil)")
       (insert "(setq ergoemacs-keyboard-layout \"us\")")
       (insert "(setq ergoemacs-command-loop-type nil)")
       (insert "(require 'ergoemacs-mode)(require 'ergoemacs-test)(setq 
ergoemacs-mode--start-p t)(ergoemacs-mode 1)")
@@ -1286,130 +331,15 @@ Should test issue #142"
     (when (file-exists-p w-file)
       (delete-file w-file))))
 
-(ert-deftest ergoemacs-test-ergoemacs-theme-component-351 ()
-  "Test `ergoemacs-theme-compenent' before load"
-  :tags '(:slow)
-  (let* ((emacs-exe (ergoemacs-emacs-exe))
-         (w-file (expand-file-name "global-test" ergoemacs-dir))
-         (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-    (with-temp-file temp-file
-      (insert "(eval-when-compile (require 'ergoemacs-macros) (require 'cl))"
-              (or (and (boundp 'wait-for-me)
-                       "(setq debug-on-error t debug-on-quit t)") "")
-              "(ergoemacs-theme-component my-theme01 ()\n"
-              "\"My ergoemacs-mode theme component\"\n"
-              "(global-set-key (kbd \"C-x 1\") 'delete-other-windows)\n"
-              "(global-set-key (kbd \"C-x 2\") 'split-window-vertically)\n"
-              "(global-set-key (kbd \"C-x 3\") 'split-window-horizontally)\n"
-              ";; more code ... \n"
-              "(global-set-key '[f2] 'save-buffer)\n)\n"
-              "(add-hook 'ergoemacs-mode-hook\n"
-              "(lambda ()\n"
-              "  (ergoemacs-require 'my-theme01)))\n"
-              "(setq ergoemacs-mode--start-p t)"
-              "(ergoemacs-mode 1)\n"
-              "(when (and (eq (key-binding (kbd \"C-x 1\")) 
'delete-other-windows)\n"
-              "           (eq (key-binding (kbd \"C-x 2\")) 
'split-window-vertically)\n"
-              "           (eq (key-binding (kbd \"C-x 3\")) 
'split-window-horizontally))\n"
-              "(with-temp-file \"" w-file "\")\n"
-              "   (message \"Passed\")"
-              "  (insert \"Found\"))\n"
-              (or (and (boundp 'wait-for-me) "")
-                  "(kill-emacs)")))
-    (byte-compile-file temp-file)
-    (message "%s"
-             (shell-command-to-string
-              (format "%s %s -Q -L %s -l %s -l %s"
-                      emacs-exe (if (boundp 'wait-for-me) "-debug-init" 
"--batch")
-                      (expand-file-name (file-name-directory (locate-library 
"ergoemacs-mode")))
-                      (expand-file-name (file-name-sans-extension 
(locate-library "ergoemacs-mode")))
-                      temp-file)))
-    (should (file-exists-p w-file))
-    (when  (file-exists-p temp-file)
-      (delete-file temp-file))
-    (when  (file-exists-p (concat temp-file "c"))
-      (delete-file (concat temp-file "c")))
-    (when (file-exists-p w-file)
-      (delete-file w-file))))
-
-
-(ert-deftest ergoemacs-test-M-J-347 ()
-  "Test keys that are not working in #347."
-  :tags '(:slow :interactive)
-  (let* ((emacs-exe (ergoemacs-emacs-exe))
-         (w-file (expand-file-name "global-test" ergoemacs-dir))
-         (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-    (with-temp-file temp-file
-      (insert "(eval-when-compile (require 'ergoemacs-macros) (require 'cl))"
-              "(setq ergoemacs-keyboard-layout \"sw\")\n"
-              "(require 'ergoemacs-mode)\n"
-              "(message \"Binding 1: %s\" (key-binding (kbd \"M-J\")))\n"
-              "(global-unset-key (kbd \"M-J\"))\n"
-              "(message \"Binding 2: %s\" (key-binding (kbd \"M-J\")))\n"
-              "(global-set-key (kbd \"M-J\") 'beginning-of-buffer)\n"
-              "(message \"Binding 3: %s\" (key-binding (kbd \"M-J\")))\n"
-              "(setq ergoemacs-mode--start-p t)(ergoemacs-mode 1)"
-              "(message \"Binding 4: %s\" (key-binding (kbd \"M-J\")))\n"
-              "(when (eq (key-binding (kbd \"M-J\")) 'beginning-of-buffer)\n"
-              "(with-temp-file \"" w-file "\")\n"
-              "   (message \"Passed\")"
-              "  (insert \"Found\"))\n"
-              (or (and (boundp 'wait-for-me) "")
-                  "(kill-emacs)")))
-    (message "%s"
-             (shell-command-to-string
-              (format "%s %s -Q -L %s -l %s -l %s"
-                      emacs-exe (if (boundp 'wait-for-me) "" "--batch")
-                      (expand-file-name (file-name-directory (locate-library 
"ergoemacs-mode")))
-                      (expand-file-name (file-name-sans-extension 
(locate-library "ergoemacs-mode")))
-                      temp-file)))
-    (should (file-exists-p w-file))
-    (when  (file-exists-p temp-file)
-      (delete-file temp-file))
-    (when (file-exists-p w-file)
-      (delete-file w-file))))
-
-(ert-deftest ergoemacs-test-issue-437 ()
-  "Test windmove bindings should be set everywhere."
-  :tags '(:slow)
-  (let* ((emacs-exe (ergoemacs-emacs-exe))
-         (w-file (expand-file-name "global-test" ergoemacs-dir))
-         (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-    (with-temp-file temp-file
-      (insert "(eval-when-compile (require 'ergoemacs-macros) (require 'cl))"
-              (or (and (boundp 'wait-for-me)
-                       "(setq debug-on-error t debug-on-quit t)") "")
-              "(ergoemacs-package foo \n"
-             ":bind* ((\"<M-left>\" . windmove-left)"
-             "(\"<M-right>\" . windmove-right)"
-             "(\"<M-up>\" . windmove-up)"
-             "(\"<M-down>\" . windmove-down)))"
-             "(setq ergoemacs-mode--start-p t)"
-              "(ergoemacs-mode 1)\n"
-              "(when (and (eq (key-binding (kbd \"<M-left>\")) 
'windmove-left)\n"
-             "           (eq (key-binding (kbd \"<M-right>\")) 
'windmove-right)\n"
-              "           (eq (key-binding (kbd \"<M-up>\")) 'windmove-up)\n"
-              "           (eq (key-binding (kbd \"<M-down>\")) 
'windmove-down))\n"
-              "(with-temp-file \"" w-file "\")\n"
-              "   (message \"Passed\")"
-              "  (insert \"Found\"))\n"
-              (or (and (boundp 'wait-for-me) "")
-                  "(kill-emacs)")))
-    (byte-compile-file temp-file)
-    (message "%s"
-             (shell-command-to-string
-              (format "%s %s -Q -L %s -l %s -l %s"
-                      emacs-exe (if (boundp 'wait-for-me) "-debug-init" 
"--batch")
-                      (expand-file-name (file-name-directory (locate-library 
"ergoemacs-mode")))
-                      (expand-file-name (file-name-sans-extension 
(locate-library "ergoemacs-mode")))
-                      temp-file)))
-    (should (file-exists-p w-file))
-    (when  (file-exists-p temp-file)
-      (delete-file temp-file))
-    (when  (file-exists-p (concat temp-file "c"))
-      (delete-file (concat temp-file "c")))
-    (when (file-exists-p w-file)
-      (delete-file w-file))))
+;; Issue 437
+;;
+;; Can override an ergoemacs binding when loading the new mode.  For
+;; example, this code changes M-left to M-right.
+;;
+;; (add-hook 'org-mode-hook
+;;   (lambda ()
+;;     (define-key org-mode-map (kbd "<M-left>") 'org-metaright)
+;;     ))
 
 ;;; Not sure why this doesn't actually use `ergoemacs-test-major-mode-map'.
 (define-derived-mode ergoemacs-test-major-mode fundamental-mode "ET"
@@ -1436,7 +366,6 @@ Should test issue #142"
     (with-temp-file temp-file
       (insert "(condition-case err (progn ")
       (insert (format "(add-to-list 'load-path \"%s\")" ergoemacs-dir))
-      (insert "(setq ergoemacs-theme nil)")
       (insert "(setq ergoemacs-keyboard-layout \"us\")")
       (insert "(setq ergoemacs-command-loop-type nil)")
       (insert "(require 'ergoemacs-mode)(require 'ergoemacs-test)(setq 
ergoemacs-mode--start-p t)(ergoemacs-mode 1)")
@@ -1468,43 +397,10 @@ Part of addressing Issue #147."
       (ergoemacs-test-major-mode)
       (when (not (current-local-map))
         (use-local-map ergoemacs-test-major-mode-map))
-      (ergoemacs-map--modify-active)
       (should (eq (key-binding (kbd "C-w")) 'ergoemacs-close-current-buffer))
       ;; The user-defined C-w should not affect kill-region remaps.
       (should (not (eq (key-binding [ergoemacs-remap kill-region]) 
'ergoemacs-close-current-buffer))))))
 
-(ert-deftest ergoemacs-test-keep-ctl-s ()
-  "Keep mode-defined C-s in major-mode `ergoemacs-test-major-mode'.
-Part of addressing Issue #147."
-  :tags '(:interactive)
-  (ergoemacs-test-layout
-   (let (ret
-         (ergoemacs-use-function-remapping t))
-     (with-temp-buffer
-       (ergoemacs-test-major-mode)
-       (when (not (current-local-map))
-         (use-local-map ergoemacs-test-major-mode-map))
-       (ergoemacs-map--modify-active)
-       (should (eq (key-binding (kbd "C-s")) 'save-buffer))
-       (should (eq (key-binding [ergoemacs-remap isearch-forward]) 
'search-forward))))))
-
-
-(ert-deftest ergoemacs-test-keep-alt-s ()
-  "Keep mode-defined M-s in major-mode `ergoemacs-test-major-mode'.
-Tests Issue #372."
-  :tags '(:interactive)
-  (ergoemacs-test-layout
-   :layout "us"
-   :theme "reduction"
-   (let (ret
-         (ergoemacs-use-function-remapping t))
-     (with-temp-buffer
-       (ergoemacs-test-major-mode)
-       (when (not (current-local-map))
-         (use-local-map ergoemacs-test-major-mode-map))
-       (ergoemacs-map--modify-active)
-       (should (eq (key-binding (kbd "M-s")) 
'ergoemacs-move-cursor-next-pane))))))
-
 (ert-deftest ergoemacs-test-dired-sort-files ()
   "Test Issue #340"
   (add-hook 'dired-mode-hook (lambda ()
@@ -1528,7 +424,6 @@ Tests Issue #372."
                                (define-key dired-mode-map "|" 
'dired-sort-menu-toggle-reverse)
                                ))
   (dired ergoemacs-dir)
-  (ergoemacs-map--modify-active)
   (should (equal (key-binding (kbd "s s")) '(lambda () "sort by Size" 
(interactive) (dired-sort-other (concat dired-listing-switches "-AlS --si 
--time-style long-iso")))))
   (should (equal (key-binding (kbd "s .")) '(lambda () "sort by eXtension" 
(interactive) (dired-sort-other (concat dired-listing-switches "X")))))
   (should (equal (key-binding (kbd "s t")) '(lambda () "sort by Time" 
(interactive) (dired-sort-other (concat dired-listing-switches "t")))))
@@ -1639,16 +534,6 @@ Tests Issue #372."
      (set-input-method nil)
      (kill-buffer (current-buffer)))))
 
-(ert-deftest ergoemacs-test-translate-bound ()
-  "Make sure that bound keys are put in the `ergoemacs-map--'
-hash appropriaetly."
-  :tags '(:translate)
-  (ergoemacs-test-layout
-   :layout "colemak"
-   :theme "reduction"
-   (should (equal (ergoemacs-gethash (read-kbd-macro "M-r" t) ergoemacs-map--)
-                  (ergoemacs-gethash (ergoemacs-translate--meta-to-escape 
(read-kbd-macro "M-r" t)) ergoemacs-map--)))))
-
 (ert-deftest ergoemacs-test-table-insert ()
   "Tests that table can insert without hanging emacs."
   :tags '(:table)
@@ -1656,7 +541,7 @@ hash appropriaetly."
     (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
     (delete-region (point-min) (point-max))
     (table-insert 1 2)
-    (ergoemacs-command-loop--internal "abc <tab> abc <tab>")
+    (execute-kbd-macro (kbd "abc <tab> abc <tab>"))
     (should (string= (buffer-string) "+-----+
 |abc  |
 +-----+
@@ -1666,29 +551,6 @@ hash appropriaetly."
     (kill-buffer (current-buffer))))
 
 ;; File variables
-(ert-deftest ergoemacs-test-component-location ()
-  "Make sure that the locations are correct."
-  (should (string= "ergoemacs-themes" (file-name-sans-extension 
(file-name-nondirectory (plist-get (ergoemacs-component-struct-plist 
(ergoemacs-component-struct--lookup-hash "standard-fixed")) :file))))))
-
-;; multiple cursors
-;; (ert-deftest ergoemacs-test-mc-mark-next ()
-;;   "Test Issue #342."
-;;   :tags '(:mc)
-;;   :expected-result :failed
-;;   (ergoemacs-test-layout
-;;    :layout "colemak"
-;;    :theme "reduction"
-;;    :macro "M-SPC M-y M-* n o t SPC f o o <return>"
-;;    (save-excursion
-;;      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-;;      (delete-region (point-min) (point-max))
-;;      (emacs-lisp-mode)
-;;      (insert "foo bar bar bar foo bar")
-;;      (goto-char (point-min))
-;;      (execute-kbd-macro macro)
-;;      (should (string= (buffer-string) "not foo bar bar bar not foo bar"))
-;;      (kill-buffer (current-buffer)))))
-
 (ert-deftest ergoemacs-test-mouse-command-list-changes ()
   "Part of test for Sub issue described in #351"
   (should (equal '(&rest arg) 
(ergoemacs-command-loop--mouse-command-drop-first '(&rest arg) t)))
@@ -1717,102 +579,6 @@ hash appropriaetly."
   (should (equal 'arg3 (ergoemacs-command-loop--mouse-command-drop-first 
'(&optional arg1 arg2 &rest arg3) :rest)))
   (should (equal '(arg2) (ergoemacs-command-loop--mouse-command-drop-first 
'(&optional arg1 arg2 &rest arg3) :drop-rest))))
 
-
-(ert-deftest ergoemacs-test-map-keymap-prefix ()
-  "Tests mapping multiple keymaps defining a prefix."
-  :tags '(:map-keymap)
-  (let ((parent (make-sparse-keymap))
-        (map (make-sparse-keymap))
-        list)
-    (define-key parent [27 ?a] 'ignore)
-    (define-key map [27 ?b] 'ignore)
-    (set-keymap-parent map parent)
-    (ergoemacs-map-keymap
-     (lambda(key item)
-       (unless (or (eq item 'ergoemacs-prefix)
-                   (consp key)
-                   (equal key [ergoemacs-labeled]))
-         (push key list)))
-     map)
-    (should (member [27 ?a] list))
-    (should (member [27 ?b] list))
-    list))
-
-(ert-deftest ergoemacs-test-issue-379 ()
-  "Test infinite recursive event-modifiers."
-  :tags '(:translate)
-  (should (equal (ignore-errors (ergoemacs-specials 
(ergoemacs-translate--event-modifiers 134217755))) '(control meta))))
-
-(ert-deftest ergoemacs-test-temp-map-issue ()
-  "Test temporary map issue."
-  (if (version-list-< (version-to-list "24.4") (version-to-list emacs-version))
-      (ergoemacs-test-layout
-       :layout "colemak"
-       :theme "reduction"
-       :macro "M-8 M-SPC M-SPC M-i"
-       (save-excursion
-        (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-        (delete-region (point-min) (point-max))
-        (insert ergoemacs-test-lorem-ipsum)
-        (goto-char (point-max))
-        (beginning-of-line)
-        (execute-kbd-macro macro)
-        (should (eq (key-binding (kbd "8")) 'self-insert-command))
-        (kill-buffer (current-buffer)))))
-  (should t))
-
-(ert-deftest ergoemacs-test--swap-translation-386 ()
-  "Test thes swapping of the translations."
-  :tags '(:translate :interactive)
-  (should (eq (lookup-key (ergoemacs ergoemacs-translate--parent-map) (or (and 
(eq system-type 'windows-nt) [apps]) [menu])) 
'ergoemacs-command-loop--swap-translation)))
-
-(ert-deftest ergoemacs-test-407 ()
-  "Test M-s is switch pane."
-  :tags '(:require-input :interactive)
-  (if (not (locate-library "icicles")) (should t)
-    (let* ((emacs-exe (ergoemacs-emacs-exe))
-           (w-file (expand-file-name "global-test" ergoemacs-dir))
-           (temp-file (make-temp-file "ergoemacs-test" nil ".el")))
-      (with-temp-file temp-file
-       (insert "(add-to-list 'load-path \"" (expand-file-name 
(file-name-directory (locate-library "ergoemacs-mode"))) "\")"
-               "(add-to-list 'load-path \"" (expand-file-name 
(file-name-directory (locate-library "icicles"))) "\")"
-               "(eval-when-compile (require 'ergoemacs-macros) (require 'cl))"
-               (or (and (boundp 'wait-for-me)
-                        "(setq debug-on-error t debug-on-quit t)") "")
-               "(setq ergoemacs-theme nil)"
-               "(setq ergoemacs-keyboard-layout \"us\")"
-               "(require 'ergoemacs-mode)\n"
-               "(ergoemacs-mode 1)\n"
-               "(require 'icicles)\n"
-               "(icy-mode 1)\n"
-               "(ergoemacs-theme-component reclaim-C-f ()\n"
-               "  \"We need to give at least one sequence to reclaim C-f from 
isearch and get the new icicle-search-key-prefix picked up.\"\n"
-               "(global-set-key (kbd \"C-f .\") 
'isearch-forward-symbol-at-point))"
-               "(ergoemacs-require 'reclaim-C-f)"
-               "(setq icicle-search-key-prefix (kbd \"C-f\"))"
-               "(ergoemacs-package smart-mode-line :ensure t (sml/setup))"
-               "(ergoemacs-package srefactor :ensure t)"
-               "(ergoemacs-package virtualenvwrapper :ensure t)"
-               "(defun test-freeze ()\n"
-               "(interactive)\n"
-               "(yes-or-no-p \"Are you sure you want to remove this file? \"))"
-               "(global-set-key (kbd \"C-1\") 'test-freeze)"
-               "(insert \"Try C-1 to see if emacs freezes.\\nThen try M-a 
test-freeze.\\nM-a calc, do something and then exit with q it should exit\nMake 
sure M-o goes forward word in icy ergoemacs-mode.\")"
-               ;; (or (and (boundp 'wait-for-me) "")
-               ;;     "(kill-emacs)")
-               ))
-      (byte-compile-file temp-file)
-      (message "%s"
-               (shell-command-to-string
-               (format "%s %s -Q -l %s"
-                       emacs-exe "-debug-init"                      
-                       temp-file)))
-      
-      (when  (file-exists-p temp-file)
-       (delete-file temp-file))
-      (when  (file-exists-p (concat temp-file "c"))
-       (delete-file (concat temp-file "c"))))))
-
 ;;; minibuffer tests...
 ;;; Related to: 
http://emacs.stackexchange.com/questions/10393/how-can-i-answer-a-minibuffer-prompt-from-elisp
 
@@ -1831,25 +597,6 @@ hash appropriaetly."
         ,minibuffer-call)
        nil))
 
-(ert-deftest ergoemacs-test-icy-407-minibuffer ()
-  "Test minibuffer keybindings for `icy-mode'.
-[f11] = `previous-history-element'
-[f12] = `next-history-element'
-M-s   = `ergoemacs-move-cursor-next-pane'
-M-r   = `kill-word'"
-  :tags '(:icy-mode :interactive)
-  (icy-mode 1)
-  (let ((keys))
-(ergoemacs-test-layout
- :layout "us"
- :theme "standard"
- (should (equal (ergoemacs-minibuffer-key-bindings
-                (call-interactively 'icicle-execute-extended-command)
-                [f11] [f12] (read-kbd-macro "M-o") (read-kbd-macro "M-s") 
(read-kbd-macro "M-r"))
-               '(previous-history-element next-history-element forward-word 
ergoemacs-move-cursor-next-pane kill-word)))))
-(icy-mode -1))
-
-
 (provide 'ergoemacs-test)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; ergoemacs-test.el ends here
diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el
index 72b224d..1355f8e 100644
--- a/ergoemacs-theme-engine.el
+++ b/ergoemacs-theme-engine.el
@@ -69,13 +69,8 @@
 (declare-function ergoemacs-save "ergoemacs-lib")
 (declare-function ergoemacs-mode-reset "ergoemacs-mode")
 (declare-function ergoemacs-component-struct--component-description 
"ergoemacs-component")
-(declare-function ergoemacs-component-struct--versions "ergoemacs-component")
-(declare-function ergoemacs-layouts--menu "ergoemacs-layouts")
 (declare-function ergoemacs-component-at-point "ergoemacs-component")
-(declare-function ergoemacs-component-find-1 "ergoemacs-component")
-(declare-function ergoemacs-component--prompt "ergoemacs-component")
 (declare-function ergoemacs-require "ergoemacs-lib")
-(declare-function ergoemacs-command-loop--message "ergoemacs-command-loop")
 (declare-function ergoemacs-command-loop--spinner-display 
"ergoemacs-command-loop")
 (declare-function ergoemacs-key-description "ergoemacs-key-description")
 (declare-function ergoemacs-key-description--keymap 
"ergoemacs-key-description")
@@ -84,553 +79,8 @@
 (declare-function ergoemacs-map--hashkey "ergoemacs-map")
 (declare-function ergoemacs-translate--svg-quote "ergoemacs-translate")
 
-(defun ergoemacs-theme-components--required-p (comp)
-  "Is COMP a required component?"
-  (let ((comp (or (and (stringp comp) (intern comp)) comp))
-        e2)
-    (catch 'found
-      (dolist (r ergoemacs-require)
-        (setq e2 (or (and (stringp (car r)) (intern (car r)))
-                     (car r)))
-        (when (eq comp e2)
-          (throw 'found t)))
-      nil)))
-
-(defun ergoemacs-theme-components (&optional theme)
-  "Get a list of components used for the current theme.
-This respects `ergoemacs-theme-options'."
-  (let* ((theme (or theme (ergoemacs :current-theme)))
-         (theme-plist (ergoemacs-gethash theme ergoemacs-theme-hash))
-         components opt first tmp required)
-    (if (not theme)
-        (error "Could not figure out the theme that you are trying to use...")
-      (setq components (plist-get theme-plist :components))
-      (while (and (< 1 (length components))
-                  (ergoemacs-theme-components--required-p (nth 0 components)))
-        (push (pop components) required))
-      (when (and (< 1 (length components))
-                 (symbolp (nth 1 components))
-                 (setq tmp (symbol-name (nth 1 components)))
-                 (< 5 (length tmp))
-                 (string= "theme" (substring tmp -5)))
-        (setq first (pop components)))
-      
-      (dolist (x (reverse (plist-get theme-plist :optional-off)))
-        (let ((a (assoc x ergoemacs-theme-options)))
-          (when a
-            (setq a (car (cdr a)))
-            (when (eq a 'on)
-              (push x opt)))))
-      (dolist (x (reverse (plist-get theme-plist :optional-on)))
-        (let ((a (assoc x ergoemacs-theme-options)))
-          (if (not a)
-              (push x opt)
-            (setq a (car (cdr a)))
-            (when (or (not a) (eq a 'on))
-              (push x opt)))))
-      (setq components (append (reverse required) (reverse opt) components))
-      (when first
-        (push first components)))
-    components))
-
-;;;###autoload
-(defun ergoemacs-theme-set-version (version)
-  "Sets the current themes default VERSION."
-  (let (found)
-    (setq ergoemacs-theme-version
-          (mapcar
-           (lambda(elt)
-             (if (not (equal (ergoemacs :current-theme) (nth 0 elt)))
-                 elt
-               (setq found t)
-               (list (ergoemacs :current-theme) version)))
-           ergoemacs-theme-version))
-    (unless found
-      (push (list (ergoemacs :current-theme) version) 
ergoemacs-theme-version))))
-
-;;;###autoload
-(defun ergoemacs-theme-option-off (option &optional no-custom)
-  "Turns OPTION off.
-Uses `ergoemacs-theme-option-on'."
-  (ergoemacs-theme-option-on option no-custom 'off))
-
-;;;###autoload
-(defun ergoemacs-theme-option-on (option &optional no-custom off)
-  "Turns OPTION on.
-When OPTION is a list turn on all the options in the list
-If OFF is non-nil, turn off the options instead."
-  (if (consp option)
-      (dolist (new-option option)
-        (let (ergoemacs-mode)
-          (ergoemacs-theme-option-on new-option no-custom off)))
-    (let* (found
-           (tmp (mapcar
-                 (lambda(elt)
-                   (if (not (eq (nth 0 elt) option))
-                       elt
-                     (setq found t)
-                     (if off
-                         (list option 'off)
-                       (list option 'on))))
-                 ergoemacs-theme-options)))
-      (unless found
-        (push (if off (list option 'off) (list option 'on))
-              tmp))
-      (if no-custom
-          (setq ergoemacs-theme-options tmp)
-        (ergoemacs-save 'ergoemacs-theme-options tmp))))
-  (when ergoemacs-mode
-    (ergoemacs-mode-reset)))
-
-;;;###autoload
-(defun ergoemacs-theme-toggle-option (option)
-  "Toggle theme OPTION."
-  (if (ergoemacs-theme-option-enabled-p option)
-      (ergoemacs-theme-option-off option)
-    (ergoemacs-theme-option-on option)))
-
-
-(defun ergoemacs-theme--list (&optional silent)
-  "Gets the list of themes.
-When SILENT is true, also include silent themes"
-  (let (ret)
-    ;; All this is done to copy lists so that sorts will not
-    ;; destroy the final list.  Please keep this here so that errors
-    ;; will not be introduced (seems silly)
-    (setq ret (mapcar (lambda(x) x)
-           (or (and silent
-                    (append (ergoemacs-gethash "defined-themes" 
ergoemacs-theme-hash)
-                            (ergoemacs-gethash "silent-themes" 
ergoemacs-theme-hash)))
-               (ergoemacs-gethash "defined-themes" ergoemacs-theme-hash))))
-    ret))
-
-(defun ergoemacs-theme--custom-documentation (&optional themes ini)
-  "Get list of all known layouts and their documentation.
-
-THEMES is the list of themes for the customize documentation.
-
-INI is provided for initilazation, to shorten the descriptions."
-  (let ((themes (or themes (sort (ergoemacs-theme--list) 'string<))))
-    (mapconcat
-     (lambda(theme)
-       (if ini
-           (concat theme "=" (plist-get (ergoemacs-gethash theme 
ergoemacs-theme-hash) :description))
-         (concat "\"" theme "\" - " (plist-get (ergoemacs-gethash theme 
ergoemacs-theme-hash) :description))))
-     themes "\n")))
-
-(defun ergoemacs-theme--customization-type ()
-  "Gets the customization types for `ergoemacs-theme'."
-  `(choice
-    (const :tag "Standard" :value nil)
-    ,@(mapcar
-       (lambda(elt)
-         `(const :tag ,elt :value ,elt))
-       (sort (ergoemacs-theme--list t) 'string<))))
-
-(defun ergoemacs-theme--regexp (&optional at-end)
-  "Return a regexp of `ergoemacs-mode' themes.
-When AT-END is non-nil, append a $ to the regular expression."
-  (let (ret)
-    (setq ret (regexp-opt (ergoemacs-theme--list t) 'symbols))
-    (when at-end
-      (setq ret (concat ret "$")))
-    ret))
-
-(defun ergoemacs-theme-option-enabled-p (option)
-  "Determines if OPTION is enabled."
-  (let* ((plist (ergoemacs-gethash (ergoemacs :current-theme) 
ergoemacs-theme-hash))
-         (options-on (plist-get plist :optional-on))
-         (options-off (plist-get plist :optional-off))
-         (required (plist-get plist :components)))
-    (or (member option required)
-        (and (member option options-on)
-             (not (member (list option 'off) ergoemacs-theme-options)))
-        (and (member option options-off)
-             (member (list option 'on) ergoemacs-theme-options)))))
-
-
-(defun ergoemacs-theme--menu-options (theme)
-  "Gets the options menu for THEME."
-  (let ((plist (ergoemacs-gethash theme ergoemacs-theme-hash))
-        (menu-list '())
-        (menu-pre '())
-        (options-on '())
-        (options-off '())
-        (menu-options '())
-        (options-list '())
-        (options-alist '())
-        (i 0))
-    (setq options-on (plist-get plist ':optional-on)
-          options-off (plist-get plist ':optional-off)
-          menu-list (plist-get plist ':options-menu))
-    (if (= 0 (length (append options-on options-off))) nil
-      (dolist (elt (reverse menu-list))
-        (let ((menu-name (nth 0 elt))
-              (menu-items (nth 1 elt))
-              desc
-              (ret '()))
-          (dolist (option (reverse menu-items))
-            (when (memq option (append options-on options-off))
-              (setq desc (ergoemacs-component-struct--component-description 
(symbol-name option)))
-              (push option menu-options)
-              (push
-               `(,option
-                 menu-item ,desc
-                 (lambda()
-                   (interactive)
-                   (ergoemacs-theme-toggle-option ',option)
-                   (customize-mark-as-set 'ergoemacs-theme-options)
-                   (ergoemacs-mode-reset))
-                 :button (:toggle . (ergoemacs-theme-option-enabled-p 
',option)))
-               ret)))
-          (unless (eq ret '())
-            (setq ret
-                  `(,(intern (format "options-menu-%s" i))
-                    menu-item ,menu-name
-                    (keymap ,@ret)))
-            (setq i (+ i 1))
-            (push ret menu-pre))))
-      (dolist (option (append options-on options-off))
-        (unless (member option menu-options)
-          (let ((desc (ergoemacs-component-struct--component-description 
(symbol-name option))))
-            (push desc options-list)
-            (push (list desc option) options-alist))))
-      `(ergoemacs-theme-options
-        menu-item "Theme Options"
-        (keymap
-         ,@menu-pre
-         ,@(mapcar
-            (lambda(desc)
-              (let ((option (car (cdr (assoc desc options-alist)))))
-                `(,option
-                  menu-item ,desc
-                  (lambda()
-                    (interactive)
-                    (ergoemacs-theme-toggle-option ',option)
-                    (customize-mark-as-set 'ergoemacs-theme-options)
-                    (ergoemacs-mode-reset))
-                  :button (:toggle . (ergoemacs-theme-option-enabled-p 
',option)))))
-            (sort options-list 'string<)))))))
-
-(defun ergoemacs-theme--get-version ()
-  "Get the current version for the current theme."
-  (let ((theme-ver (assoc (ergoemacs :current-theme) ergoemacs-theme-version)))
-    (if (not theme-ver) nil
-      (car (cdr theme-ver)))))
-
-
-(defun ergoemacs-theme--version-menu (theme)
-  "Get version menu for THEME."
-  (let ((theme-versions (ergoemacs-component-struct--versions 
(ergoemacs-theme-components theme))))
-    (if (not theme-versions) nil
-      `(ergoemacs-versions
-        menu-item "Theme Versions"
-        (keymap
-         (ergoemacs-current-version
-          menu-item "Current Version"
-          (lambda()
-            (interactive)
-            (ergoemacs-theme-set-version nil)
-            (customize-mark-as-set 'ergoemacs-theme-version)
-            (ergoemacs-mode-reset))
-          :button (:radio . (equal (ergoemacs :current-version) nil)))
-         ,@(mapcar
-            (lambda(version)
-              `(,(intern version) menu-item ,version
-                (lambda() (interactive)
-                  (ergoemacs-theme-set-version ,version)
-                  (customize-mark-as-set 'ergoemacs-theme-version)
-                  (ergoemacs-mode-reset))
-                :button (:radio . (equal (ergoemacs :current-version) 
,version))))
-            theme-versions))))))
-
-(defun ergoemacs-theme--menu (theme)
-  "Define menus for current THEME."
-  `(keymap
-    ,(ergoemacs-layouts--menu)
-    (ergoemacs-theme-sep "--")
-    (ergoemacs-themes
-     menu-item "Themes"
-     (keymap
-      ,@(mapcar
-         (lambda(theme)
-           `(,(intern theme) menu-item ,(concat theme " - " (plist-get 
(ergoemacs-gethash theme ergoemacs-theme-hash) ':description))
-             (lambda() (interactive)
-               (ergoemacs-save 'ergoemacs-theme ,theme))
-             :button (:radio . (string= (ergoemacs :current-theme) ,theme))))
-         (sort (ergoemacs-theme--list) 'string<))))
-    ,(ergoemacs-theme--menu-options theme)
-    ,(ergoemacs-theme--version-menu theme)
-    (ergoemacs-c-x-sep "--")
-    (ergoemacs-c-x-c-c
-     menu-item "Ctrl+C and Ctrl+X behavior"
-     (keymap
-      (c-c-c-x-emacs
-       menu-item "Ctrl+C and Ctrl+X are for Emacs Commands"
-       (lambda()
-         (interactive)
-         (ergoemacs-save 'ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-       :button (:radio . (eq ergoemacs-handle-ctl-c-or-ctl-x 
'only-C-c-and-C-x)))
-      (c-c-c-x-cua
-       menu-item "Ctrl+C and Ctrl+X are only Copy/Cut"
-       (lambda()
-         (interactive)
-         (ergoemacs-save 'ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut))
-       :button (:radio . (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)))
-      (c-c-c-x-both
-       menu-item "Ctrl+C and Ctrl+X are both Emacs Commands & Copy/Cut"
-       (lambda()
-         (interactive)
-         (ergoemacs-save 'ergoemacs-handle-ctl-c-or-ctl-x 'both))
-       :button (:radio . (eq ergoemacs-handle-ctl-c-or-ctl-x 'both)))
-      (c-c-c-x-timeout
-       menu-item "Customize Ctrl+C and Ctrl+X Cut/Copy Timeout"
-       (lambda() (interactive)
-         (ergoemacs-save 'ergoemacs-ctl-c-or-ctl-x-delay)))))
-    (c-v
-     menu-item "Paste behavior"
-     (keymap
-      (c-v-multiple
-       menu-item "Repeating Paste pastes multiple times"
-       (lambda()
-         (interactive)
-         (ergoemacs-save 'ergoemacs-smart-paste nil))
-       :button (:radio . (eq ergoemacs-smart-paste 'nil)))
-      (c-v-cycle
-       menu-item "Repeating Paste cycles through previous pastes"
-       (lambda()
-         (interactive)
-         (ergoemacs-save 'ergoemacs-smart-paste t))
-       :button (:radio . (eq ergoemacs-smart-paste 't)))
-      (c-v-kill-ring
-       menu-item "Repeating Paste starts browse-kill-ring"
-       (lambda()
-         (interactive)
-         (ergoemacs-save 'ergoemacs-smart-paste 'browse-kill-ring))
-       :enable (commandp 'browse-kill-ring)
-       :button (:radio . (eq ergoemacs-smart-paste 'browse-kill-ring)))))
-    (ergoemacs-sep-bash "--")
-    (ergoemacs-bash
-     menu-item "Make Bash aware of ergoemacs keys"
-     (lambda () (interactive)
-       (call-interactively 'ergoemacs-theme-create-bash)))
-    (ergoemacs-ahk
-     menu-item "Make Windows aware of ergoemacs keys (Requires Autohotkey)"
-     (lambda () (interactive)
-       (call-interactively 'ergoemacs-gen-ahk)))
-    (ergoemacs-sep-menu "--")
-    (ergoemacs-cheat
-     menu-item "Generate/Open Key binding Cheat Sheet"
-     ergoemacs-describe-current-theme)
-
-    (ergoemacs-save
-     menu-item "Save Settings for Future Sessions"
-     (lambda ()
-       (interactive)
-       (ergoemacs-exit-customize-save-customized)))
-
-    (ergoemacs-reset-cache
-     menu-item "Reset ergoemacs-mode cache"
-     (lambda ()
-       (interactive)
-       (ergoemacs-mode-clear-cache)))
-    
-    (ergoemacs-customize
-     menu-item "Customize ErgoEmacs"
-     (lambda ()
-       (interactive)
-       (customize-group 'ergoemacs-mode)))
-    (ergoemacs-mode-web-page
-     menu-item "Ergoemacs-mode web-page"
-     (lambda() (interactive)
-       (browse-url ergoemacs-mode-web-page-url)))
-    (ergoemacs-mode-exit
-     menu-item "Exit ergoemacs-mode"
-     (lambda() (interactive) (ergoemacs-mode -1)))))
-
-(defun ergoemacs-theme-at-point ()
-  "Get the `ergoemacs-theme' defined at or before point.
-Return 0 if there is no such symbol.  Uses
-`ergoemacs-component-at-point'."
-  (ergoemacs-component-at-point t))
-
-(defcustom ergoemacs-theme-find-regexp
-  (concat"^\\s-*(ergoemacs-theme" find-function-space-re "%s\\(\\s-\\|$\\)")
-  "The regexp to search for a component definition.
-
-This is used by `ergoemacs-find-theme'.
-
-Note it must contain a `%s' at the place where `format'
-should insert the face name."
-  :type 'regexp
-  :group 'find-function
-  :version "22.1")
-
-(unless (assoc 'ergoemacs-theme find-function-regexp-alist)
-  (push (cons 'ergoemacs-theme 'ergoemacs-theme-find-regexp) 
find-function-regexp-alist))
-
-(define-button-type 'ergoemacs-theme-help
-  :supertype 'help-xref
-  'help-function #'ergoemacs-theme-describe
-  'help-echo (purecopy "mouse-2, RET: describe this ergoemacs theme"))
-
-(define-button-type 'ergoemacs-theme-def
-  :supertype 'help-xref
-  'help-function #'ergoemacs-theme-find-definition
-  'help-echo (purecopy "mouse-2, RET: find this ergoemacs theme's definition"))
-
 (defvar ergoemacs-theme--svg-list nil)
 
-(defun ergoemacs-theme-find-definition (theme)
-  "Find the definition of THEME.  THEME defaults to the name near point.
-
-Finds the `ergoemacs-mode' containing the definition of the component
-near point (selected by `ergoemacs-theme-at-point') in a buffer and
-places point before the definition.
-
-Set mark before moving, if the buffer already existed.
-
-The library where FACE is defined is searched for in
-`find-function-source-path', if non-nil, otherwise in `load-path'.
-See also `find-function-recenter-line' and `find-function-after-hook'."
-  (interactive (list (ergoemacs-theme-at-point)))
-  (ergoemacs-component-find-1 theme 'ergoemacs-theme 'switch-to-buffer))
-
-(defun ergoemacs-theme-describe (theme)
-  "Display the full documentation of THEME (a symbol or string)."
-  (interactive (ergoemacs-component--prompt t))
-  (let* ((theme (and theme
-                     (or (and (stringp theme) theme)
-                         (and (symbolp theme) (symbol-name theme)))))
-         (plist (ergoemacs-gethash (or theme "") ergoemacs-theme-hash))
-         (file (plist-get plist :file))
-         (el-file (and (stringp file) (concat (file-name-sans-extension file) 
".el")))
-         (old-theme ergoemacs-theme)
-
-        (key (concat theme "-" ergoemacs-keyboard-layout "-" (symbol-name 
(ergoemacs-map--hashkey ergoemacs--start-emacs-state-2))))
-         required-p
-         svg png tmp)
-    (if (not plist)
-        (message "You did not specify a valid ergoemacs theme %s" theme)
-      (if current-prefix-arg
-         (setq svg (ergoemacs-theme--svg theme nil t)
-                 png (ergoemacs-theme--png theme nil t))
-       (setq svg (ergoemacs-theme--svg theme)
-             png (ergoemacs-theme--png theme)))
-      (help-setup-xref (list #'ergoemacs-theme-describe (or theme ""))
-                       (called-interactively-p 'interactive))
-      (with-help-window (help-buffer)
-        (with-current-buffer standard-output
-          (insert (or theme ""))
-          ;; Use " is " instead of a colon so that
-          ;; it is easier to get out the function name using forward-sexp.
-          (insert " is an `ergoemacs-mode' theme")
-          (when (and el-file (file-readable-p el-file))
-            (insert " defined in `")
-            (insert (file-name-nondirectory el-file))
-            (insert "'.")
-            (save-excursion
-              (when (re-search-backward "`\\(.*\\)'" nil t)
-                (help-xref-button 1 'ergoemacs-theme-def theme))))
-          (insert "\n\n")
-          (insert "Documentation:\n")
-          (insert (plist-get plist :description))
-          (insert "\n\n")
-          (insert "Diagram:\n")
-          (cond
-           ((and (image-type-available-p 'png)
-                 (car png)
-                 (file-exists-p (car png)))
-            
-            (insert-image (create-image (car png)))
-            (insert "\n"))
-           ((and (car svg)
-                 (file-exists-p (car svg)) (image-type-available-p 'svg))
-            (insert-image (create-image (car svg)))
-            (insert "\n")))
-          (if (and (car png) (file-exists-p (car png)))
-              (insert "[svg] [png]")
-            (insert "[svg]"))
-          (beginning-of-line)
-          (if (looking-at "\\(\\[svg\\]\\) \\(\\[png\\]\\)")
-              (progn
-                (help-xref-button 1 'help-url (car svg))
-                (help-xref-button 2 'help-url (car png)))
-            (if (looking-at "\\(\\[svg\\]\\)")
-                (help-xref-button 1 'help-url (car svg))))
-          (goto-char (point-max))
-         (when ergoemacs-theme--svg-list
-           (insert "\n")
-           (dolist (elt ergoemacs-theme--svg-list)
-             (when (string= key (nth 0 elt))
-               (insert (ergoemacs-key-description (nth 1 elt)) ":\n")
-                (cond
-                 ((and (image-type-available-p 'png)
-                       (nth 2 elt)
-                       (file-exists-p (replace-regexp-in-string "[.]svg\\'" 
".png" (nth 2 elt))))
-                  (insert-image (create-image (replace-regexp-in-string 
"[.]svg\\'" ".png" (nth 2 elt))))
-                  (insert "\n"))
-                 ((and (image-type-available-p 'svg)
-                       (nth 2 elt)
-                       (file-exists-p (nth 2 elt)))
-                  (insert-image (create-image (nth 2 elt)))
-                  (insert "\n")))
-                (when (file-exists-p (nth 2 elt))
-                  (insert "[svg]")
-                  (when (looking-back "\\(\\[svg\\]\\)" nil)
-                    (help-xref-button 1 'help-url (nth 2 elt))))
-                (when (file-exists-p (replace-regexp-in-string "[.]svg\\'" 
".png" (nth 2 elt)))
-                  (insert " [png]")
-                  (when (looking-back "\\(\\[png\\]\\)" nil)
-                    (help-xref-button 1 'help-url (replace-regexp-in-string 
"[.]svg\\'" ".png" (nth 2 elt)))))
-                (insert "\n\n"))))
-          (insert "\n\n")
-          (when (setq tmp (plist-get plist :based-on))
-            (when (eq (car tmp) 'quote)
-              (setq tmp (car (cdr tmp))))
-            (insert (format "This theme is based on: %s\n\n" tmp))
-            (when (looking-back "on: \\(.*\\)\n\n" nil)
-              (help-xref-button 1 'ergoemacs-theme-help (match-string 1))))
-
-          (when (member theme (ergoemacs-gethash "silent-themes" 
ergoemacs-theme-hash))
-            (insert (format "This theme does not appear in menus because of 
the :silent option.\n\n")))
-
-          (setq required-p t)
-          (dolist (elt '((:components . "Applied Components (from 
`ergoemacs-require')")
-                         (:components . "Theme Required Components")
-                         (:optional-on . "Optional Components (enabled by 
default)")
-                         (:optional-off . "Optional Components (disabled by 
default)")))
-            (when (setq tmp (plist-get plist (car elt)))
-              (insert (cdr elt))
-              (princ ":\n")
-              (dolist (comp tmp)
-                (when (or (and (eq (car elt) :components)
-                               (or (and required-p (memq comp (mapcar 
(lambda(x) (car x)) ergoemacs-require)))
-                                   (and (not required-p) (not (memq comp 
(mapcar (lambda(x) (car x)) ergoemacs-require))))))
-                          (not (eq (car elt) :components)))
-                  (insert (format " - %s -- " comp))
-                  (when (looking-back "- \\(.*\\) -- " nil)
-                    (help-xref-button 1 'ergoemacs-component-help 
(match-string 1)))
-                  (insert (format "%s (currently %s)\n"
-                                  
(ergoemacs-component-struct--component-description comp)
-                                  (or (and (ergoemacs-theme-option-enabled-p 
comp)
-                                           "enabled") "disabled")))
-                  ))
-              (insert "\n"))
-            (setq required-p nil))
-          
-          (insert "\n\n")
-          (if (equal (format "%s" old-theme) (format "%s" theme))
-              (ergoemacs-key-description--keymap ergoemacs-keymap t)
-            (unwind-protect
-                (progn
-                  (setq ergoemacs-theme theme)
-                  (ergoemacs-mode-reset)
-                  (ergoemacs-key-description--keymap ergoemacs-keymap t))
-              (setq ergoemacs-theme old-theme)
-              (ergoemacs-mode-reset)))
-          (buffer-string))))))
-
 (defvar ergoemacs-theme-create-bash-functions
   '((backward-char)
     (forward-char)
@@ -664,22 +114,23 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
 # should be like ErgoEmacs.
 # If none of the keys work, try replacing all instances of \\e with \\M-.
 # That's means changing Esc to Meta key.
-\nset editing-mode emacs") key-string)
+\nset editing-mode emacs"))
     (with-temp-buffer
       (dolist (cmds ergoemacs-theme-create-bash-functions)
         (dolist (cmd cmds)
           (dolist (key-cmd (where-is-internal cmd nil))
-            (setq key-string (key-description key-cmd))
-            ;; Only set up the Meta bindings, not the regular arrow or
-            ;; Control bindings.  That would require more complicated
-            ;; logic to get right.
-            (if (string-prefix-p "M-" key-string)
-                (setq ret (concat ret "\n\"\\"
-                                  (replace-regexp-in-string "M-" "e" 
key-string t)
-                                  "\": "
-                                  (symbol-name (nth 0 cmds))
-                                  )
-                      )
+            (let ((key-string (key-description key-cmd)))
+              ;; Only set up the Meta bindings, not the regular arrow or
+              ;; Control bindings.  That would require more complicated
+              ;; logic to get right.
+              (if (string-prefix-p "M-" key-string)
+                  (setq ret (concat ret "\n\"\\"
+                                    (replace-regexp-in-string "M-" "e" 
key-string t)
+                                    "\": "
+                                    (symbol-name (nth 0 cmds))
+                                    )
+                        )
+                )
               )
             )
           )
@@ -693,135 +144,137 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
 ;;;###autoload
 (defalias 'ergoemacs-bash 'ergoemacs-theme-create-bash)
 
-
 (defcustom ergoemacs-function-short-names
-      '(
-        (abort-recursive-edit "Abort Edit")
-        (ace-jump-mode "Ace Jump")
-        (backward-char  "← char")
+      '((abort-recursive-edit "abort edit")
+        (ace-jump-mode "ace jump")
+        (backward-char "← char")
+        (back-to-indentation "← indent")
         (backward-kill-word "⌫ word")
         (backward-paragraph "↑ ¶")
         (backward-word "← word")
-        (bm-next "Next Bookmark")
-        (bm-toggle "Toggle bookmark")
+        (bm-next "next bookmark")
+        (bm-toggle "toggle bookmark")
         (comment-dwim "cmt dwim")
-        (count-words-region "Count Words")
-        (cua-set-mark "Set Mark")
+        (count-words-region "count words")
+        (cua-set-mark "set mark")
+        (delete-horizontal-space "⌫space⌦")
+        (default-indent-new-line "comment↵")
         (delete-backward-char "⌫ char")
         (delete-char "⌦ char")
-        (delete-frame "x Frame")
-        (delete-indentation "⌧ indentation")
-        (delete-other-windows "x other pane")
+        (delete-frame "x frame")
+        (delete-indentation "⌧ indent")
         (delete-other-windows "x other pane")
         (delete-window "x pane")
-        (delete-window "x pane")
-        (digit-argument "#Argument")
+        (digit-argument "#arg")
+        (electric-newline-and-maybe-indent "enter↵")
         (er/contract-region "→ region ←")
         (er/expand-region "←region→")
-        (er/expand-region "←region→")
         (er/mark-outside-quotes "←quote→")
         (ergoemacs-backward-block "← ¶")
         (ergoemacs-backward-open-bracket "← bracket")
         (ergoemacs-beginning-of-line-or-what "← line/*")
         (ergoemacs-beginning-or-end-of-buffer "↑ Top*")
         (ergoemacs-call-keyword-completion "↯ compl")
-        (ergoemacs-close-current-buffer "x Close Buffer")
-        (ergoemacs-command-loop--universal-argument "Argument")
+        (ergoemacs-close-current-buffer "x buffer")
         (ergoemacs-compact-uncompact-block "fill/unfill ¶")
         (ergoemacs-copy-all "copy all")
-        (ergoemacs-copy-all "copy all")
         (ergoemacs-copy-line-or-region "copy")
-        (ergoemacs-ctl-c "Copy/Ctl+c")
-        (ergoemacs-ctl-x "Cut/Ctl+x")
-        (ergoemacs-cut-all "✂ all")
         (ergoemacs-cut-all "✂ all")
         (ergoemacs-cut-line-or-region "✂ region")
-        (ergoemacs-delete-frame "Close Frame")
+        (ergoemacs-delete-frame "x frame")
         (ergoemacs-end-of-line-or-what "→ line/*")
-        (ergoemacs-end-or-beginning-of-buffer "↓ Bottom*")
-        (ergoemacs-extend-selection "←region→")
+        (ergoemacs-end-or-beginning-of-buffer "↓ bottom*")
         (ergoemacs-extend-selection "←region→")
         (ergoemacs-forward-block  "→ ¶")
         (ergoemacs-forward-close-bracket "→ bracket")
         (ergoemacs-kill-line-backward "⌫ line")
-        (ergoemacs-move-cursor-next-pane "next pane")
         (ergoemacs-move-cursor-previous-pane "prev pane")
-        (ergoemacs-new-empty-buffer "New")
-        (ergoemacs-open-in-external-app "OS Open")
-        (ergoemacs-open-last-closed "Open Last Closed")
-        (ergoemacs-org-edit-src "Edit Source")
+        (ergoemacs-make-frame-command "new frame")
+        (ergoemacs-new-empty-buffer "new buffer")
+        (ergoemacs-open-in-external-app "open extern")
+        (ergoemacs-open-last-closed "open last")
+        (ergoemacs-org-edit-src "edit source")
         (ergoemacs-paste "paste")
         (ergoemacs-paste-cycle "paste ↑")
-        (ergoemacs-print-buffer-confirm "Print")
-        (ergoemacs-read-key--universal-argument "Argument")
-        (ergoemacs-select-current-block "Sel. Block")
-        (ergoemacs-select-current-line "Sel. Line")
+        (ergoemacs-revert-buffer "revert buf.")
+        (ergoemacs-select-current-block "sel. block")
+        (ergoemacs-select-current-line "sel. line")
         (ergoemacs-select-text-in-quote "←quote→")
         (ergoemacs-shrink-whitespaces "⌧ white")
         (ergoemacs-switch-to-next-frame "next frame")
         (ergoemacs-switch-to-previous-frame "prev frame")
-        (ergoemacs-text-scale-normal-size "Reset Zoom")
+        (ergoemacs-text-scale-normal-size "reset zoom")
         (ergoemacs-toggle-camel-case "tog. camel")
         (ergoemacs-toggle-letter-case "tog. case")
-        (ergoemacs-unchorded-alt-modal "Alt+ Mode")
-        (ergoemacs-universal-argument "Argument")
-        (execute-extended-command "M-x")
-        (find-file "Open")
+        (eval-expression "eval expr")
+        (execute-extended-command "run cmd")
+        (find-file "open")
         (flyspell-auto-correct-word "flyspell")
         (forward-char "→ char")
         (forward-paragraph "↓ ¶")
         (forward-word "→ word")
-        (goto-line "Goto line")
-        (ido-write-file "Save As")
-        (indent-for-tab-command "↹Tab")
+        (goto-line "goto line")
+        (ido-write-file "save as")
+        (indent-for-tab-command "↹tab")
         (indent-region "indent-region")  ;; Already in CUA
-        (insert-parentheses "()")
+        (insert-parentheses "insert ()")
         (isearch-backward "← isearch")
         (isearch-backward-regexp "← reg isearch")
         (isearch-forward "→ isearch")
         (isearch-forward-regexp "→ reg isearch")
-        (keyboard-quit "Stop Command")
+        (keyboard-quit "stop cmd")
         (kill-line "⌦ line")
         (kill-word "⌦ word")
+        (kmacro-start-macro-or-insert-counter "start macro")
+        (kmacro-end-or-call-macro "end/run mac.")
         (left-word  "← word")
-        (make-frame-command "New Frame")
-        (mark-paragraph "Sel ¶")
-        (mark-whole-buffer "Sel All")
-        (mc/edit-lines "Edit Lines")
-        (mc/mark-next-like-this "Mark Next")
-        (menu-bar-open "Menu bar")
-        (move-past-close-and-reindent "→) ↹Tab")
-        (negative-argument "-Argument")
-        (newline-and-indent "Enter↵ Tab↹")
+        (make-frame-command "new frame")
+        (mark-paragraph "sel. ¶")
+        (mark-whole-buffer "sel. all")
+        (mc/edit-lines "edit lines")
+        (mc/mark-next-like-this "mark next")
+        (menu-bar-open "menu bar")
+        (move-beginning-of-line "← line")
+        (move-end-of-line "→ line")
+        (move-past-close-and-reindent "→) ↹tab")
+        (negative-argument "-arg")
+        (newline-and-indent "enter↵ tab↹")
         (next-line "↓ line")
-        (pr-interface)
+        (other-window "next pane")
+        (pr-interface "print")
         (previous-line "↑ line")
         (query-replace "rep")
-        (query-replace "rep")
         (query-replace-regexp "rep reg")
+        (quoted-insert "ins. special")
         (recenter-top-bottom "recenter")
         (redo "↷ redo")
-        (revert-buffer "Revert")
+        (revert-buffer "revert")
         (right-word "→ word")
-        (save-buffer "Save")
+        (save-buffer "save")
         (scroll-down "↑ page")
         (scroll-down-command "↑ page")
         (scroll-up "↓ page")
         (scroll-up-command "↓ page")
-        (set-mark-command "Set Mark")
+        (set-mark-command "set mark")
         (shell-command "shell cmd")
         (split-window-below "split —")
         (split-window-horizontally "split —")
         (split-window-right "split |")
         (split-window-vertically "split —")
-        (switch-to-buffer "Switch Buffer")
-        (text-scale-decrease "Zoom Out")
-        (text-scale-increase "Zoom In")
+        (switch-to-buffer "switch buf.")
+        (text-scale-decrease "zoom out")
+        (text-scale-increase "zoom in")
+        (toggle-frame-fullscreen "fullscreen")
+        (toggle-frame-maximized "maximize")
+        (transpose-chars "transpose")
         (undo "↶ undo")
         (undo-tree-redo "↷ redo")
-        (universal-argument "Argument")
+        (universal-argument "arg")
         (vr/query-replace "rep reg")
-        (write-file "Save As"))
+        (write-file "save as")
+        (xref-pop-marker-stack "xref pop")
+        (xref-find-definitions "xref find")        
+        )
   "Ergoemacs short command names."
   :group 'ergoemacs-themes
   :type '(repeat :tag "Command abbreviation"
@@ -863,7 +316,7 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
       ret)
      (t ""))))
 
-(defun ergoemacs-theme--svg-elt (elt theme layout lay)
+(defun ergoemacs-theme--svg-elt (elt layout lay)
   "Handle ELT"
   (ergoemacs-translate--svg-quote
    (let (key binding no-push-p)
@@ -872,77 +325,89 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
       ((and (listp elt) (or (integerp (car elt))
                             (stringp (car elt))))
        (if (stringp (car elt))
-           (setq key "f#")
+           (if (string= (car elt) "SPC")
+               (setq key " ")
+             (setq key "f#"))
          (setq key (nth (car elt) layout)))
        (if (string= key "") ""
          (if (string= key "f#")
              (setq key (aref (read-kbd-macro (concat "<" (downcase (car elt)) 
">")) 0))
            (setq key (string-to-char key)))
-         (if (eq (nth 1 elt) 'apps)
-             (if ergoemacs-theme--svg-prefix
-                 (setq key (vector key))
-               (setq key (vconcat (or (and (eq system-type 'windows-nt) 
[apps]) [menu]) (vector key))))
-           (setq key (vector (event-convert-list (append (cdr elt) (list 
key))))))
+         (setq key (vector (event-convert-list (append (cdr elt) (list key)))))
          (setq no-push-p nil)
          (when (equal key [27])
            (setq no-push-p t))
          (when ergoemacs-theme--svg-prefix
            (setq key (vconcat ergoemacs-theme--svg-prefix key)))
-         (setq binding (lookup-key ergoemacs-keymap key))
+         (setq binding (or
+                        (lookup-key ergoemacs-override-keymap key)
+                        ;; TODO: Use only the ergoemacs global map,
+                        ;; not the regular map?
+                        (lookup-key (current-global-map) key))
+               )
          (when (integerp binding)
            (setq binding nil))
-         (or (and binding
-                  (ergoemacs-keymapp binding)
-                  (or (and (not no-push-p) (push key 
ergoemacs-theme--svg-prefixes))
-                      no-push-p)
-                  "⌨")
-             (and binding
-                  (setq key (assoc binding ergoemacs-function-short-names))
+         (or ;; Prefix keys (e.g. C-x, C-h)
+          (and binding
+               (ergoemacs-keymapp binding)
+               (or (and (not no-push-p) (push key 
ergoemacs-theme--svg-prefixes))
+                   no-push-p)
+               "Prefix Key")
+          ;; Handle the M-O binding specially.
+          (and (eq binding 'ergoemacs-handle-M-O)
+               (or
+                (progn
+                  (setq key (assoc ergoemacs-M-O-binding 
ergoemacs-function-short-names))
                   (nth 1 key))
-             (and binding
-                  (ergoemacs-theme--svg-elt-nonabbrev binding))
-             "")))
+                ""))
+          ;; Regular bindings
+          (and binding
+               (setq key (assoc binding ergoemacs-function-short-names))
+               (nth 1 key))
+          ;; Unknown binding
+          (and binding
+               (ergoemacs-theme--svg-elt-nonabbrev binding))
+          "")))
       ((memq elt '(meta control))
-       (concat (ergoemacs-key-description--modifier elt) (format " - Emacs %s" 
elt)))
+       (concat (ergoemacs-key-description--modifier elt) (format " == %s" 
elt)))
       ((memq elt '(meta-shift control-shift))
        (setq elt (intern (replace-regexp-in-string "-shift" "" (symbol-name 
elt))))
        (concat (ergoemacs-key-description--modifier elt)
                (ergoemacs-key-description--modifier 'shift)
-               (format " - Emacs %s shift" elt)))
-      ((eq elt 'apps)
-       (if ergoemacs-theme--svg-prefix
-           "Key without any modifiers"
-         "▤ Menu/Apps"))
+               (format " == %s shift" elt)))
       ((eq elt 'title)
-       (concat theme " (" lay ")"
-               (or (and ergoemacs-theme--svg-prefix (concat " for " 
(ergoemacs-key-description ergoemacs-theme--svg-prefix)))
-                    "")))
+       (concat lay
+               (or (and ergoemacs-theme--svg-prefix
+                        (concat " for "
+                                (ergoemacs-key-description 
ergoemacs-theme--svg-prefix)))
+                   "")))
       (t (setq key (format "%s" elt))
          (when (<= 10 (length key))
            (setq key (concat (substring key 0 10) "…")))
          key)))))
 
-(defun ergoemacs-theme--svg (&optional theme layout full-p reread)
+(defun ergoemacs-theme--svg (&optional layout full-p reread)
   "Creates SVG based THEME and  LAYOUT"
   (save-excursion
     (let* ((lay (or layout ergoemacs-keyboard-layout))
-           (theme (or theme ergoemacs-theme))
-           (layout (symbol-value (ergoemacs :layout  lay)))
+           (layout (symbol-value (ergoemacs :layout lay)))
            (file-dir (expand-file-name "bindings" (expand-file-name 
"ergoemacs-extras" user-emacs-directory)))
-           (file-name (expand-file-name (concat theme "-" lay "-" (symbol-name 
(ergoemacs-map--hashkey ergoemacs--start-emacs-state-2)) ".svg") file-dir))
+           (file-name (expand-file-name (concat lay "-" (symbol-name 
(ergoemacs-map--hashkey ergoemacs--start-emacs-state-2)) ".svg") file-dir))
            (reread reread)
-           (old-theme ergoemacs-theme)
            (old-layout ergoemacs-keyboard-layout)
            pt ret)
-      (if (and file-name (file-exists-p file-name) (not reread) (or (not 
full-p) ergoemacs-theme--svg-list))
+      (if (and file-name
+               (file-exists-p file-name)
+               (not reread)
+               (or (not full-p)
+                   ergoemacs-theme--svg-list)
+               )
           (progn
-            (setq ret (file-expand-wildcards (expand-file-name (concat theme 
"-" lay "-*-" (symbol-name (ergoemacs-map--hashkey 
ergoemacs--start-emacs-state-2)) ".svg") file-dir)))
+            (setq ret (file-expand-wildcards (expand-file-name (concat lay 
"-*-" (symbol-name (ergoemacs-map--hashkey ergoemacs--start-emacs-state-2)) 
".svg") file-dir)))
             (push file-name ret)
             ret)
-        (unless (and (equal theme old-theme)
-                     (equal lay old-layout))
-          (setq ergoemacs-theme theme
-                ergoemacs-keyboard-layout lay)
+        (unless (equal lay old-layout)
+          (setq ergoemacs-keyboard-layout lay)
           (ergoemacs-mode-reset))
         (unwind-protect
             (progn
@@ -966,8 +431,6 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                       (push (list (string-to-number (match-string 2)) 'meta) 
ergoemacs-theme--svg))
                      ((and (string= "C" (match-string 1)))
                       (push (list (string-to-number (match-string 2)) 
'control) ergoemacs-theme--svg))
-                     ((and (string= "A" (match-string 1)))
-                      (push (list (string-to-number (match-string 2)) 'apps) 
ergoemacs-theme--svg))
                      ((string= "title" (match-string 1))
                       (push 'title ergoemacs-theme--svg))
                      ((string= "N" (match-string 1))
@@ -977,7 +440,7 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                        ((string= "" (match-string 2))
                         (push 'meta ergoemacs-theme--svg))
                        ((string= "-SPC" (match-string 2))
-                        (push (list 32 'meta) ergoemacs-theme--svg))
+                        (push (list "SPC" 'meta) ergoemacs-theme--svg))
                        ((string-match-p "^F" (match-string 2))
                         (push (list (match-string 2) 'meta) 
ergoemacs-theme--svg))
                        (t
@@ -987,7 +450,7 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                        ((string= "" (match-string 2))
                         (push 'meta-shift ergoemacs-theme--svg))
                        ((string= "-SPC" (match-string 2))
-                        (push (list 32 'meta 'shift) ergoemacs-theme--svg))
+                        (push (list "SPC" 'meta 'shift) ergoemacs-theme--svg))
                        ((string-match-p "^F" (match-string 2))
                         (push (list (match-string 2) 'meta 'shift) 
ergoemacs-theme--svg))
                        (t
@@ -997,7 +460,7 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                        ((string= "" (match-string 2))
                         (push 'control-shift ergoemacs-theme--svg))
                        ((string= "-SPC" (match-string 2))
-                        (push (list 32 'control 'shift) ergoemacs-theme--svg))
+                        (push (list "SPC" 'control 'shift) 
ergoemacs-theme--svg))
                        ((string-match-p "^F" (match-string 2))
                         (push (list (match-string 2) 'control 'shift) 
ergoemacs-theme--svg))
                        (t
@@ -1007,21 +470,11 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                        ((string= "" (match-string 2))
                         (push 'control ergoemacs-theme--svg))
                        ((string= "-SPC" (match-string 2))
-                        (push (list 32 'control) ergoemacs-theme--svg))
+                        (push (list "SPC" 'control) ergoemacs-theme--svg))
                        ((string-match-p "^F" (match-string 2))
                         (push (list (match-string 2) 'control) 
ergoemacs-theme--svg))
                        (t
                         (push (list (string-to-number (match-string 2)) 
'control) ergoemacs-theme--svg))))
-                     ((string= "AA" (match-string 1))
-                      (cond
-                       ((string= "" (match-string 2))
-                        (push 'apps ergoemacs-theme--svg))
-                       ((string= "-SPC" (match-string 2))
-                        (push (list 32 'apps) ergoemacs-theme--svg))
-                       ((string-match-p "^F" (match-string 2))
-                        (push (list (match-string 2) 'apps) 
ergoemacs-theme--svg))
-                       (t
-                        (push (list (string-to-number (match-string 2)) 
'control) ergoemacs-theme--svg))))
                      (t (push nil ergoemacs-theme--svg)))
                     (setq pt (match-end 0)))
                   (push (buffer-substring pt (point-max)) 
ergoemacs-theme--svg))
@@ -1034,7 +487,7 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                    ((stringp w)
                     (insert w))
                    (t
-                    (insert ">" (ergoemacs-theme--svg-elt w theme layout lay) 
"<")))))
+                    (insert ">" (ergoemacs-theme--svg-elt w layout lay) 
"<")))))
               (push file-name ret)
               (unless full-p
                 (setq ergoemacs-theme--svg-prefixes nil))
@@ -1043,7 +496,7 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                       file-name (expand-file-name (concat ergoemacs-theme "-" 
lay "-"
                                                           
(replace-regexp-in-string "[^A-Za-z0-9-]+" "_" (key-description 
ergoemacs-theme--svg-prefix))
                                                           "-" (symbol-name 
(ergoemacs-map--hashkey ergoemacs--start-emacs-state-2)) ".svg") file-dir))
-               (push (list (concat ergoemacs-theme "-" lay "-" (symbol-name 
(ergoemacs-map--hashkey ergoemacs--start-emacs-state-2)))
+               (push (list (concat lay "-" (symbol-name 
(ergoemacs-map--hashkey ergoemacs--start-emacs-state-2)))
                            ergoemacs-theme--svg-prefix file-name) 
ergoemacs-theme--svg-list)
                 (ergoemacs :spinner '("%s→%s" "%s->%s") 
(ergoemacs-key-description ergoemacs-theme--svg-prefix) file-name)
                 (with-temp-file file-name
@@ -1052,12 +505,11 @@ See also `find-function-recenter-line' and 
`find-function-after-hook'."
                      ((stringp w)
                       (insert w))
                      (t
-                      (insert ">" (ergoemacs-theme--svg-elt w theme layout 
lay) "<")))))
+                      (insert ">" (ergoemacs-theme--svg-elt w layout lay) 
"<")))))
                 (push file-name ret)))
-          (unless (and (equal theme old-theme)
-                       (equal lay old-layout))
-            (setq ergoemacs-theme old-theme
-                  ergoemacs-keyboard-layout old-layout)
+          (unless (equal lay old-layout)
+            (setq ergoemacs-keyboard-layout old-layout)
+            ;; TODO: Is this OK?
             (ergoemacs-mode-reset)))
         ret))))
 
@@ -1077,7 +529,7 @@ to png files."
             process)
        (if (not png-info)
            (progn
-             (ergoemacs-command-loop--message "Done creating png files.")
+             (message "Done creating png files.")
              ;; FIXME: Update images...
              )
          
@@ -1088,10 +540,10 @@ to png files."
                ergoemacs-theme--png-last (nth 2 png-info))
          (set-process-sentinel process 'ergoemacs-theme--png--process))))))
 
-(defun ergoemacs-theme--png (&optional theme layout full-p reread)
+(defun ergoemacs-theme--png (&optional layout full-p reread)
   "Get png file for layout, or create one.
 Requires `ergoemacs-inkscape' to be specified."
-  (let* ((svg-files (ergoemacs-theme--svg theme layout full-p reread))
+  (let* ((svg-files (ergoemacs-theme--svg layout full-p reread))
          png-file ret)
     (dolist (svg-file svg-files)
       (setq png-file (concat (file-name-sans-extension svg-file) ".png"))
@@ -1099,10 +551,10 @@ Requires `ergoemacs-inkscape' to be specified."
         (if (and ergoemacs-inkscape (file-readable-p ergoemacs-inkscape))
             (progn
               (push (list (format "%s->%s" (file-name-nondirectory svg-file) 
(file-name-nondirectory png-file))
-                          (format "%s -z -f \"%s\" -e \"%s\"" 
ergoemacs-inkscape svg-file png-file)
+                          (format "%s \"%s\" -o \"%s\"" ergoemacs-inkscape 
svg-file png-file)
                          png-file) ergoemacs-theme--png)
               (push png-file ret))
-          (message "Need inkscape and to specify inkscape location with 
`ergoemacs-inkscape'.")
+          (message "Need inkscape to generate png.  Specify inkscape location 
with `ergoemacs-inkscape'.")
           nil)))
     (ergoemacs-theme--png--process)
     ret))
diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el
index ffeecba..da73750 100644
--- a/ergoemacs-themes.el
+++ b/ergoemacs-themes.el
@@ -19,51 +19,166 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with ErgoEmacs.  If not, see <http://www.gnu.org/licenses/>.
 
-;;; Commentary:
+;;;Code:
 
-;; 
-
-;; Todo:
-
-;; 
-
-;;; Code:
-(eval-when-compile 
+(eval-when-compile
   (require 'cl-lib)
   (require 'ergoemacs-macros))
 
-(declare-function ergoemacs-theme-component--create-component 
"ergoemacs-theme")
-(declare-function ergoemacs-component-struct--create-component 
"ergoemacs-component")
-(declare-function ergoemacs-translate--create "ergoemacs-translate")
-(declare-function ergoemacs-key-description--unicode-char 
"ergoemacs-key-description")
-(declare-function ergoemacs-require "ergoemacs-lib")
-
-(defvar ergoemacs-theme-hash)
-(defvar ergoemacs-theme-component-hash)
-(defvar ergoemacs-translation-hash)
-(defvar ergoemacs-component-hash)
-(defvar ergoemacs--component-file-mod-time-list)
-
 (autoload 'dired-jump "dired-x" nil t)
 
-(require 'advice)
-
-;; (ergoemacs-package undo-tree
-;;     :ensure t
-;;     (global-undo-tree-mode 1))
+(require 'ibuffer)
 
-;; (ergoemacs-package persistent-soft
-;;     :ensure t)
+(defun ergoemacs-global-set-key (key command &optional extra-keys)
+  "Translates KEY from a 'us' layout to the current layout.
+This also sets the binding as a global binding as COMMAND.
 
-(ergoemacs-component standard-vars ()
-  "Enabled/changed variables/modes"
+For example, if your layout is 'us', the command
+
+  (ergoemaces-global-set-key (kbd \"M-k\") 'next-line)
+
+will bind 'Meta-k' to next-line.  If your layout is 'colemak', it will bind
+'Meta-e' to next-line.
+
+EXTRA-KEYS are untranslated keys that are appended."
+  (if extra-keys
+      (global-set-key (vconcat (ergoemacs-translate--event-layout
+                                (vconcat (listify-key-sequence key)))
+                               (listify-key-sequence extra-keys))
+                      command)
+    (global-set-key (ergoemacs-translate--event-layout
+                     (vconcat (listify-key-sequence key)))
+                    command)))
+
+(defun ergoemacs-define-key (map key command &optional extra-keys)
+  "Translates KEY from a 'us' layout to the current layout.
+
+In this case,  the key is then  defined in the MAP to run COMMAND.
+
+For example, if your layout is 'us', the command
+
+  (ergoemacs-define-key keymap (kbd \"M-k\") 'next-line)
+
+will bind 'Meta-k' to next-line.  If your layout is 'colemak', it will bind
+'Meta-e' to next-line.
+
+EXTRA-KEYS are untranslated keys that are appended."
+  (if extra-keys
+      (define-key map
+        (vconcat (ergoemacs-translate--event-layout
+                  (vconcat (listify-key-sequence key)))
+                 (listify-key-sequence extra-keys))
+        command)
+    (define-key map
+      (ergoemacs-translate--event-layout
+       (vconcat (listify-key-sequence key)))
+      command)))
+
+(defun ergoemacs-unset-keys-in-map (local-map)
+  "Unset all of the keys in a LOCAL-MAP.
+
+This unsets the keys that we usually prefer to use the ergoemacs keys.
+
+This currently is only used for `isearch-mode-map',
+since that is the only map that manages to evade being overridden
+by the emulation map."
+  (ergoemacs-define-key local-map (kbd "M-h") nil)
+  (ergoemacs-define-key local-map (kbd "M-H") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-e") nil)
+  (ergoemacs-define-key local-map (kbd "M-r") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-g") nil)
+  (ergoemacs-define-key local-map (kbd "M-G") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-u") nil)
+  (ergoemacs-define-key local-map (kbd "M-o") nil)
+  (ergoemacs-define-key local-map (kbd "M-U") nil)
+  (ergoemacs-define-key local-map (kbd "M-O") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-s") nil)
+  (ergoemacs-define-key local-map (kbd "M-S") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-d") nil)
+  (ergoemacs-define-key local-map (kbd "M-f") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-n") nil)
+  (ergoemacs-define-key local-map (kbd "M-N") nil)
+  (ergoemacs-define-key local-map (kbd "M-p") nil)
+  (ergoemacs-define-key local-map (kbd "M-b") nil)
+  (ergoemacs-define-key local-map (kbd "M-B") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-j") nil)
+  (ergoemacs-define-key local-map (kbd "M-l") nil)
+  (ergoemacs-define-key local-map (kbd "M-i") nil)
+  (ergoemacs-define-key local-map (kbd "M-k") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-J") nil)
+  (ergoemacs-define-key local-map (kbd "M-L") nil)
+  (ergoemacs-define-key local-map (kbd "M-I") nil)
+  (ergoemacs-define-key local-map (kbd "M-K") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-z") nil)
+  (ergoemacs-define-key local-map (kbd "M-x") nil)
+  (ergoemacs-define-key local-map (kbd "M-c") nil)
+  (ergoemacs-define-key local-map (kbd "M-v") nil)
+  (ergoemacs-define-key local-map (kbd "M-C") nil)
+  (ergoemacs-define-key local-map (kbd "M-V") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-a") nil)
+  (ergoemacs-define-key local-map (kbd "M-A") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-0") nil)
+  (ergoemacs-define-key local-map (kbd "M-)") nil)
+  (ergoemacs-define-key local-map (kbd "M-2") nil)
+  (ergoemacs-define-key local-map (kbd "M-@") nil)
+  (ergoemacs-define-key local-map (kbd "M-3") nil)
+  (ergoemacs-define-key local-map (kbd "M-#") nil)
+  (ergoemacs-define-key local-map (kbd "M-4") nil)
+  (ergoemacs-define-key local-map (kbd "M-$") nil)
+  (ergoemacs-define-key local-map (kbd "M-5") nil)
+  (ergoemacs-define-key local-map (kbd "M-%") nil)
+  (ergoemacs-define-key local-map (kbd "M-6") nil)
+  (ergoemacs-define-key local-map (kbd "M-^") nil)
+  (ergoemacs-define-key local-map (kbd "M-7") nil)
+  (ergoemacs-define-key local-map (kbd "M-&") nil)
+  (ergoemacs-define-key local-map (kbd "M-8") nil)
+  (ergoemacs-define-key local-map (kbd "M-*") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-;") nil)
+  (ergoemacs-define-key local-map (kbd "M-:") nil)
+
+  (ergoemacs-define-key local-map (kbd "M-'") nil)
+  (ergoemacs-define-key local-map (kbd "M-\"") nil)
+  (ergoemacs-define-key local-map (kbd "M-w") nil)
+  (ergoemacs-define-key local-map (kbd "M-?") nil)
+  (ergoemacs-define-key local-map (kbd "M-/") nil)
+  (ergoemacs-define-key local-map (kbd "M-t") nil)
+  (ergoemacs-define-key local-map (kbd "M-T") nil)
+  (ergoemacs-define-key local-map (kbd "M-q") nil)
+
+  (define-key local-map (kbd "C-w") nil)
+  (define-key local-map (kbd "C-n") nil)
+  (define-key local-map (kbd "C-S-w") nil)
+  (define-key local-map (kbd "C-S-n") nil)
+
+  (define-key local-map (kbd "C-s") nil)
+  (define-key local-map (kbd "C-S-s") nil)
+  (define-key local-map (kbd "C-o") nil)
+  (define-key local-map (kbd "C-S-o") nil)
+  (define-key local-map (kbd "C-r") nil)
+  (define-key local-map (kbd "C-p") nil)
+  (define-key local-map (kbd "C-l") nil))
+
+(defun ergoemacs-set-standard-vars ()
+  "Enabled/changed variables/modes."
   (setq org-CUA-compatible t
         org-support-shift-select t
         set-mark-command-repeat-pop t
         org-special-ctrl-a/e t
-        ido-vertical-define-keys 'C-n-C-p-up-down-left-right
         scroll-error-top-bottom t
-        initial-scratch-message (substitute-command-keys ";; This buffer is 
for notes you don't want to save, and for Lisp evaluation.\n;; If you want to 
create a file, visit that file with \\[find-file],\n;; then enter the text in 
that file's own buffer.")
+        ergoemacs-swap-major-modes-when-clicking-major-mode-name t
+        initial-scratch-message (substitute-command-keys ";; This buffer is 
for notes you don't want to save, and for Lisp evaluation.\n;; If you want to 
create a file, visit that file with \\[find-file],\n;; then enter the text in 
that file's own buffer.\n\n")
         ;; Remove tutorial and guided tour, since the keys don't apply...
         fancy-startup-text
         `((:face (variable-pitch font-lock-comment-face)
@@ -82,11 +197,6 @@
                         "Display info on the GNU project")))
                  " operating system.\n\n"
                  "\n"
-                 ;; :link ("Emacs Guided Tour"
-                 ;;        ,(lambda (_button)
-                 ;;           (browse-url 
"http://www.gnu.org/software/emacs/tour/";))
-                 ;;        "Browse http://www.gnu.org/software/emacs/tour/";)
-                 ;; "\tOverview of Emacs features at gnu.org\n"
                  :link ("View Emacs Manual" ,(lambda (_button) 
(info-emacs-manual)))
                  "\tView the Emacs manual using Info\n"
                  :link ("Absence of Warranty" ,(lambda (_button) 
(describe-no-warranty)))
@@ -150,1566 +260,777 @@
                  :link ("Ordering Manuals" ,(lambda (_button) 
(view-order-manuals)))
                  "\tBuying printed manuals from the FSF\n"
                  "\n"
-                 ;; :link ("Emacs Guided Tour"
-                 ;;        ,(lambda (_button)
-                 ;;           (browse-url 
"http://www.gnu.org/software/emacs/tour/";))
-                 ;;        "Browse http://www.gnu.org/software/emacs/tour/";)
-                 ;; "\tSee an overview of Emacs features at gnu.org"
                 )))
   (add-hook 'dirtrack-directory-change-hook 
'ergoemacs-shell-here-directory-change-hook)
   (add-hook 'kill-buffer-hook 'ergoemacs-save-buffer-to-recently-closed)
   (add-hook 'shell-mode-hook 'ergoemacs-shell-here-hook)
   (add-hook 'eshell-post-command-hook 
'ergoemacs-shell-here-directory-change-hook)
-  ;; (dolist (hook '(dired-after-readin-hook after-change-major-mode-hook))
-  ;;   (add-hook hook 'ergoemacs-setup-local-prefixes))
-  (shift-select-mode t)
-  (delete-selection-mode 1)
-  (setq recentf-menu-before "Close"
-        recentf-menu-items-for-commands
-        (list
-         ["Open Last Closed"
-          ergoemacs-open-last-closed
-          :help "Remove duplicates, and obsoletes files from the recent list"
-          :active t]
-         ["Cleanup list"
-          recentf-cleanup
-          :help "Remove duplicates, and obsoletes files from the recent list"
-          :active t]
-         ["Edit list..."
-          recentf-edit-list
-          :help "Manually remove files from the recent list"
-          :active t]
-         ["Save list now"
-          recentf-save-list
-          :help "Save the list of recently opened files now"
-          :active t]
-         ["Options..."
-          (customize-group "recentf")
-          :help "Customize recently opened files menu and options"
-          :active t]))
-  (recentf-mode (if noninteractive -1 1))
-  ;; (setq cua--rectangle-modifier-key ergoemacs-cua-rect-modifier)
-  ;; (setq cua--rectangle-keymap (make-sparse-keymap))
-  ;; (setq cua--rectangle-initialized nil)
-  ;; (setq cua--keymap-alist
-  ;;   (progn
-  ;;     (cua--init-rectangles)
-  ;;     `((cua--ena-prefix-override-keymap . ,cua--prefix-override-keymap)
-  ;;       (cua--ena-prefix-repeat-keymap . ,cua--prefix-repeat-keymap)
-  ;;       (cua--ena-cua-keys-keymap . ,cua--cua-keys-keymap)
-  ;;       (cua--ena-global-mark-keymap . ,cua--global-mark-keymap)
-  ;;       (cua--rectangle . ,cua--rectangle-keymap)
-  ;;       (cua--ena-region-keymap . ,cua--region-keymap)
-  ;;       (cua-mode . ,cua-global-keymap))))
-  )
-
-(ergoemacs-component save-options-on-exit ()
-  "Save emacs options on exit"
-  (add-hook 'kill-emacs-hook 'ergoemacs-exit-customize-save-customized))
-
-;;; Fixed components
-(ergoemacs-component standard-fixed ()
-  "Standard Fixed Shortcuts"
-  :variable-reg nil ;; No variable keys
-  (global-set-key [tool-bar kill-buffer] 'ergoemacs-close-current-buffer)
-  (global-set-key (kbd "C-n") 'ergoemacs-new-empty-buffer)
+  (delete-selection-mode 1))
+
+(defun ergoemacs-unset-keys (keymap)
+  "Unset all of the standard keys at once.
+Call this before calling any other ergoemacs-set-* function"
+  (define-key keymap (kbd "C-x C-f") 'undefined)
+  (define-key keymap (kbd "C-x C-s") 'undefined)
+  (define-key keymap (kbd "C-x C-w") 'undefined)
+  (define-key keymap (kbd "C-x h") 'undefined)
+  (define-key keymap (kbd "C-x k") 'undefined)
+  (define-key keymap (kbd "C-b") 'undefined)
+  (define-key keymap (kbd "C-p") 'undefined)
+  (define-key keymap (kbd "C-n") 'undefined)
+  (define-key keymap (kbd "C-d") 'undefined)
+  (define-key keymap (kbd "M-b") 'undefined)
+  (define-key keymap (kbd "M-f") 'undefined)
+  (define-key keymap (kbd "M-d") 'undefined)
+
+  (define-key keymap (kbd "C-w") 'undefined)
+  (define-key keymap (kbd "M-w") 'undefined)
+  (define-key keymap (kbd "C-y") 'undefined)
+  (define-key keymap (kbd "M-y") 'undefined)
+  (define-key keymap (kbd "C-_") 'undefined)
+  (define-key keymap (kbd "C-/") 'undefined)
+  (define-key keymap (kbd "C-x u") 'undefined)
+
+  (define-key keymap (kbd "C-s") 'undefined)
+  (define-key keymap (kbd "C-r") 'undefined)
+  (define-key keymap (kbd "M-%") 'undefined)
   
-  (global-set-key (kbd "C-x C-f") nil) ;; Remove Emacs Method
-  (global-set-key (kbd "C-o") ("C-o" :emacs))
-  (global-set-key (kbd "C-S-o") 'ergoemacs-open-in-desktop)
+  (define-key keymap (kbd "M-{") 'undefined)
+  (define-key keymap (kbd "M-}") 'undefined)
+  (define-key keymap (kbd "C-a") 'undefined)
+  (define-key keymap (kbd "C-e") 'undefined)
 
-  (global-set-key (kbd "C-S-t") 'ergoemacs-open-last-closed)
-  (global-set-key (kbd "C-w") 'ergoemacs-close-current-buffer)
+  (define-key keymap (kbd "M-v") 'undefined)
+  (define-key keymap (kbd "C-v") 'undefined)
 
-  (global-set-key (kbd "C-s") nil) ;; Search Forward
-  (global-set-key (kbd "C-f") ("C-s" :emacs))
+  (define-key keymap (kbd "M->") 'undefined)
+  (define-key keymap (kbd "M-<") 'undefined)
 
-  (global-set-key (kbd "C-x C-s") nil) ;; Save File
-  (global-set-key (kbd "C-s") ("C-x C-s" :emacs))
-  
-  (global-set-key (kbd "C-x C-w") nil) ;; Write File
-  (global-set-key (kbd "C-S-s") ("C-x C-w" :emacs))
+  (define-key keymap (kbd "C-x 1") 'undefined)
+  (define-key keymap (kbd "C-x 0") 'undefined)
+  (define-key keymap (kbd "C-x 3") 'undefined)
+  (define-key keymap (kbd "C-x 2") 'undefined)
 
-  (global-set-key (kbd "C-p") 'ergoemacs-print-buffer-confirm)
+  (define-key keymap (kbd "M-x") 'undefined)
+  (define-key keymap (kbd "M-!") 'undefined)
+  (define-key keymap (kbd "C-l") 'undefined)
+  (define-key keymap (kbd "C-k") 'undefined)
+  (define-key keymap (kbd "M-;") 'undefined))
 
-  (global-set-key (kbd "C-x h") nil) ;; Mark whole buffer
-  (global-set-key (kbd "C-a") ("C-x h" :emacs))
-  
-  (global-set-key (kbd "C-z") 'undo)
+;;; Fixed components
+(defun ergoemacs-set-standard-fixed (keymap)
+  "Set the standard keys for KEYMAP.
 
-  ;; Take out undo-tree's redo bindings
-  (define-key undo-tree-map (kbd "C-?") nil)
-  (define-key undo-tree-map (kbd "M-_") nil)
-  
-  (global-set-key (kbd "C-S-z") '(redo undo-tree-redo ergoemacs-redo))
-  (global-set-key (kbd "M-S-z") '(redo undo-tree-redo ergoemacs-redo))
-  (global-set-key (kbd "<S-delete>") 'ergoemacs-cut-line-or-region)
-  (if (not (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-      (global-set-key (kbd "C-c <ergoemacs-timeout>")
-                      'ergoemacs-copy-line-or-region)
-    )
-  (global-set-key (kbd "<C-insert>") 'ergoemacs-copy-line-or-region)
-  (global-set-key (kbd "C-S-v") 'ergoemacs-paste-cycle)
+These keys do not depend on the layout."
+  (global-set-key [tool-bar kill-buffer] 'ergoemacs-close-current-buffer)
   
-  (global-set-key (kbd "<S-insert>") 'ergoemacs-paste)
-  (global-set-key (kbd "C-v") 'ergoemacs-paste)
-
-  ;; Navigation
-  (global-set-key (kbd "C-S-n") 'make-frame-command)
-
-  ;; Text editing
+  ;; These keys go into the override map
+  (define-key keymap (kbd "C-o") 'find-file)
+  (define-key keymap (kbd "C-S-o") 'ergoemacs-open-in-desktop)
   
-  ;; the Del key for forward  delete. Needed if C-d is set to nil.
-  (global-set-key (kbd "<delete>") 'delete-char ) 
+  (define-key keymap (kbd "C-w") 'ergoemacs-close-current-buffer)
 
-  (global-set-key (kbd "<M-delete>") 'kill-word)
-  (global-set-key (kbd "<C-delete>") 'kill-word)
+  (define-key keymap (kbd "C-s") 'save-buffer)
+  (define-key keymap (kbd "C-S-s") 'write-file)
+  (define-key keymap (kbd "C-p") 'pr-interface)
 
-  (global-set-key (kbd "<home>") 'move-beginning-of-line)
-  (global-set-key (kbd "<end>") 'move-end-of-line)
+  (define-key keymap (kbd "C-n") 'ergoemacs-new-empty-buffer)
+  (define-key keymap (kbd "C-S-n") 'ergoemacs-make-frame-command)
   
-  (global-set-key (kbd "<C-home>") 'beginning-of-buffer)
-  (global-set-key (kbd "<C-end>") 'end-of-buffer)
+  (define-key keymap (kbd "C-w") 'ergoemacs-close-current-buffer)
+  (define-key keymap (kbd "C-S-w") 'ergoemacs-delete-frame)
 
-  (global-set-key (kbd "<C-left>") 'backward-word)
-  (global-set-key (kbd "<C-right>") 'forward-word)
+  (define-key keymap (kbd "C-l") 'goto-line)
+  (define-key keymap (kbd "C-p") 'pr-interface)
 
-  (global-set-key (kbd "<M-up>") 'ergoemacs-backward-block)
-  (global-set-key (kbd "<M-down>") 'ergoemacs-forward-block)
+  (define-key keymap (kbd "C-+") 'text-scale-increase)
+  (define-key keymap (kbd "C-=") 'text-scale-increase)
+  (define-key keymap (kbd "C--") 'text-scale-decrease)
+  (define-key keymap (kbd "C-_") 'text-scale-decrease)
+  (define-key keymap (kbd "C-0") 'ergoemacs-text-scale-normal-size)
+  (define-key keymap (kbd "C-)") 'ergoemacs-text-scale-normal-size)
 
-  ;; C-H is search and replace.
+  ;; These go into the global map, so they can be overridden by a
+  ;; local mode map.
+  (define-key keymap (kbd "C-f") 'isearch-forward)
+  (define-key keymap (kbd "C-a") 'mark-whole-buffer)
+  (define-key keymap (kbd "C-z") 'ergoemacs-undo)
+  (define-key keymap (kbd "C-S-z") 'ergoemacs-redo)
+  (define-key keymap (kbd "C-y") 'ergoemacs-redo)
 
-  ;; C-1 to C-9 should be switch tab...  Same as in Google chrome.
-  ;; C-T should be new tab.
 
-  ;; Refresh should be <f5>; erogemacs uses <f5>.
-  ;; C-r also should be refresh
-  (global-set-key (kbd "<f5>") 'revert-buffer)
-  (global-set-key (kbd "C-r") 'revert-buffer)
-  
-  ;; Text Formatting
-  ;; Upper/Lower case toggle.
+  (define-key keymap (kbd "<S-delete>") 'ergoemacs-cut-line-or-region)
+  (define-key keymap (kbd "<C-insert>") 'ergoemacs-copy-line-or-region)
+  (define-key keymap (kbd "C-S-v") 'ergoemacs-paste-cycle)
 
-  ;; Ergoemacs fixed keys...
-  
-  (global-set-key (kbd "<M-f4>") 'ergoemacs-delete-frame) ;; Alt+f4 should 
work.
-  
-   ; Alt+→
-  ;; Allow shift selection
-  (global-set-key (kbd "<S-down-mouse-1>") 'mouse-save-then-kill)
-  (global-set-key (kbd "<S-mouse-1>") 'ignore)
-  (global-set-key (kbd "C-+") 'text-scale-increase)
-  (global-set-key (kbd "C--") 'text-scale-decrease)
-  (global-set-key (kbd "C-.") 'keyboard-quit)
-  (global-set-key (kbd "C-/") 'info)
-  (global-set-key (kbd "C-0") 'ergoemacs-text-scale-normal-size)
-  (global-set-key (kbd "C-<next>") 'ergoemacs-next-user-buffer)
-  (global-set-key (kbd "C-<pause>") 'kill-compilation) ; stop 
compilation/find/grep
-  (global-set-key (kbd "C-<prior>") 'ergoemacs-previous-user-buffer)
-  (global-set-key (kbd "C-=") 'text-scale-increase)
-  (global-set-key (kbd "C-?") 'info)
-  (global-set-key (kbd "C-S-<next>") 'ergoemacs-next-emacs-buffer)
-  (global-set-key (kbd "C-S-<prior>") 'ergoemacs-previous-emacs-buffer)
-  (global-set-key (kbd "C-S-f") 'occur)
-  
-  (global-set-key (kbd "C-S-o") 'ergoemacs-open-in-external-app)
-  (global-set-key (kbd "C-S-s") 'write-file)
-  (global-set-key (kbd "C-S-t") 'ergoemacs-open-last-closed)
-  
-  (global-set-key (kbd "C-S-w") 'delete-frame)
-  
-  (global-set-key (kbd "C-`") 'other-frame)
-  (global-set-key (kbd "C-a") 'mark-whole-buffer)
-  (global-set-key (kbd "C-f") 'isearch-forward)
-  (global-set-key (kbd "C-l") 'goto-line)
-  (global-set-key (kbd "C-n") 'ergoemacs-new-empty-buffer)
-  (global-set-key (kbd "C-o") 'find-file)
-  (global-set-key (kbd "C-p") 'ergoemacs-print-buffer-confirm)
-
-  (global-set-key (kbd "C-x k") nil)
-  (global-set-key (kbd "C-w") 'ergoemacs-close-current-buffer)
-  (if (not (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-      (global-set-key (kbd "C-x <ergoemacs-timeout>") 
'ergoemacs-cut-line-or-region)
-    )
-  (global-set-key (kbd "C-x C-b") 'ibuffer)
-  (global-set-key (kbd "C-y") '(redo undo-tree-redo ergoemacs-redo) "↷ redo")
-  
-  (global-set-key (kbd "M-S-<next>") 'forward-page)
-  (global-set-key (kbd "M-S-<prior>") 'backward-page)
-
-  ;; Mode specific changes
-  (define-key org-mode-map (kbd "<C-return>") 
'ergoemacs-org-insert-heading-respect-content)
-  (define-key org-mode-map (kbd "<M-down>") 'ergoemacs-org-metadown)
-  (define-key org-mode-map (kbd "<M-up>") 'ergoemacs-org-metaup)
-  (define-key org-mode-map (kbd "<M-left>") 'ergoemacs-org-metaleft)
-  (define-key org-mode-map (kbd "<M-right>") 'ergoemacs-org-metaright)
-  (define-key org-mode-map (kbd "<M-RET>") 'org-insert-item)
-  (define-key org-mode-map (kbd "M-v") 'ergoemacs-org-yank)
-  (define-key org-mode-map (kbd "C-v") 'ergoemacs-org-yank)
-
-  (define-key browse-kill-ring-mode-map (kbd "C-f") 
'browse-kill-ring-search-forward)
-  (define-key browse-kill-ring-mode-map (kbd "<deletechar>") 
'browse-kill-ring-delete)
-
-  (define-key log-edit-mode-map [remap save-buffer] 'log-edit-done)
-
-  (define-key eshell-mode-map (kbd "<home>") 'eshell-bol)
-  (define-key comint-mode-map (kbd "<home>") 'comint-bol)
-
-  (define-key helm-map [remap mark-whole-buffer] 'helm-mark-all)
-  (define-key helm-map (kbd "C-w") 'helm-keyboard-quit)
-  (define-key helm-map (kbd "C-z") nil)
-  
+  (define-key keymap (kbd "<S-insert>") 'ergoemacs-paste)
+  (define-key keymap (kbd "C-v") 'ergoemacs-paste)
 
-  ;; Compatibility with Icicle (allows the use of
-  ;; `icicle-read-string-completing' directly)
-  (when icicle-mode
-    (global-set-key [remap ergoemacs-apropos-user-options] 
'apropos-user-options))
-  
-  (when icicle-ido-like-mode
-    (global-set-key [remap ergoemacs-apropos-user-options] 
'apropos-user-options))
-
-  (define-key isearch-mode-map (kbd "C-S-f") 'isearch-occur)
-  (define-key isearch-mode-map (kbd "C-M-f") 'isearch-occur)
-  (define-key isearch-mode-map (kbd "<S-insert>") 'ergoemacs-paste)
-  (define-key isearch-mode-map (kbd "C-S-v") 'ergoemacs-paste-cycle)
-  (if (not (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-      (define-key isearch-mode-map (kbd "C-c") 'isearch-yank-word-or-char)
-    )
-  (define-key isearch-mode-map (kbd "M-c") 'isearch-yank-word-or-char)
-  (define-key isearch-mode-map (kbd "M-v") 'ergoemacs-paste)
-  (define-key isearch-mode-map (kbd "C-v") 'ergoemacs-paste))
-
-(ergoemacs-component tab-indents-region ()
-  "Tab indents selected region"
-  (when mark-active
-    (global-set-key (kbd "TAB") 'indent-region)))
-
-(ergoemacs-component fixed-bold-italic ()
-  "Fixed keys for bold and italic"
-  (define-key org-mode-map (kbd "C-b") 'ergoemacs-org-bold)
-  ;; C-i is TAB... This seems to cause issues?
-  ;; (define-key org-mode-map (kbd "C-i") 'ergoemacs-org-italic)
-  (define-key org-mode-map (kbd "<tab>") 'org-cycle)
-  (define-key org-mode-map (kbd "<kp-tab>") 'org-cycle))
-
-(ergoemacs-component backspace-is-back ()
-  "Backspace is back, as in browsers..."
-  (define-key Info-mode-map (kbd "<backspace>") 'Info-history-back)
-  (define-key Info-mode-map (kbd "<S-backspace>") 'Info-history-forward)
-  (define-key Info-mode-map (kbd "<M-backspace>") 'Info-history-forward)
-  (define-key help-mode-map (kbd "<backspace>") 'help-go-back)
-  (define-key help-mode-map (kbd "<S-backspace>") 'help-go-forward)
-  (define-key eww-mode-map (kbd "<backspace>") 'eww-back-url)
-  (define-key eww-mode-map (kbd "<S-backspace>") 'eww-forward-url))
-
-(ergoemacs-component fixed-newline ()
-  "Newline and indent"
-  (global-set-key (kbd "M-RET") ("C-j" :emacs))
-  (define-key helm-map (kbd "M-RET") 'helm-execute-persistent-action)
-  (define-key helm-map (kbd "<M-return>") 'helm-execute-persistent-action)
-  (define-key helm-map (kbd "M-S-RET") "C-u M-RET")
-  (define-key helm-map (kbd "<M-S-return>") "C-u M-RET")
-  
-  
-  (define-key helm-read-file-map [remap eshell] 'helm-ff-run-switch-to-eshell)
-  (define-key helm-read-file-map [remap ergoemacs-eshell-here] 
'helm-ff-run-switch-to-eshell)
-  (define-key helm-read-file-map (kbd "RET") 
'ergoemacs-helm-ff-persistent-expand-dir)
-  (define-key helm-read-file-map (kbd "<return>") 
'ergoemacs-helm-ff-persistent-expand-dir)
-  (define-key helm-read-file-map (kbd "M-RET") 
'ergoemacs-helm-ff-execute-dired-dir)
-  (define-key helm-read-file-map (kbd "<M-return>") 
'ergoemacs-helm-ff-execute-dired-dir)
-  (define-key helm-read-file-map (kbd "DEL") 'ergoemacs-helm-ff-backspace)
-  
-  (define-key helm-find-files-map [remap eshell] 'helm-ff-run-switch-to-eshell)
-  (define-key helm-find-files-map [remap ergoemacs-eshell-here] 
'helm-ff-run-switch-to-eshell)
-  (define-key helm-find-files-map (kbd "DEL") 'ergoemacs-helm-ff-backspace)
-  (define-key helm-find-files-map (kbd "RET") 
'ergoemacs-helm-ff-persistent-expand-dir)
-  (define-key helm-find-files-map (kbd "<return>") 
'ergoemacs-helm-ff-persistent-expand-dir)
-  (define-key helm-find-files-map (kbd "M-RET") 
'ergoemacs-helm-ff-execute-dired-dir)
-  (define-key helm-find-files-map (kbd "<M-return>") 
'ergoemacs-helm-ff-execute-dired-dir)
-  (define-key helm-find-files-map (kbd "RET") 
'ergoemacs-helm-ff-persistent-expand-dir)
-  (define-key helm-find-files-map (kbd "<return>") 
'ergoemacs-helm-ff-persistent-expand-dir)
-  (define-key helm-find-files-map (kbd "M-RET") 
'ergoemacs-helm-ff-execute-dired-dir)
-  (define-key helm-find-files-map (kbd "<M-return>") 
'ergoemacs-helm-ff-execute-dired-dir))
-
-(ergoemacs-component fn-keys ()
-  "Function Keys"
-  ;; Modernize isearch and add back search-map to ergoemacs-mode
-  (global-set-key (kbd "<C-f2>") 'ergoemacs-cut-all)
-  (global-set-key (kbd "<C-f3>") 'ergoemacs-copy-all)
-  (global-set-key (kbd "<C-f4>") 'ergoemacs-paste-cycle)
-  (global-set-key (kbd "<C-f5>") '(redo undo-tree-redo ergoemacs-redo))
-  (global-set-key (kbd "<C-f8>") 'highlight-symbol-prev)
-  (global-set-key (kbd "<C-f9>") 'highlight-symbol-next)
-  (global-set-key (kbd "<M-f2>") 'ergoemacs-cut-all)
-  (global-set-key (kbd "<M-f3>") 'ergoemacs-copy-all)
-  (global-set-key (kbd "<M-f5>") '(redo undo-tree-redo ergoemacs-redo))
-  (global-set-key (kbd "<S-f3>") 'ergoemacs-toggle-letter-case)
-  (global-set-key (kbd "<f11>") 'previous-line)
-  (global-set-key (kbd "<f12>") 'next-line)
-  (global-set-key (kbd "<f3>") 'ergoemacs-copy-line-or-region)
-  (global-set-key (kbd "<f6>") 'ergoemacs-unchorded-alt-modal)
-  (global-set-key (kbd "<f8>") 'search-map)
-  (global-set-key (kbd "<f8> <f8>") 'highlight-symbol-at-point)
-  (global-set-key (kbd "<f8> <f9>") 'highlight-symbol-query-replace)
-  (global-set-key (kbd "<f2>") 'ergoemacs-cut-line-or-region)
-  (global-set-key (kbd "<f4>") 'ergoemacs-paste)
-  ;; Mode Specific Changes
-  (define-key compilation-mode-map (kbd "<f11>") 'previous-error)
-  (define-key compilation-mode-map (kbd "<f12>") 'next-error)
-  (define-key browse-kill-ring-mode-map (kbd "<f11>") 
'browse-kill-ring-previous)
-  (define-key browse-kill-ring-mode-map (kbd "<f12>") 'browse-kill-ring-next)
-
-  ;; Comint
-  (define-key comint-mode-map (kbd "<f11>") 'comint-previous-input)
-  (define-key comint-mode-map (kbd "<f12>") 'comint-next-input)
-  (define-key comint-mode-map (kbd "S-<f11>") 'comint-previous-matching-input)
-  (define-key comint-mode-map (kbd "<M-f11>") 'comint-previous-matching-input)
-  (define-key comint-mode-map (kbd "S-<f12>") 'comint-next-matching-input)
-  (define-key comint-mode-map (kbd "<M-f12>") 'comint-next-matching-input)
-  
-  ;; Log Edit
-  (define-key log-edit-mode-map (kbd "<f11>") 'log-edit-previous-comment)
-  (define-key log-edit-mode-map (kbd "<f12>") 'log-edit-next-comment)
-  (define-key log-edit-mode-map (kbd "S-<f11>") 'log-edit-previous-comment)
-  (define-key log-edit-mode-map (kbd "<M-f11>") 'log-edit-previous-comment)
-  (define-key log-edit-mode-map (kbd "S-<f12>") 'log-edit-next-comment)
-  (define-key log-edit-mode-map (kbd "<M-f12>") 'log-edit-next-comment)
-
-  (define-key eshell-mode-map (kbd "<f11>") 
'eshell-previous-matching-input-from-input)
-  (define-key eshell-mode-map (kbd "<f12>") 
'eshell-next-matching-input-from-input)
-  (define-key eshell-mode-map (kbd "S-<f11>") 
'eshell-previous-matching-input-from-input)
-  (define-key eshell-mode-map (kbd "<M-f11>") 
'eshell-previous-matching-input-from-input)
-  (define-key eshell-mode-map (kbd "<f11>") 
'eshell-previous-matching-input-from-input)
-  (define-key eshell-mode-map (kbd "S-<f12>") 
'eshell-next-matching-input-from-input)
-  (define-key eshell-mode-map (kbd "<M-f12>") 
'eshell-next-matching-input-from-input)
-
-  (define-key isearch-mode-map (kbd "<S-f3>") 'isearch-toggle-regexp)
-  (define-key isearch-mode-map (kbd "<f11>") 'isearch-ring-retreat)
-  (define-key isearch-mode-map (kbd "<f12>") 'isearch-ring-advance)
-  (define-key isearch-mode-map (kbd "S-<f11>") 'isearch-ring-advance)
-  (define-key isearch-mode-map (kbd "S-<f12>") 'isearch-ring-retreat)
-
-  (when icicle-minibuffer-setup-hook
-    :command-loop-unsupported-p t
-    (define-key minibuffer-local-map (kbd "<f11>") 'previous-history-element)
-    (define-key minibuffer-local-map (kbd "M-<f11>") 
'icicle-insert-history-element)
-    (define-key minibuffer-local-map (kbd "<f12>") 'next-history-element)
-    (define-key minibuffer-local-map (kbd "S-<f11>") 'next-history-element)
-    (define-key minibuffer-local-map (kbd "M-<f12>") 
'icicle-insert-history-element)
-    (define-key minibuffer-local-map (kbd "S-<f12>") 
'previous-history-element))
-  
-  (when iswitchb-define-mode-map-hook
-    :modify-map t
-    :always t
-    (define-key iswitchb-mode-map [remap previous-history-element] 
'iswitchb-prev-match)
-    (define-key iswitchb-mode-map [remap next-history-element] 
'iswitchb-next-match)))
-
-(ergoemacs-component f2-edit ()
-  "Have <f2> edit"
-  (define-key ergoemacs-translate--parent-map [f2] 
'ergoemacs-command-loop--force-universal-argument))
-
-(ergoemacs-component backspace-del-seq ()
-  "Backspace deletes last key entered in command sequence"
-  (define-key ergoemacs-translate--parent-map (kbd "DEL") 
'ergoemacs-command-loop--force-undo-last))
-
-(ergoemacs-component help ()
-  "Help changes for ergoemacs-mode"
-  (global-set-key (kbd "C-h '") 'ergoemacs-describe-current-theme)
-  (global-set-key (kbd "C-h 1") 'describe-function)
-  (global-set-key (kbd "C-h 2") 'describe-variable)
-  (global-set-key (kbd "C-h 3") 'describe-key)
-  (global-set-key (kbd "C-h 4") 'describe-char)
-  (global-set-key (kbd "C-h 5") 'man)
-  (global-set-key (kbd "C-h 7") 'ergoemacs-lookup-google)
-  (global-set-key (kbd "C-h 8") 'ergoemacs-lookup-wikipedia)
-  (global-set-key (kbd "C-h 9") 'ergoemacs-lookup-word-definition)
-  (global-set-key (kbd "C-h `") 'elisp-index-search)
-  (global-set-key (kbd "C-h o") 'ergoemacs-where-is-old-binding)
-  (global-set-key (kbd "C-h z") 'ergoemacs-clean)
-  (global-set-key (kbd "C-h C-z") 'ergoemacs-clean-library)
-  (global-set-key (kbd "<f1> '") 'ergoemacs-describe-current-theme)
-  (global-set-key (kbd "<f1> 1") 'describe-function)
-  (global-set-key (kbd "<f1> 2") 'describe-variable)
-  (global-set-key (kbd "<f1> 3") 'describe-key)
-  (global-set-key (kbd "<f1> 4") 'describe-char)
-  (global-set-key (kbd "<f1> 5") 'man)
-  (global-set-key (kbd "<f1> 7") 'ergoemacs-lookup-google)
-  (global-set-key (kbd "<f1> 8") 'ergoemacs-lookup-wikipedia)
-  (global-set-key (kbd "<f1> 9") 'ergoemacs-lookup-word-definition)
-  (global-set-key (kbd "<f1> `") 'elisp-index-search)
-  (global-set-key (kbd "<f1> o") 'ergoemacs-where-is-old-binding))
+  (define-key keymap (kbd "<delete>") 'delete-char)
+  (define-key keymap (kbd "<home>") 'move-beginning-of-line)
+  (define-key keymap (kbd "<end>") 'move-end-of-line)
+  (define-key keymap (kbd "C-SPC") 'set-mark-command)
+  (define-key keymap (kbd "C-r") 'ergoemacs-revert-buffer)
 
+  (define-key keymap (kbd "C-/") 'info)
+  (define-key keymap (kbd "C-?") 'info)
 
-;;; Variable Components
-(ergoemacs-component move-char ()
-  "Movement by Characters & Set Mark"
-  (global-set-key (kbd "C-b") nil) 
-  (global-set-key (kbd "M-j") ("C-b" :emacs))
-  
-  (global-set-key (kbd "C-f") nil) 
-  (define-key global-map (kbd "M-l") ("C-f" :emacs))
-  
-  (global-set-key (kbd "C-p") nil)
-  (define-key (current-global-map) (kbd "M-i") ("C-p" :emacs))
-  
-  (global-set-key (kbd "C-n") nil)
-  (define-key ergoemacs-keymap (kbd "M-k") ("C-n" :emacs))
+  (define-key keymap (kbd "C-S-o") 'ergoemacs-open-in-external-app)
+  (define-key keymap (kbd "C-S-t") 'ergoemacs-open-last-closed))
 
+(defun ergoemacs-set-help (keymap)
+  "Help change for ergoemacs-mode for KEYMAP."
+  (define-key keymap (kbd "C-h '") 'ergoemacs-describe-current-theme))
 
-  ;; These are here so that C-M-i will translate to C-<up> for modes
-  ;; like inferior R mode.  That allows the command to be the last
-  ;; command.
-  ;; Not sure it belongs here or not...
-  (global-set-key (kbd "M-C-j") ("<C-left>" :emacs))
-  (global-set-key (kbd "M-C-l") ("<C-right>" :emacs))
-  (global-set-key (kbd "M-C-i") ("<C-up>" :emacs))
-  (global-set-key (kbd "M-C-k") ("<C-down>" :emacs))
+(defun ergoemacs-set-move-char (keymap)
+  "Movement by Characters & Set Mark for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-j") 'backward-char)
+  (ergoemacs-define-key keymap (kbd "M-l") 'forward-char)
+  (ergoemacs-define-key keymap (kbd "M-i") 'previous-line)
+  (ergoemacs-define-key keymap (kbd "M-k") 'next-line)
 
+  ;; Fix this binding.  Trying to avoid C-M-* combos.
+  ;; The regular binding is 'M-s o'
+  (ergoemacs-define-key keymap (kbd "C-M-:") 'occur)
+  (ergoemacs-define-key keymap (kbd "C-M-;") 'isearch-occur)
 
-  (global-set-key (kbd "C-SPC") nil) ;; Set Mark
-  (global-set-key (kbd "M-SPC") ("C-SPC" :emacs))
-  
-  ;; Mode specific changes
-  (define-key browse-kill-ring-mode-map (kbd "M-i") 'browse-kill-ring-previous)
-  (define-key browse-kill-ring-mode-map (kbd "M-k")  'browse-kill-ring-forward)
+  (ergoemacs-define-key keymap (kbd "M-SPC") 'set-mark-command)
 
   ;; Delete previous/next char.
-  (global-set-key (kbd "M-d") 'delete-backward-char)
-
-  (global-set-key (kbd "C-d") nil)
-  (global-set-key (kbd "M-f") 'delete-char)
-  ;; Mode specific changes
-
-  (define-key browse-kill-ring-mode-map (kbd "M-i") 'browse-kill-ring-backward)
-  (define-key browse-kill-ring-mode-map (kbd "M-k") 'browse-kill-ring-forward)
-  (define-key browse-kill-ring-mode-map (kbd "M-f") 'browse-kill-ring-delete)
-  
-  (when iswitchb-define-mode-map-hook 
-    (define-key iswitchb-mode-map [remap backward-char] 'iswitchb-prev-match)
-    (define-key iswitchb-mode-map [remap forward-char] 'iswitchb-next-match))
-  :version 5.7.5
-  (global-set-key (kbd "C-SPC") 'set-mark-command) ;; Set Mark
-  )
-  
+  (ergoemacs-define-key keymap (kbd "M-d") 'delete-backward-char)
+  (ergoemacs-define-key keymap (kbd "M-f") 'delete-char)
 
-(ergoemacs-component move-word ()
-  "Moving around and deleting words"
-  (global-set-key (kbd "M-b") nil)
-  (global-set-key (kbd "M-u") 'backward-word)
+  (ergoemacs-define-key keymap (kbd "<M-delete>") 'kill-word)
+  (ergoemacs-define-key keymap (kbd "<M-up>") 'ergoemacs-backward-block)
+  (ergoemacs-define-key keymap (kbd "<M-down>") 'ergoemacs-forward-block))
 
-  (global-set-key (kbd "M-f") nil)
-  (global-set-key (kbd "M-o") 'forward-word)
-  
-  ;; Delete previous/next word.
-  ;; C-backspace is standard; don't change
-  (global-set-key (kbd "M-e") 'backward-kill-word)
-  
-  (global-set-key (kbd "M-d") nil)
-  (global-set-key (kbd "M-r") 'kill-word))
-
-(ergoemacs-component move-sexp ()
-  "Instead of moving around by words, use sexps."
-  (global-set-key [remap forward-word] 'forward-sexp)
-  (global-set-key [remap backward-word] 'backward-sexp))
-
-(ergoemacs-component move-paragraph ()
-  "Move by Paragraph"
-  (global-unset-key (kbd "M-{"))
-  (global-unset-key (kbd "M-}"))
-  (global-set-key (kbd "M-U") ("M-{" :emacs))
-  (global-set-key (kbd "M-O") ("M-}" :emacs)))
-
-(ergoemacs-component move-line ()
-  "Move by Line"
-  (global-unset-key (kbd "C-a"))
-  (global-unset-key (kbd "C-e"))
-  (global-set-key (kbd "M-h") ("C-a" :emacs))
-  (global-set-key (kbd "M-H") ("C-e" :emacs))
-  ;; Mode specific movement
-  (define-key eshell-mode-map [remap move-beginning-of-line] 'eshell-bol)
-  (define-key comint-mode-map [remap move-beginning-of-line] 'comint-bol))
-
-(ergoemacs-component move-and-transpose-lines ()
-  "Move Current line/selection down or up with Alt+up or Alt+down"
-  (global-set-key [\M-up] 'ergoemacs-move-text-up)
-  (global-set-key [\M-down] 'ergoemacs-move-text-down))
-
-(ergoemacs-component alt-backspace-is-undo ()
-  "Alt+Backspace is Undo"
-  (global-set-key (kbd "<M-backspace>") 'undo))
-
-(ergoemacs-component move-page ()
-  "Move by Page"
-  (global-unset-key (kbd "M-v"))
-  (global-unset-key (kbd "C-v"))
-  (global-unset-key (kbd "C-M-v"))
-  ;; Not sure I like the scroll other window placment... C+M+ argh.
-  (global-set-key (kbd "C-M-I") 'scroll-other-window-down)
-  (global-set-key (kbd "C-M-K") ("C-M-v" :emacs))
-  ;; These are OK
-  (global-set-key (kbd "M-I") ("M-v" :emacs))
-  (global-set-key (kbd "M-K") ("C-v" :emacs)))
-
-(ergoemacs-component move-buffer ()
-  "Move Beginning/End of buffer"
-  (global-unset-key (kbd "M->"))
-  (global-unset-key (kbd "M-<"))
-  (global-set-key (kbd "M-n") 'ergoemacs-beginning-or-end-of-buffer)
-  (global-set-key (kbd "M-N") 'ergoemacs-end-or-beginning-of-buffer)
-  :version 5.7.5
-  (global-reset-key (kbd "M->"))
-  (global-reset-key (kbd "M-<"))
-  (global-unset-key (kbd "M-n"))
-  (global-unset-key (kbd "M-N")))
-
-(ergoemacs-component move-bracket ()
-  "Move By Bracket"
-  (global-set-key (kbd "M-J") 'ergoemacs-backward-open-bracket)
-  (global-set-key (kbd "M-L") 'ergoemacs-forward-close-bracket)
-  (global-set-key (kbd "<M-left>") 'ergoemacs-backward-open-bracket) ; Alt+←
-  (global-set-key (kbd "<M-right>") 'ergoemacs-forward-close-bracket))
-
-(ergoemacs-component copy ()
-  "Copy, Cut, Paste, Redo and Undo"
-  (global-set-key (kbd "C-w") nil) ;; Kill region = Cut
-  (global-set-key (kbd "M-x") 'ergoemacs-cut-line-or-region)
-  
-  (global-set-key (kbd "M-w") nil) ;; Kill ring save = Copy
-  (global-set-key (kbd "M-c") 'ergoemacs-copy-line-or-region)
+(defun ergoemacs-set-move-extra-reduction (keymap)
+  "Extra reduction keys with KEYMAP."
+  (define-key keymap (kbd "M-.") 'ergoemacs-end-of-line-or-what)
+  (define-key keymap (kbd "M-m") 'ergoemacs-beginning-of-line-or-what))
 
-  (global-set-key (kbd "C-y") nil) ;; Yank = paste
-  (global-set-key (kbd "M-v") 'ergoemacs-paste)
 
-  (global-set-key (kbd "M-y") nil) ;; Yank-pop = paste cycle
-  (global-set-key (kbd "M-V") 'ergoemacs-paste-cycle)
-  
-  (global-set-key (kbd "M-C") 'ergoemacs-copy-all)
-  (global-set-key (kbd "M-X") 'ergoemacs-cut-all)
-  (global-set-key (kbd "M-Z") '("C-_" :emacs))
+;;; Variable Components
+(defun ergoemacs-set-move-word (keymap)
+  "Moving around and deleting words with KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-u") 'backward-word)
+  (ergoemacs-define-key keymap (kbd "M-o") 'forward-word)
+
+  (ergoemacs-define-key keymap (kbd "M-e") 'backward-kill-word)
+  (ergoemacs-define-key keymap (kbd "M-r") 'kill-word))
+
+(defun ergoemacs-set-move-paragraph (keymap)
+  "Move by Paragraph for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-U") 'backward-paragraph)
+  (ergoemacs-define-key keymap (kbd "M-O") 'forward-paragraph))
+
+(defun ergoemacs-set-move-line (keymap)
+  "Move by Line for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-h") 'move-beginning-of-line)
+  (ergoemacs-define-key keymap (kbd "M-H") 'move-end-of-line))
+
+(defun ergoemacs-set-move-page (keymap)
+  "Move by Page by KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-I") 'scroll-down-command)
+  (ergoemacs-define-key keymap (kbd "M-K") 'scroll-up-command))
+
+(defun ergoemacs-set-move-buffer (keymap)
+  "Move by buffer in KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-n") 'beginning-of-buffer)
+  (ergoemacs-define-key keymap (kbd "M-N") 'end-of-buffer))
+
+(defun ergoemacs-set-move-buffer-reduction (keymap)
+  "Move by buffer in KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-n") 
'ergoemacs-beginning-or-end-of-buffer)
+  (ergoemacs-define-key keymap (kbd "M-N") 
'ergoemacs-end-or-beginning-of-buffer))
+
+(defun ergoemacs-set-move-bracket (keymap)
+  "Move By Bracket for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-J") 'ergoemacs-backward-open-bracket)
+  (ergoemacs-define-key keymap (kbd "M-L") 'ergoemacs-forward-close-bracket)
+  (ergoemacs-define-key keymap (kbd "<M-left>") 
'ergoemacs-backward-open-bracket)
+  (ergoemacs-define-key keymap (kbd "<M-right>") 
'ergoemacs-forward-close-bracket))
+
+(defun ergoemacs-set-move-bracket-reduction (keymap)
+  "Move bracket in the reduction theme for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "<M-left>") 
'ergoemacs-backward-open-bracket)
+  (ergoemacs-define-key keymap (kbd "<M-right>") 
'ergoemacs-forward-close-bracket))
+
+(defun ergoemacs-set-copy (keymap)
+  "Copy, Cut, Paste, Redo and Undo for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-x") 'ergoemacs-cut-line-or-region)
+  (ergoemacs-define-key keymap (kbd "M-c") 'ergoemacs-copy-line-or-region)
+  (ergoemacs-define-key keymap (kbd "M-v") 'ergoemacs-paste)
+  (ergoemacs-define-key keymap (kbd "M-V") 'ergoemacs-paste-cycle)
+
+  (ergoemacs-define-key keymap (kbd "M-C") 'ergoemacs-copy-all)
+  (ergoemacs-define-key keymap (kbd "M-X") 'ergoemacs-cut-all)
 
   ;; Undo
-  (global-set-key (kbd "C-_") nil)
-  (global-set-key (kbd "C-/") nil)
-  (global-set-key (kbd "C-x u") nil)
-  (global-set-key (kbd "M-z") '("C-_" :emacs))
-  
-  ;; Fixed Component; Note that <timeout> is the actual function.
-  (if (not (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-      (progn
-        (global-set-key (kbd "C-c <ergoemacs-timeout>") 
'ergoemacs-copy-line-or-region)
-        (global-set-key (kbd "C-x <ergoemacs-timeout>") 
'ergoemacs-cut-line-or-region)
-        )
-    )
-  (global-set-key (kbd "C-S-x") ("C-x" :normal))
-  (global-set-key (kbd "C-z") 'undo)
-  (global-set-key (kbd "C-S-z") '(redo undo-tree-redo ergoemacs-redo))
-  (global-set-key (kbd "C-y") '(redo undo-tree-redo ergoemacs-redo))
-
-  ;; Mode specific changes
-  (if (not (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-      (define-key isearch-mode-map (kbd "C-c") 'isearch-yank-word-or-char)
-    )
-  (define-key isearch-mode-map (kbd "M-c") 'isearch-yank-word-or-char)
-  (define-key isearch-mode-map (kbd "M-v") 'ergoemacs-paste)
-  (define-key isearch-mode-map (kbd "M-V") 'ergoemacs-paste-cycle)
-  (define-key isearch-mode-map (kbd "C-v") 'ergoemacs-paste)
-  (define-key isearch-mode-map (kbd "C-S-v") 'ergoemacs-paste-cycle)
-  
-  (define-key org-mode-map [remap ergoemacs-paste] 'ergoemacs-org-yank)
-  (define-key org-mode-map [remap ergoemacs-paste] 'ergoemacs-org-yank)
-  (define-key browse-kill-ring-mode-map [remap undo] 
'browse-kill-ring-undo-other-window)
-  (define-key browse-kill-ring-mode-map [remap undo-tree-undo] 
'browse-kill-ring-undo-other-window)
-  (define-key browse-kill-ring-mode-map [remap undo-tree-undo] 
'browse-kill-ring-undo-other-window)
-  (define-key calc-mode-map [remap ergoemacs-paste] 'calc-yank)
-  (define-key calc-mode-map [remap undo-tree-undo] 'calc-undo))
-
-(ergoemacs-component search ()
-  "Search and Replace"
-  (global-set-key (kbd "C-s") nil)
-  (global-set-key (kbd "M-y") '("C-s" :emacs))
-  
-  (global-set-key (kbd "C-r") nil)
-  (global-set-key (kbd "M-Y") '("C-r" :emacs))
-  
-  (global-set-key (kbd "M-%") nil)
-  (global-set-key (kbd "M-5") '("M-%" :emacs))
-  
-  (global-set-key (kbd "C-M-%") nil)
-  (global-set-key (kbd "M-%") '("C-M-%" :emacs))
-
-  ;; Mode specific changes
-  (define-key dired-mode-map (kbd "M-5") 'dired-do-query-replace-regexp)
-  (define-key dired-mode-map (kbd "M-%") 'dired-do-query-replace-regexp)
-  
-  ;; Reclaim dired+ overrides.
-  (define-key dired-mode-map (kbd "M-u") 'backward-word)
-  (define-key dired-mode-map (kbd "C-b") 'diredp-do-bookmark)
-
-  (define-key browse-kill-ring-mode-map [remap isearch-forward] 
'browse-kill-ring-search-forward)
-  (define-key browse-kill-ring-mode-map [remap isearch-backward] 
'browse-kill-ring-search-backward)
-  :version 5.7.5
-  (global-set-key (kbd "M-;") 'isearch-forward)
-  (global-set-key (kbd "M-:") 'isearch-backward))
-
-(ergoemacs-component search-reg ()
-  "Regular Expression Search/Replace"
-  (global-set-key [remap isearch-forward] 'isearch-forward-regexp)
-  (global-set-key [remap isearch-backward] 'isearch-backward-regexp)
-
-  (global-set-key (kbd "M-%") nil)
-  (global-set-key (kbd "M-5") '("C-M-%" :emacs))
-  
-  (global-set-key (kbd "C-M-%") nil)
-  (global-set-key (kbd "M-%") '("M-%" :emacs)))
-
-
-(ergoemacs-component switch ()
-  "Window/Frame/Tab Switching"
-  (global-set-key (kbd "M-s") 'ergoemacs-move-cursor-next-pane)
-  (global-set-key (kbd "M-S") 'ergoemacs-move-cursor-previous-pane)
-  
-  (global-set-key (kbd "M-~") 'ergoemacs-switch-to-previous-frame)
-  (global-set-key (kbd "M-`") 'ergoemacs-switch-to-next-frame)
-
-  (global-unset-key (kbd "C-x 1"))
-  (global-set-key (kbd "M-3") 'delete-other-windows)
-  
-  (global-unset-key (kbd "C-x 0"))
-  (global-set-key (kbd "M-2") 'delete-window)
-  
-  (global-unset-key (kbd "C-x 3"))
-  (global-set-key (kbd "M-4") '(split-window-below split-window-horizontally))
-  
-  (global-unset-key (kbd "C-x 2"))
-  (global-set-key (kbd "M-$") '(split-window-right split-window-vertically))
-  :version 5.7.5
-  (global-set-key (kbd "M-0") 'delete-window))
-
-(ergoemacs-component execute ()
-  "Execute Commands"
-  (global-unset-key (kbd "M-x"))
-  (global-set-key (kbd "M-a") '("M-x" :emacs))
-  (global-unset-key (kbd "M-!"))
-  (global-set-key (kbd "M-A") '("M-!" :emacs)))
-
-(ergoemacs-component  misc ()
-  "Misc Commands"
-  (global-unset-key (kbd "C-l"))
-  (global-set-key (kbd "M-p") '("C-l" :emacs))
-  (global-set-key (kbd "M-b") 'avy-goto-word-or-subword-1))
-
-(ergoemacs-component kill-line ()
-  "Kill Line"
-  (global-unset-key (kbd "C-k"))
-  (global-set-key (kbd "M-g") '("C-k" :emacs))
-  (global-set-key (kbd "M-G") 'ergoemacs-kill-line-backward))
-
-(ergoemacs-component text-transform ()
-  "Text Transformation"
-  (global-unset-key (kbd "M-;"))
-  (global-set-key (kbd "M-'") '("M-;" :emacs))
-  
-  (global-set-key (kbd "M-w") 'ergoemacs-shrink-whitespaces)
-
-  (global-set-key (kbd "M-?") 'ergoemacs-toggle-camel-case)
-  (global-set-key (kbd "M-/") 'ergoemacs-toggle-letter-case)
-
-  ;; ;; keyword completion, because Alt+Tab is used by OS
-  (global-set-key (kbd "M-t") 'ergoemacs-call-keyword-completion)
-  (global-set-key (kbd "M-T") 'flyspell-auto-correct-word)
-
-  ;; ;; Hard-wrap/un-hard-wrap paragraph
-  (global-set-key (kbd "M-q") 'ergoemacs-compact-uncompact-block)
+  (ergoemacs-define-key keymap (kbd "M-z") 'ergoemacs-undo)
+  (ergoemacs-define-key keymap (kbd "M-S-z") 'ergoemacs-redo)
+  (put 'ergoemacs-undo
+       :advertised-binding (ergoemacs-translate--event-layout
+                            (vconcat (listify-key-sequence (kbd "M-z")))))
+  (ergoemacs-define-key keymap (kbd "C-S-x") 'execute-extended-command))
+
+(defun ergoemacs-set-search (keymap)
+  "Search and Replace for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-5") 'query-replace)
+  (ergoemacs-define-key keymap (kbd "M-%") 'query-replace-regexp)
+  (ergoemacs-define-key keymap (kbd "M-;") 'isearch-forward)
+  (put 'isearch-forward
+       :advertised-binding (ergoemacs-translate--event-layout
+                            (vconcat (listify-key-sequence (kbd "M-;")))))
+  (ergoemacs-define-key keymap (kbd "M-:") 'isearch-backward))
+
+(defun ergoemacs-set-search-reduction (keymap)
+  "Search and Replace with KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-5") 'query-replace)
+  (ergoemacs-define-key keymap (kbd "M-%") 'query-replace-regexp)
+  (ergoemacs-define-key keymap (kbd "M-h") 'isearch-forward)
+  (put 'isearch-forward
+       :advertised-binding (ergoemacs-translate--event-layout
+                            (vconcat (listify-key-sequence (kbd "M-h")))))
+  (ergoemacs-define-key keymap (kbd "M-y") 'isearch-backward)
+
+  (define-key minibuffer-local-isearch-map [remap isearch-forward] 
'isearch-forward-exit-minibuffer)
+  (define-key minibuffer-local-isearch-map [remap isearch-backward] 
'isearch-reverse-exit-minibuffer))
+
+
+(defun ergoemacs-set-switch (keymap)
+  "Window/Frame/Tab Switching for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-s") 'other-window)
+  (ergoemacs-define-key keymap (kbd "M-S") 
'ergoemacs-move-cursor-previous-pane)
+
+  (ergoemacs-define-key keymap (kbd "M-~") 'ergoemacs-switch-to-previous-frame)
+  (ergoemacs-define-key keymap (kbd "M-`") 'ergoemacs-switch-to-next-frame)
+
+  (ergoemacs-define-key keymap (kbd "M-3") 'delete-other-windows)
+  (ergoemacs-define-key keymap (kbd "M-#") 'delete-other-windows)
+
+  (ergoemacs-define-key keymap (kbd "M-2") 'delete-window)
+  (ergoemacs-define-key keymap (kbd "M-@") 'delete-window)
+
+  (ergoemacs-define-key keymap (kbd "M-4") 'split-window-below)
+  (ergoemacs-define-key keymap (kbd "M-$") 'split-window-right)
+
+  (ergoemacs-define-key keymap (kbd "M-0") 'delete-window)
+  (ergoemacs-define-key keymap (kbd "M-)") 'delete-window))
+
+
+(defun ergoemacs-set-switch-reduction (keymap)
+  "Window/Frame/Tab Switching for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-1") 'switch-to-buffer)
+  (ergoemacs-define-key keymap (kbd "M-!") 'ibuffer)
+  (ergoemacs-define-key keymap (kbd "M-2") 'other-window)
+  (ergoemacs-define-key keymap (kbd "M-3") 'delete-other-windows)
+  (ergoemacs-define-key keymap (kbd "M-#") 'delete-window)
+  (ergoemacs-define-key keymap (kbd "M-4") 'split-window-below)
+  (ergoemacs-define-key keymap (kbd "M-$") 'split-window-right))
+
+(defun ergoemacs-set-execute (keymap)
+  "Execute Commands for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-a") 'execute-extended-command)
+  (ergoemacs-define-key keymap (kbd "M-A") 'shell-command))
+
+(defun ergoemacs-set-execute-reduction (keymap)
+  "Execute reduction key set for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-;") 'execute-extended-command))
+
+;; not in reduction
+(defun ergoemacs-set-misc (keymap)
+  "Misc Commands for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-p") 'recenter-top-bottom)
+  (ergoemacs-define-key keymap (kbd "M-B") 'ibuffer)
+  (ergoemacs-define-key keymap (kbd "M-b") 'switch-to-buffer))
+
+(defun ergoemacs-set-kill-line (keymap)
+  "Kill Line for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-g") 'kill-line)
+  (ergoemacs-define-key keymap (kbd "M-G") 'ergoemacs-kill-line-backward))
+
+(defun ergoemacs-set-text-transform (keymap)
+  "Text Transformation for KEYMAP."
+  (ergoemacs-define-key keymap (kbd "M-'") 'comment-dwim)
+  (ergoemacs-define-key keymap (kbd "M-\"") 'delete-horizontal-space)
+
+  (ergoemacs-define-key keymap (kbd "M-w") 'ergoemacs-shrink-whitespaces)
+
+  (ergoemacs-define-key keymap (kbd "M-?") 'ergoemacs-toggle-camel-case)
+  (ergoemacs-define-key keymap (kbd "M-/") 'ergoemacs-toggle-letter-case)
+
+  ;; keyword completion, because Alt+Tab is used by OS
+  (ergoemacs-define-key keymap (kbd "M-t") 'ergoemacs-call-keyword-completion)
+  (ergoemacs-define-key keymap (kbd "M-T") 'flyspell-auto-correct-word)
+
+  ;; Hard-wrap/un-hard-wrap paragraph
+  (ergoemacs-define-key keymap (kbd "M-q") 'ergoemacs-compact-uncompact-block)
 
-  (define-key isearch-mode-map (kbd "M-?") 'isearch-toggle-regexp)
-  (define-key isearch-mode-map (kbd "M-/") 'isearch-toggle-case-fold)
-  
-  
-  (when iswitchb-define-mode-map-hook
-    (define-key iswitchb-mode-map [remap ergoemacs-toggle-camel-case] 
'iswitchb-toggle-case)
-    (define-key iswitchb-mode-map [remap ergoemacs-toggle-letter-case] 
'iswitchb-toggle-regexp)))
-
-(ergoemacs-component select-items ()
-  "Select Items"
-  (global-set-key (kbd "M-S-SPC") 'mark-paragraph)
-  (global-set-key (kbd "M-8") '(er/expand-region ergoemacs-extend-selection))
-  (global-set-key (kbd "M-*") '(er/mark-inside-quotes 
ergoemacs-select-text-in-quote))
-  (global-set-key (kbd "M-6") 'ergoemacs-select-current-block)
-  (global-set-key (kbd "M-7") 'ergoemacs-select-current-line))
-
-(ergoemacs-component quit ()
-  "Escape exits"
-  (global-set-key (kbd "<escape>") 'keyboard-quit)
-  (define-key isearch-mode-map (kbd "<escape>") 'isearch-abort)
-
-  (when org-read-date-minibuffer-setup-hook
-    (define-key minibuffer-local-map (kbd "<escape>") 
'minibuffer-keyboard-quit)))
-
-(ergoemacs-component apps ()
-  "General Apps Key Sequence"
-  :just-first-keys (list [apps ?h] [menu ?h])
-  :bind ("<apps> '"         ergoemacs-org-edit-src
-         "<apps> 2"         delete-window
-         "<apps> 3"         delete-other-windows
-         "<apps> 4"         split-window-vertically
-         "<apps> 5"         query-replace
-         "<apps> <f2>"      ergoemacs-cut-all
-         "<apps> <f3>"      ergoemacs-copy-all
-         "<apps> <return>"  execute-extended-command
-         "<apps> RET"       execute-extended-command
-         "<apps> TAB"       indent-region  ;; Already in CUA
-         "<apps> SPC"       set-mark-command
-         "<apps> a"         mark-whole-buffer
-         "<apps> d"         ("C-x" :ctl-to-alt)
-         "<apps> f"         ("C-c" :unchorded-ctl)
-         "<apps> h"         help-map
-         "<apps> h '"       ergoemacs-describe-current-theme
-         "<apps> h 1"       describe-function
-         "<apps> h 2"       describe-variable
-         "<apps> h 3"       describe-key
-         "<apps> h 4"       describe-char
-         "<apps> h 5"       man
-         "<apps> h 7"       ergoemacs-lookup-google
-         "<apps> h 8"       ergoemacs-lookup-wikipedia
-         "<apps> h 9"       ergoemacs-lookup-word-definition
-         "<apps> h `"       elisp-index-search
-         "<apps> h o"       ergoemacs-where-is-old-binding
-         "<apps> h z"       ergoemacs-clean
-         "<apps> h C-z"     ergoemacs-clean-library
-         "<apps> h Z"       ergoemacs-clean-nw
-         "<apps> m"         (kbd "C-c C-c")
-         "<apps> s"         save-buffer
-         "<apps> C-s"       write-file
-         "<apps> o"         find-file
-         "<apps> g"         ergoemacs-read-key--universal-argument
-         "<apps> w"         ergoemacs-close-current-buffer
-         "<apps> x"         ergoemacs-cut-line-or-region
-         "<apps> c"         ergoemacs-copy-line-or-region
-         "<apps> v"         ergoemacs-paste
-         "<apps> b"         (redo undo-tree-redo ergoemacs-redo)
-         "<apps> t"         switch-to-buffer
-         "<apps> z"         undo
-         "<apps> r"         goto-map))
-
-(ergoemacs-component apps-toggle ()
-  "Toggle States and applications"
-  :just-first-keys (list [apps ?i] [menu ?i])
-  (global-set-key (kbd "<apps> i c") 'column-number-mode)
-  (global-set-key (kbd "<apps> i d") 'toggle-debug-on-error)
-  (global-set-key (kbd "<apps> i e") 'toggle-debug-on-error)
-  (global-set-key (kbd "<apps> i f") 'auto-fill-mode)
-  (global-set-key (kbd "<apps> i l") 'toggle-truncate-lines)
-  (global-set-key (kbd "<apps> i q") 'toggle-debug-on-quit)
-  (global-set-key (kbd "<apps> i r") 'read-only-mode)
-  (global-set-key (kbd "<apps> i C-r") 'revert-buffer))
-
-(ergoemacs-component apps-apps ()
-  "Applications"
-  :just-first-keys (list [apps ?n] [menu ?n])
-  (global-set-key (kbd "<apps> n a") 'org-agenda)
-  (global-set-key (kbd "<apps> n A") 'org-capture)
-  (global-set-key (kbd "<apps> n C-a") 'org-capture)
-  (global-set-key (kbd "<apps> n c") 'calc)
-  (global-set-key (kbd "<apps> n d") 'dired-jump)
-  (global-set-key (kbd "<apps> n e") 'eshell)
-  (global-set-key (kbd "<apps> n p") 'powershell)
-  (global-set-key (kbd "<apps> n f") 'ergoemacs-open-in-desktop)
-  (global-set-key (kbd "<apps> n g") 'grep)
-  (global-set-key (kbd "<apps> n m") 'magit-status)
-  (global-set-key (kbd "<apps> n o") 'ergoemacs-open-in-external-app)
-  (global-set-key (kbd "<apps> n r") 'R)
-  (global-set-key (kbd "<apps> n s") 'shell)
-  (global-set-key (kbd "<apps> n t") 'org-capture)
-  (global-set-key (kbd "<apps> n C-t") 'org-agenda)
-  (global-set-key (kbd "<apps> n T") 'org-agenda))
-
-(ergoemacs-component apps-punctuation ()
-  "Punctuation"
-  ;; Smart punctuation
-  ;; `http://xahlee.info/comp/computer_language_char_distribution.html'
-  ;; |------+-----------+---------+-----------------------|
-  ;; | Rank | Character | Percent | Defined               |
-  ;; |------+-----------+---------+-----------------------|
-  ;; |    1 | ,         |   12.1% | No; Already unchorded |
-  ;; |    2 | _         |    8.0% | Yes                   |
-  ;; |    3 | "         |    8.0% | Yes                   |
-  ;; |    4 | (         |    7.7% | Yes                   |
-  ;; |    5 | )         |    7.7% | By pair               |
-  ;; |    6 | .         |    7.4% | No; Already unchorded |
-  ;; |    7 | ;         |    4.8% | No; Already unchorded |
-  ;; |    8 | -         |    4.4% | Yes                   |
-  ;; |    9 | =         |    4.3% | Yes                   |
-  ;; |   10 | '         |    3.9% | Yes (by pair)         |
-  ;; |   11 | /         |    3.8% | No; Already unchorded |
-  ;; |   12 | *         |    3.5% | Yes                   |
-  ;; |   13 | :         |    3.2% | Yes                   |
-  ;; |   14 | {         |    3.2% | By pair               |
-  ;; |   15 | }         |    3.2% | By pair               |
-  ;; |   16 | >         |    2.4% | Yes                   |
-  ;; |   17 | $         |    2.2% | Yes                   |
-  ;; |   18 | #         |    1.7% | Yes                   |
-  ;; |   19 | +         |    1.2% | Yes                   |
-  ;; |   20 | \         |    1.1% | No; Already unchorded |
-  ;; |   21 | [         |    1.0% | Yes (by pair)         |
-  ;; |   22 | ]         |    1.0% | Yes                   |
-  ;; |   23 | <         |    1.0% | Yes                   |
-  ;; |   24 | &         |    0.9% | Yes                   |
-  ;; |   25 | @         |    0.7% | Yes                   |
-  ;; |   26 | |         |    0.5% | Yes                   |
-  ;; |   27 | !         |    0.5% | Yes                   |
-  ;; |   28 | %         |    0.3% | Yes                   |
-  ;; |   29 | ?         |    0.2% | Yes                   |
-  ;; |   30 | `         |    0.1% | Yes                   |
-  ;; |   31 | ^         |    0.1% | Yes                   |
-  ;; |   32 | ~         |    0.1% | Yes                   |
-  ;; |------+-----------+---------+-----------------------|
-
-  ;; No pinkies are used in this setup.
-  (global-set-key (kbd "<apps> k o") "#")
-  (global-set-key (kbd "<apps> k l") "$")
-  (global-set-key (kbd "<apps> k .") ":")
-
-  (global-set-key (kbd "<apps> k w") "^")
-  (global-set-key (kbd "<apps> k s") "*")
-  (global-set-key (kbd "<apps> k x") "~")
-  
-  (global-set-key (kbd "<apps> k i") 'ergoemacs-smart-bracket)
-  (global-set-key (kbd "<apps> k k") 'ergoemacs-smart-paren)
-  (global-set-key (kbd "<apps> k ,") 'ergoemacs-smart-curly)
-  
-  (global-set-key (kbd "<apps> k j") 'ergoemacs-smart-quote)
-  (global-set-key (kbd "<apps> k u") 'ergoemacs-smart-apostrophe)
-  (global-set-key (kbd "<apps> k m") "`")
-
-  (global-set-key (kbd "<apps> k y") "?")
-  (global-set-key (kbd "<apps> k h") "%")
-  (global-set-key (kbd "<apps> k n") "@")
-  
-  (global-set-key (kbd "<apps> k r") ">")
-  (global-set-key (kbd "<apps> k f") "_")
-  (global-set-key (kbd "<apps> k v") "<")
-  
-  (global-set-key (kbd "<apps> k e") "+")
-  (global-set-key (kbd "<apps> k d") "=")
-  (global-set-key (kbd "<apps> k c") "-")
-
-  (global-set-key (kbd "<apps> k t") "&")
-  (global-set-key (kbd "<apps> k g") "|")
-  (global-set-key (kbd "<apps> k b") "!"))
+  )
 
-(ergoemacs-component apps-swap ()
-  "Apps/Menu swaps key sequence translations"
+(defun ergoemacs-set-select-items (keymap)
+  "Select Items for KEYMAP."
+  (ergoemacs-global-set-key (kbd "M-S-SPC") 'mark-paragraph)
+  (ergoemacs-define-key keymap (kbd "M-8") 'ergoemacs-extend-selection)
+  (ergoemacs-define-key keymap (kbd "M-*") 'ergoemacs-select-text-in-quote)
+  (ergoemacs-define-key keymap (kbd "M-6") 'ergoemacs-select-current-block)
+  (ergoemacs-define-key keymap (kbd "M-^") 'ergoemacs-select-current-block)
+  (ergoemacs-define-key keymap (kbd "M-7") 'ergoemacs-select-current-line)
+  (ergoemacs-define-key keymap (kbd "M-&") 'ergoemacs-select-current-line))
+
+(defun ergoemacs-set-apps (keymap)
+  "Set general apps KEYMAP."
+  (ergoemacs-define-key keymap (kbd "<apps> '") 'ergoemacs-org-edit-src)
+  (ergoemacs-define-key keymap (kbd "<apps> 2") 'delete-window)
+  (ergoemacs-define-key keymap (kbd "<apps> 3") 'delete-other-windows)
+  (ergoemacs-define-key keymap (kbd "<apps> 4") 'split-window-vertically)
+  (ergoemacs-define-key keymap (kbd "<apps> 5") 'query-replace)
+  (ergoemacs-define-key keymap (kbd "<apps> <f2>") 'ergoemacs-cut-all)
+  (ergoemacs-define-key keymap (kbd "<apps> <f3>") 'ergoemacs-copy-all)
+  (ergoemacs-define-key keymap (kbd "<apps> RET") 'execute-extended-command)
+  (ergoemacs-define-key keymap (kbd "<apps> TAB") 'indent-region)
+  (ergoemacs-define-key keymap (kbd "<apps> 2")  'delete-window)
+  (ergoemacs-define-key keymap (kbd "<apps> 3")  'delete-other-windows)
+  (ergoemacs-define-key keymap (kbd "<apps> 4")  'split-window-vertically)
+  (ergoemacs-define-key keymap (kbd "<apps> 5")  'query-replace)
+  (ergoemacs-define-key keymap (kbd "<apps> <f2>")  'ergoemacs-cut-all)
+  (ergoemacs-define-key keymap (kbd "<apps> <f3>")  'ergoemacs-copy-all)
+  (ergoemacs-define-key keymap (kbd "<apps> <return>")  
'execute-extended-command)
+  (ergoemacs-define-key keymap (kbd "<apps> RET")  'execute-extended-command)
+  (ergoemacs-define-key keymap (kbd "<apps> TAB")  'indent-region)  ;; Already 
in CUA)
+  (ergoemacs-define-key keymap (kbd "<apps> SPC")  'set-mark-command)
+  (ergoemacs-define-key keymap (kbd "<apps> a")  'mark-whole-buffer)
+  (ergoemacs-define-key keymap (kbd "<apps> m")  (kbd "C-c C-c"))
+  (ergoemacs-define-key keymap (kbd "<apps> s")  'save-buffer)
+  (ergoemacs-define-key keymap (kbd "<apps> C-s")  'write-file)
+  (ergoemacs-define-key keymap (kbd "<apps> o")  'find-file)
+  (ergoemacs-define-key keymap (kbd "<apps> g")  
'ergoemacs-read-key--universal-argument)
+  (ergoemacs-define-key keymap (kbd "<apps> w")  
'ergoemacs-close-current-buffer)
+  (ergoemacs-define-key keymap (kbd "<apps> x")  'ergoemacs-cut-line-or-region)
+  (ergoemacs-define-key keymap (kbd "<apps> c")  
'ergoemacs-copy-line-or-region)
+  (ergoemacs-define-key keymap (kbd "<apps> v")  'ergoemacs-paste)
+  (ergoemacs-define-key keymap (kbd "<apps> b")  '(redo undo-tree-redo 
ergoemacs-redo))
+  (ergoemacs-define-key keymap (kbd "<apps> t")  'switch-to-buffer)
+  (ergoemacs-define-key keymap (kbd "<apps> z")  'undo)
+  (ergoemacs-define-key keymap (kbd "<apps> r")  'goto-map) ;; Already in CUA)
+  (ergoemacs-define-key keymap (kbd "<apps> SPC") 'set-mark-command)
+  (ergoemacs-define-key keymap (kbd "<apps> a") 'mark-whole-buffer)
+
+  (ergoemacs-define-key ergoemacs-override-keymap
+                       (kbd "<apps> f")
+                       (lambda ()
+                          (interactive)
+                          (ergoemacs-command-loop "C-x" :ctl-to-alt)))
+
+  (ergoemacs-define-key ergoemacs-override-keymap
+                       (kbd "<apps> d")
+                       (lambda ()
+                          (interactive)
+                          (ergoemacs-command-loop "C-c" :unchorded-ctl)))
+
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'org-agenda (kbd "a"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'org-capture (kbd "A"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'org-capture (kbd "C-a"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'calc (kbd "c"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'dired-jump (kbd "d"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'eshell (kbd "e"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'powershell (kbd "p"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'ergoemacs-open-in-desktop (kbd "f"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'grep (kbd "g"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'magit-status (kbd "m"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'ergoemacs-open-in-external-app (kbd "o"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 'R 
(kbd "R"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'shell (kbd "s"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'org-capture (kbd "t"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'org-agenda (kbd "C-t"))
+  (ergoemacs-define-key        ergoemacs-override-keymap (kbd "<menu> n") 
'org-agenda (kbd "T"))
+
+  (define-key ergoemacs-translate--parent-map [f2] 
'ergoemacs-command-loop--force-universal-argument)
+  (define-key ergoemacs-translate--parent-map (kbd "DEL") 
'ergoemacs-command-loop--force-undo-last)
   (define-key ergoemacs-translate--parent-map  (if (eq system-type 
'windows-nt) [apps] [menu])
     'ergoemacs-command-loop--swap-translation))
 
-(ergoemacs-component dired-to-wdired ()
-  "C-c C-c enters wdired, <escape> exits."
-  (define-key dired-mode-map (kbd "C-c C-c") 'wdired-change-to-wdired-mode))
-
-(ergoemacs-component dired-tab ()
-  "TAB expands a directory."
-  (define-key dired-mode-map (kbd "TAB") 'dired-maybe-insert-subdir))
-
-(ergoemacs-component guru ()
-  "Unbind some commonly used keys such as <left> and <right> to get in the 
habit of using ergoemacs keybindings."
-  (global-unset-key (kbd "<left>"))
-  (global-unset-key (kbd "<right>"))
-  (global-unset-key (kbd "<up>"))
-  (global-unset-key (kbd "<down>"))
-  (global-unset-key (kbd "<C-left>"))
-  (global-unset-key (kbd "<C-right>"))
-  (global-unset-key (kbd "<C-up>"))
-  (global-unset-key (kbd "<C-down>"))
-  (global-unset-key (kbd "<M-left>"))
-  (global-unset-key (kbd "<M-right>"))
-  (global-unset-key (kbd "<M-up>"))
-  (global-unset-key (kbd "<M-down>"))
-  (global-unset-key (kbd "<delete>"))
-  (global-unset-key (kbd "<C-delete>"))
-  (global-unset-key (kbd "<M-delete>"))
-  (global-unset-key (kbd "<next>"))
-  (global-unset-key (kbd "<C-next>"))
-  (global-unset-key (kbd "<prior>"))
-  (global-unset-key (kbd "<C-prior>"))
-  (global-unset-key (kbd "<home>"))
-  (global-unset-key (kbd "<C-home>"))
-  (global-unset-key (kbd "<end>"))
-  (global-unset-key (kbd "<C-end>")))
-
-(ergoemacs-component no-backspace ()
-  "No Backspace!"
-  (global-unset-key (kbd "<backspace>")))
-
-(ergoemacs-component helm-remaps ()
-  "Remaps for helm-mode"
-  (when helm-mode
-    ;; (global-set-key [remap grep] 'helm-do-grep)  ;; Removed grep 
https://github.com/emacs-helm/helm/issues/1377
-    (global-set-key [remap execute-extended-command] 'helm-M-x)
-    (global-set-key [remap switch-to-buffer] 'helm-mini)
-    (global-set-key [remap find-file] 'helm-find-files)
-    (global-set-key [remap eshell-pcomplete] 'helm-esh-pcomplete)
-    (global-set-key [remap occur] 'helm-occur)
-    (global-set-key [remap info] 'helm-info-at-point)
-    (global-set-key [remap ac-isearch] 'ac-complete-with-helm)))
-
-(ergoemacs-component helm-switch-sources ()
-  "Ctrl+o switches multiple sources."
-  (define-key helm-map (kbd "C-o") 'helm-next-source))
-
-(ergoemacs-component helm-find-files ()
-  "Helm find-files keymap."
-  (define-key helm-find-files-map (kbd "C-l") 'helm-find-files-up-one-level)
-  (define-key helm-find-files-map (kbd "C-c p") 
'helm-ff-run-switch-to-history))
-
-(ergoemacs-component icy-reclaim ()
-  "Reclaim some icicle key bindings."
-  (setq icicle-key-complete-keys-for-minibuffer
-        (list (ergoemacs-translate--event-layout (read-kbd-macro "M-T"))))
-  (when icicle-minibuffer-setup-hook
-    ;; (define-key minibuffer-local-map (kbd "M-p") 
'icicle-insert-history-element)
-    ;; (define-key minibuffer-local-map (kbd "C-M-h") 
'icicle-insert-list-join-string)
-    (define-key minibuffer-local-map (kbd "M-*") 'icicle-narrow-candidates)
-    (define-key minibuffer-local-map (kbd "M-?") 'icicle-minibuffer-help)
-    (define-key minibuffer-local-map (kbd "C-M-RET") 'icicle-help-on-candidate)
-    (define-key minibuffer-local-map (kbd "<C-prior>") 
'icicle-previous-apropos-candidate-action)
-    (define-key minibuffer-local-map (kbd "<C-next>") 
'icicle-next-apropos-candidate-action)
-    (define-key minibuffer-local-map (kbd "<C-M-prior>") 
'icicle-help-on-previous-apropos-candidate)
-    (define-key minibuffer-local-map (kbd "<C-M-next>") 
'icicle-help-on-next-apropos-candidate)
-    (define-key minibuffer-local-map (kbd "<C-home>") 
'icicle-previous-prefix-candidate-action)
-    (define-key minibuffer-local-map (kbd "<C-end>") 
'icicle-next-prefix-candidate-action)
-    (define-key minibuffer-local-map (kbd "<C-M-home>") 
'icicle-help-on-previous-prefix-candidate)
-    (define-key minibuffer-local-map (kbd "<C-M-end>") 
'icicle-help-on-next-prefix-candidate)
-    (define-key minibuffer-local-map (kbd "<C-M-up>") 
'icicle-previous-candidate-per-mode-help)
-    (define-key minibuffer-local-map (kbd "<C-M-down>") 
'icicle-next-candidate-per-mode-help)
-    (define-key minibuffer-local-map (kbd "<delete>") 
'icicle-remove-candidate)))
-
-(ergoemacs-component multiple-cursors-remaps ()
-  "Multiple Cursors phi-search remaps"
-  (when multiple-cursors-mode
-    (global-set-key [remap isearch-forward] 'phi-search)
-    (global-set-key [remap isearch-backward] 'phi-search-backward)))
-
-(ergoemacs-component ido-remaps ()
-  "Remaps for ido-mode"
-  (when ido-mode
-    (global-set-key [remap execute-extended-command] 'smex))
-  (setq smex-prompt-string (substitute-command-keys 
"\\[execute-extended-command] ")))
-
-(ergoemacs-component ido-prev-next-instead-of-left-right ()
-  "In Ido use, Ergoemacs left and right for previous/next match."
-  (when ido-mode
-    (global-set-key [remap ido-magic-forward-char] 'ido-next-match)
-    (global-set-key [remap ido-magic-backward-char] 'ido-prev-match)))
-
-(ergoemacs-component ergoemacs-remaps ()
-  "Remaps for ergoemacs-mode"
-  (when undo-tree-mode
-    (global-set-key [remap ergoemacs-redo] 'undo-tree-redo)
-    (global-set-key [remap undo] 'undo-tree-undo))
-  (when mark-active
-    (global-set-key (kbd "TAB") 'indent-region))
-  (when ergoemacs-mode
-    (global-set-key [remap keyboard-quit] 'ergoemacs-keyboard-quit)
-    (global-set-key [remap revert-buffer] 'ergoemacs-revert-buffer)
-    (global-set-key [remap eshell] 'ergoemacs-eshell-here)
-    (global-set-key [remap powershell] 'ergoemacs-powershell-here)
-    (global-set-key [remap shell] 'ergoemacs-shell-here)
-    (global-set-key [remap universal-argument]
-                    'ergoemacs-command-loop--universal-argument)
-    ;; (global-set-key [remap describe-key]
-    ;;                 'ergoemacs-key-description)
-    (global-set-key [remap describe-mode]
-                    'ergoemacs-describe-major-mode)
-    (global-set-key [remap ergoemacs-print-buffer-confirm]
-                    'pr-interface)))
-
-(ergoemacs-component swiper ()
-  "Swiper component"
-  (when ivy-mode
-    (setq ivy-use-virtual-buffers t)
-    (global-set-key [remap isearch-forward] 'swiper)
-    ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
-    ;; (global-set-key (kbd "<f6>") 'ivy-resume)
-    (global-set-key [remap execute-extended-command] 'counsel-M-x)
-    (global-set-key [remap find-file] 'counsel-find-file)
-    (global-set-key [remap describe-function] 'counsel-describe-function)
-    (global-set-key [remap describe-variable] 'counsel-describe-variable)
-    (global-set-key [remap find-library] 'counsel-find-library)
-    (global-set-key [remap info-lookup-symbol] 'counsel-info-lookup-symbol)
-    ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
-    ;; (global-set-key (kbd "C-c g") 'counsel-git)
-    (global-set-key [remap vc-git-grep] 'counsel-git-grep)
-    ;; (global-set-key (kbd "C-c k") 'counsel-ag)
-    (global-set-key [remap locate] 'counsel-locate)
-    ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
-    ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
-    (define-key ivy-minibuffer-map (kbd "M-RET") 'ivy-alt-done)
-    ;; (define-key ivy-minibuffer-map (kbd "C-RET") 'ivy-dispatching-done)
-    ;; (define-key ivy-minibuffer-map (kbd "M-S-RET") 'ivy-immediate-done)
-    ;; (define-key ivy-minibuffer-map [remap avy-goto-word-or-subword-1] 
'ivy-avy)
-    ))
-
-(ergoemacs-component ergoemacs-banish-shift ()
-  "Banish Shift Combinations with <apps> SPC"
-  :variable-reg ""
-  (global-set-key (kbd "<menu> SPC SPC") (kbd "_")) ;low line (underscore)
-  (global-set-key (kbd "<menu> SPC RET") (kbd "-"))
-  (global-set-key (kbd "<menu> SPC '") (kbd "\""))
-  (global-set-key (kbd "<menu> SPC ,") (kbd "<"))
-  (global-set-key (kbd "<menu> SPC -") (kbd "_"))
-  (global-set-key (kbd "<menu> SPC .") (kbd ">"))
-  (global-set-key (kbd "<menu> SPC /") (kbd "?"))
-  (global-set-key (kbd "<menu> SPC ;") (kbd ":"))
-  (global-set-key (kbd "<menu> SPC =") (kbd "+"))
-  (global-set-key (kbd "<menu> SPC \\") (kbd "|"))
-  (global-set-key (kbd "<menu> SPC `") (kbd "~"))
-
-  (global-set-key (kbd "<menu> SPC 0") (kbd ")"))
-  (global-set-key (kbd "<menu> SPC 1") (kbd "!"))
-  (global-set-key (kbd "<menu> SPC 2") (kbd "@"))
-  (global-set-key (kbd "<menu> SPC 3") (kbd "#"))
-  (global-set-key (kbd "<menu> SPC 4") (kbd "$"))
-  (global-set-key (kbd "<menu> SPC 5") (kbd "%"))
-  (global-set-key (kbd "<menu> SPC 6") (kbd "^"))
-  (global-set-key (kbd "<menu> SPC 7") (kbd "&"))
-  (global-set-key (kbd "<menu> SPC 8") (kbd "*"))
-  (global-set-key (kbd "<menu> SPC 9") (kbd "("))
-
-  (global-set-key (kbd "<menu> SPC a") (kbd "A"))
-  (global-set-key (kbd "<menu> SPC b") (kbd "B"))
-  (global-set-key (kbd "<menu> SPC c") (kbd "C"))
-  (global-set-key (kbd "<menu> SPC d") (kbd "D"))
-  (global-set-key (kbd "<menu> SPC e") (kbd "E"))
-  (global-set-key (kbd "<menu> SPC f") (kbd "F"))
-  (global-set-key (kbd "<menu> SPC g") (kbd "G"))
-  (global-set-key (kbd "<menu> SPC h") (kbd "H"))
-  (global-set-key (kbd "<menu> SPC i") (kbd "I"))
-  (global-set-key (kbd "<menu> SPC j") (kbd "J"))
-  (global-set-key (kbd "<menu> SPC k") (kbd "K"))
-  (global-set-key (kbd "<menu> SPC l") (kbd "L"))
-  (global-set-key (kbd "<menu> SPC m") (kbd "M"))
-  (global-set-key (kbd "<menu> SPC n") (kbd "N"))
-  (global-set-key (kbd "<menu> SPC o") (kbd "O"))
-  (global-set-key (kbd "<menu> SPC p") (kbd "P"))
-  (global-set-key (kbd "<menu> SPC q") (kbd "Q"))
-  (global-set-key (kbd "<menu> SPC r") (kbd "R"))
-  (global-set-key (kbd "<menu> SPC s") (kbd "S"))
-  (global-set-key (kbd "<menu> SPC t") (kbd "T"))
-  (global-set-key (kbd "<menu> SPC u") (kbd "U"))
-  (global-set-key (kbd "<menu> SPC v") (kbd "V"))
-  (global-set-key (kbd "<menu> SPC w") (kbd "W"))
-  (global-set-key (kbd "<menu> SPC x") (kbd "X"))
-  (global-set-key (kbd "<menu> SPC y") (kbd "Y"))
-  (global-set-key (kbd "<menu> SPC z") (kbd "Z")))
-
-(ergoemacs-component menu-bar-file ()
-  "File menu"
-  (global-set-key [menu-bar file]
-                  (cons "File"
-                        `(keymap
-                          (new-file menu-item "New" ergoemacs-new-empty-buffer)
-                          (make-frame menu-item "New Frame" make-frame-command)
-                          (open-file menu-item "Open..." find-file)
-                          (open-directory menu-item "Open Containing Folder"
-                                          (keymap
-                                           ;; FIXME add open in 
cmd/iTerm/xterm, etc
-                                           (open-directory-in-dired menu-item 
"In Dired" dired-jump)
-                                           (open-directory-in-desktop
-                                            menu-item  ,(cond
-                                                         ((eq system-type 
'windows-nt) "In Explorer")
-                                                         ((eq system-type 
'darwin) "In Finder")
-                                                         (t "In File Manager"))
-                                            ergoemacs-open-in-desktop)
-                                           (sep1 menu-item "--")
-                                           (open-eshell-here menu-item "In 
Emacs Shell" ergoemacs-eshell-here)
-                                           (open-shell-here menu-item ,(if (eq 
system-type 'windows-nt) "In Command Prompt" "In Shell") ergoemacs-shell-here)
-                                           ,(if (eq system-type 'windows-nt) 
'(powershell-here menu-item "In PowerShell" ergoemacs-powershell-here :enable 
(fboundp 'powershell)))
-                                           ))
-                          ;; (open-last-closed menu-item "Open last closed" 
ergoemacs-open-last-closed)
-                          (kill-buffer menu-item "Close" 
ergoemacs-close-current-buffer)
-                          (separator1 menu-item "--")
-                          (save-buffer menu-item "Save" save-buffer)
-                          (write-file menu-item "Save As..." write-file)
-                          (revert-buffer menu-item "Revert to Saved" 
revert-buffer)
-                          (print-buffer menu-item "Print" 
ergoemacs-print-buffer-confirm)
-                          ;; (ps-print-buffer-faces menu-item "Print 
(font+color)" ps-print-buffer-faces)
-                          (separator4 menu-item "--")
-                          (split-window-below menu-item "Split Window"
-                                              split-window-below)
-                          (split-window-right menu-item "Split Window right"
-                                              split-window-right)
-                          (one-window menu-item "Unsplit Window"
-                                      delete-other-windows)
-                          (separator5 menu-item "--")
-                          (execute-command menu-item "Execute Command" 
execute-extended-command)
-                          (repeat-earlier-command menu-item "Repeat Earlier 
Command"
-                                                  repeat-complex-command)
-                          (separator6 menu-item "--")
-                          (exit-emacs-menu menu-item "Quit" 
save-buffers-kill-emacs)
-                          "File"))))
-
-(ergoemacs-component menu-bar-edit ()
-  "Edit menu"
-  (global-set-key [menu-bar edit]
-                  (cons "Edit"
-                        '(keymap
-                          (undo menu-item "Undo" undo
-                                :enable (and
-                                         (not buffer-read-only)
-                                         (not
-                                          (eq t buffer-undo-list))
-                                         (if
-                                             (eq last-command 'undo)
-                                             (listp pending-undo-list)
-                                           (consp buffer-undo-list)))
-                                :help "Undo last operation")
-                          (redo menu-item "Redo" ergoemacs-redo
-                                :enable (and
-                                         (not buffer-read-only)
-                                         (not (eq t buffer-undo-list))
-                                         (or
-                                          (not (and (boundp 'undo-tree-mode) 
undo-tree-mode))
-                                          (and (and (boundp 'undo-tree-mode) 
undo-tree-mode)
-                                               (null (undo-tree-node-next 
(undo-tree-current buffer-undo-tree)))))))
-                          (redo-sep menu-item "--")
-                          (cut menu-item "Cut" ergoemacs-cut-line-or-region
-                               :help "Delete text in Line/region and copy it 
to the clipboard"
-                               :enable (or (eq ergoemacs-handle-ctl-c-or-ctl-x 
'only-copy-cut)
-                                           (region-active-p)))
-                          (copy menu-item "Copy" ergoemacs-copy-line-or-region
-                                :help "Copy text in line/region to the 
clipboard"
-                                :enable (or (eq 
ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)
-                                            (region-active-p)))
-                          (paste menu-item "Paste" ergoemacs-paste
-                                 :help "Paste text from clipboard")
-                          (paste-from-menu menu-item "Paste from Kill Menu" 
yank-menu
-                                           :enable (and
-                                                    (cdr yank-menu)
-                                                    (not buffer-read-only))
-                                           :help "Choose a string from the 
kill ring and paste it")
-                          (clear menu-item "Clear" delete-region
-                                 :enable (and mark-active (not 
buffer-read-only))
-                                 :help "Delete the text in region between mark 
and current position")
-                          (mark-whole-buffer menu-item "Select All" 
mark-whole-buffer
-                                             :help "Mark the whole buffer for 
a subsequent cut/copy")
-                          (separator-search menu-item "--")
-                          (blank-operations menu-item "Blank/Whitespace 
Operations"
-                                            (keymap
-                                             (trim-trailing-space menu-item
-                                                                  "Trim 
Trailing Space"
-                                                                  
delete-trailing-whitespace
-                                                                  :help "Trim 
Trailing spaces on each line")
-                                             (separator-tabify menu-item "--")
-                                             (tabify-region menu-item
-                                                            "Change multiple 
spaces to tabs (Tabify)"
-                                                            (lambda() 
(interactive)
-                                                              (if mark-active
-                                                                  (tabify 
(region-beginning)
-                                                                          
(region-end))
-                                                                (tabify 
(point-min) (point-max))))
-                                                            :help "Convert 
multiple spaces in the nonempty region to tabs when possible"
-                                                            :enable  (not 
buffer-read-only))
-                                             (untabify menu-item
-                                                       "Change Tabs To Spaces 
(Untabify)"
-                                                       (lambda() (interactive)
-                                                         (if mark-active
-                                                             (untabify 
(region-beginning)
-                                                                       
(region-end))
-                                                           (untabify 
(point-min) (point-max))))
-                                                       :help "Convert all tabs 
in the nonempty region or buffer to multiple spaces"
-                                                       :enable (not 
buffer-read-only))))
-                          (copy-to-clipboard menu-item "Copy File/Path to 
Clipboard"
-                                             (keymap
-                                              (copy-full-path menu-item
-                                                              "Current Full 
File Path to Clipboard"
-                                                              
ergoemacs-copy-full-path
-                                                              :enable 
(buffer-file-name))
-                                              (copy-file-name menu-item
-                                                              "Current File 
Name to Clipboard"
-                                                              
ergoemacs-copy-file-name
-                                                              :enable 
(buffer-file-name))
-                                              (copy-dir-path menu-item
-                                                             "Current Dir. 
Path to Clipboard"
-                                                             
ergoemacs-copy-dir-path
-                                                             :enable 
(buffer-file-name))))
-                          (convert-case-to menu-item "Convert Case To"
-                                           (keymap
-                                            (capitalize-region menu-item
-                                                               "Capitalize" 
capitalize-region
-                                                               :help 
"Capitalize (initial caps) words in the nonempty region"
-                                                               :enable (and 
(not buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                            (downcase-region menu-item
-                                                             "downcase" 
downcase-region
-                                                             :help "Make words 
in the nonempty region lower-case"
-                                                             :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                            (upcase-region menu-item "UPCASE" 
upcase-region
-                                                           :help "Make words 
in the nonempty region upper-case"
-                                                           :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                            (toggle-case-region menu-item 
"Toggle Capitalization/Case"
-                                                                
ergoemacs-toggle-letter-case
-                                                                :enable (not 
buffer-read-only))
-                                            (toggle-camel menu-item "Toggle 
CamelCase to camel_case"
-                                                          
ergoemacs-toggle-camel-case
-                                                          :enable (not 
buffer-read-only))))
-                          
-                          (eol-conversion menu-item "EOL Conversion"
-                                          (keymap
-                                           (windows menu-item
-                                                    "Windows/DOS"
-                                                    (lambda() (interactive)
-                                                      
(ergoemacs-eol-conversion 'dos))
-                                                    :enable (not 
(ergoemacs-eol-p 'dos)))
-                                           (unix menu-item
-                                                 "Unix/OSX"
-                                                 (lambda() (interactive)
-                                                   (ergoemacs-eol-conversion 
'unix))
-                                                 :enable (not (ergoemacs-eol-p 
'unix)))
-                                           (mac menu-item
-                                                "Old Mac"
-                                                (lambda() (interactive)
-                                                  (ergoemacs-eol-conversion 
'mac))
-                                                :enable (not (ergoemacs-eol-p 
'mac)))))
-                          ;; Taken/Adapted from menu+ by Drew Adams.
-                          ;; (region menu-item "Region"
-                          ;;         (keymap
-                          ;;          (unaccent-region
-                          ;;           menu-item "Unaccent" unaccent-region ; 
Defined in `unaccent'.
-                          ;;                     :help "Replace accented chars 
in the nonempty region by unaccented chars"
-                          ;;                     :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                          ;;          (separator-chars menu-item "--")
-                          
-                          
-                          ;;         (comment-region menu-item
-                          ;;                         "(Un)Comment" 
comment-region
-                          ;;                         :help "Comment or 
uncomment each line in the nonempty region"
-                          ;;                         :enable (and 
comment-start  (not buffer-read-only)  mark-active
-                          ;;                                    (> 
(region-end) (region-beginning))))
-                          ;;         (center-region menu-item
-                          ;;                        "Center" center-region
-                          ;;                       :help "Center each nonblank 
line that starts in the nonempty region"
-                          ;;                       :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                          ;;         ;; (indent-rigidly-region menu-item 
"Rigid Indent"
-                          ;;         ;;                        indent-rigidly
-                          ;;         ;;               :help "Indent each line 
that starts in the nonempty region"
-                          ;;         ;;               :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                          ;;         (indent-region menu-item "Column/Mode 
Indent" indent-region
-                          ;;                       :help "Indent each nonblank 
line in the nonempty region"
-                          ;;                       :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-
-                          ;;         (separator-indent menu-item "--")
-                          ;;         (abbrevs-region "Expand Abbrevs..."
-                          ;;                         expand-region-abbrevs
-                          ;;                         :help "Expand each abbrev 
in the nonempty region (with confirmation)"
-                          ;;                         :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                          
-                          ;;         (macro-region menu-item
-                          ;;                       "Exec Keyboard Macro" 
apply-macro-to-region-lines
-                          ;;                       :help "Run keyboard macro 
at start of each line in the nonempty region"
-                          ;;                       :enable (and last-kbd-macro 
mark-active  (not buffer-read-only)
-                          ;;                                    (> 
(region-end) (region-beginning))))))
-                          ;; Taken/Adapted from menu+ by Drew Adams.
-                          (sort menu-item "Sort"
-                                (keymap
-                                 (regexp-fields menu-item
-                                                "Regexp Fields" 
sort-regexp-fields
-                                                :help "Sort the nonempty 
region lexicographically"
-                                                :enable (and last-kbd-macro
-                                                             (not 
buffer-read-only)
-                                                             mark-active
-                                                             (> (region-end) 
(region-beginning))))
-                                 (pages menu-item
-                                        "Pages" sort-pages
-                                        :help "Sort pages in the nonempty 
region alphabetically"
-                                        :enable (and last-kbd-macro
-                                                     (not buffer-read-only)
-                                                     mark-active
-                                                     (> (region-end) 
(region-beginning))))
-                                 (sort-paragraphs menu-item
-                                                  "Paragraphs" sort-paragraphs
-                                                  :help "Sort paragraphs in 
the nonempty region alphabetically"
-                                                  :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                 (sort-numeric-fields menu-item
-                                                      "Numeric Field" 
sort-numeric-fields
-                                                      :help "Sort lines in the 
nonempty region numerically by the Nth field"
-                                                      :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                 (sort-fields menu-item
-                                              "Field" sort-fields
-                                              :help "Sort lines in the 
nonempty region lexicographically by the Nth field"
-                                              :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                 (sort-columns menu-item
-                                               "Columns" sort-columns
-                                               :help "Sort lines in the 
nonempty region alphabetically, by a certain range of columns"
+(defun ergoemacs-set-quit ()
+  "Escape exits."
+  (ergoemacs-global-set-key (kbd "<escape>") 'ergoemacs-keyboard-quit))
+
+(defun ergoemacs-set-remaps (keymap)
+  "Remaps for `ergoemacs-mode' for KEYMAP."
+  (define-key keymap [remap eshell] 'ergoemacs-eshell-here)
+  (define-key keymap [remap powershell] 'ergoemacs-powershell-here)
+  (define-key keymap [remap shell] 'ergoemacs-shell-here)
+  (define-key keymap [remap describe-mode]
+                  'ergoemacs-describe-major-mode)
+  (define-key keymap [remap cua-paste] 'ergoemacs-paste)
+  (define-key keymap [remap cua-cut-region] 'ergoemacs-cut-line-or-region))
+
+(defun ergoemacs-set-menu-bar-file ()
+  "File menu."
+  ;; Modify the existing File menu instead of creating it from
+  ;; scratch.  Creating it from scratch somehow breaks the "Open
+  ;; Recent" menu.
+  (let ((file-menu-map (lookup-key (current-global-map) [menu-bar file])))
+    (define-key file-menu-map [new-file]
+      '(menu-item "New" ergoemacs-new-empty-buffer :help "Open a new buffer"))
+    (define-key-after file-menu-map [open-file]
+      '(menu-item "Open File" find-file) 'new-file)
+    (define-key file-menu-map [dired]
+      '(menu-item "Open Containing Folder In"
+                  (keymap
+                   (open-directory-in-dired menu-item "Dired" dired-jump)
+                   (open-directory-in-desktop
+                    menu-item (cond
+                               ((eq system-type 'windows-nt) "Explorer")
+                               ((eq system-type 'darwin) "Finder")
+                               (t "File Manager"))
+                    ergoemacs-open-in-desktop)
+                   (open-eshell-here menu-item "Emacs Shell" 
ergoemacs-eshell-here)
+                   (open-shell-here menu-item (if (eq system-type 'windows-nt) 
"Command Prompt" "Shell") ergoemacs-shell-here)
+                   (if (eq system-type 'windows-nt) '(powershell-here 
menu-item "PowerShell" ergoemacs-powershell-here :enable (fboundp 
'powershell))))))
+
+    (define-key-after file-menu-map [kill-buffer] '(menu-item "Close" 
ergoemacs-close-current-buffer)
+      'separator-save)
+    (define-key file-menu-map [save-buffer] '(menu-item "Save" save-buffer))
+    (define-key file-menu-map [write-file] '(menu-item "Save As..." 
write-file))
+    (define-key file-menu-map [revert-buffer] '(menu-item "Revert to Saved" 
ergoemacs-revert-buffer))
+    (define-key-after file-menu-map [print] '(menu-item "Print" pr-interface) 
'revert-buffer)
+    (define-key file-menu-map [new-window-below] '(menu-item "Split Window 
Below" split-window-below))
+    (define-key file-menu-map [new-window-on-right] '(menu-item "Split Window 
Right"
+                                                                
split-window-right))
+    (define-key file-menu-map [one-window] '(menu-item "Unsplit Window"
+                                                       delete-other-windows))
+    (define-key file-menu-map [make-frame] '(menu-item "Create New Frame" 
ergoemacs-make-frame-command))
+    (define-key-after file-menu-map [delete-this-frame]
+      '(menu-item "Delete Frame" ergoemacs-delete-frame) 'make-frame)
+
+    (define-key-after file-menu-map [execute-command]
+      '(menu-item "Execute Command" execute-extended-command) 
'delete-this-frame)
+    (define-key file-menu-map [close-tab] '(menu-item "Repeat Earlier Command"
+                            repeat-complex-command))
+    (define-key file-menu-map [exit-emacs] '(menu-item "Quit" 
save-buffers-kill-emacs))
+
+    (define-key file-menu-map [insert-file] nil)
+    (define-key file-menu-map [recover-session] nil)
+    (define-key file-menu-map [make-frame-on-display] nil)
+    (define-key file-menu-map [make-frame-on-monitor] nil)
+    (define-key file-menu-map [make-tab] nil)
+    (define-key file-menu-map [close-tab] nil)
+    (define-key file-menu-map [separator-tab] nil)
+    (define-key file-menu-map [separator-print] nil)
+    (define-key file-menu-map [Print] nil)
+
+    (define-key file-menu-map [separator6] nil)
+    (define-key file-menu-map [separator5] nil)
+    (define-key file-menu-map [separator4] nil)
+    (define-key file-menu-map [separator3] nil)
+    (define-key file-menu-map [separator2] nil)
+    (define-key file-menu-map [separator1] nil)
+
+    (require 'recentf)
+    (setq recentf-menu-before "Open Containing Folder In")
+    (recentf-mode 1)))
+
+(defun ergoemacs-set-menu-bar-edit ()
+  "Edit menu."
+  (define-key-after (current-global-map) [menu-bar edit]
+    (cons "Edit"
+          '(keymap
+            (undo-item menu-item "Undo" ergoemacs-undo
+                       :enable (and
+                                (not buffer-read-only)
+                                (not
+                                 (eq t buffer-undo-list))
+                                (if
+                                    (eq last-command 'undo)
+                                    (listp pending-undo-list)
+                                  (consp buffer-undo-list)))
+                       :help "Undo last operation")
+            (cut menu-item "Cut" ergoemacs-cut-line-or-region
+                 :help "Delete text in Line/region and copy it to the 
clipboard"
+                 :enable (region-active-p))
+            (copy menu-item "Copy" ergoemacs-copy-line-or-region
+                  :help "Copy text in line/region to the clipboard"
+                  :enable (region-active-p))
+            (paste menu-item "Paste" ergoemacs-paste
+                   :help "Paste text from clipboard")
+            (paste-from-menu menu-item "Paste from Kill Menu" yank-menu
+                             :enable (and
+                                      (cdr yank-menu)
+                                      (not buffer-read-only))
+                             :help "Choose a string from the kill ring and 
paste it")
+            (insert-file menu-item "Insert File" insert-file
+                         :enable (not buffer-read-only)
+                         :help "Copy the entire contents of a file into the 
current buffer"
+                         )
+            (clear menu-item "Clear" delete-region
+                   :enable (and mark-active (not buffer-read-only))
+                   :help "Delete the text in region between mark and current 
position")
+            (mark-whole-buffer menu-item "Select All" mark-whole-buffer
+                               :help "Mark the whole buffer for a subsequent 
cut/copy")
+            (separator-search menu-item "--")
+            (blank-operations menu-item "Blank/Whitespace Operations"
+                              (keymap
+                               (trim-trailing-space menu-item
+                                                    "Trim Trailing Space"
+                                                    delete-trailing-whitespace
+                                                    :help "Trim Trailing 
spaces on each line")
+                               (separator-tabify menu-item "--")
+                               (tabify-region menu-item
+                                              "Change multiple spaces to tabs 
(Tabify)"
+                                              (lambda() (interactive)
+                                                (if mark-active
+                                                    (tabify (region-beginning)
+                                                            (region-end))
+                                                  (tabify (point-min) 
(point-max))))
+                                              :help "Convert multiple spaces 
in the nonempty region to tabs when possible"
+                                              :enable  (not buffer-read-only))
+                               (untabify menu-item
+                                         "Change Tabs To Spaces (Untabify)"
+                                         (lambda() (interactive)
+                                           (if mark-active
+                                               (untabify (region-beginning)
+                                                         (region-end))
+                                             (untabify (point-min) 
(point-max))))
+                                         :help "Convert all tabs in the 
nonempty region or buffer to multiple spaces"
+                                         :enable (not buffer-read-only))))
+            (copy-to-clipboard menu-item "Copy File/Path to Clipboard"
+                               (keymap
+                                (copy-full-path menu-item
+                                                "Current Full File Path to 
Clipboard"
+                                                ergoemacs-copy-full-path
+                                                :enable (buffer-file-name))
+                                (copy-file-name menu-item
+                                                "Current File Name to 
Clipboard"
+                                                ergoemacs-copy-file-name
+                                                :enable (buffer-file-name))
+                                (copy-dir-path menu-item
+                                               "Current Dir. Path to Clipboard"
+                                               ergoemacs-copy-dir-path
+                                               :enable (buffer-file-name))))
+            (convert-case-to menu-item "Convert Case To"
+                             (keymap
+                              (capitalize-region menu-item
+                                                 "Capitalize" capitalize-region
+                                                 :help "Capitalize (initial 
caps) words in the nonempty region"
+                                                 :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
+                              (downcase-region menu-item
+                                               "downcase" downcase-region
+                                               :help "Make words in the 
nonempty region lower-case"
                                                :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                 (sort-lines menu-item
-                                             "Lines" sort-lines
-                                             :help "Sort lines in the nonempty 
region alphabetically"
+                              (upcase-region menu-item "UPCASE" upcase-region
+                                             :help "Make words in the nonempty 
region upper-case"
                                              :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))
-                                 (reverse-region menu-item "Reverse" 
reverse-region
-                                                 :help "Reverse the order of 
the selected lines"
-                                                 :enable (and (not 
buffer-read-only)  mark-active  (> (region-end) (region-beginning))))))
-                          
-                          
-                          ;; (search menu-item "Search"
-                          ;;         (keymap
-                          ;;          (search-forward menu-item "Text..." 
search-forward)
-                          ;;          (separator-repeat-search menu-item "--")
-                          ;;          (tags-srch menu-item "Search Tagged 
Files..." tags-search
-                          ;;                     :help "Search for a regexp in 
all tagged files")
-                          ;;          (tags-continue menu-item "Continue Tags 
Search" tags-loop-continue
-                          ;;                         :help "Continue last tags 
search operation")
-                          ;;          "Search"))
-                          
-                          ;; (i-search menu-item "Incremental Search"
-                          ;;           (keymap
-                          ;;            (isearch-forward menu-item "Forward 
String..." isearch-forward
-                          ;;                             :help "Search forward 
for a string as you type it")
-                          ;;            (isearch-backward menu-item "Backward 
String..." isearch-backward
-                          ;;                              :help "Search 
backwards for a string as you type it")
-                          ;;            (isearch-forward-regexp menu-item 
"Forward Regexp..." isearch-forward-regexp
-                          ;;                                    :help "Search 
forward for a regular expression as you type it")
-                          ;;            (isearch-backward-regexp menu-item 
"Backward Regexp..." isearch-backward-regexp
-                          ;;                                     :help "Search 
backwards for a regular expression as you type it")
-                          ;;            "Incremental Search"))
-                          
-                          ;; (replace menu-item "Replace"
-                          ;;          (keymap
-                          ;;           (query-replace menu-item "Replace 
String..." query-replace
-                          ;;                          :enable (not 
buffer-read-only)
-                          ;;                          :help "Replace string 
interactively, ask about each occurrence")
-                          ;;           (query-replace-regexp menu-item 
"Replace Regexp..." query-replace-regexp
-                          ;;                                 :enable (not 
buffer-read-only)
-                          ;;                                 :help "Replace 
regular expression interactively, ask about each occurrence")
-                          ;;           (separator-replace-tags menu-item "--")
-                          ;;           (tags-repl menu-item "Replace in Tagged 
Files..." tags-query-replace
-                          ;;                      :help "Interactively replace 
a regexp in all tagged files")
-                          ;;           (tags-repl-continue menu-item "Continue 
Replace" tags-loop-continue
-                          ;;                               :help "Continue 
last tags replace operation")
-                          ;;           "Replace"))
-                          
-                          ;; (goto menu-item "Go To"
-                          ;;       (keymap
-                          ;;        (go-to-line menu-item "Goto Line..." 
goto-line
-                          ;;                    :help "Read a line number and 
go to that line")
-                          ;;        (separator-tags menu-item "--")
-                          ;;        (find-tag menu-item "Find Tag..." find-tag
-                          ;;                  :help "Find definition of 
function or variable")
-                          ;;        (find-tag-otherw menu-item "Find Tag in 
Other Window..." find-tag-other-window
-                          ;;                         :help "Find 
function/variable definition in another window")
-                          ;;        (next-tag menu-item "Find Next Tag" 
menu-bar-next-tag
-                          ;;                  :enable (and
-                          ;;                           (boundp 
'tags-location-ring)
-                          ;;                           (not
-                          ;;                            (ring-empty-p 
tags-location-ring)))
-                          ;;                  :help "Find next 
function/variable matching last tag name")
-                          ;;        (next-tag-otherw menu-item "Next Tag in 
Other Window" menu-bar-next-tag-other-window
-                          ;;                         :enable (and
-                          ;;                                  (boundp 
'tags-location-ring)
-                          ;;                                  (not
-                          ;;                                   (ring-empty-p 
tags-location-ring)))
-                          ;;                         :help "Find next 
function/variable matching last tag name in another window")
-                          ;;        (apropos-tags menu-item "Tags Apropos..." 
tags-apropos
-                          ;;                      :help "Find 
function/variables whose names match regexp")
-                          ;;        (separator-tag-file menu-item "--")
-                          ;;        (set-tags-name menu-item "Set Tags File 
Name..." visit-tags-table
-                          ;;                       :help "Tell Tags commands 
which tag table file to use")
-                          ;;        "Go To"))
-                          
-                          ;; (bookmark menu-item "Bookmarks" 
menu-bar-bookmark-map)
-                          (separator-bookmark menu-item "--")
-                          (fill menu-item "Fill" fill-region
-                                :enable (and mark-active
-                                             (not buffer-read-only))
-                                :help "Fill text in region to fit between left 
and right margin")
-                          (props menu-item "Text Properties" facemenu-menu)
-                          "Edit"))))
-
-(ergoemacs-component menu-bar-search ()
-  "Search menu"
-  (global-set-key [menu-bar search]
-                  (cons "Search"
-                        '(keymap
-                          (isearch-forward menu-item "String Forward..." 
isearch-forward
-                                           :help "Search forward for a string 
as you type it")
-                          (isearch-backward menu-item "    Backward..." 
isearch-backward
-                                            :help "Search backwards for a 
string as you type it")
-                          (re-isearch-forward menu-item "Regexp Forward..." 
isearch-forward-regexp
-                                              :help "Search forward for a 
regular expression as you type it")
-                          (re-isearch-backward menu-item "    Backward..." 
isearch-backward-regexp
-                                               :help "Search backwards for a 
regular expression as you type it")
-                          (separator-repeat-search menu-item "--" )
-                          (repeat-forward menu-item "Repeat Forward" 
nonincremental-repeat-search-forward
-                                          :enable (or (and (memq 
menu-bar-last-search-type '(string word)) search-ring)
-                                                      (and (eq 
menu-bar-last-search-type 'regexp) regexp-search-ring))
-                                          :help "Repeat last search forward")
-                          (repeat-backward menu-item "    Repeat Backward" 
nonincremental-repeat-search-backward
-                                           :enable (or (and (memq 
menu-bar-last-search-type '(string word)) search-ring)
-                                                       (and (eq 
menu-bar-last-search-type 'regexp) regexp-search-ring))
-                                           :help "Repeat last search forward")
-                          (separator-isearch menu-item "--")
-                          (i-search menu-item "String Search"
-                                    (keymap
-                                     (search-forward menu-item "Forward 
String..." search-forward)
-                                     (search-backward menu-item "    
Backward..." search-backward)
-                                     (search-forward-regexp menu-item "Forward 
Regexp..." re-search-forward)
-                                     (search-backward-regexp menu-item "    
Backward..." re-search-backward)
-                                     "String Search"))
-                          
-                          (replace menu-item "Replace"
-                                   (keymap
-                                    (query-replace menu-item "Replace 
String..." query-replace
-                                                   :enable (not 
buffer-read-only)
-                                                   :help "Replace string 
interactively, ask about each occurrence")
-                                    (query-replace-regexp menu-item "Replace 
Regexp..." query-replace-regexp
-                                                          :enable (not 
buffer-read-only)
-                                                          :help "Replace 
regular expression interactively, ask about each occurrence")
-                                    (separator-replace-tags menu-item "--")
-                                    (tags-repl menu-item "Replace in Tagged 
Files..." tags-query-replace
-                                               :help "Interactively replace a 
regexp in all tagged files")
-                                    (tags-repl-continue menu-item "Continue 
Replace" tags-loop-continue
-                                                        :help "Continue last 
tags replace operation")
-                                    "Replace"))
-                          (grep menu-item "Grep..." grep
-                                :enable (executable-find "grep"))
-                          (occur menu-item "Occurrences in buffer..." occur
-                                 :help "Show Lines in a buffer that match a 
regular expression")
-                          (moccur menu-item "Occurrences in all buffers..." 
multi-occur
-                                  :help "Show Lines in all buffers that match 
a regular expression")
-                          (separator-go-to menu-item "--" )
-                          
-                          (goto menu-item "Go To"
-                                (keymap
-                                 (go-to-line menu-item "Goto Line..." goto-line
-                                             :help "Read a line number and go 
to that line")
-                                 (separator-tags menu-item "--")
-                                 (find-tag menu-item "Find Tag..." find-tag
-                                           :help "Find definition of function 
or variable")
-                                 (find-tag-otherw menu-item "Find Tag in Other 
Window..." find-tag-other-window
-                                                  :help "Find 
function/variable definition in another window")
-                                 (next-tag menu-item "Find Next Tag" 
menu-bar-next-tag
-                                           :enable (and
-                                                    (boundp 
'tags-location-ring)
-                                                    (not
-                                                     (ring-empty-p 
tags-location-ring)))
-                                           :help "Find next function/variable 
matching last tag name")
-                                 (next-tag-otherw menu-item "Next Tag in Other 
Window" menu-bar-next-tag-other-window
-                                                  :enable (and
-                                                           (boundp 
'tags-location-ring)
-                                                           (not
-                                                            (ring-empty-p 
tags-location-ring)))
-                                                  :help "Find next 
function/variable matching last tag name in another window")
-                                 (apropos-tags menu-item "Tags Apropos..." 
tags-apropos
-                                               :help "Find function/variables 
whose names match regexp")
-                                 (separator-tag-file menu-item "--")
-                                 (set-tags-name menu-item "Set Tags File 
Name..." visit-tags-table
-                                                :help "Tell Tags commands 
which tag table file to use")
-                                 "Go To")
-                                (separator-packages))
-                          
-                          (bookmark menu-item "Bookmarks" 
menu-bar-bookmark-map)
-                          "Search"))))
-
-(ergoemacs-component menu-bar-view ()
-  "View menu"
-  (global-set-key [menu-bar view]
-                  (cons "View"
-                        '(keymap
-                          (menu-font-size menu-item "Zoom"
-                                          (keymap
-                                           (zoom-in menu-item "Zoom In" 
text-scale-increase)
-                                           (zoom-out menu-item "Zoom Out" 
text-scale-decrease)
-                                           (zoom-reset menu-item "Zoom Reset" 
ergoemacs-text-scale-normal-size)))
-                          
-                          (menu-set-font menu-item "Set Default Font..." 
menu-set-font :visible
-                                         (display-multi-font-p)
-                                         :help "Select a default font")
-                          
-                          ,(when (fboundp 'customize-themes)
-                             '(color-theme menu-item "Customize Color Themes" 
customize-themes
-                                           :help "Customize Emacs Themes."))
-                          
-                          (separator-font-size menu-item "--")
-
-                          (highlight-current-line menu-item "Highlight Current 
Line" global-hl-line-mode
-                                                  :help "Have the cursor line 
always Highlighted"
-                                                  :button (:toggle . (and 
(boundp 'global-hl-line-mode)
-                                                                          
global-hl-line-mode)))
-
-                          (paren-mode menu-item "Highlight Matching 
Parentheses" show-paren-mode
-                                      :button (:toggle . show-paren-mode))
-
-                          (ruler-mode menu-item "Ruler Mode" ruler-mode
-                                      :button (:toggle . ruler-mode))
-
-                          (blink-cursor menu-item "Cursor Blink" 
blink-cursor-mode
-                                        :button (:toggle . blink-cursor-mode))
-
-                          ;; (auto-pair menu-item "Insert Matching 
Parentheses/Bracket"
-                          ;;            (lambda() (interactive)
-                          ;;              (cond
-                          ;;               ((fboundp 'smartparens-mode)
-                          ;;                (smartparens-mode))
-                          ;;               ((fboundp 'autopair-global-mode)
-                          ;;                (autopair-global-mode))
-                          ;;               (t (electric-pair-mode))))
-                          ;;            :button (:toggle . 
-                          ;;                             (or
-                          ;;                              (and (boundp 
'smartparens-mode) smartparens-mode)
-                          ;;                              (and (boundp 
'auto-indent-mode) auto-indent-mode)
-                          ;;                              electric-pair-mode)))
-                          
-                          (tabbar-mode menu-item "Tabbar" 
ergoemacs-menu-tabbar-toggle
-                                       :button (:toggle . (and (boundp 
'tabbar-mode)
-                                                               tabbar-mode)))
-                          
-                          
-                          ;; (showhide-tool-bar menu-item "Tool-bar" 
tool-bar-mode :help "Turn tool-bar on/off"
-                          ;;                    :button (:toggle . 
tool-bar-mode))
-                          
-                          ;; (menu-bar-mode menu-item "Menu-bar" 
toggle-menu-bar-mode-from-frame :help "Turn menu-bar on/off" :button
-                          ;;                (:toggle menu-bar-positive-p
-                          ;;                         (frame-parameter
-                          ;;                          
(menu-bar-frame-for-menubar)
-                          ;;                          'menu-bar-lines))
-                          ;;                :keys "")
-
-                          ;; (showhide-tooltip-mode menu-item "Tooltips" 
tooltip-mode :help "Turn tooltips on/off" :visible
-                          ;;                        (and
-                          ;;                         (display-graphic-p)
-                          ;;                         (fboundp 'x-show-tip))
-                          ;;                        :button
-                          ;;                        (:toggle . tooltip-mode)
-                          ;;                        :keys "")
-                          (separator-speedbar menu-item "--")
-                          ;; (showhide-scroll-bar)
-                          ;; (showhide-fringe)
-
-                          (showhide-speedbar menu-item "Speedbar" 
speedbar-frame-mode :help "Display a Speedbar quick-navigation frame" :button
-                                             (:toggle and
-                                                      (boundp 'speedbar-frame)
-                                                      (frame-live-p
-                                                       speedbar-frame)
-                                                      (frame-visible-p
-                                                       speedbar-frame)))
-                          ;; (datetime-separator)
-                          ;; (showhide-date-time)
-                          (linecolumn-separator "--")
-                          (line-number-mode menu-item "Line Numbers" 
line-number-mode :help "Show the current line number in the mode line" :button
-                                            (:toggle and
-                                                     (default-boundp 
'line-number-mode)
-                                                     (default-value 
'line-number-mode)))
-                          (global-whitespace-mode menu-item "Show/Hide 
whitespaces" global-whitespace-mode :button
-                                                  (:toggle . 
global-whitespace-mode))
-                          (global-linum-mode menu-item "Show/Hide line numbers 
in margin" global-linum-mode :button
-                                             (:toggle . global-linum-mode))))))
-
-(ergoemacs-theme-component menu-bar-languages ()
-  "Languages menu"
-  (global-set-key [menu-bar languages] (cons "Languages" 
(ergoemacs-menu--get-major-modes))))
-
-(ergoemacs-theme-component menu-bar-help ()
-  "Help menu"
+                              (toggle-case-region menu-item "Toggle 
Capitalization/Case"
+                                                  ergoemacs-toggle-letter-case
+                                                  :enable (not 
buffer-read-only))
+                              (toggle-camel menu-item "Toggle CamelCase to 
camel_case"
+                                            ergoemacs-toggle-camel-case
+                                            :enable (not buffer-read-only))))
+
+            (eol-conversion menu-item "EOL Conversion"
+                            (keymap
+                             (windows menu-item
+                                      "Windows/DOS"
+                                      (lambda() (interactive)
+                                        (ergoemacs-eol-conversion 'dos))
+                                      :enable (not (ergoemacs-eol-p 'dos)))
+                             (unix menu-item
+                                   "Unix/OSX"
+                                   (lambda() (interactive)
+                                     (ergoemacs-eol-conversion 'unix))
+                                   :enable (not (ergoemacs-eol-p 'unix)))
+                             (mac menu-item
+                                  "Old Mac"
+                                  (lambda() (interactive)
+                                    (ergoemacs-eol-conversion 'mac))
+                                  :enable (not (ergoemacs-eol-p 'mac)))))
+            ;; Taken/Adapted from menu+ by Drew Adams.
+            (sort menu-item "Sort"
+                  (keymap
+                   (regexp-fields menu-item
+                                  "Regexp Fields" sort-regexp-fields
+                                  :help "Sort the nonempty region 
lexicographically"
+                                  :enable (and last-kbd-macro
+                                               (not buffer-read-only)
+                                               mark-active
+                                               (> (region-end) 
(region-beginning))))
+                   (pages menu-item
+                          "Pages" sort-pages
+                          :help "Sort pages in the nonempty region 
alphabetically"
+                          :enable (and last-kbd-macro
+                                       (not buffer-read-only)
+                                       mark-active
+                                       (> (region-end) (region-beginning))))
+                   (sort-paragraphs menu-item
+                                    "Paragraphs" sort-paragraphs
+                                    :help "Sort paragraphs in the nonempty 
region alphabetically"
+                                    :enable (and (not buffer-read-only)  
mark-active  (> (region-end) (region-beginning))))
+                   (sort-numeric-fields menu-item
+                                        "Numeric Field" sort-numeric-fields
+                                        :help "Sort lines in the nonempty 
region numerically by the Nth field"
+                                        :enable (and (not buffer-read-only)  
mark-active  (> (region-end) (region-beginning))))
+                   (sort-fields menu-item
+                                "Field" sort-fields
+                                :help "Sort lines in the nonempty region 
lexicographically by the Nth field"
+                                :enable (and (not buffer-read-only)  
mark-active  (> (region-end) (region-beginning))))
+                   (sort-columns menu-item
+                                 "Columns" sort-columns
+                                 :help "Sort lines in the nonempty region 
alphabetically, by a certain range of columns"
+                                 :enable (and (not buffer-read-only)  
mark-active  (> (region-end) (region-beginning))))
+                   (sort-lines menu-item
+                               "Lines" sort-lines
+                               :help "Sort lines in the nonempty region 
alphabetically"
+                               :enable (and (not buffer-read-only)  
mark-active  (> (region-end) (region-beginning))))
+                   (reverse-region menu-item "Reverse" reverse-region
+                                   :help "Reverse the order of the selected 
lines"
+                                   :enable (and (not buffer-read-only)  
mark-active  (> (region-end) (region-beginning))))))
+
+
+            (separator-bookmark menu-item "--")
+            (fill menu-item "Fill/Unfill" ergoemacs-compact-uncompact-block
+                  :enable (not buffer-read-only)
+                  :help "Fill text to fit within margins, or unfill to make it 
one line")
+            (props menu-item "Text Properties" facemenu-menu)
+            "Edit"))
+    'file))
+
+(defun ergoemacs-set-menu-bar-search ()
+  "Search menu."
+  (define-key-after (current-global-map) [menu-bar search]
+    (cons "Search"
+          '(keymap
+            (isearch-forward menu-item "String Forward..." isearch-forward
+                             :help "Search forward for a string as you type 
it")
+            (isearch-backward menu-item "    Backward..." isearch-backward
+                              :help "Search backwards for a string as you type 
it")
+            (re-isearch-forward menu-item "Regexp Forward..." 
isearch-forward-regexp
+                                :help "Search forward for a regular expression 
as you type it")
+            (re-isearch-backward menu-item "    Backward..." 
isearch-backward-regexp
+                                 :help "Search backwards for a regular 
expression as you type it")
+            (separator-isearch menu-item "--")
+            (i-search menu-item "String Search"
+                      (keymap
+                       (search-forward menu-item "Forward String..." 
search-forward)
+                       (search-backward menu-item "    Backward..." 
search-backward)
+                       (search-forward-regexp menu-item "Forward Regexp..." 
re-search-forward)
+                       (search-backward-regexp menu-item "    Backward..." 
re-search-backward)
+                       "String Search"))
+
+            (replace menu-item "Replace"
+                     (keymap
+                      (query-replace menu-item "Replace String..." 
query-replace
+                                     :enable (not buffer-read-only)
+                                     :help "Replace string interactively, ask 
about each occurrence")
+                      (query-replace-regexp menu-item "Replace Regexp..." 
query-replace-regexp
+                                            :enable (not buffer-read-only)
+                                            :help "Replace regular expression 
interactively, ask about each occurrence")
+                      (separator-replace-tags menu-item "--")
+                      (tags-repl menu-item "Replace in Tagged Files..." 
tags-query-replace
+                                 :help "Interactively replace a regexp in all 
tagged files")
+                      (tags-repl-continue menu-item "Continue Replace" 
tags-loop-continue
+                                          :help "Continue last tags replace 
operation")
+                      "Replace"))
+            (grep menu-item "Grep..." grep
+                  :enable (executable-find "grep"))
+            (occur menu-item "Occurrences in buffer..." occur
+                   :help "Show Lines in a buffer that match a regular 
expression")
+            (moccur menu-item "Occurrences in all buffers..." multi-occur
+                    :help "Show Lines in all buffers that match a regular 
expression")
+            (separator-go-to menu-item "--" )
+
+            (goto menu-item "Go To"
+                  (keymap
+                   (go-to-line menu-item "Goto Line..." goto-line
+                               :help "Read a line number and go to that line")
+                   (separator-tags menu-item "--")
+                   (find-tag menu-item "Find Tag..." find-tag
+                             :help "Find definition of function or variable")
+                   (find-tag-otherw menu-item "Find Tag in Other Window..." 
find-tag-other-window
+                                    :help "Find function/variable definition 
in another window")
+                   (next-tag menu-item "Find Next Tag" menu-bar-next-tag
+                             :enable (and
+                                      (boundp 'tags-location-ring)
+                                      (not
+                                       (ring-empty-p tags-location-ring)))
+                             :help "Find next function/variable matching last 
tag name")
+                   (next-tag-otherw menu-item "Next Tag in Other Window" 
menu-bar-next-tag-other-window
+                                    :enable (and
+                                             (boundp 'tags-location-ring)
+                                             (not
+                                              (ring-empty-p 
tags-location-ring)))
+                                    :help "Find next function/variable 
matching last tag name in another window")
+                   (apropos-tags menu-item "Tags Apropos..." tags-apropos
+                                 :help "Find function/variables whose names 
match regexp")
+                   (separator-tag-file menu-item "--")
+                   (set-tags-name menu-item "Set Tags File Name..." 
visit-tags-table
+                                  :help "Tell Tags commands which tag table 
file to use")
+                   "Go To")
+                  (separator-packages))
+
+            (bookmark menu-item "Bookmarks" menu-bar-bookmark-map)
+            "Search"))
+    'edit))
+
+(defun ergoemacs-set-menu-bar-view ()
+  "View menu."
+  (define-key-after (current-global-map) [menu-bar view]
+    (cons "View"
+          '(keymap
+            (menu-font-size menu-item "Zoom"
+                            (keymap
+                             (zoom-in menu-item "Zoom In" text-scale-increase)
+                             (zoom-out menu-item "Zoom Out" 
text-scale-decrease)
+                             (zoom-reset menu-item "Zoom Reset" 
ergoemacs-text-scale-normal-size)))
+
+            (menu-set-font menu-item "Set Default Font..." menu-set-font 
:visible
+                           (display-multi-font-p)
+                           :help "Select a default font")
+
+            ,(when (fboundp 'customize-themes)
+               '(color-theme menu-item "Customize Color Themes" 
customize-themes
+                             :help "Customize Emacs Themes."))
+
+            (separator-font-size menu-item "--")
+
+            (highlight-current-line menu-item "Highlight Current Line" 
global-hl-line-mode
+                                    :help "Have the cursor line always 
Highlighted"
+                                    :button (:toggle . (and (boundp 
'global-hl-line-mode)
+                                                            
global-hl-line-mode)))
+
+            (paren-mode menu-item "Highlight Matching Parentheses" 
show-paren-mode
+                        :button (:toggle . show-paren-mode))
+
+            (ruler-mode menu-item "Ruler Mode" ruler-mode
+                        :button (:toggle . ruler-mode))
+
+            (blink-cursor menu-item "Cursor Blink" blink-cursor-mode
+                          :button (:toggle . blink-cursor-mode))
+
+            (separator-speedbar menu-item "--")
+
+            (showhide-speedbar menu-item "Speedbar" speedbar-frame-mode :help 
"Display a Speedbar quick-navigation frame" :button
+                               (:toggle and
+                                        (boundp 'speedbar-frame)
+                                        (frame-live-p
+                                         speedbar-frame)
+                                        (frame-visible-p
+                                         speedbar-frame)))
+            (linecolumn-separator "--")
+            (line-number-mode menu-item "Line Numbers" line-number-mode :help 
"Show the current line number in the mode line" :button
+                              (:toggle and
+                                       (default-boundp 'line-number-mode)
+                                       (default-value 'line-number-mode)))
+            (global-whitespace-mode menu-item "Show/Hide whitespaces" 
global-whitespace-mode :button
+                                    (:toggle . global-whitespace-mode))
+            (global-linum-mode menu-item "Show/Hide line numbers in margin" 
global-linum-mode :button
+                               (:toggle . global-linum-mode))))
+    'search))
+
+(defun ergoemacs-set-menu-bar-help ()
+  "Help menu."
   (global-set-key [menu-bar help-menu]
-                  (cons (if (eq system-type 'darwin) "Help" "?")
+                  (cons "Help"
                         `(keymap
                           ;; Adapted from Menu-bar+
                           (whoops menu-item "Whoops!?"
@@ -1726,10 +1047,12 @@
                                     menu-item "Cancel Current Action"
                                     keyboard-quit
                                     :help "Quit any operation in progress")))
-                          
+
                           (help-for-help menu-item "Help for Help..."
                                          help-for-help
                                          :help "Emacs main help command")
+                          (key-bindings menu-item "Global Key Bindings"
+                                        ergoemacs-describe-current-theme)
                           (separator-1 menu-item  "--")
                           (apropos menu-item "Apropos (Find matching)"
                                    (keymap
@@ -1773,11 +1096,7 @@
                                      (coding menu-item "Coding System..."
                                              describe-coding-system)
                                      (separator-ergoemacs-describe "--")
-                                     (theme-component menu-item "Ergoemacs 
Component"
-                                                      
describe-ergoemacs-component)
-                                     (theme menu-item "Ergoemacs Theme"
-                                            describe-ergoemacs-theme)
-                                     (layout menu-item "Ergoemacs Layout"
+                                     (layout menu-item "Keyboard Layout"
                                             describe-ergoemacs-layout)
                                      (separator-curr-modes menu-item "--")
                                      (curr-major-mode menu-item "Current Major 
Mode"
@@ -1803,13 +1122,6 @@
                                                              "    Command 
Description..."
                                                              
Info-goto-emacs-command-node
                                                              :help "Show emacs 
manual section about a command")
-                                               ;; Useless for ergoemacs...
-                                               ;; (key-desc menu-item
-                                               ;;           "    Key 
Description..."
-                                               ;;           
Info-goto-emacs-key-command-node
-                                               ;;           :help "Show Emacs 
manual
-                                               ;;           section that 
describes a key
-                                               ;;           sequence.")
                                                (index menu-item
                                                       "    Index..."
                                                       emacs-index-search
@@ -1837,7 +1149,7 @@
                                                               (lambda() 
(interactive)
                                                                 (browse-url 
ergoemacs-xah-emacs-lisp-tutorial-url))
                                                               :help "Read 
Emacs Lisp Tutorial")
-                                                    
+
                                                     (intro menu-item
                                                            "Intro to Elisp"
                                                            (lambda() 
(interactive)
@@ -1864,12 +1176,12 @@
                                        (man-dir menu-item "Unix Man Pages..."
                                                 woman
                                                 :help "Unix Manual entries 
(with WoMan)")))
-                          
+
                           (separator-3 menu-item "--")
                           (send-bug-report menu-item "Send Emacs Bug Report"
                                            report-emacs-bug
                                            :help "Report an emacs bug.")
-                          
+
                           (emacs-web-page menu-item "Emacs Web Page"
                                           (lambda() (interactive)
                                             (browse-url 
"http://www.gnu.org/software/emacs/";))
@@ -1880,182 +1192,351 @@
                                    describe-copying)
                           ,(if (eq system-type 'darwin) "Help" "?")))))
 
-(ergoemacs-theme lvl0 ()
-  "CUA-mode style"
-  (if (not (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x))
-      (progn
-        (global-set-key (kbd "C-c <ergoemacs-timeout>") 
'ergoemacs-copy-line-or-region)
-        (global-set-key (kbd "C-x <ergoemacs-timeout>") 
'ergoemacs-cut-line-or-region)
-        )
-    )
-  (global-set-key (kbd "<C-insert>") 'ergoemacs-copy-line-or-region)
-  (global-set-key (kbd "C-S-v") 'ergoemacs-paste-cycle)
-  
-  (global-set-key (kbd "<S-insert>") 'ergoemacs-paste)
-  (global-set-key (kbd "C-v") 'ergoemacs-paste))
-
-(ergoemacs-theme lvl1 ()
-  "Arrow Key Movements Only"
-  :components '(move-char))
-
-(ergoemacs-theme lvl2 ()
-  "Arrow Key Movements, Moving/Deleting Words"
-  :components '(move-char
-                move-word))
-
-
-(ergoemacs-component join-line ()
-  "Join Line"; Thanks for the suggestion tuhdo
-  ;;I suggest the key bindings for joining lines are Alt + [ to
-  ;;join-top-line and Alt + ] for stock join-line.
-  (global-set-key (kbd "M-]") 'delete-indentation)
-  (global-set-key (kbd "M-[") 'ergoemacs-top-join-line))
-
-(ergoemacs-component isearch-arrows ()
-  "Set arrow keys in isearch."
-  ;;left/right is backward/forward, up/down is history. press Return
-  ;;to exit
-  ;; Xah Lee
-  ;; See http://ergoemacs.org/emacs/emacs_isearch_by_arrow_keys.html
-  (define-key isearch-mode-map (kbd "<up>") 'isearch-ring-retreat)
-  (define-key isearch-mode-map (kbd "<down>") 'isearch-ring-advance)
-  ;; single key, useful
-  (define-key isearch-mode-map (kbd "<left>") 'isearch-repeat-backward)
-  ;; single key, useful
-  (define-key isearch-mode-map (kbd "<right>") 'isearch-repeat-forward))
-
-(ergoemacs-component mode-line-major-mode-switch ()
-  "Switch major modes by clicking mode-name."
-  (setq ergoemacs-swap-major-modes-when-clicking-major-mode-name t))
-
-
-(ergoemacs-autoload multiple-cursors
-    "Multiple Cursors"
-    :bind (("M-*" mc/mark-next-like-this)
-           ("M-&" mc/edit-lines))
-    :ensure t)
-
-(ergoemacs-autoload avy
-    "Avy"
-    :bind ("M-," 'avy-goto-word-or-subword-1)
-    :ensure t)
-
-(ergoemacs-autoload expand-region
-    "Expand Region"
-    :bind (("M-8" er/expand-region)
-           ("M-9" er/contract-region)
-           ("M-*". er/mark-inside-quotes))
-    :ensure t)
-
-
-(ergoemacs-theme standard ()
-  "Standard Ergoemacs Theme"
-  :components '(copy
-                dired-tab
-                dired-to-wdired
-                execute
-                fixed-newline
-                help
-                kill-line
-                misc
-                move-bracket
-                move-buffer
-                move-char
-                move-line
-                move-page
-                move-paragraph
-                move-word
-                search
-                select-items
-                switch
-                text-transform
-                ergoemacs-remaps
-                standard-vars)
-  :optional-on '(apps-punctuation
-                 tab-indents-region
-                 icy-reclaim
-                 apps-apps
-                 apps-toggle
-                 apps
-                 backspace-del-seq
-                 backspace-is-back
-                 fn-keys
-                 f2-edit
-                 fixed-bold-italic
-                 standard-fixed
-                 ido-remaps
-                 helm-remaps
-                 helm-find-files
-                 multiple-cursors-remaps
-                 quit
-                 apps-swap
-                 ;;save-options-on-exit
-                 ;; Reverse menu-bar order
-                 menu-bar-help
-                 menu-bar-languages
-                 menu-bar-view
-                 menu-bar-search
-                 menu-bar-edit
-                 menu-bar-file
-                mode-line-major-mode-switch
-                 )
-  :optional-off '(guru
-                  alt-backspace-is-undo
-                  search-reg
-                  no-backspace
-                  helm-switch-sources
-                  ergoemacs-banish-shift
-                  move-and-transpose-lines
-                  move-sexp
-                  ido-prev-next-instead-of-left-right
-                  join-line
-                 save-options-on-exit
-                  isearch-arrows
-                 ergoemacs-swiper)
-  :options-menu '(("Menu/Apps Key" (apps apps-apps apps-punctuation 
apps-toggle))
-                  ("Function Keys" (fn-keys f2-edit))
-                  ("Helm Options" (helm-switch-sources helm-find-files))
-                  ("Remaps" (ido-remaps helm-remaps multiple-cursors-remaps 
icy-reclaim ergoemacs-swiper))
-                  ("Extreme ErgoEmacs" (guru no-backspace 
ergoemacs-banish-shift))
-                  ("Standard Keys" (standard-fixed fixed-bold-italic quit 
move-and-transpose-lines alt-backspace-is-undo))
-                  ("Keys during Key Sequence" (f2-edit apps-swap 
backspace-del-seq))
-                  ("Disputed Keys" (ido-prev-next-instead-of-left-right 
move-sexp))
-                  ("Extra Functionality" (join-line isearch-arrows))
-                  ("Packages" (avy multiple-cursors expand-region))
-                 ("Mode Line" (mode-line-major-mode-switch))
-                  ("Ergoemacs global menus" (menu-bar-file menu-bar-edit 
menu-bar-search menu-bar-view menu-bar-languages menu-bar-help))))
-
-(ergoemacs-theme reduction ()
-  "Reduce Ergoemacs keys"
-  :based-on 'standard
-  :components '(multiple-cursors avy expand-region)
-  (global-set-key (kbd "M-<") 'zap-to-char)
-  (global-set-key (kbd "M-g") 'kill-line)
-  (global-set-key (kbd "M-G") 'ergoemacs-top-join-line)
-  (global-set-key (kbd "M-b") 'ergoemacs-kill-line-backward)
-  (global-set-key (kbd "M-B") 'delete-indentation)
-  (global-set-key (kbd "M-.") 'ergoemacs-end-of-line-or-what)
-  (global-set-key (kbd "M-m") 'ergoemacs-beginning-of-line-or-what)
-  (global-set-key (kbd "M-y") 'isearch-backward)
-  (global-set-key (kbd "M-Y") 'isearch-backward-regexp)
-  (global-set-key (kbd "M-h") 'isearch-forward)
-  (global-set-key (kbd "M-H") 'isearch-forward-regexp)
-  (global-set-key (kbd "M-a") 'ergoemacs-move-cursor-previous-pane)
-  (global-set-key (kbd "M-;") 'execute-extended-command)
-  ;;
-  ;; Overwrite previous global definitions in `ergoemacs-mode'
-  ;;
-  (define-key ergoemacs-keymap (kbd "M-T") nil)
-  (define-key ergoemacs-keymap (kbd "M-I") nil)
-  (define-key ergoemacs-keymap (kbd "M-K") nil)
-  (define-key ergoemacs-keymap (kbd "M-U") nil)
-  (define-key ergoemacs-keymap (kbd "M-O") nil)
-  (define-key ergoemacs-keymap (kbd "M-N") nil)
-  ;; (define-key ergoemacs-keymap (kbd "M-G") nil)
-  ;; (define-key ergoemacs-keymap (kbd "M-S") nil)
-  (define-key ergoemacs-keymap (kbd "M-A") nil)
-  (define-key ergoemacs-keymap (kbd "M-J") nil)
-  (define-key ergoemacs-keymap (kbd "M-L") nil))
+
+(defun ergoemacs-handle-M-O ()
+  "Handle meta+O input.
+In a terminal, this can be either arrow keys (e.g. meta+O A == <up>) or 
regular meta+O keybinding."
+  (interactive)
+  (if (input-pending-p)
+      (let ((second-char (read-char)))
+        (cond
+         ((eq second-char 65) ;; A
+          (execute-kbd-macro (kbd "<up>")))
+         ((eq second-char 66) ;; B
+          (execute-kbd-macro (kbd "<down>")))
+         ((eq second-char 67) ;; C
+          (execute-kbd-macro (kbd "<right>")))
+         ((eq second-char 68) ;; D
+          (execute-kbd-macro (kbd "<left>")))
+         ((eq second-char 72) ;; H
+          (execute-kbd-macro (kbd "<home>")))
+         ((eq second-char 70) ;; F
+          (execute-kbd-macro (kbd "<end>")))
+         (t
+          (beep))))
+    (call-interactively ergoemacs-M-O-binding)))
+
+(defvar ergoemacs-M-O-binding () nil)
+(defun ergoemacs-fix-arrow-keys (keymap)
+  "Fix arrow keys for KEYMAP."
+  (setq ergoemacs-M-O-binding (lookup-key keymap (kbd "M-O")))
+  (if ergoemacs-M-O-binding
+      (define-key keymap (kbd "M-O") 'ergoemacs-handle-M-O)))
+
+(defvar ergoemacs-override-keymap)
+
+(defun ergoemacs-install-isearch-mode ()
+  "Installs keys for isearch mode."
+  (ergoemacs-save-key-state
+   'isearch-mode-map
+   (ergoemacs-unset-keys-in-map isearch-mode-map)
+   (define-key isearch-mode-map (kbd "C-x C-q") 'isearch-edit-string)
+   (define-key isearch-mode-map (kbd "<f2>") 'isearch-edit-string)
+   ;; Mode specific changes
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key isearch-mode-map (kbd "C-M-:") 'isearch-occur)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-d") 
'isearch-delete-char)
+         (ergoemacs-define-key isearch-mode-map (kbd "DEL") 
'isearch-delete-char)
+         (ergoemacs-define-key isearch-mode-map (kbd "<menu> v") 
'isearch-yank-kill)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-v") 'isearch-yank-kill)
+         (ergoemacs-define-key isearch-mode-map (kbd "C-v") 'isearch-yank-kill)
+         (ergoemacs-define-key isearch-mode-map (kbd "<S-insert>") 
'isearch-yank-kill)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-V") 'isearch-yank-pop)
+         (ergoemacs-define-key isearch-mode-map (kbd "C-S-v") 
'isearch-yank-pop)
+         (ergoemacs-define-key isearch-mode-map (kbd "<menu> 5") 
'isearch-query-replace)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-5") 
'isearch-query-replace)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-h") 
'isearch-repeat-forward)
+         (ergoemacs-define-key isearch-mode-map (kbd "C-e") 
'isearch-repeat-forward)
+         (ergoemacs-define-key isearch-mode-map (kbd "C-M-d") 
'isearch-repeat-forward)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-y") 
'isearch-repeat-backward)
+         (ergoemacs-define-key isearch-mode-map (kbd "C-M-s") 
'isearch-repeat-backward)
+         (ergoemacs-define-key isearch-mode-map (kbd "M-t") 'isearch-complete))
+     (ergoemacs-define-key isearch-mode-map (kbd "M-n") 
'isearch-beginning-oef-buffer)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-N") 'isearch-end-of-buffer)
+     (ergoemacs-define-key isearch-mode-map (kbd "C-M-:") 'isearch-occur)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-d") 'isearch-delete-char)
+     (ergoemacs-define-key isearch-mode-map (kbd "DEL") 'isearch-delete-char)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-v") 'isearch-yank-kill)
+     (ergoemacs-define-key isearch-mode-map (kbd "C-v") 'isearch-yank-kill)
+     (ergoemacs-define-key isearch-mode-map (kbd "<S-insert>") 
'isearch-yank-kill)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-V") 'isearch-yank-pop)
+     (ergoemacs-define-key isearch-mode-map (kbd "C-S-v") 'isearch-yank-pop)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-5") 'isearch-query-replace)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-;") 
'isearch-repeat-forward)
+     (ergoemacs-define-key isearch-mode-map (kbd "C-e") 
'isearch-repeat-forward)
+     (ergoemacs-define-key isearch-mode-map (kbd "C-M-d") 
'isearch-repeat-forward)
+     (ergoemacs-define-key isearch-mode-map (kbd "C-M-s") 
'isearch-repeat-backward)
+     (ergoemacs-define-key isearch-mode-map (kbd "M-t") 'isearch-complete)))
+  (ergoemacs-save-key-state
+   'minibuffer-local-isearch-map
+   (define-key minibuffer-local-isearch-map [remap isearch-forward] 
'isearch-forward-exit-minibuffer)
+   (define-key minibuffer-local-isearch-map [remap isearch-backward] 
'isearch-reverse-exit-minibuffer)))
+
+
+
+
+(defun ergoemacs-install-reduction-theme ()
+  "Install reduction theme."
+  (ergoemacs-unset-keys ergoemacs-override-keymap)
+  (ergoemacs-set-standard-vars)
+
+  (ergoemacs-set-standard-fixed ergoemacs-override-keymap)
+  (ergoemacs-set-help ergoemacs-override-keymap)
+  (ergoemacs-set-move-char ergoemacs-override-keymap)
+  (ergoemacs-set-move-buffer-reduction ergoemacs-override-keymap)
+  (ergoemacs-set-move-bracket ergoemacs-override-keymap)
+  (ergoemacs-set-move-word ergoemacs-override-keymap)
+  ;;(ergoemacs-set-move-paragraph ergoemacs-override-keymap)
+  ;;(ergoemacs-set-move-line ergoemacs-override-keymap)
+  ;;(ergoemacs-set-move-page ergoemacs-override-keymap)
+  ;;(ergoemacs-set-move-buffer ergoemacs-override-keymap)
+  (ergoemacs-set-move-bracket-reduction ergoemacs-override-keymap)
+  (ergoemacs-set-copy ergoemacs-override-keymap)
+  (ergoemacs-set-search-reduction ergoemacs-override-keymap)
+  (ergoemacs-set-switch-reduction ergoemacs-override-keymap)
+  (ergoemacs-set-execute-reduction ergoemacs-override-keymap)
+  ;;(ergoemacs-set-misc ergoemacs-override-keymap)
+  (ergoemacs-set-move-extra-reduction ergoemacs-override-keymap)
+  (ergoemacs-set-kill-line ergoemacs-override-keymap)
+  (ergoemacs-set-text-transform ergoemacs-override-keymap)
+  (ergoemacs-set-select-items ergoemacs-override-keymap)
+  (ergoemacs-fix-arrow-keys ergoemacs-override-keymap)
+  (ergoemacs-set-apps ergoemacs-override-keymap)
+
+  (ergoemacs-install-isearch-mode)
+
+  (ergoemacs-set-remaps ergoemacs-override-keymap)
+  (ergoemacs-set-quit)
+  (ergoemacs-set-menu-bar-help)
+  (ergoemacs-set-menu-bar-view)
+  (ergoemacs-set-menu-bar-search)
+  (ergoemacs-set-menu-bar-edit)
+  (ergoemacs-set-menu-bar-file))
+
+(defun ergoemacs-install-standard-theme ()
+  "Install standard ergoemacs-mode theme."
+  (ergoemacs-unset-keys ergoemacs-override-keymap)
+  (ergoemacs-set-standard-vars)
+
+  (ergoemacs-set-standard-fixed ergoemacs-override-keymap)
+  (ergoemacs-set-help ergoemacs-override-keymap)
+  (ergoemacs-set-move-char ergoemacs-override-keymap)
+  (ergoemacs-set-move-buffer ergoemacs-override-keymap)
+  (ergoemacs-set-move-bracket ergoemacs-override-keymap)
+  (ergoemacs-set-move-word ergoemacs-override-keymap)
+  (ergoemacs-set-move-paragraph ergoemacs-override-keymap)
+  (ergoemacs-set-move-line ergoemacs-override-keymap)
+  (ergoemacs-set-move-page ergoemacs-override-keymap)
+  (ergoemacs-set-move-buffer ergoemacs-override-keymap)
+  (ergoemacs-set-move-bracket ergoemacs-override-keymap)
+  (ergoemacs-set-copy ergoemacs-override-keymap)
+  (ergoemacs-set-search ergoemacs-override-keymap)
+  (ergoemacs-set-switch ergoemacs-override-keymap)
+  (ergoemacs-set-execute ergoemacs-override-keymap)
+  (ergoemacs-set-misc ergoemacs-override-keymap)
+  (ergoemacs-set-kill-line ergoemacs-override-keymap)
+  (ergoemacs-set-text-transform ergoemacs-override-keymap)
+  (ergoemacs-set-select-items ergoemacs-override-keymap)
+  (ergoemacs-fix-arrow-keys ergoemacs-override-keymap)
+  (ergoemacs-install-isearch-mode)
+  (ergoemacs-set-remaps ergoemacs-override-keymap)
+  (ergoemacs-set-quit)
+  (ergoemacs-set-menu-bar-help)
+  (ergoemacs-set-menu-bar-view)
+  (ergoemacs-set-menu-bar-search)
+  (ergoemacs-set-menu-bar-edit)
+  (ergoemacs-set-menu-bar-file))
+
+(defvar org-mode-map )
+(defun ergoemacs-install-org-bindings ()
+  "Install the `org-mode' bindings."
+  (ergoemacs-save-key-state
+   'org-mode-map
+   (define-key org-mode-map (kbd "<C-return>") 
'ergoemacs-org-insert-heading-respect-content)
+   (define-key org-mode-map (kbd "<M-down>") 'ergoemacs-org-metadown)
+   (define-key org-mode-map (kbd "<M-up>") 'ergoemacs-org-metaup)
+   (define-key org-mode-map (kbd "<M-left>") 'ergoemacs-org-metaleft)
+   (define-key org-mode-map (kbd "<M-right>") 'ergoemacs-org-metaright)
+   (define-key org-mode-map (kbd "<M-RET>") 'org-insert-item)
+
+   ;; How to do bold and italic?  I do not like using Control keys
+   ;; C-i is TAB... This seems to cause issues?
+   ;; (define-key org-mode-map (kbd "C-b") 'ergoemacs-org-bold)
+   ;; (define-key org-mode-map (kbd "C-i") 'ergoemacs-org-italic)
+
+   (define-key org-mode-map [remap beginning-of-line] 'org-beginning-of-line)
+   (define-key org-mode-map [remap end-of-line] 'org-end-of-line)
+   (define-key org-mode-map [remap forward-paragraph] 'org-forward-paragraph)
+   (define-key org-mode-map [remap backward-paragraph] 'org-backward-paragraph)
+   (define-key org-mode-map [remap ergoemacs-paste] 'ergoemacs-org-yank)
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key org-mode-map (kbd "<C-up>") 
'org-backward-element)
+         (ergoemacs-define-key org-mode-map (kbd "<C-down>") 
'org-forward-element)
+         (ergoemacs-define-key org-mode-map (kbd "<M-up>") 
'org-backward-element)
+         (ergoemacs-define-key org-mode-map (kbd "<M-down>") 
'org-forward-element))
+     (ergoemacs-define-key org-mode-map (kbd "M-U") 'org-backward-element)
+     (ergoemacs-define-key org-mode-map (kbd "<C-up>") 'org-backward-element)
+     (ergoemacs-define-key org-mode-map (kbd "M-O") 'org-forward-element)
+     (ergoemacs-define-key org-mode-map (kbd "<C-down>") 'org-forward-element)
+     (ergoemacs-define-key org-mode-map (kbd "<M-up>") 'org-backward-element)
+     (ergoemacs-define-key org-mode-map (kbd "<M-down>") 
'org-forward-element))))
+
+(add-hook 'org-load-hook #'ergoemacs-install-org-bindings)
+
+(defvar compilation-mode-map)
+(defun ergoemacs-install-compilation-minor-mode ()
+  "Install `compilation-minor-mode' bindings.
+This affects modes like `grep-mode' since this is a parent keymap"
+  (ergoemacs-save-key-state
+   'compilation-mode-map
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key compilation-mode-map (kbd "M-d") 
'scroll-down-command)
+         (ergoemacs-define-key compilation-mode-map (kbd "DEL") 
'scroll-down-command)
+         (ergoemacs-define-key compilation-mode-map (kbd "<C-up>") 
'compilation-previous-file)
+         (ergoemacs-define-key compilation-mode-map (kbd "<C-down>") 
'compilation-next-file)
+         (ergoemacs-define-key compilation-mode-map (kbd "<M-up>") 
'compilation-previous-file)
+         (ergoemacs-define-key compilation-mode-map (kbd "<M-down>") 
'compilation-next-file))
+     (ergoemacs-define-key compilation-mode-map (kbd "M-d") 
'scroll-down-command)
+     (ergoemacs-define-key compilation-mode-map (kbd "DEL") 
'scroll-down-command)
+     (ergoemacs-define-key compilation-mode-map (kbd "M-U") 
'compilation-previous-file)
+     (ergoemacs-define-key compilation-mode-map (kbd "<C-up>") 
'compilation-previous-file)
+     (ergoemacs-define-key compilation-mode-map (kbd "M-O") 
'compilation-next-file)
+     (ergoemacs-define-key compilation-mode-map (kbd "<C-down>") 
'compilation-next-file)
+     (ergoemacs-define-key compilation-mode-map (kbd "<M-up>") 
'compilation-previous-file)
+     (ergoemacs-define-key compilation-mode-map (kbd "<M-down>") 
'compilation-next-file))))
+
+(with-eval-after-load 'compile (ergoemacs-install-compilation-minor-mode))
+
+(defvar log-edit-mode-map)
+(defun ergoemacs-install-log-edit-bindings ()
+  "Install `log-edit' key bindings."
+  (ergoemacs-save-key-state
+   'log-edit-mode-map
+   (define-key log-edit-mode-map [remap save-buffer] 'log-edit-done)
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key log-edit-mode-map (kbd "M-m") 
'log-edit-beginning-of-line)
+         (ergoemacs-define-key log-edit-mode-map (kbd "<home>") 
'log-edit-beginning-of-line))
+     (ergoemacs-define-key log-edit-mode-map (kbd "<home>") 
'log-edit-beginning-of-line)
+     (ergoemacs-define-key log-edit-mode-map (kbd "M-h") 
'log-edit-beginning-of-line))))
+
+(with-eval-after-load 'log-edit (ergoemacs-install-log-edit-bindings))
+
+(defvar eshell-mode-map)
+(defun ergoemacs-install-eshell-bindings ()
+  "Install `eshell' bindings."
+  (ergoemacs-save-key-state
+   'eshell-mode-map
+   (define-key eshell-mode-map [remap move-beginning-of-line] 'eshell-bol)
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key eshell-mode-map (kbd "M-m") 'eshell-bol)
+         (ergoemacs-define-key eshell-mode-map (kbd "<home>") 'eshell-bol)
+         (ergoemacs-define-key eshell-mode-map (kbd "M-t") 
'eshell-complete-lisp-symbol))
+     (ergoemacs-define-key eshell-mode-map (kbd "<home>") 'eshell-bol)
+     (ergoemacs-define-key eshell-mode-map (kbd "M-h") 'eshell-bol)
+     (ergoemacs-define-key eshell-mode-map (kbd "M-t") 
'eshell-complete-lisp-symbol))))
+
+(add-hook 'eshell-post-command-hook #'ergoemacs-install-eshell-bindings)
+
+(defun ergoemacs-install-comint-bindings ()
+  "Install comint key bindings."
+  (ergoemacs-save-key-state
+   'comint-mode-map
+   (define-key comint-mode-map [remap move-beginning-of-line] 'comint-bol)
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key comint-mode-map (kbd "<delete>") 
'comint-delchar-or-maybe-eof)
+         (ergoemacs-define-key comint-mode-map (kbd "M-f") 
'comint-delchar-or-maybe-eof)
+         (ergoemacs-define-key comint-mode-map (kbd "C-g") 
'comint-delchar-or-maybe-eof))
+     (ergoemacs-define-key comint-mode-map (kbd "<delete>") 
'comint-delchar-or-maybe-eof)
+     (ergoemacs-define-key comint-mode-map (kbd "M-f") 
'comint-delchar-or-maybe-eof)
+     (ergoemacs-define-key comint-mode-map (kbd "C-g") 
'comint-delchar-or-maybe-eof))))
+
+(with-eval-after-load 'comint (ergoemacs-install-comint-bindings))
+
+(defun ergoemacs-install-dired-bindings ()
+  "Install `dired-mode-map' bindings."
+  (ergoemacs-save-key-state
+   'dired-mode-map
+   (define-key dired-mode-map [remap query-replace] 
'dired-do-query-replace-regexp)
+   (define-key dired-mode-map [remap query-replace-regexp] 
'dired-do-query-replace-regexp)
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key dired-mode-map (kbd "M-d") 
'dired-unmark-backward)
+         (ergoemacs-define-key dired-mode-map (kbd "DEL") 
'dired-unmark-backward)
+         (ergoemacs-define-key dired-mode-map (kbd "M-e") 
'dired-unmark-all-files)
+         (ergoemacs-define-key dired-mode-map (kbd "<C-backspace>") 
'dired-unmark-all-files)
+         (ergoemacs-define-key dired-mode-map (kbd "M-DEL") 
'dired-unmark-all-files)
+         (ergoemacs-define-key dired-mode-map (kbd "<C-up>") 
'dired-prev-marked-file)
+         (ergoemacs-define-key dired-mode-map (kbd "<C-down>") 
'dired-next-marked-file)
+         (ergoemacs-define-key dired-mode-map (kbd "<M-up>") 
'dired-prev-marked-file)
+         (ergoemacs-define-key dired-mode-map (kbd "<M-down>") 
'dired-next-marked-file))
+     (ergoemacs-define-key dired-mode-map (kbd "M-d") 'dired-unmark-backward)
+     (ergoemacs-define-key dired-mode-map (kbd "DEL") 'dired-unmark-backward)
+     (ergoemacs-define-key dired-mode-map (kbd "M-e") 'dired-unmark-all-files)
+     (ergoemacs-define-key dired-mode-map (kbd "<C-backspace>") 
'dired-unmark-all-files)
+     (ergoemacs-define-key dired-mode-map (kbd "M-DEL") 
'dired-unmark-all-files)
+     (ergoemacs-define-key dired-mode-map (kbd "M-U") 'dired-prev-marked-file)
+     (ergoemacs-define-key dired-mode-map (kbd "<C-up>") 
'dired-prev-marked-file)
+     (ergoemacs-define-key dired-mode-map (kbd "M-O") 'dired-next-marked-file)
+     (ergoemacs-define-key dired-mode-map (kbd "<C-down>") 
'dired-next-marked-file)
+     (ergoemacs-define-key dired-mode-map (kbd "<M-up>") 
'dired-prev-marked-file)
+     (ergoemacs-define-key dired-mode-map (kbd "<M-down>") 
'dired-next-marked-file))))
+(add-hook 'dired-load-hook #'ergoemacs-install-dired-bindings)
+
+(defvar calc-mode-map)
+(defun ergoemacs-install-calc-bindings ()
+  "Install `calc-mode' bindings."
+  (ergoemacs-save-key-state
+   'comint-mode-map
+   (define-key calc-mode-map [remap ergoemacs-undo] 'calc-undo)
+   (if (string-equal ergoemacs-theme "reduction")
+       (progn
+         (ergoemacs-define-key calc-mode-map (kbd "M-d") 'calc-pop)
+         (ergoemacs-define-key calc-mode-map (kbd "DEL") 'calc-pop)
+         (ergoemacs-define-key calc-mode-map (kbd "<delete>") 'calc-pop)
+         (ergoemacs-define-key calc-mode-map (kbd "M-f") 'calc-pop)
+         (ergoemacs-define-key calc-mode-map (kbd "C-g") 'calc-pop)
+         (ergoemacs-define-key calc-mode-map (kbd "M-e") 'calc-pop-above)
+         (ergoemacs-define-key calc-mode-map (kbd "<C-backspace>") 
'calc-pop-above)
+         (ergoemacs-define-key calc-mode-map (kbd "M-DEL") 'calc-pop-above)
+         (ergoemacs-define-key calc-mode-map (kbd "<C-insert>") 
'calc-copy-region-as-kill)
+         (ergoemacs-define-key calc-mode-map (kbd "<menu> c") 
'calc-copy-region-as-kill)
+         (ergoemacs-define-key calc-mode-map (kbd "M-c") 
'calc-copy-region-as-kill)
+         (ergoemacs-define-key calc-mode-map (kbd "<S-insert>") 'calc-yank)
+         (ergoemacs-define-key calc-mode-map (kbd "C-v") 'calc-yank)
+         (ergoemacs-define-key calc-mode-map (kbd "<remap> <cua-paste>") 
'calc-yank)
+         (ergoemacs-define-key calc-mode-map (kbd "<menu> v") 'calc-yank)
+         (ergoemacs-define-key calc-mode-map (kbd "M-v") 'calc-yank)
+         (ergoemacs-define-key calc-mode-map (kbd "<menu> 5") 'calc-percent)
+         (ergoemacs-define-key calc-mode-map (kbd "M-5") 'calc-percent)
+         (ergoemacs-define-key calc-mode-map (kbd "M-g") 'calc-kill)
+         (ergoemacs-define-key calc-mode-map (kbd "<deleteline>") 'calc-kill)
+         (ergoemacs-define-key calc-mode-map (kbd "M-t") 'calc-roll-up))
+     (ergoemacs-define-key calc-mode-map (kbd "M-d") 'calc-pop)
+     (ergoemacs-define-key calc-mode-map (kbd "DEL") 'calc-pop)
+     (ergoemacs-define-key calc-mode-map (kbd "<delete>") 'calc-pop)
+     (ergoemacs-define-key calc-mode-map (kbd "M-f") 'calc-pop)
+     (ergoemacs-define-key calc-mode-map (kbd "C-g") 'calc-pop)
+     (ergoemacs-define-key calc-mode-map (kbd "M-e") 'calc-pop-above)
+     (ergoemacs-define-key calc-mode-map (kbd "<C-backspace>") 'calc-pop-above)
+     (ergoemacs-define-key calc-mode-map (kbd "M-DEL") 'calc-pop-above)
+     (ergoemacs-define-key calc-mode-map (kbd "<C-insert>") 
'calc-copy-region-as-kill)
+     (ergoemacs-define-key calc-mode-map (kbd "M-c") 'calc-copy-region-as-kill)
+     (ergoemacs-define-key calc-mode-map (kbd "<S-insert>") 'calc-yank)
+     (ergoemacs-define-key calc-mode-map (kbd "C-v") 'calc-yank)
+     (ergoemacs-define-key calc-mode-map (kbd "<remap> <cua-paste>") 
'calc-yank)
+     (ergoemacs-define-key calc-mode-map (kbd "M-v") 'calc-yank)
+     (ergoemacs-define-key calc-mode-map (kbd "M-5") 'calc-percent)
+     (ergoemacs-define-key calc-mode-map (kbd "M-g") 'calc-kill)
+     (ergoemacs-define-key calc-mode-map (kbd "<deleteline>") 'calc-kill)
+     (ergoemacs-define-key calc-mode-map (kbd "M-t") 'calc-roll-up))))
+
+(add-hook 'calc-load-hook #'ergoemacs-install-calc-bindings)
 
 (ergoemacs-translation normal ()
   "Identify transformation"
@@ -2066,14 +1547,14 @@
 
 (ergoemacs-translation ctl-to-alt ()
   "Ctl <-> Alt translation"
-  :text (lambda() (format "<Ctl%sAlt> " (ergoemacs :unicode-or-alt "↔" " to 
")))
-  
+  :text  "<Ctl↔Alt> "
+
   :meta '(control)
   :control '(meta)
-  
+
   :meta-shift '(control shift)
   :control-shift '(meta shift)
-  
+
   :control-hyper '(meta hyper)
   :meta-hyper '(control hyper)
 
@@ -2091,10 +1572,10 @@
 
   :meta-super-hyper-shift '(control super hyper shift)
   :control-super-hyper-shift '(meta super hyper shift)
-  
+
   :modal-color "blue"
   :modal-always t
-  
+
   :keymap (let ((map (make-sparse-keymap)))
             (define-key map [f1] 'ergoemacs-read-key-help)
             (define-key map (read-kbd-macro "M-h") 'ergoemacs-read-key-help)
@@ -2123,19 +1604,14 @@
 (ergoemacs-translation unchorded-alt ()
   "Make the Alt key sticky."
   :text "<Alt+>"
-  :unchorded '(meta) 
+  :unchorded '(meta)
   :shift '(meta shift)
-  :meta '(meta shift) 
+  :meta '(meta shift)
   :modal-color "red"
   :keymap-modal (let ((map (make-sparse-keymap)))
                   (define-key map (read-kbd-macro "<return>") 
'ergoemacs-unchorded-alt-modal)
                   (define-key map (read-kbd-macro "RET") 
'ergoemacs-unchorded-alt-modal)
                   map))
 
-
 (provide 'ergoemacs-themes)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; ergoemacs-themes.el ends here
-;; Local Variables:
-;; coding: utf-8-emacs
-;; End:
diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el
index 0770c0a..31e9231 100644
--- a/ergoemacs-translate.el
+++ b/ergoemacs-translate.el
@@ -97,13 +97,13 @@
   "Gets the translation hash."
   (let* ((to (ergoemacs :layout  (or layout-to ergoemacs-keyboard-layout)))
          (from (ergoemacs :layout  (or layout-from "us")))
-         (hash-f (ergoemacs-gethash from ergoemacs-translate--hash 
(make-hash-table)))
-         (hash-f-t (ergoemacs-gethash to hash-f))
+         (hash-f (gethash from ergoemacs-translate--hash (make-hash-table)))
+         (hash-f-t (gethash to hash-f))
          (i 0)
          hash-t hash-t-f lay-t lay-f r-t r-f)
     (if hash-f-t hash-f-t
       (setq hash-f-t (make-hash-table)
-            hash-t (ergoemacs-gethash to ergoemacs-translate--hash 
(make-hash-table))
+            hash-t (gethash to ergoemacs-translate--hash (make-hash-table))
             hash-t-f (make-hash-table)
             lay-t (symbol-value to)
             lay-f (symbol-value from))
@@ -332,7 +332,7 @@ This uses `ergoemacs-translate--apply-key'"
 (defun ergoemacs-translate--event-modifier-hash (&optional layout)
   "Gets the event modifier hash for LAYOUT."
   (let* ((layout-symbol (ergoemacs :layout  layout))
-         (hash (ergoemacs-gethash layout-symbol 
ergoemacs-translate--event-hash)))
+         (hash (gethash layout-symbol ergoemacs-translate--event-hash)))
     (if hash hash
       ;; Not present setup modifier hash
       (setq hash (make-hash-table))
@@ -364,7 +364,7 @@ LAYOUT is the keyboard layout."
     (unless (memq 'shift modifiers)
       ;; Add 'shift for # type events.
       (setq basic (event-basic-type event))
-      (when (ergoemacs-gethash basic (ergoemacs-translate--event-modifier-hash 
layout))
+      (when (gethash basic (ergoemacs-translate--event-modifier-hash layout))
         (push 'ergoemacs-shift modifiers)))
     ;; Add 'ergoemacs-gui to the modifiers
     (when (and (symbolp event)
@@ -427,8 +427,8 @@ MODIFIERS is the precalculated modifiers from
               (if (not (memq m '(shift ergoemacs-shift)))
                   (push m new-modifiers)
                 (setq new-event (ergoemacs-translate--event-convert-list (list 
m basic) layout-from))
-                (setq new-event (or (ergoemacs-gethash new-event 
translation-hash) new-event))))
-          (setq new-event (or (ergoemacs-gethash basic translation-hash) basic)
+                (setq new-event (or (gethash new-event translation-hash) 
new-event))))
+          (setq new-event (or (gethash basic translation-hash) basic)
                 new-modifiers modifiers)))
       (ergoemacs-translate--event-convert-list (append new-modifiers (list 
new-event)) layout-to))))
 
@@ -440,7 +440,7 @@ This is different than `event-basic-type' because ?# would 
return
 This also translates <C-i> to ?i, <C-m> to ?m <C-[> to ?[
 "
   (let* ((basic (event-basic-type event))
-         (new-basic (and basic (ergoemacs-gethash basic 
(ergoemacs-translate--event-modifier-hash layout)))))
+         (new-basic (and basic (gethash basic 
(ergoemacs-translate--event-modifier-hash layout)))))
     (or new-basic basic
         (and (symbolp event)
              (setq basic (symbol-name event))
@@ -481,7 +481,7 @@ This is different than `event-convert-list' because:
          ((and cur-list (memq elt '(shift ergoemacs-shift))))
          
          ((and (not cur-list)
-               (setq tmp (ergoemacs-gethash (intern (format "s%s" elt))
+               (setq tmp (gethash (intern (format "s%s" elt))
                                   (ergoemacs-translate--event-modifier-hash 
layout))))
           ;; Special case.
           (setq new-list (append new-list (list tmp))))
@@ -755,8 +755,6 @@ When NAME is a symbol, setup the translation function for 
the symbol."
              ',(intern (concat "ergoemacs-translate--" name-str "-map"))
             "Ergoemacs-v5.16")))
        t)
-      (ergoemacs-map-properties--label-map (intern (concat 
"ergoemacs-translate--" name-str "-map")) t)
-      (ergoemacs (symbol-value (intern (concat "ergoemacs-translate--" 
name-str "-map"))) :only-local-modifications-p t)
       ;; 
       (dolist (type '("-universal-argument" "-negative-argument"
                       "-digit-argument" "-modal"))
@@ -779,13 +777,7 @@ When NAME is a symbol, setup the translation function for 
the symbol."
         -digit-argument
         -modal
         translation
-        (local-keymap (or (plist-get plist :keymap) (make-sparse-keymap)))
-       (trans-keymap (intern (concat "ergoemacs-translate--" (plist-get plist 
:name) "-map"))))
-    (when (ergoemacs-keymapp trans-keymap)
-      (set-keymap-parent (setq trans-keymap (symbol-value trans-keymap)) 
local-keymap)
-      (ergoemacs trans-keymap :only-local-modifications-p t))
-    ;; (ergoemacs :label local-keymap)
-    ;; (ergoemacs local-keymap :only-local-modifications-p t)
+        (local-keymap (or (plist-get plist :keymap) (make-sparse-keymap))))
     (let (tmp
           cur-trans
           ret)
@@ -836,7 +828,7 @@ When NAME is a symbol, setup the translation function for 
the symbol."
 
 (defun ergoemacs-translate--get (type)
   "Get translation object TYPE."
-  (let ((ret (ergoemacs-gethash type ergoemacs-translation-hash)))
+  (let ((ret (gethash type ergoemacs-translation-hash)))
     (cond
      ((and ret (ergoemacs-translation-struct-p ret))
       ret)
@@ -907,34 +899,12 @@ If there are no gui elements, return nil."
            (push elt new-mod)))
        (ergoemacs-translate--event-convert-list `(,@new-mod 
,last-basic-event))))))
 
-(defvar ergoemacs-translate--parent-map nil
+(defvar ergoemacs-translate--parent-map (make-sparse-keymap)
   "Parent map for keymaps when completing a key sequence.")
 
-(defun ergoemacs-translate--parent-map ()
-  (or ergoemacs-translate--parent-map
-      (let ((map (make-sparse-keymap)))
-       (setq ergoemacs-translate--parent-map map)
-        (ergoemacs map :label)
-        (ergoemacs map :only-local-modifications-p t)
-        (ergoemacs map :map-list-hash '(ergoemacs-translate--parent-map))
-        map)))
-
-(add-hook 'ergoemacs-mode-intialize-hook #'ergoemacs-translate--parent-map)
-
-
-(defvar ergoemacs-translate--modal-parent-map nil
+(defvar ergoemacs-translate--modal-parent-map (make-sparse-keymap)
   "Parent map for modal `ergoemacs-mode'")
 
-(defun ergoemacs-translate--modal-parent-map ()
-  (or ergoemacs-translate--modal-parent-map
-      (let ((map (make-sparse-keymap)))
-       (setq ergoemacs-translate--modal-parent-map map)
-        (ergoemacs map :label)
-        (ergoemacs map :only-local-modifications-p t)
-        (ergoemacs map :map-list-hash '(ergoemacs-translate--modal-parent-map))
-        map)))
-(add-hook 'ergoemacs-mode-intialize-hook 
#'ergoemacs-translate--modal-parent-map)
-
 (defvar ergoemacs-translate--keymap-hash (make-hash-table)
   "Translation keymaps")
 
@@ -956,14 +926,14 @@ This takes into consideration the modal state of 
`ergoemacs-mode'."
                           (ergoemacs-translate--get (or translation :normal))))
          (key (or (and modal (intern (concat ":" 
(ergoemacs-translation-struct-name translation) "-modal")))
                   (ergoemacs-translation-struct-key translation)))
-         (ret (ergoemacs-gethash key ergoemacs-translate--keymap-hash))
+         (ret (gethash key ergoemacs-translate--keymap-hash))
          keymap)
     (unless ret
       (if modal
           (setq keymap (ergoemacs-translation-struct-keymap-modal translation)
                 ret keymap)
         (setq keymap (ergoemacs-translation-struct-keymap translation)
-              ret (make-composed-keymap (ergoemacs keymap) (ergoemacs 
ergoemacs-translate--parent-map))))
+              ret (make-composed-keymap keymap 
ergoemacs-translate--parent-map)))
       (puthash key ret ergoemacs-translate--keymap-hash))
     ret))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]