[emacs] local keybinding in a mode
keybinding
keybinding을 local mode에서 하기 위해서 hook을 사용한다.
(defun my-text-mode-settings ()
"Custom settings for text-mode."
(local-set-key (kbd "C-c m") 'some-function)) ; 여기서 'some-function'은 호출하고자 하는 함수입니다.
(add-hook 'text-mode-hook 'my-text-mode-settings)
local-set-key로 binding하는데, keymap-local-set으로 binding해도 된다.
(defun my-text-mode-settings ()
"Custom settings for text-mode."
(keymap-local-set 'text-mode-map (kbd "C-c m") 'some-function)) ; 'some-function'은 호출하고자 하는 함수입니다.
(add-hook 'text-mode-hook 'my-text-mode-settings)
add-hook
mode들은 모두 hook이라는 placeholder를 가지고 있다. hook은 function을 list로 가지고 있다. 그래서 mode가 실행되면, hook에 있는 function들을 호출한다.
(add-hook HOOK FUNCTION &optional DEPTH LOCAL)
add-hook이란 function을 사용할때는 hook은 mode-hook형태로 되어 있고, function은 name을 기술하면 된다.