Default behavior of man <command> (opens inside less) when q is pressed it is closed.

I am using following to open MANPAGER with emacs:

emacsclient -nw -e "(let ((Man-notify-method 'bully)) (man \"$1\"))"

Here pressing q closes buffer but does not close the emacs like Ctrl-x Ctrl-c does. Is it possible to bind q into the same action Ctrl-x Ctrl-c to exit the emacs and get back to shell.

  • 3
    Given that you want to use your Emacs session as a presentation layer for man, I would think you'd be better off setting Man-notify-method to newframe and then exiting by using C-x 5 0. You could even set a single key like Q (upper case) to delete-frame. That way you would never accidentally leave Emacs altogether - since q is such a useful key in many modes
    – gregoryg
    Commented Jul 14, 2020 at 15:23
  • I think you are right! Becase when I click to a linked man page, it opens it on other window and clicking q closes that opened buffer. Instead to be more clear Q could be used, which also exists on the Man page via less
    – alper
    Commented Jul 14, 2020 at 15:31

1 Answer 1


the incantation you want is

(define-key Man-mode-map "q" 'save-buffers-kill-emacs)

I am guessing that you can do this inside your let form.

emacsclient -nw -e "(let ((Man-notify-method 'bully)) (man \"$1\") (define-key Man-mode-map \"q\" 'save-buffers-kill-emacs))"
  • save-buffers-kill-terminal is going to kill emacs and kill the terminal which is why I suggested save-buffers-kill-emacs. Commented Jul 14, 2020 at 15:55
  • Ah my bad I confused them. //Lets say I did man printf and click to printf(3) at the bottom of the page right under SEE ALSO. At this point, when I press q instead of doing save-buffers-kill-terminal can it also do its default behaviour which is only to close one of the buffer?
    – alper
    Commented Jul 14, 2020 at 16:09
  • 1
    I think that typing k will kill just the buffer you are viewing. When you are viewing a man page in emacs type C-h m to find all the things you can do in Man-mode. Commented Jul 14, 2020 at 16:33
  • Thanks @Aidan Schofield
    – alper
    Commented Jul 14, 2020 at 16:36
  • The *-kill-emacs function kills the Emacs process, so for client processes you may want to use save-buffers-kill-terminal.
    – jagrg
    Commented Jul 14, 2020 at 23:46

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.