I updated magit today using el-get.

When I defined a function,

(global-set-key "c" 
  (lambda () (interactive) (call-interactively 'self-insert-command)))

I couldn't use c c magit status buffer to commit. I get the following *message* buffer:

funcall-interactively: Buffer is read-only: #<buffer *magit-commit-popup*>
enter code here

Is there a proper way for user defined functions in magit?

Note that defining minor-mode doesn't solve my problem as I want to bind functions in global map.

1 Answer 1


When you press c c to create a commit from inside a Magit buffer, this is what happens:

The first c constitutes a complete key binding, established in magit-mode-map. The bound command is magit-commit-popup, which shows the commit popup in a new buffer.

The second c also is a complete key binding. It is invoked while the popup buffer is already the current buffer, and it is established in magit-popup-mode-map like so:

(define-key magit-popup-mode-map [remap self-insert-command]

I.e. whenever a key would be bound to self-insert-command without this binding, then bind it to magit-invoke-popup-action instead. See Remapping Commands for more information.

Because you have mutilated c's binding in global-mode, that doesn't work anymore. Binding c to that lambda has absolutely no benefit. It does the same thing as using self-insert-command directly would. And that's even the default binding, so binding to that lambda does not even change the behavior in normal circumstances.

But using a lambda causes the binding to lose its "identity", which results in Magit, and all other packages that do remap self-insert-command (e.g. isearch) to something else, to break.

You should never override a self-insert-command binding in global-map, certainly not for alphanumeric keys.

Note that defining minor-mode doesn't solve my problem

Depending on what you actually want to do (please explain what it is), this might be your only option. Sorry.

  • I'm not Emacs expert like you, so please let me know if there is solution. I'm using over 50+ emacs lisp packages and worrying if random packages activate their minor-mode, how can we ensure user defined keybinds in minor mode? I always want to prior other minor-mode map keybinds than my keybinds. As the example, I use an emacs e-mail client mew and it binds almost "a" to "z" keys on minor-mode-map. I want to use key pair "C-u w" to spell check at point of cursor, but without C-u, I want to ignore the spell check. I do same thing in twittering-mode. May 24, 2016 at 21:19
  • As the potential reason, I like Emacs default keybinds and I don't want to change from default. In that case, there aren't many empty key combinations except C-u + a-z in short keystroke. (I wouldn't use C-M-s- keys or something similar due to my short fingers) May 24, 2016 at 21:27
  • The bind-key package provides a mechanism for doing this. You don't actually have to use that package if you don't want to, the essential part is just this.
    – tarsius
    May 24, 2016 at 22:22

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.