(defun pipe (filename buffer-name)
  "Open FILENAME and append its content to buffer BUFFER-NAME.

If a buffer with that name does not exist, it's created."
  (find-file filename)
  (append-to-buffer (get-buffer-create buffer-name) (point-min) (point-max))
  (kill-buffer)
  (switch-to-buffer buffer-name))

(defun pipe (filename buffer-name)
  "Open FILENAME and insert its content to buffer BUFFER-NAME.

If the buffer BUFFER-NAME does not exist, it's created.
If narrowing is taking place in buffer BUFFER-NAME only the narrowed region is
replaced by the piped content."
  (find-file filename)
  (let ((stdin (get-buffer-create buffer-name))
        (tmp (current-buffer)))
    (switch-to-buffer stdin)
    (delete-region (point-min) (point-max))
    (switch-to-buffer tmp)
    (append-to-buffer stdin (point-min) (point-max))
    (kill-buffer)))

Support for replacing buffer contents and respect narrowing
Support for replacing buffer contents and respect narrowing
Emacs-Madrid/emacs-terminal