5

The info.el library allows us to view manuals not only for ELisp packages, but also for applications that are independent of Emacs.

E.g.,

(info "gcc")

has the same effect as /usr/bin/info:

$ info gcc

info, which looks like a simplified & trimmed Emacs, doesn't highlight; whereas Emacs does.

How can I replace info with emacs so that I can get full Emacs feature support?

2 Answers 2

4

Here's a way that re-uses your running Emacs instance:

emacsclient --eval '(info "gcc")' --tty --alternate-editor=

(--eval tells the Emacs instance to evaluate a lisp form. --tty ensures that it displays in the current terminal. --alternate-editor= will automatically start Emacs if it isn't already running. See the emacsclient options page for more info.)

In your shell, you'll have to use a function instead of an alias, because emacsclient has no way to properly pass through its arguments as-is to the Elisp form: once --eval is in play, all non-options are interpreted as Elisp.

If you want just the quick and dirty version, this will do:

info()
{
    emacsclient --alternate-editor= --tty --eval "(info \"$1\")"
}

"But what if the argument has characters that are special within lisp strings?" To be robust, we need to escape all \ to \\ and all " to \" - based on the Elisp string syntax and some basic testing, that seems to be enough.

So if you're already using a modern shell like bash/zsh, you can do this:

info()
{
    local escaped_backslashes="${1//\\/\\\\}"
    local escaped="${escaped_backslashes//\"/\\\"}"
    emacsclient --alternate-editor= --tty --eval "(info \"$escaped\")"
}

If you need to be more portable, this should be good enough for most purposes:

info()
{
    emacsclient --alternate-editor= --tty --eval "(info \"$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/\"/\\\"/g')\")"
}
2
  • Why not use -create-frame instead of -tty?
    – shynur
    Commented Aug 12 at 14:17
  • @shynur --create-frame is fine if you want it to display in a new GUI window when possible. I went with--tty for this question because displaying in the same terminal is closer to the UX/workflow you'd normally get with the info command. I figured the visual switch might be unwanted (finding where the new GUI frame appeared, possibly needing to move/resize the new window, having something else get covered up). And if someone does want a GUI frame, idk if they would want to reuse an existing frame. (Maybe I'll eventually flesh this comment out into an edit enumerating these options.)
    – mtraceur
    Commented Aug 12 at 17:17
6

Use emacs -f info-standalone. E.g.,

$ emacs -f info-standalone gcc

I prefer alias info='emacs -Q -f info-standalone' in my .bash_profile.

3
  • 1
    +1, but a couple notes: 1) With this approach, the info buffer will be buried if your Emacs config has (setq initial-buffer-choice ...). 2) Since this is starting a new Emacs process, you'll have to wait your entire Emacs start-up time.
    – mtraceur
    Commented Aug 11 at 19:51
  • 1
    @mtraceur: Re(1): Thank you. I forgot the option because I only tested the -Q startup. |||| Re(2): Yes, I know that. This answer is just to be enlightening - telling people that there is such a way. Then people can form their own methods to suit their needs and preferences.
    – shynur
    Commented Aug 11 at 20:52
  • 1
    cheers! Re(2): I figured you knew; that half of my comment was mainly for any newbies who come across this Q&A before they know about that trade-off.
    – mtraceur
    Commented Aug 11 at 21:38

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.