I am trying to write my function for line duplcation. I have to maintain the cursor position. This is the code in the .emacs file :
(defun line-duplicate
"line duplication."
(setq position (point)) ;Store the original position of cursor
(global-set-key "\C-d" "\C-a\C-k\C-k\C-y\C-y")
(goto-char position) ;move the cursor to original position
)
(line-duplicate)
However, some error is arising. What is the mistake?
EDIT
Just discovered the command-execute function:
(defun line-duplicate ()
(interactive)
(setq position (point))
(command-execute (kbd "C-a C-k C-k C-y C-y"))
(goto-char position)
)
(global-set-key (kbd "C-d") 'line-duplicate)
And this worked.
global-set-keytakes two arguments,KEYandCOMMAND.COMMANDis not a key sequence, it is a function (usually it is a symbol naming an interactively-callable function, says the documentation). You probably do not want to change the behaviour of C-d when the function is called, you want to bind the function to the key.