0

There are always links in help-mode which suppose to be entered by the <return> button. Since I remapped the <return> button to indent-and-new-line, I can no longer enter the link. I would like to find the correct key map for the enter button.

Help mode defined in `help-mode.el' (`help-mode'):
Major mode for viewing help text and navigating references in it.
Entry to this mode runs the normal hook `help-mode-hook'.
Commands:
key             binding
---             -------

C-c             Prefix Command
TAB             forward-button
  (that binding is currently shadowed by another mode)
RET             help-follow
  (that binding is currently shadowed by another mode)
ESC             Prefix Command
SPC             scroll-up-command

I get this help from the describe mode. I tried the help-follow but it does not work. What should be the correct key bind?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
tom
  • 1,302
  • 1
  • 16
  • 30

1 Answers1

2

By default RET runs push-button when on a link in help-mode. You should also be able to click on links with your primary mouse button if you like using the rodent. This function is not bound to any other keys out of the box.

I'm not sure how you're rebinding RET, but it probably makes sense to do it a bit more selectively. indent-and-new-line might make sense in most modes, but as you have discovered there are situations where you may want the default behaviour.

Perhaps you could do this via prog-mode-hook, so it only affects programming modes?

Alternatively you could bind some other key to push-button in help-mode.

By the way, here is a useful technique that would have let you discover this keybinding yourself:

  1. Run Emacs with the -Q flag to suppress loading of your init file and the system init file.
  2. Activate a buffer that uses help-mode, e.g. by using C-h f message RET to see the documentation for the message function and then C-x o to switch to the help window.
  3. Press C-h k RET to see what function is bound to RET.
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • I found that keybind exactly by `C-h k`. I know I can always use mouse click to go in the link but it is so slow. Indeed, I tried rebounding `help-follow` but it did not work. I tried put the cursor on link and `M-x help-follow` which also not working. – tom Jan 05 '16 at 16:06
  • But I did not check the function itself. Maybe it requires a region as a parameter. – tom Jan 05 '16 at 16:11
  • @tom, apparently I got this wrong. `RET` is bound to `push-button` when on a link and to `help-follow` when not. Sorry for the confusion. I have updated my answer. – ChrisGPT was on strike Jan 05 '16 at 16:15
  • Works. But how do you find `push-button`? There is no `push-button` in `help-mode.el`. – tom Jan 05 '16 at 17:13
  • 1
    @tom, I found it by putting point on a link (using `tab`, which is bound to `forward-button`) and then doing `C-h k RET` again. On my system both of these functions are defined in `/usr/share/emacs/25.1.50/lisp/button.elc` (the `.el` file is not present), which can be found using e.g. `M-x find-function RET push-button RET`. – ChrisGPT was on strike Jan 05 '16 at 19:01
  • tom: I second the advice to be careful about clobbering bindings like `RET` which have quite variable behaviour (otherwise you'll just end up with a huge mess of special cases just to restore the default behaviours). I would leave the likes of `RET` out of your http://stackoverflow.com/a/34563431 configuration. – phils Jan 05 '16 at 20:58
  • 3
    If it's of interest, my own approach to `RET` is to evaluate `(local-set-key (kbd "RET") (key-binding (kbd "M-j")))` in `prog-mode-hook` (plus a few other selected hooks for modes not derived from `prog-mode`). `M-j` is the standard key for `indent-new-comment-line`, but some major modes have custom commands for that functionality, so this way I always get the appropriate one. – phils Jan 05 '16 at 21:02
  • @Chris Yeah. I found it. I am also curious that where the fallback mechanism located. There should be sth. like `(unless (push-button) 'help-follow)`. – tom Jan 06 '16 at 04:27
  • @phils I am a newbie to emacs. I found the built-in keymap is a disaster to me. So, basically, I am remapping every keys to fit myself. I do it by defining a minor mode, which you help me a lot, to contain my keymap. I need my minor mode to define keymap beacause if I use `global-set-key`, other packages sometimes override it. To make my keymap to be consistent across every mode, I make it as aggressive as possible. It is done by the code provided by you (the load advice function). – tom Jan 06 '16 at 04:55
  • @phils There is time my-defined keymap shadowed other minor mode keymap causing problem. This is usally found in read-only mode and related to the tab and enter key. So, I just need to find what the originally key command is and make a overriding to my minor mode keymap. To this question, I override the enter key like this `(defun smart-help-mode-override () (smartoverride (kbd "") '(lambda () (interactive) (unless (push-button) (help-follow))))) (add-hook 'help-mode-hook 'smart-help-mode-override)` – tom Jan 06 '16 at 05:17