Are there any emacs key combinations reserved for custom commands?

前端 未结 4 569
忘了有多久
忘了有多久 2020-12-29 07:46

If I want to create a custom key combination to run a command, are there any keyboard shortcuts reserved for this? I always find it difficult to decide on which shortcut to

相关标签:
4条回答
  • 2020-12-29 08:24

    Also remember that all of the reserved sequences can trivially be used as prefix bindings, if you want to group related tasks together, or simply want to take maximum advantage of a particular easy-to-type C-c<letter> sequence.

    For instance, I use C-cm as a prefix for some of the magit (and related) functionality I want quick access to. e.g.:

    (global-set-key (kbd "C-c m m") 'magit-status)
    (global-set-key (kbd "C-c m l") 'magit-key-mode-popup-logging
    (global-set-key (kbd "C-c m b") 'mo-git-blame-current)
    

    And of course, C-cmC-h then shows me all the bindings I have under that prefix.

    0 讨论(0)
  • 2020-12-29 08:32

    You can redefine anything, but the convention is to use C-c l (where l is any letter).

    As a user, you can redefine any key; but it is usually best to stick to key sequences that consist of C-c followed by a letter (upper or lower case). These keys are "reserved for users," so they won't conflict with any properly designed Emacs extension. The function keys F5 through F9 are also reserved for users. If you redefine some other key, your definition may be overridden by certain extensions or major modes which redefine the same key.

    Personally, I try to find a hole in the keybindings to slip my customizations - and there are usually enough for me to find something reasonable. Also, I usually make my custom keybindings local to a minor mode, or major mode keymap, and avoid using global-set-key whenever possible. This helps keep holes in the keymaps.

    For example, I overrode C-r in the minibuffer-local-map to change the path in the minibuffer to the "Resolved" pathname. So while C-r is globally bound to 'isearch-reverse, I don't miss that binding from within the minibuffer (and, it's becomes available if I start searching forward in the minibuffer).

    Another example is that I wrote something that kills all the other buffers whose file name matches the filename of the current buffer. C-x k is 'kill-buffer, and luckily C-x K was free for my 'kill-other-buffers-of-this-file-name, which I like because it's a slight variation on the original keybinding. That is a global setting, but I do want the functionality available globally.

    0 讨论(0)
  • 2020-12-29 08:32

    No, you can map any command to any key you feel like, if it is your configuration.

    If you are creating your mode or lib, then choose keybinding that is not already taken.

    0 讨论(0)
  • 2020-12-29 08:49

    I would suggest using unbound. It was made for just this type of scenario.

    Once you have it required in your emacs config, typing the following will list possible unbound keys for your customization:

    M-x describe-unbound-keys
    

    It asks for a complexity level (I generally just use 5) for the key combination depending on how convenient (less options) or esoteric (more options) a key binding you are interested it.

    0 讨论(0)
提交回复
热议问题