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.

Drew
  • 75,699
  • 9
  • 109
  • 225
Or Dicker
  • 51
  • 2
  • This is a known bug, first reported in November 2016: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25044 – Tyler Jun 13 '18 at 19:50

2 Answers2

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.

John DeBord
  • 550
  • 3
  • 13
Or Dicker
  • 51
  • 2
  • 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
0

Another simple solution is to use Ctrl+Ins/Shift-Delete instead of Ctrl+C/Ctrl-X when recording the macro.

cayhorstmann
  • 171
  • 1
  • 2