我正在尝试编写用于行重复的函数。我必须保持光标位置。这是 .emacs 文件中的代码:
(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)
但是,出现了一些错误。错误是什么?
编辑
刚刚发现了命令执行功能:
(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)
这奏效了。