1

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.

alper
  • 1,238
  • 11
  • 30
  • 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 Jul 14 '20 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 Jul 14 '20 at 15:31

1 Answers1

3

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))"
jagrg
  • 3,824
  • 4
  • 19
Aidan Schofield
  • 514
  • 3
  • 5
  • `save-buffers-kill-terminal` is going to kill emacs and kill the terminal which is why I suggested `save-buffers-kill-emacs`. – Aidan Schofield Jul 14 '20 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 Jul 14 '20 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`. – Aidan Schofield Jul 14 '20 at 16:33
  • Thanks @Aidan Schofield – alper Jul 14 '20 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 Jul 14 '20 at 23:46