From d209e519afee2551a1e9700caf819c2053988cff Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 13 Apr 2025 02:49:03 -0400 Subject: [PATCH] fix(eshell): highlight syntax after completing from history Fix: #6867 Co-authored-by: aikrahguzar --- modules/term/eshell/config.el | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/term/eshell/config.el b/modules/term/eshell/config.el index 2fc5eee4f..d06e2ab9e 100644 --- a/modules/term/eshell/config.el +++ b/modules/term/eshell/config.el @@ -261,7 +261,29 @@ Return nil if there is none." (use-package eshell-syntax-highlighting :hook (eshell-mode . eshell-syntax-highlighting-mode) - :init + :config + (defadvice! +eshell-filter-history-from-highlighting-a (&rest _) + "Selectively inhibit `eshell-syntax-highlighting-mode'. +So that mathces from history show up with highlighting." + :before-until #'eshell-syntax-highlighting--enable-highlighting + (memq this-command '(eshell-previous-matching-input-from-input + eshell-next-matching-input-from-input))) + + (defun +eshell-syntax-highlight-maybe-h () + "Hook added to `pre-command-hook' to restore syntax highlighting +when inhibited to show history matches." + (when (and eshell-syntax-highlighting-mode + (memq last-command '(eshell-previous-matching-input-from-input + eshell-next-matching-input-from-input))) + (eshell-syntax-highlighting--enable-highlighting))) + + (add-hook! 'eshell-syntax-highlighting-elisp-buffer-setup-hook + (defun +eshell-syntax-highlighting-mode-h () + "Hook to enable `+eshell-syntax-highlight-maybe-h'." + (if eshell-syntax-highlighting-mode + (add-hook 'pre-command-hook #'+eshell-syntax-highlight-maybe-h nil t) + (remove-hook 'pre-command-hook #'+eshell-syntax-highlight-maybe-h t)))) + (add-hook 'eshell-syntax-highlighting-elisp-buffer-setup-hook #'highlight-quoted-mode))