Warn about key rebinds

This commit is contained in:
Gergely Polonkai 2016-11-18 09:52:15 +01:00
parent 4ea052b970
commit 4e666d5c6b
2 changed files with 30 additions and 0 deletions

View File

@ -40,6 +40,9 @@
(load "frame-manip")
(load "file-manip")
(load "window-manip")
(load "gpolonkai-misc")
(advice-add 'define-key :before #'warn-key-rebind)
;; Define aliases
(defalias 'yes-or-no-p 'y-or-n-p)

27
lisp/gpolonkai-misc.el Normal file
View File

@ -0,0 +1,27 @@
(defun warn-key-rebind (keymap key new-def)
"Warn if a key is being rebound."
(let ((global-def (global-key-binding key))
(local-def (local-key-binding key))
(minor-defs (minor-mode-key-binding key))
(key-desc (key-description key)))
(when (and global-def
(not (numberp global-def))
(not (equal global-def new-def)))
(warn "'%s' from the global keymap is being rebound from '%s' to '%s'"
key-desc
global-def
new-def))
(when (and local-def
(not (numberp local-def))
(not (equal local-def new-def)))
(warn "'%s' from the local keymap is being rebound from '%s' to '%s'"
key-desc
local-def
new-def))
(when minor-defs
(dolist (binding minor-defs)
(warn "'%s' from '%s' keymap is being rebound from '%s' to '%s'"
key-desc
(car binding)
(cdr binding)
new-def)))))