branch: externals/ergoemacs-mode commit 8b47756c5ac884320b70713614af2ccecee0915e Author: Walter Landry <wlan...@caltech.edu> Commit: Walter Landry <wlan...@caltech.edu>
Revert "Remove cttl-x-c 'both' option" This reverts commit 30ed2020e3f770e237aaa2562b210517c8d3a38b. --- ergoemacs-command-loop.el | 28 ++++++++++++++++------------ ergoemacs-functions.el | 12 ++++++++++-- ergoemacs-lib.el | 4 ++-- ergoemacs-test.el | 10 ++++++---- ergoemacs-theme-engine.el | 11 ++++++++++- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el index cf2358a..8628dbb 100644 --- a/ergoemacs-command-loop.el +++ b/ergoemacs-command-loop.el @@ -189,6 +189,7 @@ ignore the post-command hooks.") (defvar ergoemacs-command-loop-type) (defvar ergoemacs-keymap) (defvar ergoemacs-handle-ctl-c-or-ctl-x) +(defvar ergoemacs-ctl-c-or-ctl-x-delay) (defun ergoemacs-command-loop--modal-show () @@ -662,11 +663,11 @@ inconjunction with `input-method-function' to translate keys if (ergoemacs-keymapp test-ret)) ;; The translation needs more keys... (if timeout-key - (setq next-key (ergoemacs-command-loop--history - nil - ergoemacs-command-loop--decode-event-delay - current-key) - ) + (setq next-key (with-timeout (ergoemacs-ctl-c-or-ctl-x-delay + (progn + (setq ergoemacs-command-loop--decode-event-timeout-p t) + nil)) + (ergoemacs-command-loop--history nil ergoemacs-command-loop--decode-event-delay current-key))) (setq next-key (ergoemacs-command-loop--history nil ergoemacs-command-loop--decode-event-delay current-key))) (when next-key ;; Since a key was read, save it to be read later. (push last-command-event new-ergoemacs-input)) @@ -821,13 +822,14 @@ KEYS is the keys information" (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 'only-copy-cut))) - ((eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut) + (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 - (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 @@ -2192,17 +2194,19 @@ pressed the translated key by changing ((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 'only-copy-cut))) + (eq ergoemacs-handle-ctl-c-or-ctl-x 'both))) ;; Immediate - ((eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut) + ((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 (ergoemacs-command-loop--read-event nil key)) + (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 @@ -2215,7 +2219,7 @@ pressed the translated key by changing ;; Shift+Control+c (when (and (ergoemacs-keymapp ret) (setq tmp (lookup-key ret [ergoemacs-timeout])) - (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)) + (eq ergoemacs-handle-ctl-c-or-ctl-x 'both)) (setq ret tmp)) (ergoemacs-command-loop--message-binding new-key ret key)) (t diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el index 8c31e4f..d91deb7 100644 --- a/ergoemacs-functions.el +++ b/ergoemacs-functions.el @@ -102,11 +102,19 @@ '(delete-backward-char delete-char kill-word backward-kill-word) "Defines deletion functions that ergoemacs is aware of.") -(defcustom ergoemacs-handle-ctl-c-or-ctl-x 'only-C-c-and-C-x +(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 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) (defvar ergoemacs-revert-buffer 0) diff --git a/ergoemacs-lib.el b/ergoemacs-lib.el index 9ff6c62..261578a 100644 --- a/ergoemacs-lib.el +++ b/ergoemacs-lib.el @@ -409,9 +409,9 @@ All other modes are assumed to be minor modes or unimportant. "Figures out ergoemacs-mode menu's preferred key-binding for CMD." (cond ((not cmd)) - ((and (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut) + ((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 (eq ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut) + ((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 diff --git a/ergoemacs-test.el b/ergoemacs-test.el index f7d8b417..88d6736 100644 --- a/ergoemacs-test.el +++ b/ergoemacs-test.el @@ -435,7 +435,7 @@ Tests issue #347" "Issue #184; Not replace the \"selected all\" by paste." :tags '(:copy :interactive) (let ((ret t) - (ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)) + (ergoemacs-handle-ctl-c-or-ctl-x 'both)) (ergoemacs-test-layout :macro "C-v" (save-excursion @@ -462,7 +462,7 @@ Tests issue #347" Selected mark would not be cleared after paste." :tags '(:copy) (ergoemacs-test-layout - (let ((ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)) + (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)) @@ -505,7 +505,8 @@ not using cua or cutting line. I think kill-region is what is meant." :tags '(:copy :interactive) (ergoemacs-test-layout (let ((ret t) - (ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut)) + (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)) @@ -522,7 +523,8 @@ not using cua or cutting line. I think kill-region is what is meant." "Attempts to test Issue #130 -- Copy" :tags '(:copy :interactive) (ergoemacs-test-layout - (let ((ergoemacs-handle-ctl-c-or-ctl-x 'only-copy-cut) + (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*")) diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el index 48b24c1..60ef0d8 100644 --- a/ergoemacs-theme-engine.el +++ b/ergoemacs-theme-engine.el @@ -377,7 +377,16 @@ When AT-END is non-nil, append a $ to the regular expression." (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