In eshell I can redirect the output of a command (foo) to a buffer (bar) by inputting:

foo > #<buffer bar>

I want to customize this syntax the following way:

foo > #bar

Is it possible to customize it? How?

Details emacs version: GNU Emacs 24.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.10) of 2017-09-20 on c1bm.rdu2.centos.org

  • Note that also foo > #<bar> works. You do not need the word buffer. Don't know if that is still too much for you. Works for me on cygwin emacs 26.1. – Tobias Jun 19 '18 at 11:44
  • @Tobias I tried this on my emacs and I get the error Eshell does not support input redirection. I had a look on the eshell manual and it mentions that this command should work. – rph Jun 19 '18 at 11:47
  • Please add version info (emacs-version). Does foo > #<bar> also fail with emacs -Q? – Tobias Jun 19 '18 at 12:58
  • @Tobias, I have just added. Please, see my question. Yes, it also fails with emacs -Q, as well as with emacs --no-window-system. – rph Jun 19 '18 at 14:01
  • Rather old version... Have you already tried foo >>> #<bar>? – Tobias Jun 19 '18 at 14:04

To redirect to a buffer, use #<buffer buffer-name>, since Emacs 24.4, you can also use the shorthand #<buffer-name>. For example,

echo hello >>> #<buffer *scratch*>
echo world >>> #<*scratch*>

It looks like it is possible to customize the syntax via the hook eshell-parse-argument-hook, such as supporting #buffer-name as well. Here is my attempt,

(defun eshell-parse-my-special-reference ()
  (when (and (not eshell-current-argument)
             (not eshell-current-quoted)
             ;; Don't overwrite `eshell-parse-special-reference'
             (not (looking-at "#<\\(\\(buffer\\|process\\)\\s-\\)?"))
             (looking-at "#\\(\\S-+\\)")
             (match-string 1))
    (goto-char (match-end 0)) ;; Go to the end of the match.
    (list 'get-buffer-create (match-string 1))))

(add-hook 'eshell-parse-argument-hook #'eshell-parse-my-special-reference)

and the following worked as expected

echo foobar >>> #*scratch*
  • 1
    Just as a side note: The corresponding changeset: github.com/emacs-mirror/emacs/commit/… – Tobias Jun 20 '18 at 8:53
  • This has a weird side effect. When I type a normal command with arguments, such as ls -lah, the eshell will not recognize the command. It prints the message ls -lah: command not found. – rph Jun 20 '18 at 13:05

May not be a direct answer to your problem. But you can use key binding C-c M-b to insert the buffer name at the point. With fido-mode enabled, these key binding help me easily choose the buffer name from the mini-buffer and insert in the form which eshell understands. See Useful Keybindings section of masteringemacs-mastering-eshell for more details.

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.