3

I have just started using emacs, so I decided to use cua-mode. I got this weird problem when I'm using macros and copy/cut (C-c/ C-x).

let's assume this simple macro for example: <F3> C-S-right C-c C-v <F4> When I execute it I'm getting this message: After 0 kbd macro iterations: keyboard macro terminated by a command ringing the bell

After some digging I found this at the recording (C-x C-k C-e): Macro:

<C-S-right>
C-c C-c <============== C-c twice!!!!
<timeout>
C-v ;; yank

I think the problem is the second C-c. When I remove the second C-c the macro works as expected. More info from C-h l (after making the macro):

<f3> [kmacro-start-macro-or-insert-counter]
<C-S-right> [right-word]
C-c [cua--prefix-override-handler]
C-c <timeout> [cua-copy-region]
C-v [cua-paste]
<f4> [kmacro-end-or-call-macro]

I'm guessing that I'm not the first one who uses cua-mode and macro, but I didn't found anything on it :(.

How do I fix this problem?

Stop using cua-mode is not an option of me right now.

2

I wrote some lisp code to fix this. I just added this to my init.el

;; fix problem of cua-mode and macro  
;; fix function   
(defun cua-macro-fix()   
  (kmacro-edit-macro)  
  ;; fix the C-c C-c   
  (goto-char (point-min))  
  (forward-line 7)  
  (while (search-forward "C-c C-c" nil t)  
    (replace-match "C-c"))  
  ;; fix the C-x C-x   
  (goto-char (point-min))  
  (forward-line 7)  
  (while (search-forward "C-x C-x" nil t)  
    (replace-match "C-x"))  
  (edmacro-finish-edit))  
;;bind the two functions  
(defun end-kbd-macro-with-fix()  
  (interactive)  
  (end-kbd-macro)  
  (cua-macro-fix))  
;;bind the function to f4  
(global-set-key (kbd "<f4>") 'end-kbd-macro-with-fix)  

hope it will help someone.

  • Note that this problem doesn't appear when using Emacs on Windows. I don't have a precise explanation for that but it makes sense... – jcm69 Mar 17 '19 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.