1

I recently used a package that overwrote C-x C-s to something other than save, causing me to lose a lot of work. Is there a way I can advise emacs to check for a blacklist of keybindings that it shouldn't allow to be remapped?

Edit: The package in question is (the otherwise excellent) atomic-chrome, and this looks to be the offending line:

(defvar atomic-chrome-edit-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-x C-s") 'atomic-chrome-send-buffer-text)
    (define-key map (kbd "C-c C-c") 'atomic-chrome-close-current-buffer)
    map)
  "Keymap for minor mode `atomic-chrome-edit-mode'.")
3
  • Can you give more details? What package was it? How did you install it? Melpa? What you are describing is strange. Usually global keybindings don't get remapped by installing a new package.
    – Ajned
    Sep 14, 2020 at 21:17
  • Clearly that's a bug in the package you were using. Have you reported it? What was it?
    – phils
    Sep 14, 2020 at 22:58
  • They probably meant C-c C-s - please report it to them.
    – NickD
    Oct 1, 2020 at 2:27

1 Answer 1

1
+50

One solution could be to advise the define-key function and check which key is being bound against a block list:

(defvar define-key-block-list
  '("C-x C-s"))

(defun define-key-filter (define-key &rest args)
  (if (cl-member (nth 1 args) define-key-block-list :key 'kbd :test 'equal)
      (message "Blocked %s from being bound" (key-description (nth 1 args)))
    (apply define-key args)))

(advice-add 'define-key :around #'define-key-filter)

(global-set-key (kbd "C-x C-s") (lambda () (interactive) (message "test")))
;; Blocked C-x C-s from being bound

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.