branch: externals/ergoemacs-mode commit d8d4d309db28259fa6dac7f66c88bc2d2dfe6dfa Author: Matthew Fidler <514778+mattfid...@users.noreply.github.com> Commit: Matthew Fidler <514778+mattfid...@users.noreply.github.com>
Move to swap keymaps #510 --- ergoemacs-cua.el | 85 +++++++++++++++++++++++++++++++------------------------ ergoemacs-mode.el | 18 ++---------- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/ergoemacs-cua.el b/ergoemacs-cua.el index c73bb61cf8..c8cf3b27ae 100644 --- a/ergoemacs-cua.el +++ b/ergoemacs-cua.el @@ -122,46 +122,57 @@ This override is enabled for active regions before the copy and paste are enable (defvar ergoemacs--temporary-disable) (defvar ergoemacs-mode-regular) (defvar ergoemacs-mode-send-emacs-keys) +(defvar ergoemacs-send-keys-term) +(defvar term-raw-map) (defun ergoemacs--select-keymaps () "Setup conditions for selecting the proper keymaps in `ergoemacs--keymap-alist'." - (when ergoemacs--temporary-disable - ;; The temporary disable commands set `ergoemacs--temporary-disable' to t - ;; The first time when the keys are put on the `unread-command-events', `ergoemacs-mode' is disabled - ;; The second command is executed, and `ergoemacs-mode' is turned back on and `ergoemacs--temporary-disable' is to nil - (if ergoemacs-mode-regular - (progn - (setq ergoemacs--ena-region-keymap nil - ergoemacs--ena-prefix-override-keymap nil - ergoemacs--ena-prefix-repeat-keymap nil - ergoemacs-mode-regular nil - ergoemacs-mode-send-emacs-keys nil)) - (setq ergoemacs--temporary-disable nil + (if (and (eq major-mode 'term-mode) + (eq (current-local-map) term-raw-map)) + (setq ergoemacs-mode-regular nil + ergoemacs-mode-send-emacs-keys nil + ergeoemacs-mode-term-raw-mode t) + (when ergeoemacs-mode-term-raw-mode + (setq ergeoemacs-mode-term-raw-mode nil ergoemacs-mode-regular t - ;; This assumes that `ergoemacs--tempoary-disable' is only called on the remap keys layer - ergoemacs-mode-send-emacs-keys t))) - (when ergoemacs-mode - ;; The prefix override (when mark-active) operates in three substates: - ;; [1] Before using a prefix key - ;; [2] Immediately after using a prefix key - ;; [3] A fraction of a second later - (setq ergoemacs--ena-region-keymap ; Determines if the ergion is active - (and (not ergeoemacs-mode-term-raw-mode) (region-active-p) (not deactivate-mark)) - ;; Enable Override -- This is the first state where the keys are intercepted; cua state [1] - ergoemacs--ena-prefix-override-keymap - (and ergoemacs--ena-region-keymap - (not ergeoemacs-mode-term-raw-mode) - ergoemacs-enable-cua-keys - (not ergoemacs-inhibit-cua-keys) - (or (eq ergoemacs-enable-cua-keys t) - (region-active-p)) - (not executing-kbd-macro) - (not ergoemacs--prefix-override-timer)) - ;; Enable The repeat layer. This is the layer that the keys are intercepted; cua state [2] - ergoemacs--ena-prefix-repeat-keymap - (and ergoemacs--ena-region-keymap - (not ergeoemacs-mode-term-raw-mode) - (or (timerp ergoemacs--prefix-override-timer) - (eq ergoemacs--prefix-override-timer 'shift)))))) + ergoemacs-mode-send-emacs-keys ergoemacs-send-keys-term)) + (when ergoemacs--temporary-disable + ;; The temporary disable commands set `ergoemacs--temporary-disable' to t + ;; The first time when the keys are put on the `unread-command-events', `ergoemacs-mode' is disabled + ;; The second command is executed, and `ergoemacs-mode' is turned back on and `ergoemacs--temporary-disable' is to nil + (if ergoemacs-mode-regular + (progn + (setq ergoemacs--ena-region-keymap nil + ergoemacs--ena-prefix-override-keymap nil + ergoemacs--ena-prefix-repeat-keymap nil + ergoemacs-mode-regular nil + ergoemacs-mode-send-emacs-keys nil)) + (setq ergoemacs--temporary-disable nil + ergoemacs-mode-regular t + ;; This assumes that `ergoemacs--tempoary-disable' is only called on the remap keys layer + ergoemacs-mode-send-emacs-keys t))) + (when ergoemacs-mode + ;; The prefix override (when mark-active) operates in three substates: + ;; [1] Before using a prefix key + ;; [2] Immediately after using a prefix key + ;; [3] A fraction of a second later + (setq ergoemacs--ena-region-keymap ; Determines if the ergion is active + (and (not ergeoemacs-mode-term-raw-mode) (region-active-p) (not deactivate-mark)) + ;; Enable Override -- This is the first state where the keys are intercepted; cua state [1] + ergoemacs--ena-prefix-override-keymap + (and ergoemacs--ena-region-keymap + (not ergeoemacs-mode-term-raw-mode) + ergoemacs-enable-cua-keys + (not ergoemacs-inhibit-cua-keys) + (or (eq ergoemacs-enable-cua-keys t) + (region-active-p)) + (not executing-kbd-macro) + (not ergoemacs--prefix-override-timer)) + ;; Enable The repeat layer. This is the layer that the keys are intercepted; cua state [2] + ergoemacs--ena-prefix-repeat-keymap + (and ergoemacs--ena-region-keymap + (not ergeoemacs-mode-term-raw-mode) + (or (timerp ergoemacs--prefix-override-timer) + (eq ergoemacs--prefix-override-timer 'shift))))))) (defun ergoemacs--prefix-override-timeout () "This is whap happens on the `ergoemacs-mode' timeout for C-c and C-v are supplied." diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el index 193e89c58a..65c93e51eb 100644 --- a/ergoemacs-mode.el +++ b/ergoemacs-mode.el @@ -232,20 +232,7 @@ The TEXT will be what the mode-line is set to be." (defun ergoemacs-post-command-hook () "Run `ergoemacs-mode' post command hooks." (when ergoemacs-mode - (if (and (eq major-mode 'term-mode) - (eq (current-local-map) term-raw-map)) - (setq-local ergoemacs-mode-regular nil - ergoemacs-send-keys-term ergoemacs-mode-send-emacs-keys - ergoemacs-mode-send-emacs-keys nil - ergeoemacs-mode-term-raw-mode t) - (run-hooks 'ergoemacs-post-command-hook))) - (when ergeoemacs-mode-term-raw-mode - (when (and (eq major-mode 'term-mode) - (not (eq (current-local-map) term-raw-map))) - (setq-local ergoemacs-mode-regular t - ergoemacs-mode-send-emacs-keys ergoemacs-send-keys-term - ergeoemacs-mode-term-raw-mode nil) - (run-hooks 'ergoemacs-post-command-hook)))) + (run-hooks 'ergoemacs-post-command-hook))) (defvar ergoemacs-after-load-functions nil) (defun ergoemacs-after-load-functions (absoulte-file-name) @@ -348,7 +335,8 @@ The `execute-extended-command' is now \\[execute-extended-command]. ((string-equal ergoemacs-theme "reduction") (ergoemacs-setup-override-keymap)) (t (ergoemacs-setup-override-keymap))) - (setq ergoemacs-require--ini-p t) + (setq ergoemacs-require--ini-p t + ergoemacs-send-keys-term ergoemacs-mode-send-emacs-keys) (message "Ergoemacs-mode turned ON (%s)." ergoemacs-keyboard-layout)) ;; Turn off