branch: externals/ergoemacs-mode
commit f7a68f67aee3e390d0b595db4be8f5691f1ece00
Author: Fidler <[email protected]>
Commit: Fidler <[email protected]>
Add back Ctrl+Shift+c and Ctrl+Shift+x.
- This should address issue #444
---
ergoemacs-advice.el | 2 +-
ergoemacs-command-loop.el | 27 +++++++++++++++++++--------
ergoemacs-component.el | 1 +
ergoemacs-translate.el | 40 +++++++++++++++++++++++++++++++++++++---
4 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/ergoemacs-advice.el b/ergoemacs-advice.el
index 91d34da..31ef9c0 100644
--- a/ergoemacs-advice.el
+++ b/ergoemacs-advice.el
@@ -341,7 +341,7 @@ TYPE is the type of translation installed."
current-prefix-arg (aref (substring keys (- i 1) i) 0))
ergoemacs-command-loop--history)
(setq i (+ 1 i)))
- (ergoemacs-command-loop keys nil nil nil
ergoemacs-command-loop--history))
+ (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)))
diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el
index a8ba7d8..1f858e1 100644
--- a/ergoemacs-command-loop.el
+++ b/ergoemacs-command-loop.el
@@ -798,6 +798,9 @@ KEYS is the keys information"
(push 'ergoemacs-timeout unread-command-events))
(setq ergoemacs-command--timeout-keys nil))))
+(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))
@@ -815,7 +818,7 @@ KEYS is the keys information"
((eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)
(push 'ergoemacs-timeout unread-command-events))
((not (region-active-p))) ;; active
- ((and this-command-keys-shift-translated
+ ((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))
@@ -823,8 +826,7 @@ KEYS is the keys information"
(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)))
- ))
+ (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
@@ -1570,7 +1572,8 @@ The RECORD-FLAG and KEYS are sent to
`ergoemacs-command-loop--grow-interactive'.
(ergoemacs-specials
(ergoemacs-command-loop--grow-interactive command record-flag keys)))
(t
- (ergoemacs-command-loop--grow-interactive command record-flag keys))))
+ (ergoemacs-command-loop--grow-interactive command record-flag keys)))
+ (setq ergoemacs-this-command-keys-shift-translated nil))
(defun ergoemacs-command-loop-start ()
@@ -1823,7 +1826,8 @@ Emacs versions)."
"Key sequence %s aborted by %s"
(ergoemacs-key-description last-current-key)
(ergoemacs-key-description raw-key))
- (setq quit-flag t))
+ (setq quit-flag t
+ ergoemacs-this-command-keys-shift-translated nil))
;; Handle local commands.
((and (or modal-p
(not (equal current-key raw-key)))
@@ -2130,7 +2134,7 @@ pressed the translated key by changing
(ergoemacs-command-loop--sync-point)
(let ((trials (ergoemacs-translate--trials key))
tmp tmp2 ret)
- (setq this-command-keys-shift-translated nil)
+ (setq this-command-keys-shift-translated nil)
(catch 'found-command
(dolist (cur-key trials)
(when cur-key
@@ -2184,7 +2188,7 @@ pressed the translated key by changing
((< 1 (length ergoemacs-command-loop--history)))
((not (region-active-p))) ;; its a key sequence.
- ((and this-command-keys-shift-translated
+ ((and (or ergoemacs-this-command-keys-shift-translated
this-command-keys-shift-translated)
(eq ergoemacs-handle-ctl-c-or-ctl-x 'both)))
;; Immediate
@@ -2307,7 +2311,14 @@ For instance in QWERTY M-> is shift translated to M-."
(setq ergoemacs-command-loop--single-command-keys nil)))))
;; (ergoemacs-command-loop--spinner-end)
))
-
+(defun ergoemacs-command-loop--shift-timeout ()
+ "This is the shift-timeout function for a key."
+ (interactive)
+ (let ((shift-trans (ergoemacs-translate--emacs-shift
(this-single-command-keys))))
+ (if (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)
+ (setq unread-command-events (append (ergoemacs-translate--emacs-shift
shift-trans) '(ergoemacs-timeout)))
+ (setq ergoemacs-this-command-keys-shift-translated t)
+ (ergoemacs-command-loop--internal shift-trans))))
(provide 'ergoemacs-command-loop)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ergoemacs-command-loop.el ends here
diff --git a/ergoemacs-component.el b/ergoemacs-component.el
index 0a1ad4b..4ad954f 100644
--- a/ergoemacs-component.el
+++ b/ergoemacs-component.el
@@ -461,6 +461,7 @@ Allows the component not to be calculated."
(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))
diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el
index cf9272d..6931f8c 100644
--- a/ergoemacs-translate.el
+++ b/ergoemacs-translate.el
@@ -156,6 +156,12 @@ modifier occurred, such as in
`ergoemacs-translate--meta-to-escape'.
(setq found t)))
(if found (vconcat seq) nil))))
+(defvar ergoemacs-translate--define-key-if-defined-p t
+ "Define a key if even if it is already defined in the keymap.")
+(defvar ergoemacs-translate--define-key-replacement-function nil
+ "When non-nil, use the replacement function for defining a key.")
+
+
(defun ergoemacs-translate--meta-to-escape (key-seq)
"Escapes a KEY-SEQ M-q becomes ESC q.
KEY-SEQ must be a vector. If there is no need to escape the key sequence
return nil."
@@ -226,6 +232,25 @@ If no changes are performed, return nil."
(setq ret new-key))
ret)))
+(defun ergoemacs-translate--ergoemacs-timeout (key)
+ "Translates KEY to allow Shift translation to default to key sequence.
+
+This is done for key sequences like Ctrl+Shift+c which should
+allow the Ctrl+c key sequence to be called when text is
+seleceted (instead of copying the text)."
+ (let (modifiers basic)
+ (when (and (vectorp key)
+ ;; only makes sense for single key combinations.
+ (= (length key) 2)
+ (eq 'ergoemacs-timeout (aref key 1))
+ ;; Doesn't make sense if shifted...
+ (not (or (memq 'shift (setq modifiers
(ergoemacs-translate--event-modifiers (aref key 0))))
+ (memq 'ergoemacs-shift modifiers))))
+ (setq basic (ergoemacs-translate--event-basic-type (aref key 0))
+ ergoemacs-translate--define-key-if-defined-p nil
+ ergoemacs-translate--define-key-replacement-function
'ergoemacs-command-loop--shift-timeout)
+ (vector (ergoemacs-translate--event-convert-list (append modifiers (list
'shift basic)))))))
+
(defun ergoemacs-translate--to-string (key)
"Translates KEY to string format.
@@ -244,7 +269,8 @@ If no chanegs are performed, return nil."
ergoemacs-translate--swap-apps
ergoemacs-translate--swap-menu
ergoemacs-translate--to-string
- ergoemacs-translate--to-vector)
+ ergoemacs-translate--to-vector
+ ergoemacs-translate--ergoemacs-timeout)
"Functions to apply to key.
These functions take a key as an argument and translate it in
@@ -259,7 +285,11 @@ variants are created using
`ergoemacs-translate--apply-funs'."
(apply function key args)
(dolist (fn ergoemacs-translate--apply-funs)
(when (setq test-key (funcall fn key))
- (apply function test-key args)))))
+ (apply function test-key args)
+ (setq ergoemacs-translate--define-key-if-defined-p t
+ ergoemacs-translate--define-key-replacement-function nil)))))
+
+
(defun ergoemacs-translate--define-key (keymap key def)
"Similar to `define-key', with the following differences:
@@ -273,7 +303,11 @@ DEF is the definition of what will be run.
This uses `ergoemacs-translate--apply-key'"
(unwind-protect
- (ergoemacs-translate--apply-key key (lambda(new-key) (define-key keymap
new-key def)))
+ (ergoemacs-translate--apply-key
+ key (lambda(new-key)
+ (when (or ergoemacs-translate--define-key-if-defined-p
+ (not (lookup-key keymap new-key)))
+ (define-key keymap new-key (or
ergoemacs-translate--define-key-replacement-function def)))))
(setq ergoemacs-define-key-after-p nil)))
(defun ergoemacs-translate--event-modifier-hash (&optional layout)