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

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

[elpa] externals/ergoemacs-mode a5febc9 291/325: Remove shift selection


From: Stefan Monnier
Subject: [elpa] externals/ergoemacs-mode a5febc9 291/325: Remove shift selection and try to fix C-S-x C-S-c
Date: Sat, 23 Oct 2021 18:49:13 -0400 (EDT)

branch: externals/ergoemacs-mode
commit a5febc9591de5953528547e020f44fe1cfccfebd
Author: Matthew Fidler <514778+mattfidler@users.noreply.github.com>
Commit: Matthew Fidler <514778+mattfidler@users.noreply.github.com>

    Remove shift selection and try to fix C-S-x C-S-c
---
 ergoemacs-advice.el       |  7 +------
 ergoemacs-command-loop.el | 41 ++++++++++++++++++++++++++++++++++++-----
 ergoemacs-mode.el         |  6 +++---
 3 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/ergoemacs-advice.el b/ergoemacs-advice.el
index 9338ce6..38af9d6 100644
--- a/ergoemacs-advice.el
+++ b/ergoemacs-advice.el
@@ -99,12 +99,7 @@ TYPE is the type of translation installed."
   (if ergoemacs-mode
       (ergoemacs-mode--undefined-advice)
     (call-interactively orig-fun)))
-
- (defun ergoemacs-advice-handle-shift-selection ()
-  "Allow `ergoemacs-mode' to do shift selection on keys like Alt+# to Alt+3."
-  (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))
diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el
index dd340c6..95da1af 100644
--- a/ergoemacs-command-loop.el
+++ b/ergoemacs-command-loop.el
@@ -862,7 +862,7 @@ KEYS is the keys information"
 
 (defun ergoemacs-command--dispach-cua ()
   "Dispatches the CUA C-x and C-c."
-  (when ergoemacs-mode-cua-mode
+  (when (and (not this-command-keys-shift-translated) ergoemacs-mode-cua-mode)
     (let ((keys (this-single-command-keys)))
       (when (and (= 1 (length keys))
                  (memq (aref keys 0) ergoemacs-command--cua-key-codes)
@@ -881,15 +881,46 @@ KEYS is the keys information"
 
 (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))))
+  (if (and mark-active ergoemacs-mode-cua-mode
+           (not (eq erogemacs-command--cua-timer 'shift)))
+      (setq erogemacs-command--cua-timer
+            (run-at-time t ergoemacs-command-loop-blink-rate 
#'ergoemacs-command--dispach-cua))
+    (unless mark-active
+      (ergoemacs-command--cua-timer-off)
+      (setq erogemacs-command--cua-timer nil))))
 
 (defun ergoemacs-command--cua-timer-off ()
   "Turn off the  cua timer."
-  (when erogemacs-command--cua-timer
+  (when (timerp erogemacs-command--cua-timer)
     (cancel-timer erogemacs-command--cua-timer)))
 
+
+;;;;;;;;;;;;
+;; Taken and modified from cua-base
+(defun ergoemacs-cua--shift-control-prefix (prefix)
+  ;; handle S-C-x and S-C-c by emulating the fast double prefix function.
+  ;; Don't record this command
+  (setq this-command last-command)
+  ;; Restore the prefix arg
+  ;; This should make it so that exchange-point-and-mark gets the prefix when
+  ;; you do C-u S-C-x C-x work (where the C-u is properly passed to the C-x
+  ;; C-x binding after the first S-C-x was rewritten to just C-x).
+  (prefix-command-preserve-state)
+  ;; Activate the cua--prefix-repeat-keymap
+  (setq erogemacs-command--cua-timer 'shift)
+  (ergoemacs-command--cua-timer-off)
+  ;; Repalce key
+  (setq unread-command-events (list prefix)))
+
+(defun ergoemacs-cua--shift-control-c-prefix ()
+  (interactive)
+  (ergoemacs-cua--shift-control-prefix ?\C-c))
+
+(defun ergoemacs-cua--shift-control-x-prefix ()
+  (interactive)
+  (ergoemacs-cua--shift-control-prefix ?\C-x))
+;;;;
+
 (add-hook 'ergoemacs-post-command-hook #'ergoemacs-command--cua-timer-on)
 (add-hook 'ergoemacs-shutdown-hook #'ergoemacs-command--cua-timer-off)
 
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index 5d0536c..07b4502 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -412,7 +412,9 @@ after initializing ergoemacs-mode.
 
 (defvar ergoemacs-mark-active-cua-keymap (let ((map (make-sparse-keymap)))
                                            (define-key map (kbd "C-c 
<ergoemacs-timeout>") 'ergoemacs-copy-line-or-region)
-                                           (define-key map (kbd "C-v 
<ergoemacs-timeout>") 'ergoemacs-paste)
+                                           (define-key map (kbd "C-x 
<ergoemacs-timeout>") 'ergoemacs-cut-line-or-region)
+                                           (define-key map [(shift control c)] 
'ergoemacs-cua--shift-control-c-prefix)
+                                           (define-key map [(shift control x)] 
'ergoemacs-cua--shift-control-x-prefix)
                                            map)
   "The keybinding that is active when the mark is active.")
 
@@ -440,7 +442,6 @@ after initializing ergoemacs-mode.
   (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))
 
 (defun ergoemacs-remove-override-keymap ()
@@ -450,7 +451,6 @@ after initializing ergoemacs-mode.
   (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))
 
 



reply via email to

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