1

I'm running cua-mode, and I'm trying to override the cua binding for C-c so that I can insert a function somefunc before passing the baton to the original cua binding which is cua-prefix-override-handler.

However, I find I can't override the original cua binding. (And even if could, I'm still not sure it would work because cua-prefix-override-handler appears to be a tricky function based on timing in a loop.)

;; .emacs
...
(cua-mode t)
...
(defun somefunc--cua ()
  "Run `some-command' and `some-other-command' in sequence."
  (interactive)
  (somefunc))
  (cua-prefix-override-handler))

;; THIS FAILS TO OVERRIDE CUA BINDING FOR C-c
(global-set-key (kbd "C-c") 'somefunc--cua)

How can I achieve the desired effect of insert an extra function somefunct and then continuing on with the cua processing?

(Background information about the motivation for this question is here.)

Craig Hicks
  • 304
  • 2
  • 9

2 Answers2

1

Does

(define-key cua--cua-keys-keymap (kbd "C-c <timeout>") 'somefunc)

(without wrapping somefunc) do what you want it to?

Investigation

When in CUA mode, the usual method of investigating keybindings, describe-key did not work with C-c (at least with no selected text), as C-h k C-c continued waiting for further input (displaying C-c-). Hence, I tried C-c ? (if a certain key, say KEY, is a prefix-key, then KEY ? or KEY C-h, will display the keybindings starting with KEY (this also works for a sequence of keys — e.g. C-x n ?)).

This gave the following relevant information:

`cua--ena-cua-keys-keymap' Minor Mode Bindings Starting With C-c:
key             binding
---             -------

C-c <timeout>   copy-region-as-kill

which tells us that the relevant keybinding is C-c <timeout> and that the keymap in which it's bound is cua--ena-cua-keys-keymap (which overrides the global map, so just using (global-set-key (kbd ("C-c <timeout>")) 'somefunc) wouldn't work).

aplaice
  • 2,126
  • 17
  • 23
0

Try

   (global-set-key [remap copy-region-to-clipboard--cua] 'your-replacement-function)
user1404316
  • 769
  • 5
  • 12
  • Thanks for your answer - I'm not sure what `'your-replacement-function` represents in this context. – Craig Hicks Mar 08 '19 at 00:32
  • @CraigHicks: In your specific case, `somefunc--cua `. – user1404316 Mar 08 '19 at 01:29
  • What I called `somefunc-cue` in this question is a just a name substitution for 'copy-region-to-clipboard--cua` in the previous question (in which I selected your answer as correct). This question is leftover unanswered part of that question. I changed the name to make this question more clear. – Craig Hicks Mar 08 '19 at 02:31
  • @CraigHicks: So 'your-replacement-function would be your custom function to replace the emacs-standard cua funtion that you are remapping. – user1404316 Mar 08 '19 at 08:42
  • I read this documentation on `remap` : https://www.gnu.org/software/emacs/manual/html_node/elisp/Remapping-Commands.html . "... Note that remapping only takes place through active keymaps; for example, putting a remapping in a prefix keymap like ctl-x-map typically has no effect, as such keymaps are not themselves active. In addition, remapping only works through a single level ... ". The problem is that cua-mode is not usually active, so perhaps cua mode's keytable wouldn't always be modified? Too hard to think about! – Craig Hicks Mar 08 '19 at 22:08