Emacs에서 전체적으로 키 바인딩 무시
전역 적으로 재정의하고 해당 키에 대한 다른 모든 바인딩보다 우선하는 키 바인딩을 어떻게 설정할 수 있습니까? 모든 주 / 부 모드 맵을 재정의하고 내 바인딩이 항상 적용되는지 확인하고 싶습니다.
물론 이것은 작동하지 않습니다.
(global-set-key "\C-i" 'some-function)
그것은 작동 text-mode
하지만 내가 사용할 때 lisp-mode
, C-i
반동 lisp-indent-line
입니다.
이 바인딩을 통해 lisp-mode
다른 모든 모드에서 개별적으로 재정의 할 수 있지만 더 쉬운 방법이 있어야합니다. 새 파일 형식에 대한 새 모드를 설치할 때마다 돌아가서 모든 키 바인딩이 새 모드로 재정의되지 않는지 확인해야합니다.
저는 이미 다른 편집자들로부터 배웠고 뿌리 내린 바인딩을 에뮬레이트하고 싶기 때문에 이것을하고 싶습니다.
모든 "재정의"키 바인딩에 대해 부 모드를 사용합니다.
(defvar my-keys-minor-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-i") 'some-function)
map)
"my-keys-minor-mode keymap.")
(define-minor-mode my-keys-minor-mode
"A minor mode so that my key settings override annoying major modes."
:init-value t
:lighter " my-keys")
(my-keys-minor-mode 1)
다른 사람이 키보드를 운전하거나 기본 키 바인딩이 수행하는 작업을 확인해야하는 경우 한 번에 모든 수정 사항을 해제 할 수 있다는 추가 이점이 있습니다 (부 모드를 비활성화하면됩니다).
미니 버퍼에서이 기능을 꺼야 할 수도 있습니다.
(defun my-minibuffer-setup-hook ()
(my-keys-minor-mode 0))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
scottfrazer의 답변에 추가로 다음을 작성하여 이후에로드 된 라이브러리가 자체의 새 키맵을 가져 오더라도 키 바인딩이 우선 순위를 유지하도록 다음을 작성했습니다.
키맵은 컴파일 시간에 생성 될 수 있기 때문에 load
이를 수행하는 가장 좋은 장소 인 것 같습니다.
(add-hook 'after-load-functions 'my-keys-have-priority)
(defun my-keys-have-priority (_file)
"Try to ensure that my keybindings retain priority over other minor modes.
Called via the `after-load-functions' special hook."
(unless (eq (caar minor-mode-map-alist) 'my-keys-minor-mode)
(let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
(assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
(add-to-list 'minor-mode-map-alist mykeys))))
use-package
, eval을 설치 하면 완료됩니다.
(require 'bind-key)
(bind-key* "C-i" 'some-function)
"emacs undefine org mode keybindings"를 검색하는 동안이 질문을 발견했습니다. 기존 Cc Cb 동작의 바인딩을 해제하여 내 글로벌 맵이 조직 버퍼에서 작동하도록 버퍼 버퍼를 허용하기를 원했기 때문입니다.
이것은 저에게 가장 간단한 해결책이되었습니다.
(add-hook 'org-mode-hook
(lambda ()
(local-unset-key (kbd "C-c C-b"))))
scottfrazer의 대답이 정확히 당신이 요청한 것이지만, 나는 후손에 대해 또 다른 해결책을 언급 할 것입니다.
에서 매뉴얼 이맥스 :
"Lisp 프로그램에서 Cc 문자를 키로 정의하지 마십시오. Cc와 문자 (대문자 또는 소문자)로 구성된 시퀀스는 사용자를 위해 예약되어 있습니다. 사용자를 위해 예약 된 유일한 시퀀스이므로 차단하지 마십시오."
개인 전역 바인딩을 Cc와 문자에 바인딩하면 "안전해야"합니다. 그러나 이것은 단지 관례 일 뿐이며 모든 모드는 여전히 바인딩을 재정의 할 수 있습니다.
If you want to "always use the keybinds in the map, unless I explicitly override them for a specific mode-map", and assuming you are using scottfrazier's approach, you want:
(defun locally-override (key cmd)
(unless (local-variable-p 'my-keys-minor-mode-map)
(set (make-variable-buffer-local 'my-keys-minor-mode-map)
(make-sparse-keymap))
(set-keymap-parent my-keys-minor-mode-map
(default-value 'my-keys-minor-mode-map)))
(define-key my-keys-minor-mode-map key cmd))
So
(locally-override "\C-i" nil)
should remove the "\C-i" binding from the minor mode in the current buffer only. Warning: this is completely untested, but seems like the right approach. The point of setting the parent rather than just coping the global value of my-keys-minor-mode-map is so any later changes to the global value are automatically reflected in the local value.
I don't think you can. That is roughly equivalent to saying that you want to define a global variable that cannot be hidden by local variable declarations in functions. Scope just doesn't work that way.
However, there might be a way to write an elisp function to go through the mode list and reassign it in every single one for you.
Unless you really want to do this yourself, you should check around and see if anyone else already has done it.
There is a package for Emacs which gives your windows-like keybindings. You should be able to find it through google.
참고URL : https://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs
'program tip' 카테고리의 다른 글
쿼리 계획에서 "비트 맵 힙 스캔"이란 무엇입니까? (0) | 2020.08.24 |
---|---|
iPad 세로 및 가로 모드에 대한 크기 조정 클래스 (0) | 2020.08.23 |
Ruby를 사용하여 한 단계로 배열을 초기화하는 방법은 무엇입니까? (0) | 2020.08.23 |
자바 스크립트로 업로드하기 전에 이미지 너비와 높이를 확인하세요. (0) | 2020.08.23 |
Rails에서 문제를 테스트하는 방법 (0) | 2020.08.23 |