branch: externals/ergoemacs-mode commit aba186d362d455c1205827e18ae015612c70bdf1 Author: Matthew Fidler <514778+mattfid...@users.noreply.github.com> Commit: Matthew Fidler <514778+mattfid...@users.noreply.github.com>
Add back cua keys without cua mode, back to ergoemacs-timeout --- ergoemacs-command-loop.el | 43 +++++++++++++++++++++++++++++++++---------- ergoemacs-functions.el | 2 ++ ergoemacs-mode.el | 19 +++++++++++++++++-- ergoemacs-themes.el | 2 -- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el index 7d2c449..dd340c6 100644 --- a/ergoemacs-command-loop.el +++ b/ergoemacs-command-loop.el @@ -853,6 +853,23 @@ KEYS is the keys information" trans keys))) +(defvar erogemacs-command--cua-timer nil) + +(defvar ergoemacs-command--cua-key-codes + (list (nth 0 (listify-key-sequence (kbd "C-c"))) + (nth 0 (listify-key-sequence (kbd "C-x")))) + "Key codes to check against for C-c and C-x") + +(defun ergoemacs-command--dispach-cua () + "Dispatches the CUA C-x and C-c." + (when ergoemacs-mode-cua-mode + (let ((keys (this-single-command-keys))) + (when (and (= 1 (length keys)) + (memq (aref keys 0) ergoemacs-command--cua-key-codes) + mark-active) + (setq unread-command-events (cons 'ergoemacs-timeout unread-command-events)) + (ergoemacs-command--cua-timer-off))))) + (defvar erogemacs-command--echo-timer nil) (defvar ergoemacs-command--blink-on nil) (defvar ergoemacs-orig-echo-keystrokes nil) @@ -860,15 +877,21 @@ KEYS is the keys information" (defvar ergoemacs-command--timeout-timer nil) (defvar ergoemacs-command--timeout-keys nil) -(defun ergoemacs-command--timer-timeout () - "Send the [ergoemacs-timeout] event (after timeout)." - (let ((keys (this-single-command-keys))) - (when ergoemacs-command--timeout-timer - (cancel-timer ergoemacs-command--timeout-timer) - (setq ergoemacs-command--timeout-timer nil) - (when (equal keys ergoemacs-command--timeout-keys) - (push 'ergoemacs-timeout unread-command-events)) - (setq ergoemacs-command--timeout-keys nil)))) +(defvar erogemacs-command--cua-timer nil) + +(defun ergoemacs-command--cua-timer-on () + "Turn on the cua timer." + (when (and mark-active ergoemacs-mode-cua-mode) + (setq erogemacs-command--cua-timer + (run-at-time t ergoemacs-command-loop-blink-rate #'ergoemacs-command--dispach-cua)))) + +(defun ergoemacs-command--cua-timer-off () + "Turn off the cua timer." + (when erogemacs-command--cua-timer + (cancel-timer erogemacs-command--cua-timer))) + +(add-hook 'ergoemacs-post-command-hook #'ergoemacs-command--cua-timer-on) +(add-hook 'ergoemacs-shutdown-hook #'ergoemacs-command--cua-timer-off) (defvar ergoemacs-this-command-keys-shift-translated nil "ergoemacs override of shift translation in command loop.") @@ -885,7 +908,7 @@ NEW-KEYS replaces the value of `this-single-command-keys' if specified." ergoemacs-command--timeout-timer nil)) (unless (or (equal [] keys) (ergoemacs-command-loop-p)) - (when (ergoemacs-keymapp (key-binding keys)) + (when (keymapp (key-binding keys)) (unless unread-command-events (ergoemacs-command-loop--message "%s" (ergoemacs-command-loop--key-msg diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el index f308931..e1773f3 100644 --- a/ergoemacs-functions.el +++ b/ergoemacs-functions.el @@ -413,6 +413,7 @@ If `narrow-to-region' is in effect, then cut that region only." "Copy current line, or current text selection. Pass prefix ARG to the respective copy functions." (interactive "P") + (setq unread-command-events nil) (cond ;;; cua-copy-rectangle ((and (boundp 'cua--rectangle) cua--rectangle cua-mode) @@ -464,6 +465,7 @@ major-modes like `org-mode'. The ARG is passed to the respective function for any prefixes." (interactive "P") + (setq unread-command-events nil) (cond ((and (boundp 'cua--rectangle) cua--rectangle) (cua-cut-rectangle-as-text arg)) diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el index b619519..5d0536c 100644 --- a/ergoemacs-mode.el +++ b/ergoemacs-mode.el @@ -404,8 +404,15 @@ after initializing ergoemacs-mode. "The keybinding that is active when the mark is active.") +(defcustom ergoemacs-mode-cua-mode t + "Use C-c and C-v for copy paste when mark is active." + :type 'boolean + :group 'ergoemacs-mode) + + (defvar ergoemacs-mark-active-cua-keymap (let ((map (make-sparse-keymap))) - (define-key map (kbd "C-c") 'indent-region) + (define-key map (kbd "C-c <ergoemacs-timeout>") 'ergoemacs-copy-line-or-region) + (define-key map (kbd "C-v <ergoemacs-timeout>") 'ergoemacs-paste) map) "The keybinding that is active when the mark is active.") @@ -416,6 +423,9 @@ after initializing ergoemacs-mode. (defvar ergoemacs-minor-alist nil "ErgoEmacs minor mode keymap.") +(defvar ergoemacs-minor-cua-alist nil + "ErgoEmacs cua mode keymap.") + (declare-function ergoemacs-advice-undefined "ergoemacs-advice") (defun ergoemacs-setup-override-keymap () @@ -423,9 +433,12 @@ after initializing ergoemacs-mode. (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)) + ergoemacs-minor-alist `(mark-active . ,ergoemacs-mark-active-keymap) + ergoemacs-minor-cua-alist `(mark-active . ,ergoemacs-mark-active-cua-keymap)) (add-hook 'emulation-mode-map-alists ergoemacs-override-alist) (add-hook 'minor-mode-map-alist ergoemacs-minor-alist) + (when ergoemacs-mode-cua-mode + (add-hook 'minor-mode-map-alist ergoemacs-minor-cua-alist)) (advice-add 'undefined :around #'ergoemacs-advice-undefined) (advice-add 'handle-shift-selection :before #'ergoemacs-advice-handle-shift-selection) (advice-add 'read-key :before #'ergoemacs-advice-read-key)) @@ -434,6 +447,8 @@ after initializing ergoemacs-mode. "Remove `ergoemacs-mode' keymaps." (remove-hook 'emulation-mode-map-alists 'ergoemacs-override-alist) (remove-hook 'minor-mode-map-alist ergoemacs-minor-alist) + (when ergoemacs-mode-cua-mode + (remove-hook 'minor-mode-map-alist ergoemacs-minor-cua-alist)) (advice-remove 'undefined #'ergoemacs-advice-undefined) (advice-remove 'handle-shift-selection #'ergoemacs-advice-handle-shift-selection) (advice-remove 'read-key #'ergoemacs-advice-read-key)) diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el index 1dfb5f5..1c9b235 100644 --- a/ergoemacs-themes.el +++ b/ergoemacs-themes.el @@ -1513,7 +1513,6 @@ This affects modes like `grep-mode' since this is a parent keymap" (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) @@ -1533,7 +1532,6 @@ This affects modes like `grep-mode' since this is a parent keymap" (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)