>From ccc4427ff06bf6dc63840517aefbb7fb899d4b8c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 6 Feb 2021 00:01:50 -0700 Subject: [PATCH 1/2] Add eshell-restore-unexpanded-input * lisp/eshell/esh-mode.el (eshell-send-input): Store the original input before running eshell-expand-input-functions. * lisp/eshell/esh-mode.el (eshell-restore-unexpanded-input): Define new function and register as a customization option for eshell-input-filter-functions. --- lisp/eshell/esh-mode.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index d29b010ea0..6036829941 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -197,6 +197,7 @@ This is used by `eshell-watch-for-password-prompt'." ;; byte-compiler, when compiling other files which `require' this one (defvar eshell-mode nil) (defvar eshell-command-running-string "--") +(defvar eshell-last-unexpanded-input nil) (defvar eshell-last-input-start nil) (defvar eshell-last-input-end nil) (defvar eshell-last-output-start nil) @@ -631,6 +632,7 @@ newline." (progn (setq input (buffer-substring-no-properties eshell-last-output-end (1- (point)))) + (setq eshell-last-unexpanded-input input) (run-hook-with-args 'eshell-expand-input-functions eshell-last-output-end (1- (point))) (let ((cmd (eshell-parse-command-input @@ -664,6 +666,21 @@ newline." (custom-add-option 'eshell-input-filter-functions 'eshell-kill-new) +(defun eshell-restore-unexpanded-input () + "Restore the input text before `eshell-expand-input-functions' ran. +Useful when you want to see the unexpanded input rather than the +expanded input in the Eshell buffer, and when you want later +entries in `eshell-input-filter-functions' to use the unexpanded +input. For example, you might want the unexpanded input to be +what gets stored in the history list." + (setf (buffer-substring eshell-last-input-start + (1- eshell-last-input-end)) + eshell-last-unexpanded-input) + (eshell-update-markers eshell-last-output-end)) + +(custom-add-option 'eshell-input-filter-functions + 'eshell-restore-unexpanded-input) + (defun eshell-output-filter (process string) "Send the output from PROCESS (STRING) to the interactive display. This is done after all necessary filtering has been done." -- 2.29.2