0

I want to set a key binding for outline-next-visible-heading but I fail to do so. I believe using hooks is a solution for this so I added this to my .emacs

(defun outline-mode-test-hook()
  (define-key outline-mode-prefix-map "j" 'outline-next-visible-heading))
(add-hook 'outline-mode-hook 'outline-mode-test-hook)

The key binding has no effect.

P.S. Who actually runs outline-mode-hook ? I didn't see any invocation within file outline.el.

5
  • The hook is no doubt invoked by outline-mode.
    – Drew
    May 8, 2018 at 0:41
  • @Drew: I don't understand why you think a function-vs-command confusion might be linked to the user's problem.
    – Stefan
    May 8, 2018 at 2:05
  • @Pommy: Can you describe what you tried to do, which made you think "the key binding" has no effect? E.g. what key have you pressed which you thought would trigger the command?
    – Stefan
    May 8, 2018 at 2:06
  • @Stefan: Oops, my bad; sorry. I didn't pay attention to the code.
    – Drew
    May 8, 2018 at 14:14
  • @Stefan I have (setq outline-minor-mode-prefix "\C-co") set so all of my outline commands are prefixed with Ctrl-c o and work fine. When I type Ctrl-c o j nothing happens. If I manually (using C-x C-e) execute define-key directive custom key binding start to work. But of course I need it to be done automatically on startup.
    – Pommy
    May 8, 2018 at 15:41

1 Answer 1

1

Your question doesn't mention it, but your comment hints at the fact that you're using outline-minor-mode rather than outline-mode.

outline-mode-hook is run when you enter the outline-mode major mode. Since you use outline-minor-mode that hook is not run, instead the outline-minor-mode-hook is run, hence you'd need something like:

(add-hook 'outline-minor-mode-hook #'outline-mode-test-hook)

Another option is to use

(with-eval-after-load 'outline
  (define-key outline-mode-prefix-map "j" 'outline-next-visible-heading))

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.