;;; pipe-save.el --- Pipe instead of saving -*- lexical-binding: t -*- ;; Copyright (C) 2023 Philip Kaludercic ;; Author: Philip Kaludercic ;; Maintainer: Philip Kaludercic ;; Version: $Id: pipe-save.el,v 1.1 2023/03/04 14:28:42 oj14ozun Exp $ ;; URL: https://wwwcip.cs.fau.de/~oj14ozun/src+etc/pipe-save.el ;; Package-Requires: ((emacs "24.3")) ;; Package-Version: 1 ;;; Commentary: ;; Use `pipe-save' to create a "virtual" buffer that is populated and ;; saved using command. ;;; Code: (defun pipe-save (cmd &optional in-cmd) "Pipe buffer input through CMD when saving. If the optional argument IN-CMD is non-nil (or the command is invoked using a prefix argument), then use this command to generate the buffer contents and CMD to save them." (interactive (list (read-shell-command "Command: ") (and current-prefix-arg (read-shell-command "In Command: ")))) (with-current-buffer (generate-new-buffer "*IO*") (shell-command (or in-cmd cmd) (current-buffer)) (setq-local write-contents-functions (list (lambda () (if in-cmd (shell-command-on-region (point-min) (point-max) cmd (current-buffer) t) (shell-command-on-region (point-min) (point-max) cmd) (shell-command in-cmd (current-buffer))) t))) (pop-to-buffer-same-window (current-buffer)))) (provide 'pipe-save) ;;; pipe-save.el ends here