While in cua mode, I want C-x to act as if cua mode was not active. I like cua C-c, C-v and C-z. But, I grew accustomed to eMacs use of C-x, and I want C-x to remain exactly as it was, with or without a selection.

(define-key cua--prefix-repeat-keymap (kbd "C-x") nil)

successfully modifies the value to nil, but cua still strangely affects the functioning of C-x, if it does anything at all.

I would like a way to completely remove the keybinding because in this case, setting the value to nil does not cause the binding to be ignored.

For the curious... I prefer delete to cause deleted ranges to enter the yank stack (like the cua C-x would do). I achieved this with the following:

(bind-keys ([delete] . (lambda ()
      "Kill active region to the yank stack.
Otherwise, perform normal delete.
Use backspace for an emacs range delete into register 0."
       (interactive)
       (if (use-region-p)
           (delete-active-region t) ;; yank selection into stack
         (delete-char 1))))) ;; forget singly removed characters
2

There are 2 answers

0
Paul On

Via stack exchange How to implement remove-key to completely undo the effect of define-key, I extracted elisp which successfully removes the key binding.

(defun remove-key (keymap key)
  (define-key keymap key nil)
  (setq key (cl-mapcan (lambda (k)
                         (if (and (integerp k)
                                  (/= (logand k ?\M-\^@) 0))
                             (list ?\e (- k ?\M-\^@))
                           (list k)))
                       key))
  (if (= (length key) 1)
      (delete key keymap)
    (let* ((prefix (vconcat (butlast key)))
           (submap (lookup-key keymap prefix)))
      (delete (last key) submap)
      (when (= (length submap) 1)
        (remove-key keymap prefix)))))

Using remove-key, all cua reaction to C-x is successfully eliminated:

(remove-key cua--prefix-repeat-keymap (kbd "C-x"))
0
phils On

Do you care at all about C-c, C-v, and C-z ?

If not, then you just want to use cua-selection-mode instead of cua-mode.