0

I am willing to learn how to use ediff-mode.

One of the reasons that I am struggling is because I need to ask for help which is bound to ?. Unfortunately, I am having a hard time with ? on an American keyboard with Brazilian Portuguese input (see [the previous question][3]).

My hack (described in the previous question) is not handy in situations like this.

How to change the binding for help to something else in my init file?

For instance, I would like to have > instead of ?.

1
  • 1
    "the previous question" doesn't mean anything. Questions have no effective order. Please link to the question where you describe your hack. Or describe it here.
    – Drew
    Sep 20, 2022 at 22:03

2 Answers 2

3

It is not a good idea to change the global map for this as this answer recommends: it affects far more than the binding that you want to change which is only valid inside the Ediff Control Panel buffer. In particular, it will affect how > is handled in fundamental mode, text modes, programming modes - anywhere where the mode itself does not redefine >, so its definition would be fetched from the global map. When you type > in such a buffer, you will get an error message: ediff-toggle-help: This command runs in Ediff Control Buffer only!.

You need to change it in the appropriate keymap, the one that corresponds to the major mode of the Ediff Control Panel buffer. In this case, that is the keymap called ediff-mode-map.

You can do that (using the "new" interface from keymap.el) like this:

(keymap-set ediff-mode-map ">" #'ediff-toggle-help)

However, putting the above in your init file will not work. ediff-mode-map is not defined at that point. The usual solution is to do the mapping in a function that is called from the major mode hook, but that solution does not work here because ediff-mode-map is a local keymap to each Ediff Control Panel and is not defined when the mode hook is run. But ediff provides a number of hooks (do C-h v ediff--hook<TAB> to see a completion buffer with all twenty-seven of them): the problem is to find one that is run after the local ediff-mode-map is defined and populated. The one I picked certainly satisfies this condition but it may not be the only one: it is ediff-startup-hook. The code that you should put in your init file then looks like this:

(defun my/ediff-mode-bindings ()
  (keymap-set ediff-mode-map ">" #'ediff-toggle-help))

(add-hook 'ediff-startup-hook #'my/ediff-mode-bindings)

Lightly tested.

Note that the above will overwrite the current binding of > in ediff-mode-map, which by default is the function ediff-scroll-horizontally. If you need that function, you can always do M-x ediff-scroll-horizontally. But it is probably better to use a different key, one that is not currently used in ediff-mode-map. Assuming that the inverted ? is easily typed on your keyboard, maybe use that instead?

1

The command corresponding to your desctiption seems to be ediff-toggle-help. So I that guess adding the following line to your init might work:

(global-set-key (kbd ">") 'ediff-toggle-help)

Notes:

  • You can find out the name of the command corresponding to a keybinding with C-h k
  • You might also consider remapping your keyboard at OS level
2
  • 3
    It is not a good idea to change the global map like this: it affects far more than what happens when you press > in an ediff control panel. Try opening a file in fundamental mode and pressing > there. Instead what you need to do is modify the binding in the ediff-mode-map: that will limit the impact to just the case the OP is interested in. BTW, you probably should use the "new" interface in keymap.el: (keymap-set ediff-mode-map ">" #'ediff-toggle-help) should do it. Untested.
    – NickD
    Sep 21, 2022 at 2:36
  • I fully agree with your point. However, as I think that ? is an important key, if I were the OP, I would remap it at OS level, for easy access.
    – crocefisso
    Sep 21, 2022 at 12:41

Your Answer

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

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