1

Goal: unbind <C-return> key ONLY in dired mode in order to rebind it to dired-w32explore.
My configuration is using use-package with something like this:

(use-package dired
  :init
  (unbind-key "<C-return>" cua-global-keymap)
  :bind (:map dired-mode-map
              ("<C-return>" . dired-w32explore))

The key works in dired-mode as I want.
But I get the CUA key completely removed in the rest of modes.
Is it possible to unbind that key only for dired-mode?

Drew
  • 75,699
  • 9
  • 109
  • 225
nephewtom
  • 2,219
  • 17
  • 29

2 Answers2

1

Ok, so following Drew's answer, I came across with these lines:

(defun special-c-return-in-dired ()
  (interactive)
  (if (derived-mode-p 'dired-mode)
      (dired-w32explore)
    (cua-set-rectangle-mark))
  )

(define-key cua-global-keymap [C-return] 'special-c-return-in-dired)

That works for me! Thanks Drew!

nephewtom
  • 2,219
  • 17
  • 29
0

cua-mode is a minor mode, so its keymap takes precedence over major-mode keymaps.

You can explicitly turn off cua-mode in dired-mode-hook, but you would then need to explicitly turn it on in other major modes where you want it on.

Alternatively, you can bind <C-return> in cua-global-keymap to your own command that checks (derived-mode-p 'dired-mode) and in that case invokes dired-w32explore and otherwise invokes cua-set-rectangle-mark.

Drew
  • 75,699
  • 9
  • 109
  • 225