I am able to use man inside emacs. M-x man , <ln> , [enter].

=> From the shell can I open man pages from the shell? For examlpe doing $ man ln can open the man page inside the emacs?

$ export MANPAGER='emacsclient -t -q'
$ man ln
❯ # opens the `*scratch*` file

  • 1
    I am not aware of an existing solution. MANPAGER needs a) the program to read from standard input, but Emacs and Emacsclient can't do this, though maybe vip or vipe can help? b) display the rendered man pager, that is, handle the terminal escape code, an Emacs major mode is needed, I tried Man-mode but it didn't work. According to lobste.rs/s/gquf4t/one_small_step_for_man#c_bukh5l, Neovim meets both the requirements, export MANPAGER="nvim -u NORC -c 'set ft=man' -", the result looks good, it even has specific sytnax highlight for C functions such as man 3 printf.
    – xuchunyang
    Jul 5 '20 at 13:18
  • nvim seems pretty nice thank you for sharing. If it also highlights in different color of the current word on the search it would be much better :-) During search(/) in nvim I wish I able to use basic emacs's key bindings like ctrl-a to fo to beginning of line ctrl-k to kill the line etc.
    – alper
    Jul 5 '20 at 13:41
  • seems like it enter a endless loop and does not open anything :(
    – alper
    Jul 5 '20 at 18:26
  • Sorry, I meant a function: man() { emacsclient -nw -e "(woman \"$1\")" }.
    – jagrg
    Jul 5 '20 at 20:15
  • I pasted it into bash and called man printf but didn't work as I wanted
    – alper
    Jul 5 '20 at 23:28

Define a shell function that uses the first argument to man as a parameter

macsman() {
    emacsclient -c -e "(man \"$1\")"

alias man=macsman

You could invoke the function without the alias (e.g. macman ls), but it may be useful to set the alias for specific shells.

One note: You may want to assure your Man page is visible in the Emacs session as soon as it is invoked. Check the settings of the Man-notify-method variable to achieve that. Either set it using customize-variable, or set it explicitly as part of the function, i.e.

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

(Hat tip to @phils)

  • it gives #<buffer *Man *> error
    – alper
    Jul 12 '20 at 0:09
  • I only see that message at the shell if I specify a non-existent man page. Can you execute macsman ls ? That should work as long as the function is sourced and the quotes are escaped. (Assuming bash, BTW). Also check the Messages buffer in Emacs, it should indicate that it's invoking man in the background)
    – gregoryg
    Jul 12 '20 at 0:14
  • You might find --eval "(let ((Man-notify-method 'bully)) (man \"$1\"))" preferable.
    – phils
    Jul 12 '20 at 11:19
  • I keep getting the same error :-( emacsclient --eval "(let ((Man-notify-method 'bully)) (man \"ls\"))" output: #<buffer *Man ls*> @phils
    – alper
    Jul 12 '20 at 16:52
  • 1
    All good seems like there is something is wrong on my end
    – alper
    Jul 13 '20 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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