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')\")"
}