Emacs: a function that writes elisp code that adds a user-specified key binding

How can I make an interactive function that interactively reads the key from the user (for example, when you press Ch k), and then writes some line as follows:

(global-set-key (kbd "C-x C-s") 'hello)

where part of Cx Cs is replaced accordingly by the read key.

Some novice users have a problem creating keys ... and I'm actually embarrassed too, so I thought let's just automate it.

+3
source share
2 answers

It works:

(defun insert-key (key)
  (interactive (list (read-key-sequence "Key: ")))
  (insert "(global-set-key (kbd \"" (key-description key) "\") 'hello)\n"))
+5
source

? , , , : global-set-key - . , (IIUC): (, ..), .

0

Source: https://habr.com/ru/post/1717366/


All Articles