diff options
| -rw-r--r-- | bard-elisp/bard-eshell.el | 38 | ||||
| -rw-r--r-- | bard-emacs-modules/bard-emacs-eshell.el | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/bard-elisp/bard-eshell.el b/bard-elisp/bard-eshell.el index 0a2f9c5..9625a13 100644 --- a/bard-elisp/bard-eshell.el +++ b/bard-elisp/bard-eshell.el @@ -36,6 +36,44 @@ open the directory in a `dired' buffer." (find-file file) (user-error "No file at point")))) +(defcustom prot-eshell-output-buffer "*Exported Eshell output*" + "Name of buffer with the last output of Eshell command. +Used by `prot-eshell-export'." + :type 'string + :group 'prot-eshell) + +(defcustom prot-eshell-output-delimiter "* * *" + "Delimiter for successive `prot-eshell-export' outputs. +This is formatted internally to have newline characters before +and after it." + :type 'string + :group 'prot-eshell) + +(defun prot-eshell--command-prompt-output () + "Capture last command prompt and its output." + (let ((beg (save-excursion + (goto-char (eshell-beginning-of-input)) + (goto-char (point-at-bol))))) + (when (derived-mode-p 'eshell-mode) + (buffer-substring-no-properties beg (eshell-end-of-output))))) + +;;;###autoload +(defun prot-eshell-export () + "Produce a buffer with output of the last Eshell command. +If `prot-eshell-output-buffer' does not exist, create it. Else +append to it, while separating multiple outputs with +`prot-eshell-output-delimiter'." + (interactive) + (let ((eshell-output (prot-eshell--command-prompt-output))) + (with-current-buffer (get-buffer-create prot-eshell-output-buffer) + (let ((inhibit-read-only t)) + (goto-char (point-max)) + (unless (eq (point-min) (point-max)) + (insert (format "\n%s\n\n" prot-eshell-output-delimiter))) + (goto-char (point-at-bol)) + (insert eshell-output) + (switch-to-buffer-other-window (current-buffer)))))) + (defgroup bard-eshell-faces nil "Faces for my custom modeline." :group 'prot-eshell-faces) diff --git a/bard-emacs-modules/bard-emacs-eshell.el b/bard-emacs-modules/bard-emacs-eshell.el index 412ef7b..b129ac0 100644 --- a/bard-emacs-modules/bard-emacs-eshell.el +++ b/bard-emacs-modules/bard-emacs-eshell.el @@ -8,6 +8,7 @@ (define-key eshell-mode-map (kbd "C-c f") #'bard/eshell-find-file-at-point) (define-key eshell-mode-map (kbd "C-c h") #'prot-eshell-narrow-output-highlight-regexp) (define-key eshell-mode-map (kbd "C-c d") #'prot-eshell-complete-recent-dir) - (define-key eshell-mode-map (kbd "M-k") #'eshell-kill-input)) + (define-key eshell-mode-map (kbd "M-k") #'eshell-kill-input) + (define-key eshell-mode-map (kbd "C-c C-e") #'prot-eshell-export)) (provide 'bard-emacs-eshell) |
