How can I tweak this elisp function to distinguish between C-d & DEL?

人盡茶涼 提交于 2019-12-10 23:18:03

问题


Here's my current function (blindly copy-pasted from a website)

(defun tweakemacs-delete-one-line ()
  "Delete current line."
  (interactive)
  (beginning-of-line)
  (kill-line)
  (kill-line))
(global-set-key (kbd "C-d") 'tweakemacs-delete-one-line)

There are two quirks here that I want to get rid of. 1) This actually rebinds DEL to the same function. I want my DEL to remain "delete one character". 2) There needs to be a condition where it will not double-kill if the line is only a newline character.


回答1:


To distinguish those two, use the preferred vector syntax for keys:

(global-set-key [delete] 'foo)
(global-set-key [(control d)] 'bar)

As for the second thing, it sounds as if you either want

(setq kill-whole-line t)

or just want to use the function kill-entire-line instead.




回答2:


I read part of the manual on keybindings, and it said that C-d and <DEL>, like other special keys, are bound. To unbind them you have to explicitly set both of them.

Ultimately, I used this solution:

(global-set-key (kbd "<delete>") 'delete-char)
(global-set-key ([control d]) 'kill-whole-word)


来源:https://stackoverflow.com/questions/2874587/how-can-i-tweak-this-elisp-function-to-distinguish-between-c-d-del

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!