From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Nov 2024 01:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 74287@debbugs.gnu.org Cc: Jim Porter , Sean Whitton , James Thomas , Juri Linkov X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17312017678886 (code B ref -1); Sun, 10 Nov 2024 01:23:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Nov 2024 01:22:47 +0000 Received: from localhost ([127.0.0.1]:54988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wf5-0002JC-T3 for submit@debbugs.gnu.org; Sat, 09 Nov 2024 20:22:46 -0500 Received: from lists.gnu.org ([209.51.188.17]:47482) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wf2-0002J2-2B for submit@debbugs.gnu.org; Sat, 09 Nov 2024 20:22:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9wf0-0004HJ-Ei for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:22:38 -0500 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9wex-0005Vn-9q for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:22:38 -0500 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.stl.internal (Postfix) with ESMTP id 21A4425400F2; Sat, 9 Nov 2024 20:22:34 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Sat, 09 Nov 2024 20:22:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1731201753; x=1731288153; bh=lVbyOeC+C4vLy+xAzHW52zud3Rzqlfyw VthoAxVD9ng=; b=EzzXuDGAlEPWN5u3i/SdyFz7Ca4u7aAe0mKO0qFVxIjFoLHI AiN+P/zqXZVuxhQYaM8vqSyvVXpB9m7vKomZyUVvFIlUPyCLOfmy+6VYm+/Lyfox 1EWcfx0xMWJsh1LDIPjhHkeljNyjME4QWTt+YCUt2W8nbb5814GIeASJvWS89P8W uoKDOSxy0ChA6NixXkp8P2EKQQ+w7jpQ6odXmXm3sWIlR3X1NycUHGGR1RmR+abF GF8MookU/mO4VzaQicWGIUYTJB61eN8ZAhxM+/X7D5zX5qs5k6GUPxexMzpovRm8 55N3brh2+wSgPVkyx/pAr3qxXgphRgOW1+kEpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1731201753; x= 1731288153; bh=lVbyOeC+C4vLy+xAzHW52zud3RzqlfywVthoAxVD9ng=; b=P 5DyAY8FzT8IWET2LxwyN9PNgDTL3d4ZUgu/GUYjdiugYzg2tuIVJShiVwu+32KmH gledpOOTohsHLDfwHCx6cE7FXSeZdAf66lC10ZkII9h3rNO4VUMtgixdwleyo2lZ 2vcEDd0pJ118sUQZFP/FKyppp+wfbOapX7Y6x9F75/QTozeomf4wp49tygLINC/X 4irmOG367S9ZCmzRqtzcuoshT/y1ouDuPzgPURbCz2BtgZbLL8eJ7LlRW8Kfvf+F xynjNl9Y9ZSUsyR5yWI1B9aKmjgveR0ntImztzN/Us2ZwKsZ1I1x0e+fe7+XFYtu LCr1jwqs8AORQYuXH6hoQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdelgdefgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkfggtgesmhdtreertddttdenucfhrhho mheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenucggtf frrghtthgvrhhnpeeugedtkeejtefgleeuffeljeffuddtvddvleefffelieekteelgfdt fefhkeeikeenucffohhmrghinhepghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgs pghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepsghughdqgh hnuhdqvghmrggtshesghhnuhdrohhrghdprhgtphhtthhopehjphhorhhtvghrsghughhs sehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvthdprh gtphhtthhopehsphifhhhithhtohhnsehsphifhhhithhtohhnrdhnrghmvgdprhgtphht thhopehjihhmjhhovgesghhmgidrnhgvth X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 9 Nov 2024 20:22:32 -0500 (EST) From: Pengji Zhang Date: Sun, 10 Nov 2024 09:22:09 +0800 Message-ID: <871pzjkhmm.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=202.12.124.154; envelope-from=me@pengjiz.com; helo=fhigh-b3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) --=-=-= Content-Type: text/plain Hello, This patch brings a comint-like interface for history Isearch to Eshell. To try it, type 'M-r' in Eshell, and search through the input history ring incrementally. Compared to the existing implementation, this patch integrates with Isearch properly, like what we do for the minibuffer and comint modes. There are relevant discussions (thank you all for the feedback!) in the mailing list: https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00069.html For Jim's concern, I do not think this implementation closes the door for a history completion interface, as shown by Sean and Juri. Thanks! Pengji --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Rework-history-Isearch-for-Eshell.patch >From d455ec1bf1b49871cf866457df77f6ab45f5623f Mon Sep 17 00:00:00 2001 From: Pengji Zhang Date: Sun, 10 Nov 2024 08:50:27 +0800 Subject: [PATCH] Rework history Isearch for Eshell This is to make history Isearch for Eshell similar to that of 'comint-mode', by hooking into Isearch properly instead of defining new commands to emulate Isearch. * lisp/eshell/em-hist.el (eshell-history-isearch): New user option. (eshell-goto-history, eshell--isearch-setup) (eshell-history-isearch-end, eshell-history-isearch-search) (eshell-history-isearch-message, eshell-history-isearch-wrap) (eshell-history-isearch-push-state): New functions. (eshell-isearch-backward-regexp, eshell-isearch-forward-regexp): New commands. (eshell--history-isearch-messasge-overlay) (eshell--stored-incomplete-input): New internal variables. (eshell-hist-mode-map): Bind 'M-r' to 'eshell-isearch-backward-regexp' and free 'M-s' binding for normal in-buffer search commands. (eshell-isearch-backward, eshell-isearch-forward): Use the new way to start searching. (eshell-hist-initialize): Use the new Isearch setup function. (eshell-previous-matching-input): Use 'eshell-goto-history'. Also inhibit messages when searching. (eshell-isearch-map, eshell-isearch-repeat-backward) (eshell-isearch-abort, eshell-isearch-delete-char) (eshell-isearch-return, eshell-isearch-cancel) (eshell-isearch-repeat-forward, eshell-test-imatch) (eshell-return-to-prompt, eshell-prepare-for-search): Remove. These are for the old history Isearch implementation. * doc/misc/eshell.texi (History): Document changes. * etc/NEWS: Annouce changes. --- doc/misc/eshell.texi | 15 +- etc/NEWS | 23 +++ lisp/eshell/em-hist.el | 322 ++++++++++++++++++++++++----------------- 3 files changed, 223 insertions(+), 137 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index ee4d0ca09c8..701137ea1b4 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -2661,10 +2661,10 @@ History @table @kbd @kindex M-r -@kindex M-s @item M-r -@itemx M-s -History I-search. +History I-search. @kbd{M-r} starts an incremental search in input +history. While searching, type @kbd{C-r} to move to the previous match, +and @kbd{C-s} to move to the next match in the input history. @kindex M-p @kindex M-n @@ -2675,6 +2675,15 @@ History previous or next line that begins with that string. @end table +@vindex eshell-history-isearch +If you would like to use the default Isearch key-bindings to search +through input history, you may customize @code{eshell-history-isearch} +to @code{t}. That makes, for example, @kbd{C-r} and @kbd{C-M-r} in an +Eshell buffer search in input history only. In addition, if the value +of @code{eshell-history-isearch} is @code{dwim}, those commands search +in the history when the point is after the last prompt, and search in +the buffer when the point is before or within the last prompt. + @node Extension modules @chapter Extension modules Eshell provides a facility for defining extension modules so that they diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..c1df6f78d9f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -288,6 +288,29 @@ This hook runs after an Eshell session has been fully initialized, immediately before running 'eshell-post-command-hook' for the first time. ++++ +*** Improved history Isearch. +History Isearch in Eshell is reworked. Two new commands +'eshell-isearch-backward-regexp' and 'eshell-isearch-forward-regexp' are +added for incrementally searching through the input history. +'eshell-isearch-backward-regexp' is bound to 'M-r' by default, and 'M-s' +is freed for normal search commands. If you would like to restore the +previous key-bindings for the non-incremental search commands, put in +your configuration: + + (keymap-set eshell-hist-mode-map "M-r" + #'eshell-previous-matching-input) + (keymap-set eshell-hist-mode-map "M-s" + #'eshell-next-matching-input) + ++++ +*** New user option 'eshell-history-isearch' +When 'eshell-history-isearch' is nil (the default), Isearch commands +search in the buffer contents. If you customize it to t, those commands +only search in input history. If you customize it to the symbol 'dwim', +those commands search in input history only when the point is after the +last prompt. + ** SHR +++ diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index fffd611c06f..de986b05f48 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -34,7 +34,6 @@ ;; Also, most of `comint-mode's keybindings are accepted: ;; ;; M-r ; search backward for a previous command by regexp -;; M-s ; search forward for a previous command by regexp ;; M-p ; access the last command entered, repeatable ;; M-n ; access the first command entered, repeatable ;; @@ -132,6 +131,17 @@ eshell-input-filter (function :tag "Other function")) :risky t) +(defcustom eshell-history-isearch nil + "Non-nil to Isearch in input history only. +If t, usual Isearch keys like \\[isearch-forward] in Eshell search in +the input history only. If `dwim', Isearch in the input history when +point is at the command line, otherwise search in the current Eshell +buffer." + :type '(choice (const :tag "Don't search in input history" nil) + (const :tag "Search histroy when point is on command line" dwim) + (const :tag "Always search in input history" t)) + :version "31.1") + (defun eshell-hist--update-keymap (symbol value) "Update `eshell-hist-mode-map' for `eshell-hist-match-partial'." ;; Don't try to set this before it is bound. See below. @@ -204,25 +214,17 @@ eshell-save-history-index (defvar eshell-hist--new-items nil "The number of new history items that have not been written to file. This variable is local in each eshell buffer.") - -(defvar-keymap eshell-isearch-map - :doc "Keymap used in isearch in Eshell." - :parent isearch-mode-map - "C-m" #'eshell-isearch-return - "C-r" #'eshell-isearch-repeat-backward - "C-s" #'eshell-isearch-repeat-forward - "C-g" #'eshell-isearch-abort - "" #'eshell-isearch-delete-char - "" #'eshell-isearch-delete-char - "C-c C-c" #'eshell-isearch-cancel) +(defvar-local eshell--history-isearch-messasge-overlay nil + "Overlay for Isearch message when searching through input history.") +(defvar-local eshell--stored-incomplete-input nil + "Stored input for history cycling.") (defvar-keymap eshell-hist-mode-map "" #'eshell-previous-matching-input-from-input "" #'eshell-next-matching-input-from-input "C-" #'eshell-previous-input "C-" #'eshell-next-input - "M-r" #'eshell-previous-matching-input - "M-s" #'eshell-next-matching-input + "M-r" #'eshell-isearch-backward-regexp "C-c M-r" #'eshell-previous-matching-input-from-input "C-c M-s" #'eshell-next-matching-input-from-input "C-c C-l" #'eshell-list-history @@ -261,20 +263,9 @@ eshell-hist-initialize (not eshell-non-interactive-p)) (let ((rebind-alist eshell-rebind-keys-alist)) (setq-local eshell-rebind-keys-alist - (append rebind-alist eshell-hist-rebind-keys-alist)) - (setq-local search-invisible t) - (setq-local search-exit-option t) - (add-hook 'isearch-mode-hook - (lambda () - (if (>= (point) eshell-last-output-end) - (setq overriding-terminal-local-map - eshell-isearch-map))) - nil t) - (add-hook 'isearch-mode-end-hook - (lambda () - (setq overriding-terminal-local-map nil)) - nil t)) + (append rebind-alist eshell-hist-rebind-keys-alist))) (eshell-hist-mode)) + (add-hook 'isearch-mode-hook #'eshell--isearch-setup nil t) (make-local-variable 'eshell-history-size) (or eshell-history-size @@ -384,6 +375,23 @@ eshell-get-history "Get an input line from the history ring." (ring-ref (or ring eshell-history-ring) index)) +(defun eshell-goto-history (pos) + "Replace command line with the element at POS of history ring. +Also update `eshell-history-index'. As a special case, if POS is nil +and `eshell--stored-incomplete-input' is a non-empty string, restore the +saved input." + (when (null eshell-history-index) + (setq eshell--stored-incomplete-input + (buffer-substring-no-properties eshell-last-output-end + (point-max)))) + (setq eshell-history-index pos) + ;; Can't use kill-region as it sets this-command + (delete-region eshell-last-output-end (point-max)) + (if (and pos (not (ring-empty-p eshell-history-ring))) + (insert-and-inherit (eshell-get-history pos)) + (when (> (length eshell--stored-incomplete-input) 0) + (insert-and-inherit eshell--stored-incomplete-input)))) + (defun eshell-add-input-to-history (input) "Add the string INPUT to the history ring. Input is entered into the input history ring, if the value of @@ -897,12 +905,12 @@ eshell-previous-matching-input ;; Has a match been found? (if (null pos) (error "Not found") - (setq eshell-history-index pos) - (unless (minibuffer-window-active-p (selected-window)) - (message "History item: %d" (- (ring-length eshell-history-ring) pos))) - ;; Can't use kill-region as it sets this-command - (delete-region eshell-last-output-end (point)) - (insert-and-inherit (eshell-get-history pos))))) + (eshell-goto-history pos) + (unless (or (minibuffer-window-active-p (selected-window)) + ;; No messages for Isearch because it will show the + ;; same messages (and more). + isearch-mode) + (message "History item: %d" (- (ring-length eshell-history-ring) pos)))))) (defun eshell-next-matching-input (regexp arg) "Search forwards through input history for match for REGEXP. @@ -937,114 +945,160 @@ eshell-next-matching-input-from-input (interactive "p") (eshell-previous-matching-input-from-input (- arg))) -(defun eshell-test-imatch () - "If isearch match good, put point at the beginning and return non-nil." - (if (get-text-property (point) 'history) - (progn (beginning-of-line) t) - (let ((before (point))) - (beginning-of-line) - (if (and (not (bolp)) - (<= (point) before)) - t - (if isearch-forward - (progn - (end-of-line) - (forward-char)) - (beginning-of-line) - (backward-char)))))) - -(defun eshell-return-to-prompt () - "Once a search string matches, insert it at the end and go there." - (setq isearch-other-end nil) - (let ((found (eshell-test-imatch)) before) - (while (and (not found) - (setq before - (funcall (if isearch-forward - 're-search-forward - 're-search-backward) - isearch-string nil t))) - (setq found (eshell-test-imatch))) - (if (not found) - (progn - (goto-char eshell-last-output-end) - (delete-region (point) (point-max))) - (setq before (point)) - (let ((text (buffer-substring-no-properties - (point) (line-end-position))) - (orig (marker-position eshell-last-output-end))) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (when (and text (> (length text) 0)) - (insert text) - (put-text-property (1- (point)) (point) - 'last-search-pos before) - (set-marker eshell-last-output-end orig) - (goto-char eshell-last-output-end)))))) - -(defun eshell-prepare-for-search () - "Make sure the old history file is at the beginning of the buffer." - (unless (get-text-property (point-min) 'history) - (save-excursion - (goto-char (point-min)) - (let ((end (copy-marker (point) t))) - (insert-file-contents eshell-history-file-name) - (set-text-properties (point-min) end - '(history t invisible t)))))) +(defun eshell--isearch-setup () + "Set up Isearch to search the input history. +Intended to be added to `isearch-mode-hook' in an Eshell buffer." + (when (and + ;; Eshell is busy running a foreground process + (not eshell-foreground-command) + (or (eq eshell-history-isearch t) + (and (eq eshell-history-isearch 'dwim) + (>= (point) eshell-last-output-end)))) + (setq isearch-message-prefix-add "history ") + (setq-local isearch-lazy-count nil) + (setq-local isearch-search-fun-function #'eshell-history-isearch-search + isearch-message-function #'eshell-history-isearch-message + isearch-wrap-function #'eshell-history-isearch-wrap + isearch-push-state-function #'eshell-history-isearch-push-state) + (add-hook 'isearch-mode-end-hook #'eshell-history-isearch-end nil t))) + +(defun eshell-history-isearch-end () + "Clean up after terminating history Isearch." + (when (overlayp eshell--history-isearch-messasge-overlay) + (delete-overlay eshell--history-isearch-messasge-overlay)) + (setq isearch-message-prefix-add nil) + (kill-local-variable 'isearch-lazy-count) + (setq-local isearch-search-fun-function #'isearch-search-fun-default + isearch-message-function nil + isearch-wrap-function nil + isearch-push-state-function nil) + (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) + (setq isearch-opoint (point)) + (unless isearch-suspended + (custom-reevaluate-setting 'eshell-history-isearch))) + +(defun eshell-history-isearch-search () + "Return search function for Isearch in input history." + (lambda (string bound noerror) + (let ((search-fun (isearch-search-fun-default)) + (found nil)) + ;; Avoid highlighting matches in and before the last prompt + (when (and bound isearch-forward + (< (point) eshell-last-output-end)) + (goto-char eshell-last-output-end)) + (or + ;; First search in the initial input + (funcall search-fun string + (if isearch-forward bound eshell-last-output-end) + noerror) + ;; Then search in the input history: put next/previous history + ;; element in the command line successively, then search the + ;; string in the command line. Do this only when not + ;; lazy-highlighting (`bound' is nil). + (unless bound + (condition-case nil + (progn + (while (not found) + (cond (isearch-forward + ;; Signal an error explicitly to break + (when (or (null eshell-history-index) + (eq eshell-history-index 0)) + (error "End of history; no next item")) + (eshell-next-input 1) + (goto-char eshell-last-output-end)) + (t + ;; Signal an error explicitly to break + (when (eq eshell-history-index + (1- (ring-length eshell-history-ring))) + (error "Beginning of history; no preceding item")) + (eshell-previous-input 1) + (goto-char (point-max)))) + (setq isearch-barrier (point) + isearch-opoint (point)) + ;; After putting an history element in the command + ;; line, search the string in them. + (setq found (funcall search-fun string + (unless isearch-forward + eshell-last-output-end) + noerror))) + (point)) + ;; Return when no next/preceding element error signaled + (error nil))))))) + +(defun eshell-history-isearch-message (&optional c-q-hack ellipsis) + "Display the input history search prompt. +If there are no search errors, this function displays an overlay with +the Isearch prompt which replaces the original Eshell prompt. +Otherwise, it displays the standard Isearch message returned from the +function `isearch-message'." + (if (not (and isearch-success (not isearch-error))) + ;; Use standard message function (which displays a message in the + ;; echo area) when not in command line, or search fails or has + ;; errors (like incomplete regexp). + (isearch-message c-q-hack ellipsis) + ;; Otherwise, use an overlay over the Eshell prompt. + (if (overlayp eshell--history-isearch-messasge-overlay) + (move-overlay eshell--history-isearch-messasge-overlay + (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end) + (setq eshell--history-isearch-messasge-overlay + (make-overlay (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end)) + (overlay-put eshell--history-isearch-messasge-overlay 'evaporate t)) + (overlay-put eshell--history-isearch-messasge-overlay + 'display (isearch-message-prefix ellipsis + isearch-nonincremental)) + (if (and eshell-history-index (not ellipsis)) + (message "History item: %d" (- (ring-length eshell-history-ring) + eshell-history-index)) + (message "")))) + +(defun eshell-history-isearch-wrap () + "Wrap the input history search." + (if isearch-forward + (eshell-goto-history (1- (ring-length eshell-history-ring))) + (eshell-goto-history nil)) + (goto-char (if isearch-forward eshell-last-output-end (point-max)))) + +(defun eshell-history-isearch-push-state () + "Save a function restoring the state of input history search. +Save `eshell-history-index' to the additional state parameter in the +search status stack." + (let ((index eshell-history-index)) + (lambda (_cmd) + (eshell-goto-history index)))) (defun eshell-isearch-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((inhibit-read-only t)) - (eshell-prepare-for-search) - (goto-char (point-max)) - (set-marker eshell-last-output-end (point)) - (delete-region (point) (point-max))) - (isearch-mode invert t 'eshell-return-to-prompt)) - -(defun eshell-isearch-repeat-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((old-pos (get-text-property (1- (point-max)) - 'last-search-pos))) - (when old-pos - (goto-char old-pos) - (if invert - (end-of-line) - (backward-char))) - (setq isearch-forward invert) - (isearch-search-and-update))) + "Do incremental search backward through past commands." + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward nil t) + (isearch-backward nil t))) (defun eshell-isearch-forward () - "Do incremental regexp search backward through past commands." - (interactive) + "Do incremental search forward through past commands." + (interactive nil eshell-mode) (eshell-isearch-backward t)) -(defun eshell-isearch-repeat-forward () +(defun eshell-isearch-backward-regexp (&optional invert) "Do incremental regexp search backward through past commands." - (interactive) - (eshell-isearch-repeat-backward t)) - -(defun eshell-isearch-cancel () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-cancel)) - -(defun eshell-isearch-abort () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-abort)) - -(defun eshell-isearch-delete-char () - (interactive) - (save-excursion - (isearch-delete-char))) - -(defun eshell-isearch-return () - (interactive) - (isearch-done) - (eshell-send-input)) + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward-regexp nil t) + (isearch-backward-regexp nil t))) + +(defun eshell-isearch-forward-regexp () + "Do incremental regexp search forward through past commands." + (interactive nil eshell-mode) + (eshell-isearch-backward-regexp t)) (defun em-hist-unload-function () (remove-hook 'kill-emacs-hook 'eshell-save-some-history)) -- 2.47.0 --=-=-=-- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: James Thomas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Nov 2024 23:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173128202616050 (code B ref 74287); Sun, 10 Nov 2024 23:41:01 +0000 Received: (at 74287) by debbugs.gnu.org; 10 Nov 2024 23:40:26 +0000 Received: from localhost ([127.0.0.1]:57047 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tAHXd-0004An-SF for submit@debbugs.gnu.org; Sun, 10 Nov 2024 18:40:26 -0500 Received: from mout.gmx.net ([212.227.17.22]:47189) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tAHXZ-0004AU-NG for 74287@debbugs.gnu.org; Sun, 10 Nov 2024 18:40:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1731282013; x=1731886813; i=jimjoe@gmx.net; bh=/IV5joABwZcVi6+ClhEHX8iwR20mnilq8rr4T8CIDuY=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=JgvvAaP9qn6QTIQSEtoFBYue99zmVtZt3QsJUXKs8xDVB0EEj3vQdSYoYhxpxcuO x9dQB8oI8KV7CJvCLadhYfR04LeB6VNFUb3BBF+85I1wAbx+7ORA1+VINEYQ/zlSs J7JoqsjnCkunlYvglgLx3oCsLgM25xeJBRlbzQyWcEjDzY3pUy5EuqCZFkdpusAeD /l7TqFO+NF8SOUKR9eC9kpSjSPZ/r5QX7O3pmtrXuim3K5P7KKpoTWyIC13iRP2uN GsuM8UrgCuLT2yKrIkPJJOJz7I3R7ldM+UGluRsd4QeMtgj+5xnUJy42fGM1NjpQO FEjUNj7B/Q57Ctm1VQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from user-Inspiron-3493 ([42.108.14.13]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1ML9uU-1tSMcT3F8k-00Kgwu; Mon, 11 Nov 2024 00:40:12 +0100 From: James Thomas In-Reply-To: <871pzjkhmm.fsf@pengjiz.com> (Pengji Zhang's message of "Sun, 10 Nov 2024 09:22:09 +0800") References: <871pzjkhmm.fsf@pengjiz.com> User-Agent: Gnus/5.13 (Gnus v5.13) Date: Mon, 11 Nov 2024 05:10:06 +0530 Message-ID: <861pziejzd.fsf@gmx.net> MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:Oy9WUH2SKRBglcDHw6URihgx78Hqdqj/d3cOUrFdACZ/ua91iix 2c4l+ZWq0QpIIuzyJZ7VtCcnm6PNmw5x2Wmpil6286DpQX8Wwh6l66K4SPTOLK6FkZ7mQjc QtoqC06qDyqRD1j9oV4JfnA9kRkyDYqxEVzVjs/eXLBoWtlbpFAlJ+01T9KLUZvHxR5kux+ BO0xWAG4XWhBjor7PkBfw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:cpSei2HeeJk=;pOv1lJSvLMu9ibAoJ5h+HsMsjEW Xe/6mUExo982k5zyQnpattYPrpdu0vwLQMRAoxaR1qkjUbHecRawrbuNoPbTWkZBq0qSgTM5k UPMPcIMKqbnsZdiGu0YiXWj/V+lhg9XVUkFgce0b9AeFLN+wN5G/CLc2JoavXTQWl7gkj881x sN6agfW4FARSooL0DDzF/gy7/zxNQFR95vquGFmxbu5MovYr5DRtzz7x9coaveftu0lJtgPsN YY1AQaySJR0UsiCsIhGxtm1EEDcN46qUuwAZw1sEL+S5bMAQxe94X+IqFGGtMhHJM+kJbEku6 IpnGO2+DnaWV2VtnWfC4ze0xTF+B2UZPG8aBNCsGcCp0zJR8Q5D57wALwtzR/EBDqNuAhhd5q 0ToDJ9+Skp4Rr6P6l6EpOf/EUg64JIYSd/87qtbqZTse0Ex9kWmIIxGZ08UXUCpBlHQPLF8/W evyvxbJjsv5fNSOYBUIEH2vj09ya4wqLBZEXr4u86Q9KlAQsgY2oNAIzDzi2+ScpoqhPyEen9 E3fkNl0qCFidfFQGIZePSXcTff2ud0wzj1kUDRdGrLYBVF8iruMR0l2GdvafES0EkPxvTPOCu 2lrL6pbkxHRleyVP606JS4iMUyWpwm+DQb9o4VIwqeBkvdU5/l74YYJaXa3swlDxMVRruceyw X/h57PEwlXchA3+R6KVtMtGdTsEaWJ/Shi6G1HhHmEKmb+yIGnMdYaDsdws9dcwP4AOIEtKR7 l5kkKDbTbrChIV5dhJIVMWjRmaCvah8jXdW3Cwi0WpqlEkXoi4+dlbdMQotMpaabtUQZfsQi3 v9/xqVh/v1FnujopkpGhwwrs1XbfdeS3ayXwiZTQPjgRGZKzpzGHhOCkL8t6RKgeK8/HOp0Cz eIMo1C9a11S572fOn5JOHmMO/BsxwoqCXseKzwG3b1lnfzTpNMBoXNldI X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Pengji Zhang wrote: > Hello, > > This patch brings a comint-like interface for history Isearch to Eshell. > To try it, type 'M-r' in Eshell, and search through the input history > ring incrementally. > > Compared to the existing implementation, this patch integrates with > Isearch properly, like what we do for the minibuffer and comint modes. > > There are relevant discussions (thank you all for the feedback!) in the > mailing list: > > https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00069.html > > For Jim's concern, I do not think this implementation closes the door > for a history completion interface, as shown by Sean and Juri. Just wanna add a POC to the alternatives suggested. WDYT? Does not use regexps for now, and C-. and C-, for cycling (rather than C-r and C-s): (setq icomplete-in-buffer t) (icomplete-mode 1) (defun my/eshell-history-complete nil (interactive) (let ((icomplete-compute-delay 0) (completion-at-point-functions '((lambda nil `(,eshell-last-output-end ,(point) ,(append (cddr eshell-history-ring) nil) . nil))))) (completion-at-point))) (define-key eshell-hist-mode-map (kbd "M-r") #'my/eshell-history-complete) -- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Nov 2024 08:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: James Thomas Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173140168913395 (code B ref 74287); Tue, 12 Nov 2024 08:55:02 +0000 Received: (at 74287) by debbugs.gnu.org; 12 Nov 2024 08:54:49 +0000 Received: from localhost ([127.0.0.1]:60560 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tAmfh-0003Tz-4P for submit@debbugs.gnu.org; Tue, 12 Nov 2024 03:54:49 -0500 Received: from fout-a6-smtp.messagingengine.com ([103.168.172.149]:49499) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tAmff-0003Tl-D6 for 74287@debbugs.gnu.org; Tue, 12 Nov 2024 03:54:48 -0500 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id CDBA11380446; Tue, 12 Nov 2024 03:54:41 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 12 Nov 2024 03:54:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1731401681; x=1731488081; bh=bmftXB3MdA GZiHyzfjV1SwjLhq9Fh5aBWESljP+3T8s=; b=dQWsnbx/sftb4MPB0h3jbjMQUe EHcJrbRQCcV8tw7Xfya0FoJN+Ebpi/ryaNZyHsybKLXbNEjcHPG6Dn7fyNxJanHY iAtgpDiTv5fdLHuwvzBXUpX2ueKFYTl4ot492u3LEONhSdB/jDByi9PWZtmPtetZ 9NedeAZ/Ho57X7RRV03SBCjOC/SORkQmP71fRWnNXAsIsuV42HYvoiIkKgpGO14Q aegaqY+fGFCw79qvtq7s7MVLOrGefiIIHRt2GH1omvwUYG8k3x8HR6+uxSmQcd4/ JjWLV2uyTn4W7NI+NKDnf2pPpT2Jlnt9FzyFvCICOLyw8IJBPIX+oysnPZMA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731401681; x=1731488081; bh=bmftXB3MdAGZiHyzfjV1SwjLhq9Fh5aBWES ljP+3T8s=; b=Ca8MoNKFpMIrk+waeEIgej9d8olsj21eMUVZwzCdRdRDtXtg9Wf 8ksTZrD/jHq/qXNow+KdBUfWSx2MKS93UXK5ThiYTLopKvp8A0h27E75h3WGODyh +U0qbFis8CDjInbo3HtW+dSvfYm2rONZEBZLDZMp3ibF0mBSnsUrW4a1qWdzlzpA pRkhuDHlkiZaeIjqu7muKPVQLPcAiL5BfWwXwdczFgpmuiz7+rdSlLnIkzoaOR7n jM/66MFsHogtvxo5kliK+XM+nZ8a16Rzogw5s9KtElFchBBqPCcHd0keQ/jAVeXB ddLwpWb3/ezPz+DbuUcKFtHn/JG1rY+r9fg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudefgdduvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf gjfhffkfggtgesthdtredttddttdenucfhrhhomheprfgvnhhgjhhiucgkhhgrnhhguceo mhgvsehpvghnghhjihiirdgtohhmqeenucggtffrrghtthgvrhhnpeegfeeiiedvudekie dtgedufedtvedtueetieffhfdvhefftefgieejieelleehgeenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmvgesphgvnhhgjhhiiidrtghomh dpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhi mhhjohgvsehgmhigrdhnvghtpdhrtghpthhtohepjeegvdekjeesuggvsggsuhhgshdrgh hnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Nov 2024 03:54:40 -0500 (EST) From: Pengji Zhang In-Reply-To: <861pziejzd.fsf@gmx.net> References: <871pzjkhmm.fsf@pengjiz.com> <861pziejzd.fsf@gmx.net> Date: Tue, 12 Nov 2024 16:54:27 +0800 Message-ID: <87frnw96ik.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) James Thomas writes: > Just wanna add a POC to the alternatives suggested. WDYT? Does not use > regexps for now, and C-. and C-, for cycling (rather than C-r and C-s): > > (setq icomplete-in-buffer t) > (icomplete-mode 1) > > (defun my/eshell-history-complete nil > (interactive) > (let ((icomplete-compute-delay 0) > (completion-at-point-functions > '((lambda nil > `(,eshell-last-output-end ,(point) ,(append (cddr eshell-history-ring) nil) . nil))))) > (completion-at-point))) > > (define-key eshell-hist-mode-map (kbd "M-r") #'my/eshell-history-complete) Thanks! While I like the simplicity of your approach, I am not sure if it is a good idea to depend on 'icomplete-mode'. People may have different preferences for the in-buffer completion framework. From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Nov 2024 06:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang , 74287@debbugs.gnu.org Cc: Juri Linkov , James Thomas , Sean Whitton Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17326040812986 (code B ref 74287); Tue, 26 Nov 2024 06:55:01 +0000 Received: (at 74287) by debbugs.gnu.org; 26 Nov 2024 06:54:41 +0000 Received: from localhost ([127.0.0.1]:45441 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tFpT6-0000m4-QC for submit@debbugs.gnu.org; Tue, 26 Nov 2024 01:54:41 -0500 Received: from mail-pf1-f174.google.com ([209.85.210.174]:45330) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tFpT5-0000ls-9R for 74287@debbugs.gnu.org; Tue, 26 Nov 2024 01:54:39 -0500 Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-724e6c53fe2so3279047b3a.3 for <74287@debbugs.gnu.org>; Mon, 25 Nov 2024 22:54:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732604018; x=1733208818; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=8ke4zp6TQWLZ/6lCDOu2CufeB+Lks98fU8qid34t2cA=; b=axx1faanu7kSPp1mEOmyt46SkF1I6++YwIjQCHgMq708udZqsbQQa+z96g74ABJjwe bH3mBLEjJ9vDnqIiVbuYStGHs8unjtrXLPi0tcJKSSiF7zNpO6vCJN8Dvyny2TNsJ5RK AyXXzbfMi5n4tR7Njc8pmLFyUApqFTiaaFMkepY7uMl+/ggurk2WlUQ6W7WsWLxF3/UD EMSeINF2tww2ceQK44uO52p5TWa99FgNVtxPTajhzUv2XX0ZVnXar5bNpJyMT0q6mtVi 38XnNcpbqMOGEYRwLbJFCWMBzd1aJt3vURzqzdX0GdhZX9HAZn2rAQMe34jJysRJeotI uqbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732604018; x=1733208818; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8ke4zp6TQWLZ/6lCDOu2CufeB+Lks98fU8qid34t2cA=; b=o5OTJb1pMH+L+fj7BmQ45oPq+9qFsuFtHIkIWCxN20+zpszvsoL5RT8ef9/FV++Bk9 GFYFxt18s7SgyMZjXjfJkWHNEh9rSDG3jTn6BOySCXif6a6rMgA3MdI6ZOYogazvJfF6 xdRfC2vxIZIkDqJ2sa9mGLypeGvhKJxz+Z5YLtXFefsFGn3qYjWib2yoMbC8Vbo2o9K5 QvM6z2Jb9pZqr8XMxSFRJj+RCh6hpE1295YPxG8i8dA/mQINv/wa1VymjrBgwuswY0/x grNBlCKLThutfj3XU1BiW4EgpINdUB+dNE8dmJ8J37XAM+VsIdo9cHvdGayJmx1R1RYS qSvA== X-Forwarded-Encrypted: i=1; AJvYcCVLRa9wQ4aMTNHh26b1s8VCFXmZJ01R49hhtIOHIIKtjSf4cySe6T4sKWb19a6qOsg0EaApxw==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzECjFK/06wJ1/rvRGWamnm3mA022EErQTxgCORaptvCxrgTLYy lq7SfXE1K/RY2KCZxNdTBZgepbvNAqea32EtX9o5Hf7sgzhR8AJW X-Gm-Gg: ASbGncuFDQFTLcZdPt3rWe2wx0zOiFUeoFM+TGe3Pdln67w28AmSPmv8A2PyeGF32xZ 0GSiXN3lKXtvvEqh2a52sJUSdHPKNyTiNeNuuZIA8FjWQPTY6NlJdefzAdgYqEFUcS4QD7meLcv 9WFuymeW908R3fN3BoBd8+aQV1mJzq2DfNh8czSJsWYN0BK2KuV2VyaR/q4TLo+sv4g0AaoScV7 5g8WjO5OC8UwZF6gQUxOFoekg+W7GTT7RSkhMZiP2MUH6b0/hWjtdzAonm7R+y8p04oNpciIwE8 OzduvZuOiUEslz2piLa3kqoD6hY= X-Google-Smtp-Source: AGHT+IHw9otIeTWYrKn75of+CnhXhOgk6vEdkkevXZZUnVMe+c9tswO7oXB6zjMChe1LN14n2fhgQw== X-Received: by 2002:a05:6a00:1390:b0:71e:7174:3ae with SMTP id d2e1a72fcca58-724df5ed802mr18840306b3a.11.1732604018120; Mon, 25 Nov 2024 22:53:38 -0800 (PST) Received: from [192.168.1.2] (syn-023-240-098-037.res.spectrum.com. [23.240.98.37]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-724de531b5bsm7591853b3a.99.2024.11.25.22.53.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Nov 2024 22:53:37 -0800 (PST) Message-ID: <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> Date: Mon, 25 Nov 2024 22:53:36 -0800 MIME-Version: 1.0 Content-Language: en-US References: <871pzjkhmm.fsf@pengjiz.com> From: Jim Porter In-Reply-To: <871pzjkhmm.fsf@pengjiz.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 11/9/2024 5:22 PM, Pengji Zhang wrote: > Hello, > > This patch brings a comint-like interface for history Isearch to Eshell. > To try it, type 'M-r' in Eshell, and search through the input history > ring incrementally. From inspection, this code all looks good to me. At least, it matches what Comint does; I don't know much about Isearch's implementation, so I'm just trusting that Comint is right here. Since this is a somewhat-large patch, I'm going to try and find some time this week to test it out so that I understand how it all works, and assuming I don't find any major problems, I'll merge it shortly after that. Thanks for your contribution to Eshell (and Emacs as a whole)! From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: James Thomas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Nov 2024 09:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Jim Porter Cc: 74287@debbugs.gnu.org, Juri Linkov , Pengji Zhang , Sean Whitton Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173261413032653 (code B ref 74287); Tue, 26 Nov 2024 09:43:02 +0000 Received: (at 74287) by debbugs.gnu.org; 26 Nov 2024 09:42:10 +0000 Received: from localhost ([127.0.0.1]:45786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tFs5C-0008Ub-Cj for submit@debbugs.gnu.org; Tue, 26 Nov 2024 04:42:10 -0500 Received: from mout.gmx.net ([212.227.15.15]:53259) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tFs5A-0008UL-A4 for 74287@debbugs.gnu.org; Tue, 26 Nov 2024 04:42:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1732614117; x=1733218917; i=jimjoe@gmx.net; bh=Nswr/yN0CnfkNCqkS3pGCTB/l/Sc22SWzIFa2vJ1nvA=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=NsJ0FawSGrRpIo32J3bqiWcgcvbNNKBxIlHXCnGr4gbvgI7nAxrw0G1EiL1qHipT 67M+dwmlEW8OXidH6KeULtMq+FgCygDP2t+Nqoi0eob2inNvufcp83w0Y3RWrC4go LxBH1UI/6+G3EUg6TCp+lxpN9Lg8gyP1z+jG1CXlz/lcTUPK6Vj0ZsUpxGuvdNIYD NuM/F2VSD2ZHkN2fbiVy4NfN7PCZ/L25IGg813FxqDk04x27mxk46Qjd5dWTVHRyE 9CX1GR0QwBFHgzpG9qONYd8pQXYBOhvPO6An1U+yk2DvQa9YGNOSEWBO3WSOqWhW6 LRt1/ga4qOfxXD4RSA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from user-Inspiron-3493 ([42.108.19.2]) by mail.gmx.net (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MOREi-1t4NLO2L8g-00Tvwl; Tue, 26 Nov 2024 10:41:57 +0100 From: James Thomas In-Reply-To: <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> (Jim Porter's message of "Mon, 25 Nov 2024 22:53:36 -0800") References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> Date: Tue, 26 Nov 2024 15:11:48 +0530 Message-ID: <86v7waz603.fsf@gmx.net> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:amVqeLLT/rRQCLZIBQgemseEhdUJT6IkmF2nPaNEgKGuxSD6mSG lD4UEG8f6ZMz//e9yHqK2CVQThYK3RPEpRILWqVMuY7AOEX0AffoyyzGnDHaY7p5BRYJY0d +e2MT7qfZPhRf0o5yntAUsFGrO2C6kLYU8nENEl5QV1wiR3owhRR4OI2X/tIMKR1/Sr87IA tRDKfN2fQWF5rcBL+0MBg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:FLADxacvPD0=;hMw1BlWO4TPMI7+mSh3hqTFciKK sVWuP7KKsSsc7FIrIVKJE3m6ZmqqXbhI1HkVgvifEmdLZpU7rGMcXemNNgfxVMAdbHgcI2dYN uhqBQ6Ve3i2UnJMKalUlBAtDh2jT2fvFl/CSUpWv+XWBwJPVsWRhrh0dKAcc+i8jcPJsmt3CH 6L6EfQ5Fl1JTrtjaDzuQx7SUfCpBbgr2Yvs08nowsQcYxpzVgGoLv1XT4x6ofU09DeAH7tXdT pyoWkgzjiYajB/L+PzIXxJvOfTfTi7s0ijxqR6CTVKDFydqeZbHXVdWenGAPyJkQ1VtwvqRCD Cafi54gzLIPbtASk8MJbhrWw0RFW0TlF8qFDYflMk3UF0YIaNyuKhsG1sU7oBWy8HV7fIAmGU i5k0Qm1fg8/3SrTKNeNZAUhjDuuOXjDKcblAdLUg9rjm4baSbGbUrwyh/mFruq/oml3jRJwhI OvC60UhmSVUTpF0n04pUZWrwYodPaXw2bPNVvqrbNCb7QkIVhdFPKMpYxSFXkmBQz9Oxj6hhh 2oJRtVrsuzeyXL74uKO0SqLLzHRSa5tl1oiWBLKn5UoPD17W7dF6Wp3dExPDCo5FRkN7gcrwa d016xpSytDFs/Oz42Z+3XiAsUCTUUVqOzznQj/kLFNag3NYLxWCskUajCVfnNW2mfXMHdQA5V P2FkNrPjKsva/HNhFZDlE95HQI/2ijaBjUlPeZQi/sZAIpVG3B2dKBXazqjXYNmrqmExP9d8E 3nXpD0jGPUWbzdT+susH+SkucV5B8Wp7poRebJh1FtF0lSFh41v5q0pNkjm6eVeXX1Bwc2I1d LiDkvDFwlnwjkDukBH9nhAqnsuIRxzIQ+UR/n6OIKOWrYVHF8UW+zDlfcwLpBGUpg0QkEQKCt dji5T8PZ65DQtB1mowEt1UB/IZU2rrvuLZPwwQHKGR0OorCslBSYRmqbA X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jim Porter wrote: > On 11/9/2024 5:22 PM, Pengji Zhang wrote: >> Hello, >> This patch brings a comint-like interface for history Isearch to >> Eshell. >> To try it, type 'M-r' in Eshell, and search through the input history >> ring incrementally. > > From inspection, this code all looks good to me. At least, it matches > what Comint does; I don't know much about Isearch's implementation, so > I'm just trusting that Comint is right here. Since this is a > somewhat-large patch, I'm going to try and find some time this week to > test it out so that I understand how it all works, and assuming I > don't find any major problems, I'll merge it shortly after that. My 2c: I now think it's better to hold out for something with way less code, using capf. -- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Nov 2024 17:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: James Thomas Cc: 74287@debbugs.gnu.org, Sean Whitton , Pengji Zhang , Juri Linkov Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173264047616623 (code B ref 74287); Tue, 26 Nov 2024 17:02:02 +0000 Received: (at 74287) by debbugs.gnu.org; 26 Nov 2024 17:01:16 +0000 Received: from localhost ([127.0.0.1]:50723 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tFyw8-0004K1-7v for submit@debbugs.gnu.org; Tue, 26 Nov 2024 12:01:16 -0500 Received: from mail-pf1-f177.google.com ([209.85.210.177]:56717) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tFyw6-0004Jt-Ee for 74287@debbugs.gnu.org; Tue, 26 Nov 2024 12:01:15 -0500 Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-724f41d520cso2190429b3a.1 for <74287@debbugs.gnu.org>; Tue, 26 Nov 2024 09:01:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732640413; x=1733245213; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=Dd2q8oXoPW2tjaKWhrhv+CkGE7AEdLDaP4iH25G3qvc=; b=VH8R3EjGrB0wQru28nerfPhM0GK8E6VGXAv9Kob1KgyXySuKwEOjJ6ypOnGIfyW6rN VGkbTnlfbMkIUHtg1lcWN5cvbRw9XcRe+lH1SvX+g5SoWWL2b21y/j6fGJnfMY0NbRgC SdS96RuNqY5SX+CkoBAxiQvID0EKInwyFQKRl8OYV51yrqdwjsxvB+mLrWJ0UHofMgGB BR1ZEAQz2+rEy7phTZTh/dWIHVPw3yNY7RGj0V8DNkm63SlGwekmWZ6Rwizia3xIRQ5x acgfqLzXYKq1TlhSBRg0b8t7P7+9Qd1WUK8vUJARH6F1kNWpRxI1M4XhxYElceZQcG5S vAWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732640413; x=1733245213; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dd2q8oXoPW2tjaKWhrhv+CkGE7AEdLDaP4iH25G3qvc=; b=bO8GW+l/iw92MiELpO5bxbwQnjd4iW1KMkGUtcfAFSJtu2laHhCXfTDFr/A6RM75rf HqE+MA2yA9u9KuMrwXbGyDeGq7weoXeZBG96/PU4oiw13VJ6XyBgIuPrP4sxxgbaQXn1 IXTzoHdi0sjTY0fYElcDvVMPSLM2NHpIcOHlfOXj08iA3DEwHuNGWfTDA56YGfZvospI h2+ewLZFPCz7zQh6n799Kl2kjeFUhQzt06niqLv+6pFobXW6USeUUMLXhkk408sLeZ6e B0uKKMe5xvSCPMOJmbozd64VaUuDMRNTg4OS+aXQnxbRQ3q0Pl7BlqSULjqfVkkA8LYh lbzA== X-Gm-Message-State: AOJu0Yze3QQHu6BWKp43qYBiv/AMVsxCbokIyJo+tm1sVzeV3yY51h9+ QwEWYU+TyJSzTOV6Jm7vxDKYYqVXRLwKWhQHuTd/+taZRxpT64Qt X-Gm-Gg: ASbGncsl+aI/LlSvsoZfh+ERiPWJCmAGbBcjAlDRrD6k+OGklN4YV3sWg7Vd9AeDPi1 DMHmVCmQuBe28Xhza2vjig3RXHAUGC8ucZw9wzydtVQxWshybfPmGB59DUkxU/FwMlqJCHEIcbd bTS+ZOOI7Fw2uxG4F315bQ3OCaMFweYR+b9PqlRFT9s84ziUSvoBFH2qv5MAclY/vA/Z7ozhJ7/ //hzJZIt0Om1cJeTD3Nf0SBC7uhhK0er2gAI92FfuE7jZ2Cp3nFRI5VKY3fr3EQNgNv0DeYL+G+ 8RUZl+SJ/xq6kVTLSMYZeR7Grek= X-Google-Smtp-Source: AGHT+IEFMyYdkIqLzUnojOc30XudscLHKh+njVeJzL4QCFd+ONSXoqMLlEc34wJdN1nou0qDSc1Y/w== X-Received: by 2002:a05:6a00:4a10:b0:724:e80a:330 with SMTP id d2e1a72fcca58-724e80a0f26mr14926604b3a.5.1732640412923; Tue, 26 Nov 2024 09:00:12 -0800 (PST) Received: from [192.168.1.2] (syn-023-240-098-037.res.spectrum.com. [23.240.98.37]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-724de55b160sm8638120b3a.161.2024.11.26.09.00.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Nov 2024 09:00:12 -0800 (PST) Message-ID: <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> Date: Tue, 26 Nov 2024 09:00:13 -0800 MIME-Version: 1.0 Content-Language: en-US References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> From: Jim Porter In-Reply-To: <86v7waz603.fsf@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 11/26/2024 1:41 AM, James Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: > My 2c: I now think it's better to hold out for something with way less > code, using capf. Like mentioned in the emacs-devel list, that's probably how *I'd* want a command history search implementation to use, but I also think that an Isearch interface makes a lot of sense as an option, depending on user preferences. As far as I can tell, we'd have to write different code for each of these styles (i.e. you can't just make Isearch use capf). Though as mentioned I'm not very familiar with Isearch's internals. So long as this doesn't prevent a capf-based implementation (and I'm guessing it wouldn't, since that would just be a new option), I think we could merge this patch. I also prefer to have Shell and Eshell work the same way unless there's some compelling reason why they should be different. From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: James Thomas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 27 Nov 2024 05:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Jim Porter Cc: 74287@debbugs.gnu.org, Sean Whitton , Pengji Zhang , Juri Linkov Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17326858481929 (code B ref 74287); Wed, 27 Nov 2024 05:38:02 +0000 Received: (at 74287) by debbugs.gnu.org; 27 Nov 2024 05:37:28 +0000 Received: from localhost ([127.0.0.1]:57981 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tGAjw-0000V0-Dw for submit@debbugs.gnu.org; Wed, 27 Nov 2024 00:37:28 -0500 Received: from mout.gmx.net ([212.227.17.22]:50217) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tGAju-0000Um-JQ for 74287@debbugs.gnu.org; Wed, 27 Nov 2024 00:37:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1732685835; x=1733290635; i=jimjoe@gmx.net; bh=XDvNL2HPPOlN52bGBLCPhwSFEmimsAQmtKqbCSW2LBQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=lxBleLBT4XAQ4AxpSFtCroRsp4Md4e0e/Es+Y97ATnWGY2vgATq9uEpEv0F9cVb3 GYmxE95FBXYC3rawMIsgEqBjf8otU5iodhVBC8AE9etYNV/KHSYPUpv0aSFWZa5rw 49uZNdmJgAseeoVBuuCKQbK+HMAPpFFqfq+KhltPWk61wpeLA+x7Iy9A4JRI5+kA6 ZtScMfVq5geMP5VyTh87vvqoB3xDgVIyWLEQl5Y/kWSb1PB2INfYinZyZjbyfZT+R AC6WN1WhpdPja/82uuOAsR+6boRKj98d7wWdzRar+DJ6JJo7D50aoG08Tr4j58x8c BYMtxfmJ9u5RUe3G0g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from user-Inspiron-3493 ([42.108.29.45]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MjjCF-1tzw1K49uN-00aOXe; Wed, 27 Nov 2024 06:37:14 +0100 From: James Thomas In-Reply-To: <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> (Jim Porter's message of "Tue, 26 Nov 2024 09:00:13 -0800") References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> Date: Wed, 27 Nov 2024 11:07:07 +0530 Message-ID: <867c8pxmnw.fsf@gmx.net> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:G/DRbnwMAz7smcDMZDl0eS570dd6nMcfYy36PfWdCQGUZBppePN TIl2jGEkKnR8Ebrimr7gQcCNGjPV3cMhEH/SYlXWaB/uKPip6q4j/w0XO0JaTq64AULqK4a vPXjl7SxX5BkRyFzJMLTiw+d3RguO2VmyHvlsUH/O9Oy4/HwBCmjW7ZwTh+G2aAypkj6B3W pWGrGiWSbRrnWtQK1YwTA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:HQm0W8WQVXI=;JllORWN0aTdLCkFgorbt4jYG1G0 7vKGBSXCnAPzRgKzwEyRVOCbrdBdX9YalKMuzXgq8P39omgvUEzcJEM0t9KawROrc8HOR91KR raHi4VgO6zmdUQ7T54rik3s0tWtPFD04/WIj60IqK6JVpPfrI5wTENMy71HMLS6rkoYS0bRz/ Iqem+iSSZHiEb7xLttqTG4BVDBG3al81hSNXPeVFIGWJc9nptxKxN/iRzhGKfq15VcmvXL9iS mJHQcZnYrEVVG+UhLG1oaRf9NdyeNxPWxPZWh9QQ1V0JmhGy8eXiFNiwYlzFi1vLePnnkPnVC dx6OMZII775lmSd1CEsBtMuX4CZq0xd97HgjY7XCAXPp2NsqDOgsdxCBB0q5GG6f8evd2xkIM nxd9HiN47DYbsAJ/ixOyFJ9KYbwaZvyzxH3MGgiGWp11ZVaeg/0EWEedYFT0daPY8SSqg44m2 4ah30Mz3CyBx4+qu7u2MPmwwpOs7dQ3D2RPxmKbLGeHOyzgglnXmUDLCG+8akUIM90cmAiQNO h5ClbdZwKQsvA2N51qBiZ1mKiN6U17ATAVc7QR63NhIZliQPgkmyLr/XsL5nDnzK5DuT5bitu MhDihWCxkY/Kt5PVcc/napJKdxTyXoGxjo4nH4Elz0W8dIq/12PauxrnNGboUbRJySwL2Vjh9 lcTz/hhP2jg4ER5OiGacf7TGka45XfZ+AUQlJzADNY31ms0MsInQkQSPEG907WDSaZdYEdMCx W+Ordpk8zgvFwFTnjG46cH57PgXqp41fT5DNtx2A3pqffFhka6mWnidkfS/AQTfDnALTLTsLu Zpx52LON1LUP4Wjc9+63u2xMJHdeph8ofmw0uTZN7QfmEFdEaoz6tozb1YdEVmfMe3EokYhlg FaSElk4BvwK3IJwwNuBirZPYi4PVfwAJWwK03t6m350YJo6y1O295idSH X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jim Porter wrote: > On 11/26/2024 1:41 AM, James Thomas via Bug reports for GNU Emacs, the > Swiss army knife of text editors wrote: >> My 2c: I now think it's better to hold out for something with way less >> code, using capf. > > Like mentioned in the emacs-devel list, that's probably how *I'd* want > a command history search implementation to use, but I also think that > an Isearch interface makes a lot of sense as an option, depending on > user preferences. As far as I can tell, we'd have to write different > code for each of these styles (i.e. you can't just make Isearch use > capf). Though as mentioned I'm not very familiar with Isearch's > internals. > > So long as this doesn't prevent a capf-based implementation (and I'm > guessing it wouldn't, since that would just be a new option), I think > we could merge this patch. Okay. In that case, my preference would be for it to be a separate module ala eshell-smart et. al., if possible; the motive being easing the maintenance burden. > I also prefer to have Shell and Eshell work the same way unless > there's some compelling reason why they should be different. Shell could change to be like eshell, for that, no? (like Wittgenstein's bit with the ruler) ;-) -- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 04 Dec 2024 19:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Jim Porter Cc: 74287@debbugs.gnu.org, Sean Whitton , Pengji Zhang , James Thomas Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17333387645447 (code B ref 74287); Wed, 04 Dec 2024 19:00:02 +0000 Received: (at 74287) by debbugs.gnu.org; 4 Dec 2024 18:59:24 +0000 Received: from localhost ([127.0.0.1]:36850 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tIuaq-0001Pm-GV for submit@debbugs.gnu.org; Wed, 04 Dec 2024 13:59:24 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:37919) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tIuao-0001PT-IS for 74287@debbugs.gnu.org; Wed, 04 Dec 2024 13:59:23 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id AB74AC0004; Wed, 4 Dec 2024 18:59:14 +0000 (UTC) From: Juri Linkov In-Reply-To: <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> (Jim Porter's message of "Tue, 26 Nov 2024 09:00:13 -0800") Organization: LINKOV.NET References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> Date: Wed, 04 Dec 2024 20:56:29 +0200 Message-ID: <87v7vzgtuq.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Like mentioned in the emacs-devel list, that's probably how *I'd* want > a command history search implementation to use, but I also think that an > Isearch interface makes a lot of sense as an option, depending on user > preferences. As far as I can tell, we'd have to write different code for > each of these styles (i.e. you can't just make Isearch use capf). Though as > mentioned I'm not very familiar with Isearch's internals. I confirm that the patch uses the right Isearch's internals to implement the search through Eshell history. (There is only one typo in the variable name 'eshell--history-isearch-messasge-overlay'.) > So long as this doesn't prevent a capf-based implementation (and I'm > guessing it wouldn't, since that would just be a new option), I think we > could merge this patch. I also prefer to have Shell and Eshell work the > same way unless there's some compelling reason why they should be > different. Having Shell and Eshell work the same way is a nice goal. There is a patch that implements completion for Shell in bug#74694. Then Eshell could have something like this later as well. From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Dec 2024 12:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Juri Linkov , Jim Porter Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173340259810500 (code B ref 74287); Thu, 05 Dec 2024 12:44:01 +0000 Received: (at 74287) by debbugs.gnu.org; 5 Dec 2024 12:43:18 +0000 Received: from localhost ([127.0.0.1]:38608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJBCP-0002jF-Hy for submit@debbugs.gnu.org; Thu, 05 Dec 2024 07:43:18 -0500 Received: from fhigh-b2-smtp.messagingengine.com ([202.12.124.153]:38917) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJBCM-0002iy-04 for 74287@debbugs.gnu.org; Thu, 05 Dec 2024 07:43:16 -0500 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 98EF92540227; Thu, 5 Dec 2024 07:43:08 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Thu, 05 Dec 2024 07:43:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733402588; x=1733488988; bh=uODlpwywhM R2AUsiB8YurItobRKPG43vIq0Y2FQ5ctI=; b=BV+dtusfAhko/mY28H0DawLFgu SyGpYxVExEyjXXNg5YmTfm8M1eZ4neKq5SlxM1/kVs80ANh9VntAzD970gbTFLCp 35imaPwXnYIIpKInoobCPNsbGrvydFLgN87cN77ipPR2ju6KcedN1uX4YUSwoqjZ QCRXjDK+lnHEovoGGwI8XdjI0QfXrGxqZ3IyfHHb3Qhz0jv51XOPxQ9kpqmZAM5e vUahOVHpRhI4HMp2GYZS6XBplFc3mWHjpI5kLzFpOW3PpEW211g8PM7ImmdO0nkx Z9iX1YyV+QlXZ9QBH1zhAUfmBmfS3Ni41f4G7FDu/CVVW8VXjbuq9K9AiTTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733402588; x=1733488988; bh=uODlpwywhMR2AUsiB8YurItobRKPG43vIq0 Y2FQ5ctI=; b=L7RBmXtimzuEHR32AQKEMFTLKHcs7J7m3Sudwj4p1Vai+JNpmZm 1pY9j3PkoGyJGvs1gM75C4L+fYWOl882wwFrL7K+cyoDXtJJoPSxi5BYFYpaL6YY 3GuD0+ZSazaTy+eQil7VXwzxW4VQxqRqeB35vD6fJhakCnKnyLIuzdOGZKJxiDg5 Pr+P+VjEGM0AJJVrVNRlLq2CrT97W8uzms31EpwTuQmLe5iFVX17WDtGnja3v/4b 2dM3Iz/ma9Jk73vRAGJU2abS+eHuazJVXRJ+vPiwBjRHQH1hd1xosdLBy9NQTj8f UQU1ccXW+fD63DOnENwZFI4M+lcv1Mu3woA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrieejgdegvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesmhdtreertddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeeifffgieeulefgjeejiedvleehffffueeiiefhhfffveejuefh gedvhfekgfelkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvthdprhgtph htthhopehjphhorhhtvghrsghughhssehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Dec 2024 07:43:06 -0500 (EST) From: Pengji Zhang In-Reply-To: <87v7vzgtuq.fsf@mail.linkov.net> References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> Date: Thu, 05 Dec 2024 20:43:02 +0800 Message-ID: <87jzcecnc9.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Juri Linkov writes: > (There is only one typo in the variable name > 'eshell--history-isearch-messasge-overlay'.) Thanks! Corrected in the attached updated patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Rework-history-Isearch-for-Eshell.patch Content-Description: Updated patch >From 9df1d8eaf626c396b88fe616a6e89d5a8e7b963c Mon Sep 17 00:00:00 2001 From: Pengji Zhang Date: Thu, 5 Dec 2024 20:25:25 +0800 Subject: [PATCH] Rework history Isearch for Eshell This is to make history Isearch for Eshell similar to that of 'comint-mode', by hooking into Isearch properly instead of defining new commands to emulate Isearch. * lisp/eshell/em-hist.el (eshell-history-isearch): New user option. (eshell-goto-history, eshell--isearch-setup) (eshell-history-isearch-end, eshell-history-isearch-search) (eshell-history-isearch-message, eshell-history-isearch-wrap) (eshell-history-isearch-push-state): New functions. (eshell-isearch-backward-regexp, eshell-isearch-forward-regexp): New commands. (eshell--history-isearch-messasge-overlay) (eshell--stored-incomplete-input): New internal variables. (eshell-hist-mode-map): Bind 'M-r' to 'eshell-isearch-backward-regexp' and free 'M-s' binding for normal in-buffer search commands. (eshell-isearch-backward, eshell-isearch-forward): Use the new way to start searching. (eshell-hist-initialize): Use the new Isearch setup function. (eshell-previous-matching-input): Use 'eshell-goto-history'. Also inhibit messages when searching. (eshell-isearch-map, eshell-isearch-repeat-backward) (eshell-isearch-abort, eshell-isearch-delete-char) (eshell-isearch-return, eshell-isearch-cancel) (eshell-isearch-repeat-forward, eshell-test-imatch) (eshell-return-to-prompt, eshell-prepare-for-search): Remove. These are for the old history Isearch implementation. * doc/misc/eshell.texi (History): Document changes. * etc/NEWS: Annouce changes. --- doc/misc/eshell.texi | 15 +- etc/NEWS | 23 +++ lisp/eshell/em-hist.el | 322 ++++++++++++++++++++++++----------------- 3 files changed, 223 insertions(+), 137 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index ee4d0ca09c8..701137ea1b4 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -2661,10 +2661,10 @@ History @table @kbd @kindex M-r -@kindex M-s @item M-r -@itemx M-s -History I-search. +History I-search. @kbd{M-r} starts an incremental search in input +history. While searching, type @kbd{C-r} to move to the previous match, +and @kbd{C-s} to move to the next match in the input history. @kindex M-p @kindex M-n @@ -2675,6 +2675,15 @@ History previous or next line that begins with that string. @end table +@vindex eshell-history-isearch +If you would like to use the default Isearch key-bindings to search +through input history, you may customize @code{eshell-history-isearch} +to @code{t}. That makes, for example, @kbd{C-r} and @kbd{C-M-r} in an +Eshell buffer search in input history only. In addition, if the value +of @code{eshell-history-isearch} is @code{dwim}, those commands search +in the history when the point is after the last prompt, and search in +the buffer when the point is before or within the last prompt. + @node Extension modules @chapter Extension modules Eshell provides a facility for defining extension modules so that they diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..c1df6f78d9f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -288,6 +288,29 @@ This hook runs after an Eshell session has been fully initialized, immediately before running 'eshell-post-command-hook' for the first time. ++++ +*** Improved history Isearch. +History Isearch in Eshell is reworked. Two new commands +'eshell-isearch-backward-regexp' and 'eshell-isearch-forward-regexp' are +added for incrementally searching through the input history. +'eshell-isearch-backward-regexp' is bound to 'M-r' by default, and 'M-s' +is freed for normal search commands. If you would like to restore the +previous key-bindings for the non-incremental search commands, put in +your configuration: + + (keymap-set eshell-hist-mode-map "M-r" + #'eshell-previous-matching-input) + (keymap-set eshell-hist-mode-map "M-s" + #'eshell-next-matching-input) + ++++ +*** New user option 'eshell-history-isearch' +When 'eshell-history-isearch' is nil (the default), Isearch commands +search in the buffer contents. If you customize it to t, those commands +only search in input history. If you customize it to the symbol 'dwim', +those commands search in input history only when the point is after the +last prompt. + ** SHR +++ diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index fffd611c06f..c85e7704eca 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -34,7 +34,6 @@ ;; Also, most of `comint-mode's keybindings are accepted: ;; ;; M-r ; search backward for a previous command by regexp -;; M-s ; search forward for a previous command by regexp ;; M-p ; access the last command entered, repeatable ;; M-n ; access the first command entered, repeatable ;; @@ -132,6 +131,17 @@ eshell-input-filter (function :tag "Other function")) :risky t) +(defcustom eshell-history-isearch nil + "Non-nil to Isearch in input history only. +If t, usual Isearch keys like \\[isearch-forward] in Eshell search in +the input history only. If `dwim', Isearch in the input history when +point is at the command line, otherwise search in the current Eshell +buffer." + :type '(choice (const :tag "Don't search in input history" nil) + (const :tag "Search histroy when point is on command line" dwim) + (const :tag "Always search in input history" t)) + :version "31.1") + (defun eshell-hist--update-keymap (symbol value) "Update `eshell-hist-mode-map' for `eshell-hist-match-partial'." ;; Don't try to set this before it is bound. See below. @@ -204,25 +214,17 @@ eshell-save-history-index (defvar eshell-hist--new-items nil "The number of new history items that have not been written to file. This variable is local in each eshell buffer.") - -(defvar-keymap eshell-isearch-map - :doc "Keymap used in isearch in Eshell." - :parent isearch-mode-map - "C-m" #'eshell-isearch-return - "C-r" #'eshell-isearch-repeat-backward - "C-s" #'eshell-isearch-repeat-forward - "C-g" #'eshell-isearch-abort - "" #'eshell-isearch-delete-char - "" #'eshell-isearch-delete-char - "C-c C-c" #'eshell-isearch-cancel) +(defvar-local eshell--history-isearch-message-overlay nil + "Overlay for Isearch message when searching through input history.") +(defvar-local eshell--stored-incomplete-input nil + "Stored input for history cycling.") (defvar-keymap eshell-hist-mode-map "" #'eshell-previous-matching-input-from-input "" #'eshell-next-matching-input-from-input "C-" #'eshell-previous-input "C-" #'eshell-next-input - "M-r" #'eshell-previous-matching-input - "M-s" #'eshell-next-matching-input + "M-r" #'eshell-isearch-backward-regexp "C-c M-r" #'eshell-previous-matching-input-from-input "C-c M-s" #'eshell-next-matching-input-from-input "C-c C-l" #'eshell-list-history @@ -261,20 +263,9 @@ eshell-hist-initialize (not eshell-non-interactive-p)) (let ((rebind-alist eshell-rebind-keys-alist)) (setq-local eshell-rebind-keys-alist - (append rebind-alist eshell-hist-rebind-keys-alist)) - (setq-local search-invisible t) - (setq-local search-exit-option t) - (add-hook 'isearch-mode-hook - (lambda () - (if (>= (point) eshell-last-output-end) - (setq overriding-terminal-local-map - eshell-isearch-map))) - nil t) - (add-hook 'isearch-mode-end-hook - (lambda () - (setq overriding-terminal-local-map nil)) - nil t)) + (append rebind-alist eshell-hist-rebind-keys-alist))) (eshell-hist-mode)) + (add-hook 'isearch-mode-hook #'eshell--isearch-setup nil t) (make-local-variable 'eshell-history-size) (or eshell-history-size @@ -384,6 +375,23 @@ eshell-get-history "Get an input line from the history ring." (ring-ref (or ring eshell-history-ring) index)) +(defun eshell-goto-history (pos) + "Replace command line with the element at POS of history ring. +Also update `eshell-history-index'. As a special case, if POS is nil +and `eshell--stored-incomplete-input' is a non-empty string, restore the +saved input." + (when (null eshell-history-index) + (setq eshell--stored-incomplete-input + (buffer-substring-no-properties eshell-last-output-end + (point-max)))) + (setq eshell-history-index pos) + ;; Can't use kill-region as it sets this-command + (delete-region eshell-last-output-end (point-max)) + (if (and pos (not (ring-empty-p eshell-history-ring))) + (insert-and-inherit (eshell-get-history pos)) + (when (> (length eshell--stored-incomplete-input) 0) + (insert-and-inherit eshell--stored-incomplete-input)))) + (defun eshell-add-input-to-history (input) "Add the string INPUT to the history ring. Input is entered into the input history ring, if the value of @@ -897,12 +905,12 @@ eshell-previous-matching-input ;; Has a match been found? (if (null pos) (error "Not found") - (setq eshell-history-index pos) - (unless (minibuffer-window-active-p (selected-window)) - (message "History item: %d" (- (ring-length eshell-history-ring) pos))) - ;; Can't use kill-region as it sets this-command - (delete-region eshell-last-output-end (point)) - (insert-and-inherit (eshell-get-history pos))))) + (eshell-goto-history pos) + (unless (or (minibuffer-window-active-p (selected-window)) + ;; No messages for Isearch because it will show the + ;; same messages (and more). + isearch-mode) + (message "History item: %d" (- (ring-length eshell-history-ring) pos)))))) (defun eshell-next-matching-input (regexp arg) "Search forwards through input history for match for REGEXP. @@ -937,114 +945,160 @@ eshell-next-matching-input-from-input (interactive "p") (eshell-previous-matching-input-from-input (- arg))) -(defun eshell-test-imatch () - "If isearch match good, put point at the beginning and return non-nil." - (if (get-text-property (point) 'history) - (progn (beginning-of-line) t) - (let ((before (point))) - (beginning-of-line) - (if (and (not (bolp)) - (<= (point) before)) - t - (if isearch-forward - (progn - (end-of-line) - (forward-char)) - (beginning-of-line) - (backward-char)))))) - -(defun eshell-return-to-prompt () - "Once a search string matches, insert it at the end and go there." - (setq isearch-other-end nil) - (let ((found (eshell-test-imatch)) before) - (while (and (not found) - (setq before - (funcall (if isearch-forward - 're-search-forward - 're-search-backward) - isearch-string nil t))) - (setq found (eshell-test-imatch))) - (if (not found) - (progn - (goto-char eshell-last-output-end) - (delete-region (point) (point-max))) - (setq before (point)) - (let ((text (buffer-substring-no-properties - (point) (line-end-position))) - (orig (marker-position eshell-last-output-end))) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (when (and text (> (length text) 0)) - (insert text) - (put-text-property (1- (point)) (point) - 'last-search-pos before) - (set-marker eshell-last-output-end orig) - (goto-char eshell-last-output-end)))))) - -(defun eshell-prepare-for-search () - "Make sure the old history file is at the beginning of the buffer." - (unless (get-text-property (point-min) 'history) - (save-excursion - (goto-char (point-min)) - (let ((end (copy-marker (point) t))) - (insert-file-contents eshell-history-file-name) - (set-text-properties (point-min) end - '(history t invisible t)))))) +(defun eshell--isearch-setup () + "Set up Isearch to search the input history. +Intended to be added to `isearch-mode-hook' in an Eshell buffer." + (when (and + ;; Eshell is busy running a foreground process + (not eshell-foreground-command) + (or (eq eshell-history-isearch t) + (and (eq eshell-history-isearch 'dwim) + (>= (point) eshell-last-output-end)))) + (setq isearch-message-prefix-add "history ") + (setq-local isearch-lazy-count nil) + (setq-local isearch-search-fun-function #'eshell-history-isearch-search + isearch-message-function #'eshell-history-isearch-message + isearch-wrap-function #'eshell-history-isearch-wrap + isearch-push-state-function #'eshell-history-isearch-push-state) + (add-hook 'isearch-mode-end-hook #'eshell-history-isearch-end nil t))) + +(defun eshell-history-isearch-end () + "Clean up after terminating history Isearch." + (when (overlayp eshell--history-isearch-message-overlay) + (delete-overlay eshell--history-isearch-message-overlay)) + (setq isearch-message-prefix-add nil) + (kill-local-variable 'isearch-lazy-count) + (setq-local isearch-search-fun-function #'isearch-search-fun-default + isearch-message-function nil + isearch-wrap-function nil + isearch-push-state-function nil) + (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) + (setq isearch-opoint (point)) + (unless isearch-suspended + (custom-reevaluate-setting 'eshell-history-isearch))) + +(defun eshell-history-isearch-search () + "Return search function for Isearch in input history." + (lambda (string bound noerror) + (let ((search-fun (isearch-search-fun-default)) + (found nil)) + ;; Avoid highlighting matches in and before the last prompt + (when (and bound isearch-forward + (< (point) eshell-last-output-end)) + (goto-char eshell-last-output-end)) + (or + ;; First search in the initial input + (funcall search-fun string + (if isearch-forward bound eshell-last-output-end) + noerror) + ;; Then search in the input history: put next/previous history + ;; element in the command line successively, then search the + ;; string in the command line. Do this only when not + ;; lazy-highlighting (`bound' is nil). + (unless bound + (condition-case nil + (progn + (while (not found) + (cond (isearch-forward + ;; Signal an error explicitly to break + (when (or (null eshell-history-index) + (eq eshell-history-index 0)) + (error "End of history; no next item")) + (eshell-next-input 1) + (goto-char eshell-last-output-end)) + (t + ;; Signal an error explicitly to break + (when (eq eshell-history-index + (1- (ring-length eshell-history-ring))) + (error "Beginning of history; no preceding item")) + (eshell-previous-input 1) + (goto-char (point-max)))) + (setq isearch-barrier (point) + isearch-opoint (point)) + ;; After putting an history element in the command + ;; line, search the string in them. + (setq found (funcall search-fun string + (unless isearch-forward + eshell-last-output-end) + noerror))) + (point)) + ;; Return when no next/preceding element error signaled + (error nil))))))) + +(defun eshell-history-isearch-message (&optional c-q-hack ellipsis) + "Display the input history search prompt. +If there are no search errors, this function displays an overlay with +the Isearch prompt which replaces the original Eshell prompt. +Otherwise, it displays the standard Isearch message returned from the +function `isearch-message'." + (if (not (and isearch-success (not isearch-error))) + ;; Use standard message function (which displays a message in the + ;; echo area) when not in command line, or search fails or has + ;; errors (like incomplete regexp). + (isearch-message c-q-hack ellipsis) + ;; Otherwise, use an overlay over the Eshell prompt. + (if (overlayp eshell--history-isearch-message-overlay) + (move-overlay eshell--history-isearch-message-overlay + (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end) + (setq eshell--history-isearch-message-overlay + (make-overlay (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end)) + (overlay-put eshell--history-isearch-message-overlay 'evaporate t)) + (overlay-put eshell--history-isearch-message-overlay + 'display (isearch-message-prefix ellipsis + isearch-nonincremental)) + (if (and eshell-history-index (not ellipsis)) + (message "History item: %d" (- (ring-length eshell-history-ring) + eshell-history-index)) + (message "")))) + +(defun eshell-history-isearch-wrap () + "Wrap the input history search." + (if isearch-forward + (eshell-goto-history (1- (ring-length eshell-history-ring))) + (eshell-goto-history nil)) + (goto-char (if isearch-forward eshell-last-output-end (point-max)))) + +(defun eshell-history-isearch-push-state () + "Save a function restoring the state of input history search. +Save `eshell-history-index' to the additional state parameter in the +search status stack." + (let ((index eshell-history-index)) + (lambda (_cmd) + (eshell-goto-history index)))) (defun eshell-isearch-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((inhibit-read-only t)) - (eshell-prepare-for-search) - (goto-char (point-max)) - (set-marker eshell-last-output-end (point)) - (delete-region (point) (point-max))) - (isearch-mode invert t 'eshell-return-to-prompt)) - -(defun eshell-isearch-repeat-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((old-pos (get-text-property (1- (point-max)) - 'last-search-pos))) - (when old-pos - (goto-char old-pos) - (if invert - (end-of-line) - (backward-char))) - (setq isearch-forward invert) - (isearch-search-and-update))) + "Do incremental search backward through past commands." + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward nil t) + (isearch-backward nil t))) (defun eshell-isearch-forward () - "Do incremental regexp search backward through past commands." - (interactive) + "Do incremental search forward through past commands." + (interactive nil eshell-mode) (eshell-isearch-backward t)) -(defun eshell-isearch-repeat-forward () +(defun eshell-isearch-backward-regexp (&optional invert) "Do incremental regexp search backward through past commands." - (interactive) - (eshell-isearch-repeat-backward t)) - -(defun eshell-isearch-cancel () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-cancel)) - -(defun eshell-isearch-abort () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-abort)) - -(defun eshell-isearch-delete-char () - (interactive) - (save-excursion - (isearch-delete-char))) - -(defun eshell-isearch-return () - (interactive) - (isearch-done) - (eshell-send-input)) + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward-regexp nil t) + (isearch-backward-regexp nil t))) + +(defun eshell-isearch-forward-regexp () + "Do incremental regexp search forward through past commands." + (interactive nil eshell-mode) + (eshell-isearch-backward-regexp t)) (defun em-hist-unload-function () (remove-hook 'kill-emacs-hook 'eshell-save-some-history)) -- 2.47.1 --=-=-=-- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Dec 2024 12:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Juri Linkov , Jim Porter Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173340325412393 (code B ref 74287); Thu, 05 Dec 2024 12:55:02 +0000 Received: (at 74287) by debbugs.gnu.org; 5 Dec 2024 12:54:14 +0000 Received: from localhost ([127.0.0.1]:38626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJBMz-0003Dl-46 for submit@debbugs.gnu.org; Thu, 05 Dec 2024 07:54:14 -0500 Received: from fout-b1-smtp.messagingengine.com ([202.12.124.144]:55829) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJBMt-0003DK-FK for 74287@debbugs.gnu.org; Thu, 05 Dec 2024 07:54:12 -0500 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id BE0A8114021F; Thu, 5 Dec 2024 07:54:01 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 05 Dec 2024 07:54:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733403241; x=1733489641; bh=00tJ9R2n2m Ipw72frSJcf+4RaOXt6cT+v3CaNkCtHUk=; b=Tv+/y27gRyFd08Hps3+f75sTYF PkXPhZzkYX9Afu5RcTI1Rtal15yRgsOagin+TrKM2+g3sozdU1L9X7CnTZChQHXP X71CC7HDdeL9xcB0yy56Dn1fDOQBTT5eSZrlznanvRg27HASrk2LahoEO0nrTopB yYoXiSEe8En0xYvhCLl8ZsF15RWOgPYGinxnXB2a1s73NQv+MmqpqG3XnBh98Gda 4/v+3Lh88rciCNIhIz2zTSHrIh4O8D0YKznNrz1dvW/DWUMzNatnOr1gMuRMZ+uu KPmpsA+iGZ8rB3m/osC+BFkkvjgUHX6DPIZj/V9763GUhN/KatdyTRDpcI3Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733403241; x=1733489641; bh=00tJ9R2n2mIpw72frSJcf+4RaOXt6cT+v3C aNkCtHUk=; b=usW3DeszyO1WSrsr/XiEQaXqQG8NuA2/p2QpHFiudz9UlDniyt9 HWgjIjndVig51RN8mvHj5DvJiao0qiWMemM6yfWgkVLSbXdbXZQH79bz271xlXFN PTsU088S/gBhzKRnk3knOXy1mDZake7dmCgXH6oKeVCDtLFvuTsyk5F7cin9tYF4 I6gvSRxWxdnSZxdKR/SE/4TBWqTMyqzO9y5jcqL2gt6UNM6olhZVI2xXaXw8bjKQ B3tdL3gna1e2Peduo3QMKSir5owMC8oERtgfQ9Tts9ne99G3Y8UEJdhIQ32m8o5v V+GJ87ZkRse5MUkwyscVczdeQJ3kFxloizw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrieejgdeghecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesmhdtreertddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeeifffgieeulefgjeejiedvleehffffueeiiefhhfffveejuefh gedvhfekgfelkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvthdprhgtph htthhopehjphhorhhtvghrsghughhssehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Dec 2024 07:54:00 -0500 (EST) From: Pengji Zhang In-Reply-To: <87jzcecnc9.fsf@pengjiz.com> References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> Date: Thu, 05 Dec 2024 20:53:58 +0800 Message-ID: <87h67icmu1.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Pengji Zhang writes: > Juri Linkov writes: > >> (There is only one typo in the variable name >> 'eshell--history-isearch-messasge-overlay'.) > > Thanks! Corrected in the attached updated patch. Forgot to update the commit message. Please disregard the previous patch and check the one attached to this email instead. Sorry for the noise! --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Rework-history-Isearch-for-Eshell.patch Content-Description: Patch updated to correct typos >From e5242e679090d999549805c30bc63685c1035439 Mon Sep 17 00:00:00 2001 From: Pengji Zhang Date: Thu, 5 Dec 2024 20:25:25 +0800 Subject: [PATCH] Rework history Isearch for Eshell This is to make history Isearch for Eshell similar to that of 'comint-mode', by hooking into Isearch properly instead of defining new commands to emulate Isearch. * lisp/eshell/em-hist.el (eshell-history-isearch): New user option. (eshell-goto-history, eshell--isearch-setup) (eshell-history-isearch-end, eshell-history-isearch-search) (eshell-history-isearch-message, eshell-history-isearch-wrap) (eshell-history-isearch-push-state): New functions. (eshell-isearch-backward-regexp, eshell-isearch-forward-regexp): New commands. (eshell--history-isearch-message-overlay) (eshell--stored-incomplete-input): New internal variables. (eshell-hist-mode-map): Bind 'M-r' to 'eshell-isearch-backward-regexp' and free 'M-s' binding for normal in-buffer search commands. (eshell-isearch-backward, eshell-isearch-forward): Use the new way to start searching. (eshell-hist-initialize): Use the new Isearch setup function. (eshell-previous-matching-input): Use 'eshell-goto-history'. Also inhibit messages when searching. (eshell-isearch-map, eshell-isearch-repeat-backward) (eshell-isearch-abort, eshell-isearch-delete-char) (eshell-isearch-return, eshell-isearch-cancel) (eshell-isearch-repeat-forward, eshell-test-imatch) (eshell-return-to-prompt, eshell-prepare-for-search): Remove. These are for the old history Isearch implementation. * doc/misc/eshell.texi (History): Document changes. * etc/NEWS: Annouce changes. --- doc/misc/eshell.texi | 15 +- etc/NEWS | 23 +++ lisp/eshell/em-hist.el | 322 ++++++++++++++++++++++++----------------- 3 files changed, 223 insertions(+), 137 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index ee4d0ca09c8..701137ea1b4 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -2661,10 +2661,10 @@ History @table @kbd @kindex M-r -@kindex M-s @item M-r -@itemx M-s -History I-search. +History I-search. @kbd{M-r} starts an incremental search in input +history. While searching, type @kbd{C-r} to move to the previous match, +and @kbd{C-s} to move to the next match in the input history. @kindex M-p @kindex M-n @@ -2675,6 +2675,15 @@ History previous or next line that begins with that string. @end table +@vindex eshell-history-isearch +If you would like to use the default Isearch key-bindings to search +through input history, you may customize @code{eshell-history-isearch} +to @code{t}. That makes, for example, @kbd{C-r} and @kbd{C-M-r} in an +Eshell buffer search in input history only. In addition, if the value +of @code{eshell-history-isearch} is @code{dwim}, those commands search +in the history when the point is after the last prompt, and search in +the buffer when the point is before or within the last prompt. + @node Extension modules @chapter Extension modules Eshell provides a facility for defining extension modules so that they diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..c1df6f78d9f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -288,6 +288,29 @@ This hook runs after an Eshell session has been fully initialized, immediately before running 'eshell-post-command-hook' for the first time. ++++ +*** Improved history Isearch. +History Isearch in Eshell is reworked. Two new commands +'eshell-isearch-backward-regexp' and 'eshell-isearch-forward-regexp' are +added for incrementally searching through the input history. +'eshell-isearch-backward-regexp' is bound to 'M-r' by default, and 'M-s' +is freed for normal search commands. If you would like to restore the +previous key-bindings for the non-incremental search commands, put in +your configuration: + + (keymap-set eshell-hist-mode-map "M-r" + #'eshell-previous-matching-input) + (keymap-set eshell-hist-mode-map "M-s" + #'eshell-next-matching-input) + ++++ +*** New user option 'eshell-history-isearch' +When 'eshell-history-isearch' is nil (the default), Isearch commands +search in the buffer contents. If you customize it to t, those commands +only search in input history. If you customize it to the symbol 'dwim', +those commands search in input history only when the point is after the +last prompt. + ** SHR +++ diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index fffd611c06f..c85e7704eca 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -34,7 +34,6 @@ ;; Also, most of `comint-mode's keybindings are accepted: ;; ;; M-r ; search backward for a previous command by regexp -;; M-s ; search forward for a previous command by regexp ;; M-p ; access the last command entered, repeatable ;; M-n ; access the first command entered, repeatable ;; @@ -132,6 +131,17 @@ eshell-input-filter (function :tag "Other function")) :risky t) +(defcustom eshell-history-isearch nil + "Non-nil to Isearch in input history only. +If t, usual Isearch keys like \\[isearch-forward] in Eshell search in +the input history only. If `dwim', Isearch in the input history when +point is at the command line, otherwise search in the current Eshell +buffer." + :type '(choice (const :tag "Don't search in input history" nil) + (const :tag "Search histroy when point is on command line" dwim) + (const :tag "Always search in input history" t)) + :version "31.1") + (defun eshell-hist--update-keymap (symbol value) "Update `eshell-hist-mode-map' for `eshell-hist-match-partial'." ;; Don't try to set this before it is bound. See below. @@ -204,25 +214,17 @@ eshell-save-history-index (defvar eshell-hist--new-items nil "The number of new history items that have not been written to file. This variable is local in each eshell buffer.") - -(defvar-keymap eshell-isearch-map - :doc "Keymap used in isearch in Eshell." - :parent isearch-mode-map - "C-m" #'eshell-isearch-return - "C-r" #'eshell-isearch-repeat-backward - "C-s" #'eshell-isearch-repeat-forward - "C-g" #'eshell-isearch-abort - "" #'eshell-isearch-delete-char - "" #'eshell-isearch-delete-char - "C-c C-c" #'eshell-isearch-cancel) +(defvar-local eshell--history-isearch-message-overlay nil + "Overlay for Isearch message when searching through input history.") +(defvar-local eshell--stored-incomplete-input nil + "Stored input for history cycling.") (defvar-keymap eshell-hist-mode-map "" #'eshell-previous-matching-input-from-input "" #'eshell-next-matching-input-from-input "C-" #'eshell-previous-input "C-" #'eshell-next-input - "M-r" #'eshell-previous-matching-input - "M-s" #'eshell-next-matching-input + "M-r" #'eshell-isearch-backward-regexp "C-c M-r" #'eshell-previous-matching-input-from-input "C-c M-s" #'eshell-next-matching-input-from-input "C-c C-l" #'eshell-list-history @@ -261,20 +263,9 @@ eshell-hist-initialize (not eshell-non-interactive-p)) (let ((rebind-alist eshell-rebind-keys-alist)) (setq-local eshell-rebind-keys-alist - (append rebind-alist eshell-hist-rebind-keys-alist)) - (setq-local search-invisible t) - (setq-local search-exit-option t) - (add-hook 'isearch-mode-hook - (lambda () - (if (>= (point) eshell-last-output-end) - (setq overriding-terminal-local-map - eshell-isearch-map))) - nil t) - (add-hook 'isearch-mode-end-hook - (lambda () - (setq overriding-terminal-local-map nil)) - nil t)) + (append rebind-alist eshell-hist-rebind-keys-alist))) (eshell-hist-mode)) + (add-hook 'isearch-mode-hook #'eshell--isearch-setup nil t) (make-local-variable 'eshell-history-size) (or eshell-history-size @@ -384,6 +375,23 @@ eshell-get-history "Get an input line from the history ring." (ring-ref (or ring eshell-history-ring) index)) +(defun eshell-goto-history (pos) + "Replace command line with the element at POS of history ring. +Also update `eshell-history-index'. As a special case, if POS is nil +and `eshell--stored-incomplete-input' is a non-empty string, restore the +saved input." + (when (null eshell-history-index) + (setq eshell--stored-incomplete-input + (buffer-substring-no-properties eshell-last-output-end + (point-max)))) + (setq eshell-history-index pos) + ;; Can't use kill-region as it sets this-command + (delete-region eshell-last-output-end (point-max)) + (if (and pos (not (ring-empty-p eshell-history-ring))) + (insert-and-inherit (eshell-get-history pos)) + (when (> (length eshell--stored-incomplete-input) 0) + (insert-and-inherit eshell--stored-incomplete-input)))) + (defun eshell-add-input-to-history (input) "Add the string INPUT to the history ring. Input is entered into the input history ring, if the value of @@ -897,12 +905,12 @@ eshell-previous-matching-input ;; Has a match been found? (if (null pos) (error "Not found") - (setq eshell-history-index pos) - (unless (minibuffer-window-active-p (selected-window)) - (message "History item: %d" (- (ring-length eshell-history-ring) pos))) - ;; Can't use kill-region as it sets this-command - (delete-region eshell-last-output-end (point)) - (insert-and-inherit (eshell-get-history pos))))) + (eshell-goto-history pos) + (unless (or (minibuffer-window-active-p (selected-window)) + ;; No messages for Isearch because it will show the + ;; same messages (and more). + isearch-mode) + (message "History item: %d" (- (ring-length eshell-history-ring) pos)))))) (defun eshell-next-matching-input (regexp arg) "Search forwards through input history for match for REGEXP. @@ -937,114 +945,160 @@ eshell-next-matching-input-from-input (interactive "p") (eshell-previous-matching-input-from-input (- arg))) -(defun eshell-test-imatch () - "If isearch match good, put point at the beginning and return non-nil." - (if (get-text-property (point) 'history) - (progn (beginning-of-line) t) - (let ((before (point))) - (beginning-of-line) - (if (and (not (bolp)) - (<= (point) before)) - t - (if isearch-forward - (progn - (end-of-line) - (forward-char)) - (beginning-of-line) - (backward-char)))))) - -(defun eshell-return-to-prompt () - "Once a search string matches, insert it at the end and go there." - (setq isearch-other-end nil) - (let ((found (eshell-test-imatch)) before) - (while (and (not found) - (setq before - (funcall (if isearch-forward - 're-search-forward - 're-search-backward) - isearch-string nil t))) - (setq found (eshell-test-imatch))) - (if (not found) - (progn - (goto-char eshell-last-output-end) - (delete-region (point) (point-max))) - (setq before (point)) - (let ((text (buffer-substring-no-properties - (point) (line-end-position))) - (orig (marker-position eshell-last-output-end))) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (when (and text (> (length text) 0)) - (insert text) - (put-text-property (1- (point)) (point) - 'last-search-pos before) - (set-marker eshell-last-output-end orig) - (goto-char eshell-last-output-end)))))) - -(defun eshell-prepare-for-search () - "Make sure the old history file is at the beginning of the buffer." - (unless (get-text-property (point-min) 'history) - (save-excursion - (goto-char (point-min)) - (let ((end (copy-marker (point) t))) - (insert-file-contents eshell-history-file-name) - (set-text-properties (point-min) end - '(history t invisible t)))))) +(defun eshell--isearch-setup () + "Set up Isearch to search the input history. +Intended to be added to `isearch-mode-hook' in an Eshell buffer." + (when (and + ;; Eshell is busy running a foreground process + (not eshell-foreground-command) + (or (eq eshell-history-isearch t) + (and (eq eshell-history-isearch 'dwim) + (>= (point) eshell-last-output-end)))) + (setq isearch-message-prefix-add "history ") + (setq-local isearch-lazy-count nil) + (setq-local isearch-search-fun-function #'eshell-history-isearch-search + isearch-message-function #'eshell-history-isearch-message + isearch-wrap-function #'eshell-history-isearch-wrap + isearch-push-state-function #'eshell-history-isearch-push-state) + (add-hook 'isearch-mode-end-hook #'eshell-history-isearch-end nil t))) + +(defun eshell-history-isearch-end () + "Clean up after terminating history Isearch." + (when (overlayp eshell--history-isearch-message-overlay) + (delete-overlay eshell--history-isearch-message-overlay)) + (setq isearch-message-prefix-add nil) + (kill-local-variable 'isearch-lazy-count) + (setq-local isearch-search-fun-function #'isearch-search-fun-default + isearch-message-function nil + isearch-wrap-function nil + isearch-push-state-function nil) + (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) + (setq isearch-opoint (point)) + (unless isearch-suspended + (custom-reevaluate-setting 'eshell-history-isearch))) + +(defun eshell-history-isearch-search () + "Return search function for Isearch in input history." + (lambda (string bound noerror) + (let ((search-fun (isearch-search-fun-default)) + (found nil)) + ;; Avoid highlighting matches in and before the last prompt + (when (and bound isearch-forward + (< (point) eshell-last-output-end)) + (goto-char eshell-last-output-end)) + (or + ;; First search in the initial input + (funcall search-fun string + (if isearch-forward bound eshell-last-output-end) + noerror) + ;; Then search in the input history: put next/previous history + ;; element in the command line successively, then search the + ;; string in the command line. Do this only when not + ;; lazy-highlighting (`bound' is nil). + (unless bound + (condition-case nil + (progn + (while (not found) + (cond (isearch-forward + ;; Signal an error explicitly to break + (when (or (null eshell-history-index) + (eq eshell-history-index 0)) + (error "End of history; no next item")) + (eshell-next-input 1) + (goto-char eshell-last-output-end)) + (t + ;; Signal an error explicitly to break + (when (eq eshell-history-index + (1- (ring-length eshell-history-ring))) + (error "Beginning of history; no preceding item")) + (eshell-previous-input 1) + (goto-char (point-max)))) + (setq isearch-barrier (point) + isearch-opoint (point)) + ;; After putting an history element in the command + ;; line, search the string in them. + (setq found (funcall search-fun string + (unless isearch-forward + eshell-last-output-end) + noerror))) + (point)) + ;; Return when no next/preceding element error signaled + (error nil))))))) + +(defun eshell-history-isearch-message (&optional c-q-hack ellipsis) + "Display the input history search prompt. +If there are no search errors, this function displays an overlay with +the Isearch prompt which replaces the original Eshell prompt. +Otherwise, it displays the standard Isearch message returned from the +function `isearch-message'." + (if (not (and isearch-success (not isearch-error))) + ;; Use standard message function (which displays a message in the + ;; echo area) when not in command line, or search fails or has + ;; errors (like incomplete regexp). + (isearch-message c-q-hack ellipsis) + ;; Otherwise, use an overlay over the Eshell prompt. + (if (overlayp eshell--history-isearch-message-overlay) + (move-overlay eshell--history-isearch-message-overlay + (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end) + (setq eshell--history-isearch-message-overlay + (make-overlay (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end)) + (overlay-put eshell--history-isearch-message-overlay 'evaporate t)) + (overlay-put eshell--history-isearch-message-overlay + 'display (isearch-message-prefix ellipsis + isearch-nonincremental)) + (if (and eshell-history-index (not ellipsis)) + (message "History item: %d" (- (ring-length eshell-history-ring) + eshell-history-index)) + (message "")))) + +(defun eshell-history-isearch-wrap () + "Wrap the input history search." + (if isearch-forward + (eshell-goto-history (1- (ring-length eshell-history-ring))) + (eshell-goto-history nil)) + (goto-char (if isearch-forward eshell-last-output-end (point-max)))) + +(defun eshell-history-isearch-push-state () + "Save a function restoring the state of input history search. +Save `eshell-history-index' to the additional state parameter in the +search status stack." + (let ((index eshell-history-index)) + (lambda (_cmd) + (eshell-goto-history index)))) (defun eshell-isearch-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((inhibit-read-only t)) - (eshell-prepare-for-search) - (goto-char (point-max)) - (set-marker eshell-last-output-end (point)) - (delete-region (point) (point-max))) - (isearch-mode invert t 'eshell-return-to-prompt)) - -(defun eshell-isearch-repeat-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((old-pos (get-text-property (1- (point-max)) - 'last-search-pos))) - (when old-pos - (goto-char old-pos) - (if invert - (end-of-line) - (backward-char))) - (setq isearch-forward invert) - (isearch-search-and-update))) + "Do incremental search backward through past commands." + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward nil t) + (isearch-backward nil t))) (defun eshell-isearch-forward () - "Do incremental regexp search backward through past commands." - (interactive) + "Do incremental search forward through past commands." + (interactive nil eshell-mode) (eshell-isearch-backward t)) -(defun eshell-isearch-repeat-forward () +(defun eshell-isearch-backward-regexp (&optional invert) "Do incremental regexp search backward through past commands." - (interactive) - (eshell-isearch-repeat-backward t)) - -(defun eshell-isearch-cancel () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-cancel)) - -(defun eshell-isearch-abort () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-abort)) - -(defun eshell-isearch-delete-char () - (interactive) - (save-excursion - (isearch-delete-char))) - -(defun eshell-isearch-return () - (interactive) - (isearch-done) - (eshell-send-input)) + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward-regexp nil t) + (isearch-backward-regexp nil t))) + +(defun eshell-isearch-forward-regexp () + "Do incremental regexp search forward through past commands." + (interactive nil eshell-mode) + (eshell-isearch-backward-regexp t)) (defun em-hist-unload-function () (remove-hook 'kill-emacs-hook 'eshell-save-some-history)) -- 2.47.1 --=-=-=-- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Dec 2024 04:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang , Juri Linkov Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173371896017662 (code B ref 74287); Mon, 09 Dec 2024 04:36:02 +0000 Received: (at 74287) by debbugs.gnu.org; 9 Dec 2024 04:36:00 +0000 Received: from localhost ([127.0.0.1]:52527 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKVV2-0004ao-8J for submit@debbugs.gnu.org; Sun, 08 Dec 2024 23:36:00 -0500 Received: from mail-pf1-f177.google.com ([209.85.210.177]:45551) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKVV0-0004ag-MM for 74287@debbugs.gnu.org; Sun, 08 Dec 2024 23:35:59 -0500 Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-725f3594965so135416b3a.3 for <74287@debbugs.gnu.org>; Sun, 08 Dec 2024 20:35:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733718898; x=1734323698; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=zAsQGmYVFaugMVzbP8M65yU4Gcx9Jmta2cO/Nj7vBEQ=; b=I9fHn3hE8LSlewYxO1+ZiLDvcEuD4ZEwY7FzlyQ1L926Fh1Mi56afW+BhSapIPhwVe u30NSTU/JIDnIkIWvY5Pb+gKAfk6NeIZ8RY2HmeHm/Rv1l22u+k96l4wJqngulc5e6D5 jznxyvStkcXA+r6a5reRPKZXgn+Yj/pwSSTP1UfXft9dneadIiNRu/wUZY0NPm4dC6eC mE8+VTbkY8q9BBZ+JeRO5dzakUE7F+WZKDEOEzy9V2zHpRP+4PuyQeV1t0GrMe4qs4Cu KpwOvQV+vNlB7Jd9M+RbKYeI+1bImGJyO3ggCaw8B1rsXOPZ1NWZq187PtwezDo/Oy1W 7bIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733718898; x=1734323698; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zAsQGmYVFaugMVzbP8M65yU4Gcx9Jmta2cO/Nj7vBEQ=; b=voMi7dwdJlN/X6rvjEGCi0io+XLt8wPlk7HUPV9Yhn1tAuacZE8EZGOHjrRCY9+Ee9 dF2aBZzyQ+68whwgmPJT9WdVhyTq4pfV/FpArcy4707a7a6eYPfXRDiBSuhmE2/FR/Ef xLV+HhyWmPfxsUauoWxbTmWWxleDepua4VRsmsOEFgFyw4sZyenrlvNyMfWhoo2tTIKd 1GtKndy6kHAZAYp4Lvk4vI25nQJHCDx4kZnJ1l7PMGHVU+hkhDJfprtw9NXFOtm1f4K3 PngcsGHfkGInYXKu7dORjee9tLNzZT7ExDuaIqOQr5EQUkoghkw3z5izEO81hNNqv62k ImVg== X-Gm-Message-State: AOJu0YxTYLiljBWC33CdX/Y/8TgK2B5hNkyXSm832oQRBHanRWa86Vrl LP4xZoZ89cmpI4O7XjbtqxanjyUJOufSZDdXKWT6JHO22fE12F/i X-Gm-Gg: ASbGncuUsL6OoDEUvsryBcoec61zM3E+R6pgfbXVgJp/qX9/DHY6VtMpzhHsCFr0a7y r0MnvoNeq3t343dd3dG/raGRB75de1UeRb3jsKJSma1eKJmvaUUQaktjwbDH++if10TxE/WY4h8 RIDinzAIv+Gjnt4gIF7tmiajkov/t9av/e5Dlb425PXwCHzje2qVm2CoVKMNcCOYO8CdtQv/Wpm wrAEign6qu5syTtjJhIFyo/90LDXPkrw9BjxeVnIPx1f0bq6g8bPFU75DQ88a5fY3Tqbv0qBDPz h+RrS+Ezor9HPs1uEQC0e/ihZeA= X-Google-Smtp-Source: AGHT+IEEOziomjF+ASdHOJJK7kdOeGlG76zSteFyac9xcg5pIcpdSa5eW+j2lvtsLiKqDN/wcHdb/g== X-Received: by 2002:a05:6a00:b87:b0:725:937a:b124 with SMTP id d2e1a72fcca58-725b81d84b5mr18644839b3a.26.1733718898063; Sun, 08 Dec 2024 20:34:58 -0800 (PST) Received: from [192.168.1.2] (syn-023-240-098-037.res.spectrum.com. [23.240.98.37]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-725ee10f928sm922392b3a.32.2024.12.08.20.34.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Dec 2024 20:34:57 -0800 (PST) Message-ID: Date: Sun, 8 Dec 2024 20:34:57 -0800 MIME-Version: 1.0 Content-Language: en-US References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> From: Jim Porter In-Reply-To: <87h67icmu1.fsf@pengjiz.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 12/5/2024 4:53 AM, Pengji Zhang wrote: > Forgot to update the commit message. Please disregard the previous patch > and check the one attached to this email instead. Sorry for the noise! I finally had time to test this out. This seems to work well, except for one issue. In 'eshell-history-isearch-end' you have this bit: > + (unless isearch-suspended > + (custom-reevaluate-setting 'eshell-history-isearch))) Unfortunately, this doesn't work well when using "(setopt eshell-history-isearch t)". The value gets reset to nil when exiting history Isearch, so the next time a user Isearches, they'll just get "regular" Isearch. Is there a way we could change this so that users who use 'setopt' (or even 'setq'?) instead of the Customize package can enable this feature? From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Dec 2024 12:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Jim Porter , Juri Linkov Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17337466313385 (code B ref 74287); Mon, 09 Dec 2024 12:18:01 +0000 Received: (at 74287) by debbugs.gnu.org; 9 Dec 2024 12:17:11 +0000 Received: from localhost ([127.0.0.1]:53127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKchL-0000sX-3n for submit@debbugs.gnu.org; Mon, 09 Dec 2024 07:17:11 -0500 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]:42089) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKchI-0000sK-Pd for 74287@debbugs.gnu.org; Mon, 09 Dec 2024 07:17:09 -0500 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 70F5C1384197; Mon, 9 Dec 2024 07:17:03 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 09 Dec 2024 07:17:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733746623; x=1733833023; bh=hvJ3R4UlTl /9UzsRAfDC+PaGk2SBUUuTkpWH0mMtBsE=; b=abze8mnW2c4lSlUnW9p/v3DLbd 3Z484/DJ0jL2/KVwm3JYFH6jHd0xzu5Dy3MSsjg3+ea0DWL6rYfu9N+qYh/rp74S QXOu3t7ycJq0rU7RomPIG8UqkGYAC3RNn9nNctNx8nDIml5q37KLcg6Nr/vjo/a1 TJe4y82Yc9bxJE45MOTvuhfZzuutooqNqjnLYZMhPC/hSD+7vHacIWufMa9clewi c7F91IKmSOH1mxYoSgMaUoYGKNLndHfERyRJhgpi8oS6kwh6nctXjV8MVyWRjleh U62qhHwSciLHZjm8qps0S2wJMZb1LyFdQva63J8KZjPp2D9TQgyVBSqt1SkA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733746623; x=1733833023; bh=hvJ3R4UlTl/9UzsRAfDC+PaGk2SBUUuTkpW H0mMtBsE=; b=C+LOTr6YMziPfCfOz49GcuEumLwkqyUDTXVlGyP6zElxdyRhwJH SmZah/o1242xcS90f4DJcHXDUlwSOOjU1WZ2Fs8gGlSJvOHEyNb72+5ePP++EW8H OFYvmjq259JT8DFHQksNNN1P1DqMm8GXczv7cmHPHvIAXk0loo/YAUtb7/LX8LJ3 IJhL9YU5QNmO0J/3Vy9WqKgN7M+j3wn+I/N4aFX/wRevasWcIEfr9PAjk3RsFEPa 4/IAI86LN+oad6DKu/g637BUAUNv90gFWdS8EYSipEFWn/OKd2dMvlmGOsxCT9Ea mLLXXfb5fucZ1sO0e55uVVJizTyUxCFNFgg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjeeigdduvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesthdtredttddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeegfeeiiedvudekiedtgedufedtvedtueetieffhfdvhefftefg ieejieelleehgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhpohhrthgvrhgsuhhgshesghhmrghilhdrtg homhdprhgtphhtthhopehjuhhriheslhhinhhkohhvrdhnvghtpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Dec 2024 07:17:02 -0500 (EST) From: Pengji Zhang In-Reply-To: References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> Date: Mon, 09 Dec 2024 20:16:59 +0800 Message-ID: <87cyi159vo.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jim Porter writes: > Is there a way we could change this so that users who use 'setopt' (or > even 'setq'?) instead of the Customize package can enable this > feature? Indeed, it only works with 'M-x customize' (and friends). I guess we can instead save the original value to another variable and restore from it. Juri, since you wrote that for 'comint.el' in commit 71e458505f3, what do you think? Thanks! From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Dec 2024 13:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Jim Porter , Juri Linkov Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173375136617926 (code B ref 74287); Mon, 09 Dec 2024 13:37:02 +0000 Received: (at 74287) by debbugs.gnu.org; 9 Dec 2024 13:36:06 +0000 Received: from localhost ([127.0.0.1]:53269 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKdvh-0004f3-P1 for submit@debbugs.gnu.org; Mon, 09 Dec 2024 08:36:06 -0500 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]:47439) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKdve-0004eU-Qj for 74287@debbugs.gnu.org; Mon, 09 Dec 2024 08:36:04 -0500 Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 60AB311401B3; Mon, 9 Dec 2024 08:35:57 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Mon, 09 Dec 2024 08:35:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733751357; x=1733837757; bh=Tc909s4faU lnsHVxKRxahqipyJNKG7OB3ykEr8t34iE=; b=SDARuARv320fWDm+Kw9hEO11jt gmx0zZ5wuAE4/8DvPeauxMlw9tBjv6Vr9/TYnvQaairpPWERynVSq9xRvaMM8Qf9 Ad9tn56B1OjpNZon9Uyk8XsB14Sj9GWjEN2tF4OXDWoM6yzFxEaCSSjpfgwZwXuk bAuDEQcNVbeblz0yP+eOKZnrlYkV2GwKzi9/scNR32x44bS0bHpA+H47ksuLXm/S GxoxWQLorbvphxX0EPMoSwQMENjn8eWh/bgzoHCNRkARmg86Wgb9E0pTnSK9XgnN N6o67gP2vy6RsbCQJz6t4b1+tLe4e4MpRgHFaIFHEWSgJaUEs/Gay4Czz0TA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733751357; x=1733837757; bh=Tc909s4faUlnsHVxKRxahqipyJNKG7OB3yk Er8t34iE=; b=r+7mPhlzVYvFO1SD7HQ7jk4AbnBZ2MtJcXAXnnlHWuuWRLYS+hJ RxQL5u99LZYhksmbH02quLlNMzz8Dt83+zc2+vdIZKWMaJ2Tv5lnEoihclxSpI+p tUd1QNMOxRykfQqF3CUetAU3ajG5ketNJLgtUi5MrJmU50YtuywEpNRHlu6o0laZ KJ2ryA2/NAKXrDrV1XU5GHBX+gYllfqHSjA42e9ML5mLFVDZXDo/0zTn7jMWz2nB 7rdve+0mJjfQvvaicpP9zFVVxrJQAJWF3i2nab3khm90blV0iL0IdeT6wSzhnxfn 3UiqXnLy7r8pnmBLi3mRIzKFBQYUsNhc9yw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjeeigddvkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesmhdtreertddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeeifffgieeulefgjeejiedvleehffffueeiiefhhfffveejuefh gedvhfekgfelkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhpohhrthgvrhgsuhhgshesghhmrghilhdrtg homhdprhgtphhtthhopehjuhhriheslhhinhhkohhvrdhnvghtpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Dec 2024 08:35:56 -0500 (EST) From: Pengji Zhang In-Reply-To: <87cyi159vo.fsf@pengjiz.com> References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> Date: Mon, 09 Dec 2024 21:35:52 +0800 Message-ID: <87wmg9htc7.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Pengji Zhang writes: > Jim Porter writes: > >> Is there a way we could change this so that users who use 'setopt' >> (or even 'setq'?) instead of the Customize package can enable this >> feature? > > Indeed, it only works with 'M-x customize' (and friends). I guess we > can instead save the original value to another variable and restore > from it. How about the change in the attachment? If it looks good to you, I will merge it into the main patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=em-hist-restore-option.patch diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index c85e7704eca..4bcf434f6e4 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -218,6 +218,9 @@ eshell--history-isearch-message-overlay "Overlay for Isearch message when searching through input history.") (defvar-local eshell--stored-incomplete-input nil "Stored input for history cycling.") +(defvar eshell--force-history-isearch nil + "Non-nil means to force searching in input history. +If nil, respect the option `eshell-history-isearch'.") (defvar-keymap eshell-hist-mode-map "" #'eshell-previous-matching-input-from-input @@ -951,7 +954,8 @@ eshell--isearch-setup (when (and ;; Eshell is busy running a foreground process (not eshell-foreground-command) - (or (eq eshell-history-isearch t) + (or eshell--force-history-isearch + (eq eshell-history-isearch t) (and (eq eshell-history-isearch 'dwim) (>= (point) eshell-last-output-end)))) (setq isearch-message-prefix-add "history ") @@ -975,7 +979,7 @@ eshell-history-isearch-end (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) (setq isearch-opoint (point)) (unless isearch-suspended - (custom-reevaluate-setting 'eshell-history-isearch))) + (setq eshell--force-history-isearch nil))) (defun eshell-history-isearch-search () "Return search function for Isearch in input history." @@ -1077,7 +1081,7 @@ eshell-history-isearch-push-state (defun eshell-isearch-backward (&optional invert) "Do incremental search backward through past commands." (interactive nil eshell-mode) - (setq eshell-history-isearch t) + (setq eshell--force-history-isearch t) (if invert (isearch-forward nil t) (isearch-backward nil t))) @@ -1090,7 +1094,7 @@ eshell-isearch-forward (defun eshell-isearch-backward-regexp (&optional invert) "Do incremental regexp search backward through past commands." (interactive nil eshell-mode) - (setq eshell-history-isearch t) + (setq eshell--force-history-isearch t) (if invert (isearch-forward-regexp nil t) (isearch-backward-regexp nil t))) --=-=-=-- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Dec 2024 18:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang Cc: Jim Porter , 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173376869916894 (code B ref 74287); Mon, 09 Dec 2024 18:25:01 +0000 Received: (at 74287) by debbugs.gnu.org; 9 Dec 2024 18:24:59 +0000 Received: from localhost ([127.0.0.1]:55572 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKiRH-0004OP-7o for submit@debbugs.gnu.org; Mon, 09 Dec 2024 13:24:59 -0500 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:45317) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKiRF-0004O7-2h for 74287@debbugs.gnu.org; Mon, 09 Dec 2024 13:24:58 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id EC6B040008; Mon, 9 Dec 2024 18:24:48 +0000 (UTC) From: Juri Linkov In-Reply-To: <87cyi159vo.fsf@pengjiz.com> (Pengji Zhang's message of "Mon, 09 Dec 2024 20:16:59 +0800") Organization: LINKOV.NET References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> Date: Mon, 09 Dec 2024 20:23:59 +0200 Message-ID: <87msh4n29s.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> Is there a way we could change this so that users who use 'setopt' (or >> even 'setq'?) instead of the Customize package can enable this >> feature? > > Indeed, it only works with 'M-x customize' (and friends). I guess we can > instead save the original value to another variable and restore from it. > > Juri, since you wrote that for 'comint.el' in commit 71e458505f3, what > do you think? Thanks! I confirm the same problem in comint. The current solution was described in bug#30187 as the least bad. Fortunately, no one complained because it works with saved customizations. But still we need to fix it. So do you propose to add an internal variable that duplicates the user option? From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Dec 2024 19:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang , Juri Linkov Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173377122828706 (code B ref 74287); Mon, 09 Dec 2024 19:08:02 +0000 Received: (at 74287) by debbugs.gnu.org; 9 Dec 2024 19:07:08 +0000 Received: from localhost ([127.0.0.1]:55663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKj63-0007Sw-LQ for submit@debbugs.gnu.org; Mon, 09 Dec 2024 14:07:07 -0500 Received: from mail-pl1-f169.google.com ([209.85.214.169]:61897) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKj62-0007Sn-GD for 74287@debbugs.gnu.org; Mon, 09 Dec 2024 14:07:07 -0500 Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21669fd5c7cso5827635ad.3 for <74287@debbugs.gnu.org>; Mon, 09 Dec 2024 11:07:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733771164; x=1734375964; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=VrWw6ypsDPJfo0wD3FPGEBbmnIoaUv4yy/V4RqP2qFs=; b=WVOZa67zfxYOn3l6CfkqJrpnnrsGw+Iz2+NciglwxNC6dgf+KlypbjB0GVsQb/TH/6 KjhyA2dFgLMZmlJu9i1ZS/4c3Bo2TiZJ9OZhUflbxsH2pHKAooQrMyRIncziTPWqV3+v 8SQ3a89QLPJc3nJHPXcYiNQHKjIBOjf9m7dzRvHA6pn557MXABZcKoS/J67OIRGHUJwm p9L1wRJQSpnpq9t2HLyOimntSM2T0Vl31Z/nRSYlexDbk0uJ6LvJIZGEPYMyGj8+QjLS a+MOITwe/U7NwVoHk5vtqS3/IdyuE3/L1yMAAebyCcL2q9uHhNwErBcQfytPA/dJ8Mce NNJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733771164; x=1734375964; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VrWw6ypsDPJfo0wD3FPGEBbmnIoaUv4yy/V4RqP2qFs=; b=TS3XdVo/Ntf6f0T+ROjZHqidHbAzi3w2tXs34Pr+XvYAAWMblrKflWGj628SzC5EGk dCi9hiIIUZdRzDGQ+b9LcR4J7/prZiIf1tzQeiIA0KPAnrmyL+aCnJ9Fhy3dQtlhQOVU 0isyieWUCavH9meSefVBsf/vRASLwsGyjOD+CigsvvBcR4DPevdonVmQIhkxYQAhFf99 A3WE7n4+Vqst4xRBvoFjs9qO478RTl40J9JFTiMt83n9jsTCqj0RT6dF5eIDCev1QEiv 5zfc1aWq5Jt81RI5GhSTiCUeAKXb5fRzUNruJTnxFSZi9CpnLZxRIdamM7qQPWTReORX xzqA== X-Gm-Message-State: AOJu0YxP4sbXg/EzwHJbxuZI3rU5yvXUnBWm88jFT7N2Xf+r3GUqCbKG lcVvck+HEPfWVZ03LCbdcCRbiDa9e6xGXxt1AdeaS5Z//TFjVrBO X-Gm-Gg: ASbGncu+qFoYqzpY4quQlJwxLSRl0h+fkmZOJ+bY0bNawwsqAzoTUW1dm7D7cNZVKwA QRLRFHV/mxrFHD8jS9JlMAEFDaosMEI5FabOlJVbI5bQ9rXQlC2XQ7wg2q7aJb37rLFAoLdEfdZ dSxfAz2TLbXZ3ORwByGuAG3JtS9mRuv/qBmYnWnR1OouR7rqJsgvcw+V6rBmiEY9L+HuRrOwsJI hVSiALB9fOEtIo4e8reJ770eY2S4AVlE27gFSPC5FOQ98D/UaHsjxz2TDqRE1V594D/1zcP1cnf 88dWWnuY4rTTTy1/rtM/Xcr6TWM= X-Google-Smtp-Source: AGHT+IH0TdfM/HKg70OYbKo7IncgHTHBKOM5giGTZEPTPhSBdyV1KwVZU6BWAYPVZTClU7G1nQTFfQ== X-Received: by 2002:a17:902:cecc:b0:215:b468:1a33 with SMTP id d9443c01a7336-21614d1ed2fmr175424735ad.4.1733771163862; Mon, 09 Dec 2024 11:06:03 -0800 (PST) Received: from [192.168.1.2] (syn-023-240-098-037.res.spectrum.com. [23.240.98.37]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2161e5a6f23sm55677385ad.266.2024.12.09.11.06.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Dec 2024 11:06:03 -0800 (PST) Message-ID: Date: Mon, 9 Dec 2024 11:06:02 -0800 MIME-Version: 1.0 References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87wmg9htc7.fsf@pengjiz.com> Content-Language: en-US From: Jim Porter In-Reply-To: <87wmg9htc7.fsf@pengjiz.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 12/9/2024 5:35 AM, Pengji Zhang wrote: > How about the change in the attachment? If it looks good to you, I will > merge it into the main patch. This change works for me, so if Juri thinks it's ok, then let's do it this way. (Later, we can port this change to Comint to keep this code in sync.) From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Dec 2024 00:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Juri Linkov Cc: Jim Porter , 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173379214129582 (code B ref 74287); Tue, 10 Dec 2024 00:56:01 +0000 Received: (at 74287) by debbugs.gnu.org; 10 Dec 2024 00:55:41 +0000 Received: from localhost ([127.0.0.1]:56246 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKoXM-0007h4-PD for submit@debbugs.gnu.org; Mon, 09 Dec 2024 19:55:41 -0500 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]:50431) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKoXJ-0007gk-LR for 74287@debbugs.gnu.org; Mon, 09 Dec 2024 19:55:38 -0500 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id BAE13254016E; Mon, 9 Dec 2024 19:55:31 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Mon, 09 Dec 2024 19:55:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733792131; x=1733878531; bh=p1B7XBEzff U4CexAKA4rozQVH87Fddt9HgashpZKzlQ=; b=I8R4ZxspEor1bDT50N2jSu3ffx CyMNOCRkHHZjNvWeqS/iNlcB7rWOTeSpqsoOLEily6dHmioDrGhHGyIti0bl6EpU 33nsuQg+YzXL9dGc+8JdbAvWagizz2dTFQ8UNBg6q/g9H3ZfPPe0+hiilOm4VLU+ d9+EU0cFEF5nnQGvEg83lSpVI39Y14MwjjobqPbI8vS0dONnQglGFInFf5U6ByHD JFFEOL1YGeRooJaRRsDFW8SNo2FFCRaQvSntp89TX/VJzrnQRzIPA0i74BApXE5C W+Dz1gHXQupMvwGyraOYq3ypJbr7fEGdIonbzZW8oyI86UcjNq+DEf7+5Ekg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733792131; x=1733878531; bh=p1B7XBEzffU4CexAKA4rozQVH87Fddt9Hga shpZKzlQ=; b=x0rWHLMHNlUoXLI+sgYG8A0yDJ5W59L8VM6zYOYN1s6lzow70YX 0tKAuhlS9BbT7Srp6No3jLtm/7XaV11cYMqWWZcC75uJ/YgAzjrviSq8Np/aJ8Kl QrTe0BhbxB9ppXnflePhGckgpSozE4m3Kara5SsMnHQvDDZYLbRCfVdiuIyKX+6O cqqxJWevUhe80/k/uugnMW+gTVJ1dDLZbK+ins6O441Je0pPWnRC+rALhCEsCNU+ v/vtU/JSlWxwDJxAj+kv2VsOr6674wu6YRL4JT4SMlc6vspEWSHgWxIA64ebiL2y E4I4FeqVy5Dm2VsbGMRU9SqKn3k+qhEXmsw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjeejgddvkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesthdtredttddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeegfeeiiedvudekiedtgedufedtvedtueetieffhfdvhefftefg ieejieelleehgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvthdprhgtph htthhopehjphhorhhtvghrsghughhssehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Dec 2024 19:55:30 -0500 (EST) From: Pengji Zhang In-Reply-To: <87msh4n29s.fsf@mail.linkov.net> References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> Date: Tue, 10 Dec 2024 08:55:27 +0800 Message-ID: <8734iwl5kw.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Juri Linkov writes: > [...] > > So do you propose to add an internal variable that duplicates the user > option? Yes, sort of. It does not fully duplicates the user option though. Because we only need to force turning *on* history search, it is made to override the user option only when it is non-nil. Basically, it is something like: --8<---------------cut here---------------start------------->8--- @@ -951,7 +954,8 @@ eshell--isearch-setup (when (and ;; Eshell is busy running a foreground process (not eshell-foreground-command) - (or (eq eshell-history-isearch t) + (or eshell--force-history-isearch + (eq eshell-history-isearch t) (and (eq eshell-history-isearch 'dwim) (>= (point) eshell-last-output-end)))) (setq isearch-message-prefix-add "history ") @@ -975,7 +979,7 @@ eshell-history-isearch-end (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) (setq isearch-opoint (point)) (unless isearch-suspended - (custom-reevaluate-setting 'eshell-history-isearch))) + (setq eshell--force-history-isearch nil))) --8<---------------cut here---------------end--------------->8--- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Dec 2024 07:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang Cc: Jim Porter , 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17338170003046 (code B ref 74287); Tue, 10 Dec 2024 07:50:02 +0000 Received: (at 74287) by debbugs.gnu.org; 10 Dec 2024 07:50:00 +0000 Received: from localhost ([127.0.0.1]:56807 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKv0J-0000n3-WD for submit@debbugs.gnu.org; Tue, 10 Dec 2024 02:50:00 -0500 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:56193) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKv0F-0000mS-QF for 74287@debbugs.gnu.org; Tue, 10 Dec 2024 02:49:56 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id DE30260007; Tue, 10 Dec 2024 07:49:48 +0000 (UTC) From: Juri Linkov In-Reply-To: <8734iwl5kw.fsf@pengjiz.com> (Pengji Zhang's message of "Tue, 10 Dec 2024 08:55:27 +0800") Organization: LINKOV.NET References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> <8734iwl5kw.fsf@pengjiz.com> Date: Tue, 10 Dec 2024 09:46:27 +0200 Message-ID: <8734iwq8to.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> So do you propose to add an internal variable that duplicates the user >> option? > > Yes, sort of. It does not fully duplicates the user option though. > Because we only need to force turning *on* history search, it is made to > override the user option only when it is non-nil. Basically, it is > something like: > > @@ -951,7 +954,8 @@ eshell--isearch-setup > (when (and > ;; Eshell is busy running a foreground process > (not eshell-foreground-command) > - (or (eq eshell-history-isearch t) > + (or eshell--force-history-isearch > + (eq eshell-history-isearch t) > (and (eq eshell-history-isearch 'dwim) > (>= (point) eshell-last-output-end)))) > (setq isearch-message-prefix-add "history ") > @@ -975,7 +979,7 @@ eshell-history-isearch-end > (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) > (setq isearch-opoint (point)) > (unless isearch-suspended > - (custom-reevaluate-setting 'eshell-history-isearch))) > + (setq eshell--force-history-isearch nil))) I agree this would be the right thing, because even in Isearch we have variables that duplicate the user options such as e.g. the option 'search-invisible' and the internal variable 'isearch-invisible'. From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Dec 2024 11:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Jim Porter , Juri Linkov Cc: 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.173382848910845 (code B ref 74287); Tue, 10 Dec 2024 11:02:01 +0000 Received: (at 74287) by debbugs.gnu.org; 10 Dec 2024 11:01:29 +0000 Received: from localhost ([127.0.0.1]:57111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKxzb-0002of-J6 for submit@debbugs.gnu.org; Tue, 10 Dec 2024 06:01:29 -0500 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]:40897) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKxzX-0002nR-VE for 74287@debbugs.gnu.org; Tue, 10 Dec 2024 06:01:26 -0500 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id A5D641380274; Tue, 10 Dec 2024 06:01:18 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 10 Dec 2024 06:01:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733828478; x=1733914878; bh=VzXS++pUjw lc1qiT0Grzp3eYObi0M1xhbkK+zDa2CNs=; b=OXzsvbnrHHWKeSPnj1/RZcFaTo vR15fgMUpn/9rgIe3k6j3ZK+L+Sgfhelyo9z2CTgY31iGNicOUGHmlJt/20m6epD UoMuI8tuGKB1sGHmBwVidxRnQwd4UrOznkVUhT0Hj9KVCW2lujLlb5RbK8sDSqRD xexeo1wSKzO2EOubs7eJrRNZUKEpPSPpRvRZZYKSgT7YytBmIr8bE9hMdPR/XmF1 Nn3HU/GzwJoiH5uoiaB5p/KO/aFP5RvtXVnEovsGP4eGkOmHU6QEw6gatS3BvDdS 5V5b4dwLET13bainNaDJTnZK2csFxl6Xb3CI0A0Ceidr73cipN6zhDSEjWIw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733828478; x=1733914878; bh=VzXS++pUjwlc1qiT0Grzp3eYObi0M1xhbkK +zDa2CNs=; b=IeXOgqAVKvAkS2O2GKuAoUfSKRCCGQBEQ5ZkRyZxqq/ICqn3QMs Nkvwr7kx1T1e8Yspc3GtSBU1jQfxhkOHvKJx87KcdhZm83uNVDylDGf5z3nqKmJm 9+BZx0FDdCUW/FBcPVm7L1sA8pMspAQ/eaLQlxGolvzmIwkH+RW2HvGJptx4Wku/ /P6b4x461IDkgurFDe/RKOfAFYeOHl+fee7K1C3UabY7M7urbAb82Ycnue8lutOe mwo8sqMnFsq/6UcO3+4fvqM/JN7DiF7Ku3JeC2rjXA8aLdyJUxzDx0b137oMfQCp W2o/97xJ9ImiKq5gAXrewgBMGro/s+NAGDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjeekgddvvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesmhdtreertddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeeifffgieeulefgjeejiedvleehffffueeiiefhhfffveejuefh gedvhfekgfelkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhpohhrthgvrhgsuhhgshesghhmrghilhdrtg homhdprhgtphhtthhopehjuhhriheslhhinhhkohhvrdhnvghtpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 10 Dec 2024 06:01:16 -0500 (EST) From: Pengji Zhang In-Reply-To: <8734iwq8to.fsf@mail.linkov.net> References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> <8734iwl5kw.fsf@pengjiz.com> <8734iwq8to.fsf@mail.linkov.net> Date: Tue, 10 Dec 2024 19:01:08 +0800 Message-ID: <87frmv245n.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Juri Linkov writes: > I agree this would be the right thing, because even in Isearch we have > variables that duplicate the user options such as e.g. the option > 'search-invisible' and the internal variable 'isearch-invisible'. Thanks! Jim, please have a look at the attached updated patch, which includes this change. Thank you! --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Rework-history-Isearch-for-Eshell.patch >From 2cc9e260da56a5df24cf8932fb688143a356c150 Mon Sep 17 00:00:00 2001 From: Pengji Zhang Date: Tue, 10 Dec 2024 18:55:36 +0800 Subject: [PATCH] Rework history Isearch for Eshell This is to make history Isearch for Eshell similar to that of 'comint-mode', by hooking into Isearch properly instead of defining new commands to emulate Isearch. * lisp/eshell/em-hist.el (eshell-history-isearch): New user option. (eshell-goto-history, eshell--isearch-setup) (eshell-history-isearch-end, eshell-history-isearch-search) (eshell-history-isearch-message, eshell-history-isearch-wrap) (eshell-history-isearch-push-state): New functions. (eshell-isearch-backward-regexp, eshell-isearch-forward-regexp): New commands. (eshell--history-isearch-message-overlay) (eshell--stored-incomplete-input, eshell--force-history-isearch): New internal variables. (eshell-hist-mode-map): Bind 'M-r' to 'eshell-isearch-backward-regexp' and free 'M-s' binding for normal in-buffer search commands. (eshell-isearch-backward, eshell-isearch-forward): Use the new way to start searching. (eshell-hist-initialize): Use the new Isearch setup function. (eshell-previous-matching-input): Use 'eshell-goto-history'. Also inhibit messages when searching. (eshell-isearch-map, eshell-isearch-repeat-backward) (eshell-isearch-abort, eshell-isearch-delete-char) (eshell-isearch-return, eshell-isearch-cancel) (eshell-isearch-repeat-forward, eshell-test-imatch) (eshell-return-to-prompt, eshell-prepare-for-search): Remove. These are for the old history Isearch implementation. * doc/misc/eshell.texi (History): Document changes. * etc/NEWS: Annouce changes. --- doc/misc/eshell.texi | 15 +- etc/NEWS | 23 +++ lisp/eshell/em-hist.el | 326 ++++++++++++++++++++++++----------------- 3 files changed, 227 insertions(+), 137 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index ee4d0ca09c8..701137ea1b4 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -2661,10 +2661,10 @@ History @table @kbd @kindex M-r -@kindex M-s @item M-r -@itemx M-s -History I-search. +History I-search. @kbd{M-r} starts an incremental search in input +history. While searching, type @kbd{C-r} to move to the previous match, +and @kbd{C-s} to move to the next match in the input history. @kindex M-p @kindex M-n @@ -2675,6 +2675,15 @@ History previous or next line that begins with that string. @end table +@vindex eshell-history-isearch +If you would like to use the default Isearch key-bindings to search +through input history, you may customize @code{eshell-history-isearch} +to @code{t}. That makes, for example, @kbd{C-r} and @kbd{C-M-r} in an +Eshell buffer search in input history only. In addition, if the value +of @code{eshell-history-isearch} is @code{dwim}, those commands search +in the history when the point is after the last prompt, and search in +the buffer when the point is before or within the last prompt. + @node Extension modules @chapter Extension modules Eshell provides a facility for defining extension modules so that they diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..c1df6f78d9f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -288,6 +288,29 @@ This hook runs after an Eshell session has been fully initialized, immediately before running 'eshell-post-command-hook' for the first time. ++++ +*** Improved history Isearch. +History Isearch in Eshell is reworked. Two new commands +'eshell-isearch-backward-regexp' and 'eshell-isearch-forward-regexp' are +added for incrementally searching through the input history. +'eshell-isearch-backward-regexp' is bound to 'M-r' by default, and 'M-s' +is freed for normal search commands. If you would like to restore the +previous key-bindings for the non-incremental search commands, put in +your configuration: + + (keymap-set eshell-hist-mode-map "M-r" + #'eshell-previous-matching-input) + (keymap-set eshell-hist-mode-map "M-s" + #'eshell-next-matching-input) + ++++ +*** New user option 'eshell-history-isearch' +When 'eshell-history-isearch' is nil (the default), Isearch commands +search in the buffer contents. If you customize it to t, those commands +only search in input history. If you customize it to the symbol 'dwim', +those commands search in input history only when the point is after the +last prompt. + ** SHR +++ diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index fffd611c06f..4bcf434f6e4 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -34,7 +34,6 @@ ;; Also, most of `comint-mode's keybindings are accepted: ;; ;; M-r ; search backward for a previous command by regexp -;; M-s ; search forward for a previous command by regexp ;; M-p ; access the last command entered, repeatable ;; M-n ; access the first command entered, repeatable ;; @@ -132,6 +131,17 @@ eshell-input-filter (function :tag "Other function")) :risky t) +(defcustom eshell-history-isearch nil + "Non-nil to Isearch in input history only. +If t, usual Isearch keys like \\[isearch-forward] in Eshell search in +the input history only. If `dwim', Isearch in the input history when +point is at the command line, otherwise search in the current Eshell +buffer." + :type '(choice (const :tag "Don't search in input history" nil) + (const :tag "Search histroy when point is on command line" dwim) + (const :tag "Always search in input history" t)) + :version "31.1") + (defun eshell-hist--update-keymap (symbol value) "Update `eshell-hist-mode-map' for `eshell-hist-match-partial'." ;; Don't try to set this before it is bound. See below. @@ -204,25 +214,20 @@ eshell-save-history-index (defvar eshell-hist--new-items nil "The number of new history items that have not been written to file. This variable is local in each eshell buffer.") - -(defvar-keymap eshell-isearch-map - :doc "Keymap used in isearch in Eshell." - :parent isearch-mode-map - "C-m" #'eshell-isearch-return - "C-r" #'eshell-isearch-repeat-backward - "C-s" #'eshell-isearch-repeat-forward - "C-g" #'eshell-isearch-abort - "" #'eshell-isearch-delete-char - "" #'eshell-isearch-delete-char - "C-c C-c" #'eshell-isearch-cancel) +(defvar-local eshell--history-isearch-message-overlay nil + "Overlay for Isearch message when searching through input history.") +(defvar-local eshell--stored-incomplete-input nil + "Stored input for history cycling.") +(defvar eshell--force-history-isearch nil + "Non-nil means to force searching in input history. +If nil, respect the option `eshell-history-isearch'.") (defvar-keymap eshell-hist-mode-map "" #'eshell-previous-matching-input-from-input "" #'eshell-next-matching-input-from-input "C-" #'eshell-previous-input "C-" #'eshell-next-input - "M-r" #'eshell-previous-matching-input - "M-s" #'eshell-next-matching-input + "M-r" #'eshell-isearch-backward-regexp "C-c M-r" #'eshell-previous-matching-input-from-input "C-c M-s" #'eshell-next-matching-input-from-input "C-c C-l" #'eshell-list-history @@ -261,20 +266,9 @@ eshell-hist-initialize (not eshell-non-interactive-p)) (let ((rebind-alist eshell-rebind-keys-alist)) (setq-local eshell-rebind-keys-alist - (append rebind-alist eshell-hist-rebind-keys-alist)) - (setq-local search-invisible t) - (setq-local search-exit-option t) - (add-hook 'isearch-mode-hook - (lambda () - (if (>= (point) eshell-last-output-end) - (setq overriding-terminal-local-map - eshell-isearch-map))) - nil t) - (add-hook 'isearch-mode-end-hook - (lambda () - (setq overriding-terminal-local-map nil)) - nil t)) + (append rebind-alist eshell-hist-rebind-keys-alist))) (eshell-hist-mode)) + (add-hook 'isearch-mode-hook #'eshell--isearch-setup nil t) (make-local-variable 'eshell-history-size) (or eshell-history-size @@ -384,6 +378,23 @@ eshell-get-history "Get an input line from the history ring." (ring-ref (or ring eshell-history-ring) index)) +(defun eshell-goto-history (pos) + "Replace command line with the element at POS of history ring. +Also update `eshell-history-index'. As a special case, if POS is nil +and `eshell--stored-incomplete-input' is a non-empty string, restore the +saved input." + (when (null eshell-history-index) + (setq eshell--stored-incomplete-input + (buffer-substring-no-properties eshell-last-output-end + (point-max)))) + (setq eshell-history-index pos) + ;; Can't use kill-region as it sets this-command + (delete-region eshell-last-output-end (point-max)) + (if (and pos (not (ring-empty-p eshell-history-ring))) + (insert-and-inherit (eshell-get-history pos)) + (when (> (length eshell--stored-incomplete-input) 0) + (insert-and-inherit eshell--stored-incomplete-input)))) + (defun eshell-add-input-to-history (input) "Add the string INPUT to the history ring. Input is entered into the input history ring, if the value of @@ -897,12 +908,12 @@ eshell-previous-matching-input ;; Has a match been found? (if (null pos) (error "Not found") - (setq eshell-history-index pos) - (unless (minibuffer-window-active-p (selected-window)) - (message "History item: %d" (- (ring-length eshell-history-ring) pos))) - ;; Can't use kill-region as it sets this-command - (delete-region eshell-last-output-end (point)) - (insert-and-inherit (eshell-get-history pos))))) + (eshell-goto-history pos) + (unless (or (minibuffer-window-active-p (selected-window)) + ;; No messages for Isearch because it will show the + ;; same messages (and more). + isearch-mode) + (message "History item: %d" (- (ring-length eshell-history-ring) pos)))))) (defun eshell-next-matching-input (regexp arg) "Search forwards through input history for match for REGEXP. @@ -937,114 +948,161 @@ eshell-next-matching-input-from-input (interactive "p") (eshell-previous-matching-input-from-input (- arg))) -(defun eshell-test-imatch () - "If isearch match good, put point at the beginning and return non-nil." - (if (get-text-property (point) 'history) - (progn (beginning-of-line) t) - (let ((before (point))) - (beginning-of-line) - (if (and (not (bolp)) - (<= (point) before)) - t - (if isearch-forward - (progn - (end-of-line) - (forward-char)) - (beginning-of-line) - (backward-char)))))) - -(defun eshell-return-to-prompt () - "Once a search string matches, insert it at the end and go there." - (setq isearch-other-end nil) - (let ((found (eshell-test-imatch)) before) - (while (and (not found) - (setq before - (funcall (if isearch-forward - 're-search-forward - 're-search-backward) - isearch-string nil t))) - (setq found (eshell-test-imatch))) - (if (not found) - (progn - (goto-char eshell-last-output-end) - (delete-region (point) (point-max))) - (setq before (point)) - (let ((text (buffer-substring-no-properties - (point) (line-end-position))) - (orig (marker-position eshell-last-output-end))) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (when (and text (> (length text) 0)) - (insert text) - (put-text-property (1- (point)) (point) - 'last-search-pos before) - (set-marker eshell-last-output-end orig) - (goto-char eshell-last-output-end)))))) - -(defun eshell-prepare-for-search () - "Make sure the old history file is at the beginning of the buffer." - (unless (get-text-property (point-min) 'history) - (save-excursion - (goto-char (point-min)) - (let ((end (copy-marker (point) t))) - (insert-file-contents eshell-history-file-name) - (set-text-properties (point-min) end - '(history t invisible t)))))) +(defun eshell--isearch-setup () + "Set up Isearch to search the input history. +Intended to be added to `isearch-mode-hook' in an Eshell buffer." + (when (and + ;; Eshell is busy running a foreground process + (not eshell-foreground-command) + (or eshell--force-history-isearch + (eq eshell-history-isearch t) + (and (eq eshell-history-isearch 'dwim) + (>= (point) eshell-last-output-end)))) + (setq isearch-message-prefix-add "history ") + (setq-local isearch-lazy-count nil) + (setq-local isearch-search-fun-function #'eshell-history-isearch-search + isearch-message-function #'eshell-history-isearch-message + isearch-wrap-function #'eshell-history-isearch-wrap + isearch-push-state-function #'eshell-history-isearch-push-state) + (add-hook 'isearch-mode-end-hook #'eshell-history-isearch-end nil t))) + +(defun eshell-history-isearch-end () + "Clean up after terminating history Isearch." + (when (overlayp eshell--history-isearch-message-overlay) + (delete-overlay eshell--history-isearch-message-overlay)) + (setq isearch-message-prefix-add nil) + (kill-local-variable 'isearch-lazy-count) + (setq-local isearch-search-fun-function #'isearch-search-fun-default + isearch-message-function nil + isearch-wrap-function nil + isearch-push-state-function nil) + (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) + (setq isearch-opoint (point)) + (unless isearch-suspended + (setq eshell--force-history-isearch nil))) + +(defun eshell-history-isearch-search () + "Return search function for Isearch in input history." + (lambda (string bound noerror) + (let ((search-fun (isearch-search-fun-default)) + (found nil)) + ;; Avoid highlighting matches in and before the last prompt + (when (and bound isearch-forward + (< (point) eshell-last-output-end)) + (goto-char eshell-last-output-end)) + (or + ;; First search in the initial input + (funcall search-fun string + (if isearch-forward bound eshell-last-output-end) + noerror) + ;; Then search in the input history: put next/previous history + ;; element in the command line successively, then search the + ;; string in the command line. Do this only when not + ;; lazy-highlighting (`bound' is nil). + (unless bound + (condition-case nil + (progn + (while (not found) + (cond (isearch-forward + ;; Signal an error explicitly to break + (when (or (null eshell-history-index) + (eq eshell-history-index 0)) + (error "End of history; no next item")) + (eshell-next-input 1) + (goto-char eshell-last-output-end)) + (t + ;; Signal an error explicitly to break + (when (eq eshell-history-index + (1- (ring-length eshell-history-ring))) + (error "Beginning of history; no preceding item")) + (eshell-previous-input 1) + (goto-char (point-max)))) + (setq isearch-barrier (point) + isearch-opoint (point)) + ;; After putting an history element in the command + ;; line, search the string in them. + (setq found (funcall search-fun string + (unless isearch-forward + eshell-last-output-end) + noerror))) + (point)) + ;; Return when no next/preceding element error signaled + (error nil))))))) + +(defun eshell-history-isearch-message (&optional c-q-hack ellipsis) + "Display the input history search prompt. +If there are no search errors, this function displays an overlay with +the Isearch prompt which replaces the original Eshell prompt. +Otherwise, it displays the standard Isearch message returned from the +function `isearch-message'." + (if (not (and isearch-success (not isearch-error))) + ;; Use standard message function (which displays a message in the + ;; echo area) when not in command line, or search fails or has + ;; errors (like incomplete regexp). + (isearch-message c-q-hack ellipsis) + ;; Otherwise, use an overlay over the Eshell prompt. + (if (overlayp eshell--history-isearch-message-overlay) + (move-overlay eshell--history-isearch-message-overlay + (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end) + (setq eshell--history-isearch-message-overlay + (make-overlay (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end)) + (overlay-put eshell--history-isearch-message-overlay 'evaporate t)) + (overlay-put eshell--history-isearch-message-overlay + 'display (isearch-message-prefix ellipsis + isearch-nonincremental)) + (if (and eshell-history-index (not ellipsis)) + (message "History item: %d" (- (ring-length eshell-history-ring) + eshell-history-index)) + (message "")))) + +(defun eshell-history-isearch-wrap () + "Wrap the input history search." + (if isearch-forward + (eshell-goto-history (1- (ring-length eshell-history-ring))) + (eshell-goto-history nil)) + (goto-char (if isearch-forward eshell-last-output-end (point-max)))) + +(defun eshell-history-isearch-push-state () + "Save a function restoring the state of input history search. +Save `eshell-history-index' to the additional state parameter in the +search status stack." + (let ((index eshell-history-index)) + (lambda (_cmd) + (eshell-goto-history index)))) (defun eshell-isearch-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((inhibit-read-only t)) - (eshell-prepare-for-search) - (goto-char (point-max)) - (set-marker eshell-last-output-end (point)) - (delete-region (point) (point-max))) - (isearch-mode invert t 'eshell-return-to-prompt)) - -(defun eshell-isearch-repeat-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((old-pos (get-text-property (1- (point-max)) - 'last-search-pos))) - (when old-pos - (goto-char old-pos) - (if invert - (end-of-line) - (backward-char))) - (setq isearch-forward invert) - (isearch-search-and-update))) + "Do incremental search backward through past commands." + (interactive nil eshell-mode) + (setq eshell--force-history-isearch t) + (if invert + (isearch-forward nil t) + (isearch-backward nil t))) (defun eshell-isearch-forward () - "Do incremental regexp search backward through past commands." - (interactive) + "Do incremental search forward through past commands." + (interactive nil eshell-mode) (eshell-isearch-backward t)) -(defun eshell-isearch-repeat-forward () +(defun eshell-isearch-backward-regexp (&optional invert) "Do incremental regexp search backward through past commands." - (interactive) - (eshell-isearch-repeat-backward t)) - -(defun eshell-isearch-cancel () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-cancel)) - -(defun eshell-isearch-abort () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-abort)) - -(defun eshell-isearch-delete-char () - (interactive) - (save-excursion - (isearch-delete-char))) - -(defun eshell-isearch-return () - (interactive) - (isearch-done) - (eshell-send-input)) + (interactive nil eshell-mode) + (setq eshell--force-history-isearch t) + (if invert + (isearch-forward-regexp nil t) + (isearch-backward-regexp nil t))) + +(defun eshell-isearch-forward-regexp () + "Do incremental regexp search forward through past commands." + (interactive nil eshell-mode) + (eshell-isearch-backward-regexp t)) (defun em-hist-unload-function () (remove-hook 'kill-emacs-hook 'eshell-save-some-history)) -- 2.47.1 --=-=-=-- From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Dec 2024 17:50:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang Cc: Jim Porter , 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17338529488320 (code B ref 74287); Tue, 10 Dec 2024 17:50:03 +0000 Received: (at 74287) by debbugs.gnu.org; 10 Dec 2024 17:49:08 +0000 Received: from localhost ([127.0.0.1]:59484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tL4M7-0002A8-RG for submit@debbugs.gnu.org; Tue, 10 Dec 2024 12:49:08 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:42465) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tL4M6-00029L-Aq for 74287@debbugs.gnu.org; Tue, 10 Dec 2024 12:49:06 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id A13BC20002; Tue, 10 Dec 2024 17:48:57 +0000 (UTC) From: Juri Linkov In-Reply-To: <87frmv245n.fsf@pengjiz.com> (Pengji Zhang's message of "Tue, 10 Dec 2024 19:01:08 +0800") Organization: LINKOV.NET References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> <8734iwl5kw.fsf@pengjiz.com> <8734iwq8to.fsf@mail.linkov.net> <87frmv245n.fsf@pengjiz.com> Date: Tue, 10 Dec 2024 19:41:32 +0200 Message-ID: <87zfl3mo4z.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> I agree this would be the right thing, because even in Isearch we have >> variables that duplicate the user options such as e.g. the option >> 'search-invisible' and the internal variable 'isearch-invisible'. > > Thanks! Please also see the commit 98f8c5fb07dcb4e20b8ba6648bdabf5c0d3b5145 that fixed this in dired by using a buffer-local variable. Do you agree it's a good fix? Otherwise using a separate variable is also fine. From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2024 00:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Juri Linkov Cc: Jim Porter , 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17338779158216 (code B ref 74287); Wed, 11 Dec 2024 00:46:01 +0000 Received: (at 74287) by debbugs.gnu.org; 11 Dec 2024 00:45:15 +0000 Received: from localhost ([127.0.0.1]:60217 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLAqp-00028I-3K for submit@debbugs.gnu.org; Tue, 10 Dec 2024 19:45:15 -0500 Received: from fhigh-a1-smtp.messagingengine.com ([103.168.172.152]:55493) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLAql-000254-S1 for 74287@debbugs.gnu.org; Tue, 10 Dec 2024 19:45:13 -0500 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4D42E1140205; Tue, 10 Dec 2024 19:45:06 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Tue, 10 Dec 2024 19:45:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1733877906; x=1733964306; bh=0jhtsFs6Di htH8w61rlNmkumuXxzRgYXlntjoU6OHzI=; b=SxbArvIeu0RvFgheGI2RrDZvof PPblD11d/QPt+TSfEnrO3+bXlJvEO+ZleL73fR9eHRkdHSbj0w4LEJmS/khgt1XU /dhk7IDGuaMSqNftCtF5xnUFEiwjtv+NzsV8Vygit5rsMdGXvYzjwDBNgLuUngrI 502LilcJUSziIL1F6o/37Z8w8FAYlVHCYxgSgFo5qf+vimwssCA/RiLMIKvCtFdu KUPCxZXPKtM1GJRZpdtpWKnF4z7PwTDXuE0slO/OKYjnTBYaFDxGQZjUX+H989uM QD3CxqfSwC4oY3nKQ7o27NXwRXiHDVx/gAux1bb9yXIaURMrwa0swnI7w4bA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733877906; x=1733964306; bh=0jhtsFs6DihtH8w61rlNmkumuXxzRgYXlnt joU6OHzI=; b=XkMksV42G353a4pTWIMRaDOovu4Dy3OY/2IzGZ+6H6pXa31Tfg+ bA7unvfCpy5K2kqNpGYl6fHr061fEU5ndUqYdWNPh5XrxScO7zS+Y4fKo4gCKawS MLK2jIq2eCxcKn5ExHdqHzwdfA0G7XQyJz9g+mYMjhm6UkSrqL7oL3i2I9T9AFJx UvPTFIaOQir7DvuGR57pAlDuizwzza2FC30GHixM0G0tDyadzi2ac3f5yH0jf/U9 H+yrjDvbIPnP0It0FaCpqqsPLS4CebVZM2Lb85daGQRFexny0a62bJI0NsD1NJKF 1N7MY8y9gqxbyhb3B8qmpImot2/CSOb4BLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjeelgddvhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesthdtredttddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeegfeeiiedvudekiedtgedufedtvedtueetieffhfdvhefftefg ieejieelleehgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvthdprhgtph htthhopehjphhorhhtvghrsghughhssehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeeg vdekjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 10 Dec 2024 19:45:04 -0500 (EST) From: Pengji Zhang In-Reply-To: <87zfl3mo4z.fsf@mail.linkov.net> References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> <8734iwl5kw.fsf@pengjiz.com> <8734iwq8to.fsf@mail.linkov.net> <87frmv245n.fsf@pengjiz.com> <87zfl3mo4z.fsf@mail.linkov.net> Date: Wed, 11 Dec 2024 08:45:01 +0800 Message-ID: <87y10navzm.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Juri Linkov writes: >>> I agree this would be the right thing, because even in Isearch we >>> have variables that duplicate the user options such as e.g. the >>> option 'search-invisible' and the internal variable >>> 'isearch-invisible'. >> >> Thanks! > > Please also see the commit 98f8c5fb07dcb4e20b8ba6648bdabf5c0d3b5145 > that fixed this in dired by using a buffer-local variable. Do you > agree it's a good fix? Otherwise using a separate variable is also > fine. My concern with using a local variable is that users may also set the user option locally. That is perhaps not a problem for eshell or dired, but for comint, e.g., I may set 'comint-history-isearch' to 'dwim' only in 'M-x shell' via the mode hook. IMO, changing an internal variable feels a bit cleaner and safer than manipulating a user option. So I would prefer using a separate variable. From unknown Mon Jun 23 22:06:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74287: [PATCH] Rework history Isearch for Eshell Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2024 07:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74287 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pengji Zhang Cc: Jim Porter , 74287@debbugs.gnu.org Received: via spool by 74287-submit@debbugs.gnu.org id=B74287.17339009143051 (code B ref 74287); Wed, 11 Dec 2024 07:09:01 +0000 Received: (at 74287) by debbugs.gnu.org; 11 Dec 2024 07:08:34 +0000 Received: from localhost ([127.0.0.1]:60926 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLGpm-0000n8-05 for submit@debbugs.gnu.org; Wed, 11 Dec 2024 02:08:34 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:43071) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLGpi-0000ml-IG for 74287@debbugs.gnu.org; Wed, 11 Dec 2024 02:08:31 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id 1959120003; Wed, 11 Dec 2024 07:08:22 +0000 (UTC) From: Juri Linkov In-Reply-To: <87y10navzm.fsf@pengjiz.com> (Pengji Zhang's message of "Wed, 11 Dec 2024 08:45:01 +0800") Organization: LINKOV.NET References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> <8734iwl5kw.fsf@pengjiz.com> <8734iwq8to.fsf@mail.linkov.net> <87frmv245n.fsf@pengjiz.com> <87zfl3mo4z.fsf@mail.linkov.net> <87y10navzm.fsf@pengjiz.com> Date: Wed, 11 Dec 2024 09:06:38 +0200 Message-ID: <87jzc6em0x.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> Please also see the commit 98f8c5fb07dcb4e20b8ba6648bdabf5c0d3b5145 >> that fixed this in dired by using a buffer-local variable. Do you >> agree it's a good fix? Otherwise using a separate variable is also >> fine. > > My concern with using a local variable is that users may also set the > user option locally. That is perhaps not a problem for eshell or dired, > but for comint, e.g., I may set 'comint-history-isearch' to 'dwim' only > in 'M-x shell' via the mode hook. Indeed, this is a valid use case. > IMO, changing an internal variable feels a bit cleaner and safer than > manipulating a user option. So I would prefer using a separate variable. I agree that a separate variable is better. So now I added to comint.el 'comint--force-history-isearch' extracted from your Eshell patch. Thanks for the fix! From unknown Mon Jun 23 22:06:32 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Pengji Zhang Subject: bug#74287: closed (Re: bug#74287: [PATCH] Rework history Isearch for Eshell) Message-ID: References: <471c7893-e55d-ccb7-7d31-fab88567923a@gmail.com> <871pzjkhmm.fsf@pengjiz.com> X-Gnu-PR-Message: they-closed 74287 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 74287@debbugs.gnu.org Date: Wed, 11 Dec 2024 20:01:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1733947263-10502-1" This is a multi-part message in MIME format... ------------=_1733947263-10502-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #74287: [PATCH] Rework history Isearch for Eshell which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 74287@debbugs.gnu.org. --=20 74287: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D74287 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1733947263-10502-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 74287-done) by debbugs.gnu.org; 11 Dec 2024 20:00:04 +0000 Received: from localhost ([127.0.0.1]:36326 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLSsM-0002YT-Bm for submit@debbugs.gnu.org; Wed, 11 Dec 2024 15:00:03 -0500 Received: from mail-pl1-f181.google.com ([209.85.214.181]:59604) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLSsJ-0002Xd-TK for 74287-done@debbugs.gnu.org; Wed, 11 Dec 2024 15:00:00 -0500 Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21675fd60feso27706305ad.2 for <74287-done@debbugs.gnu.org>; Wed, 11 Dec 2024 11:59:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733947139; x=1734551939; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=Qao9gRROZnjgl7U5lLECMwKD9fo8jVnVe9z02ywiuFY=; b=JeCvuvj8uqT6s3vZSfNObTjutOQZV1/ZhR1ZvXgeAYBztgvAJru4vOjaVF5f2tjP1t oKDGj4y3en37KcJYHEV0WdHz8PNV6v3keQXWvEhJBmGN1nYonrsusA5QcIlc+mFyuNR+ AavbXqhYwIpSOoYeSZSqARkt9/9M10qzvZ+P39oCEzXUJVZ2F1BeLzjfRU7zbalQ3DPP tfpX24gzat7Z2hxqhRGqm11bymb0NzGUiOLGM59AdmQARpXcwVR/2+HbIMx9JqDwUhdT kJ3cUjl9YolrSTgIOO0tE0guDRKoKEg7b5NLAz7IUlSQT9uThZFLaBB3IO165SWXAQjF hQPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733947139; x=1734551939; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qao9gRROZnjgl7U5lLECMwKD9fo8jVnVe9z02ywiuFY=; b=oIhCgOohxrdvF02JnTwgWu6FVCpLTbD7gIxDarNm4N6BTriSaU/MUeSYEIBH4QifYa jf/nsgyq6sy2rGqSAkYjGZeMz/e+ORfH1XticNenhHSw4kS6iiR2SszQJTGHN3haQPTK AbOhrQbyohSkHuh6gMcYNYBqkgc959JPkBDPmCUB1X1Y8wj8YT1o1VgROwkEHk9hGVzW 60kz6cDXwa27GsCgFEy3Ha3+FBp2A01UJjXRUh7Aa6jrhpKLFHPfvQDENRn7Kguo2QSI MPW1U1FIHkXbbwK/6LmwIxH0oByAiZW+qv0jqMje3F9Uf4fkj1uZePbLB1GB6IKiKYnL /Yzg== X-Gm-Message-State: AOJu0YzZA2+7Z5kh8pFiCQnScn7JpJf/I1omCOyu6NthJkJI8WYIcrrs KI/OP1Lo9JrXTRWv7RFbXrn8vAklnl2CVoyI5Fxj9vKDq+bb/Hqn X-Gm-Gg: ASbGnctmJTpVI4C6MVniW/ZSk07v2/oTgVXEHnu2UmHwAVINNMTtSbc2qYnShV4aDsY nncDuNkis/n9ydLlnwJgsrrZf6RFyuqmtxY/v948ucGe8I+5ka/PlYG91i4wg4ArUu/iP6kHYMw XO3UfLoOR/DnqoZVu5NEvuB0+rlv/KucMq4Yjhg4QLwsaYbjYWEi0M8F+C//3YjKQLdgh2tO5Te kdao2LVAOOrvqjuy57CCQd1pELNBjxhA5kZ/p3niAg++1Mc/G5BBeU29eHkfEnu79bKlVKRPYDK EdmAqitZ5bjsXlIqxR6bzvs9NevL4Po= X-Google-Smtp-Source: AGHT+IHBXuU509lhQWoIJO+MadhvshfnUFuzeQlvuCBX8neI1aRzo5mzxdPVCAxGrnyVseTHTgAxAw== X-Received: by 2002:a17:902:da92:b0:216:25a2:2ebe with SMTP id d9443c01a7336-2178ae72744mr16691795ad.19.1733947138970; Wed, 11 Dec 2024 11:58:58 -0800 (PST) Received: from [192.168.1.2] (syn-023-240-098-037.res.spectrum.com. [23.240.98.37]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-215f8e3e875sm110372265ad.19.2024.12.11.11.58.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Dec 2024 11:58:58 -0800 (PST) Message-ID: <471c7893-e55d-ccb7-7d31-fab88567923a@gmail.com> Date: Wed, 11 Dec 2024 11:58:57 -0800 MIME-Version: 1.0 Subject: Re: bug#74287: [PATCH] Rework history Isearch for Eshell To: Pengji Zhang , Juri Linkov References: <871pzjkhmm.fsf@pengjiz.com> <8c80ae91-476e-e665-43be-86d72fb57ed1@gmail.com> <86v7waz603.fsf@gmx.net> <6fdd8386-8915-e3a8-046a-b18750a7057d@gmail.com> <87v7vzgtuq.fsf@mail.linkov.net> <87jzcecnc9.fsf@pengjiz.com> <87h67icmu1.fsf@pengjiz.com> <87cyi159vo.fsf@pengjiz.com> <87msh4n29s.fsf@mail.linkov.net> <8734iwl5kw.fsf@pengjiz.com> <8734iwq8to.fsf@mail.linkov.net> <87frmv245n.fsf@pengjiz.com> Content-Language: en-US From: Jim Porter In-Reply-To: <87frmv245n.fsf@pengjiz.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74287-done Cc: 74287-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 12/10/2024 3:01 AM, Pengji Zhang wrote: > Jim, please have a look at the attached updated patch, which includes > this change. Thank you! Thanks for your work on this! I've now merged your patch to the master branch as 3959ea66448, so I'm closing this bug now. (Of course, if I missed something, just let me know.) ------------=_1733947263-10502-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 10 Nov 2024 01:22:47 +0000 Received: from localhost ([127.0.0.1]:54988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wf5-0002JC-T3 for submit@debbugs.gnu.org; Sat, 09 Nov 2024 20:22:46 -0500 Received: from lists.gnu.org ([209.51.188.17]:47482) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wf2-0002J2-2B for submit@debbugs.gnu.org; Sat, 09 Nov 2024 20:22:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9wf0-0004HJ-Ei for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:22:38 -0500 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9wex-0005Vn-9q for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:22:38 -0500 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.stl.internal (Postfix) with ESMTP id 21A4425400F2; Sat, 9 Nov 2024 20:22:34 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Sat, 09 Nov 2024 20:22:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1731201753; x=1731288153; bh=lVbyOeC+C4vLy+xAzHW52zud3Rzqlfyw VthoAxVD9ng=; b=EzzXuDGAlEPWN5u3i/SdyFz7Ca4u7aAe0mKO0qFVxIjFoLHI AiN+P/zqXZVuxhQYaM8vqSyvVXpB9m7vKomZyUVvFIlUPyCLOfmy+6VYm+/Lyfox 1EWcfx0xMWJsh1LDIPjhHkeljNyjME4QWTt+YCUt2W8nbb5814GIeASJvWS89P8W uoKDOSxy0ChA6NixXkp8P2EKQQ+w7jpQ6odXmXm3sWIlR3X1NycUHGGR1RmR+abF GF8MookU/mO4VzaQicWGIUYTJB61eN8ZAhxM+/X7D5zX5qs5k6GUPxexMzpovRm8 55N3brh2+wSgPVkyx/pAr3qxXgphRgOW1+kEpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1731201753; x= 1731288153; bh=lVbyOeC+C4vLy+xAzHW52zud3RzqlfywVthoAxVD9ng=; b=P 5DyAY8FzT8IWET2LxwyN9PNgDTL3d4ZUgu/GUYjdiugYzg2tuIVJShiVwu+32KmH gledpOOTohsHLDfwHCx6cE7FXSeZdAf66lC10ZkII9h3rNO4VUMtgixdwleyo2lZ 2vcEDd0pJ118sUQZFP/FKyppp+wfbOapX7Y6x9F75/QTozeomf4wp49tygLINC/X 4irmOG367S9ZCmzRqtzcuoshT/y1ouDuPzgPURbCz2BtgZbLL8eJ7LlRW8Kfvf+F xynjNl9Y9ZSUsyR5yWI1B9aKmjgveR0ntImztzN/Us2ZwKsZ1I1x0e+fe7+XFYtu LCr1jwqs8AORQYuXH6hoQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdelgdefgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufffkfggtgesmhdtreertddttdenucfhrhho mheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenucggtf frrghtthgvrhhnpeeugedtkeejtefgleeuffeljeffuddtvddvleefffelieekteelgfdt fefhkeeikeenucffohhmrghinhepghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgs pghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepsghughdqgh hnuhdqvghmrggtshesghhnuhdrohhrghdprhgtphhtthhopehjphhorhhtvghrsghughhs sehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvthdprh gtphhtthhopehsphifhhhithhtohhnsehsphifhhhithhtohhnrdhnrghmvgdprhgtphht thhopehjihhmjhhovgesghhmgidrnhgvth X-ME-Proxy: Feedback-ID: i16614472:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 9 Nov 2024 20:22:32 -0500 (EST) From: Pengji Zhang To: bug-gnu-emacs@gnu.org Subject: [PATCH] Rework history Isearch for Eshell Date: Sun, 10 Nov 2024 09:22:09 +0800 Message-ID: <871pzjkhmm.fsf@pengjiz.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=202.12.124.154; envelope-from=me@pengjiz.com; helo=fhigh-b3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit Cc: Jim Porter , Sean Whitton , James Thomas , Juri Linkov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) --=-=-= Content-Type: text/plain Hello, This patch brings a comint-like interface for history Isearch to Eshell. To try it, type 'M-r' in Eshell, and search through the input history ring incrementally. Compared to the existing implementation, this patch integrates with Isearch properly, like what we do for the minibuffer and comint modes. There are relevant discussions (thank you all for the feedback!) in the mailing list: https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00069.html For Jim's concern, I do not think this implementation closes the door for a history completion interface, as shown by Sean and Juri. Thanks! Pengji --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Rework-history-Isearch-for-Eshell.patch >From d455ec1bf1b49871cf866457df77f6ab45f5623f Mon Sep 17 00:00:00 2001 From: Pengji Zhang Date: Sun, 10 Nov 2024 08:50:27 +0800 Subject: [PATCH] Rework history Isearch for Eshell This is to make history Isearch for Eshell similar to that of 'comint-mode', by hooking into Isearch properly instead of defining new commands to emulate Isearch. * lisp/eshell/em-hist.el (eshell-history-isearch): New user option. (eshell-goto-history, eshell--isearch-setup) (eshell-history-isearch-end, eshell-history-isearch-search) (eshell-history-isearch-message, eshell-history-isearch-wrap) (eshell-history-isearch-push-state): New functions. (eshell-isearch-backward-regexp, eshell-isearch-forward-regexp): New commands. (eshell--history-isearch-messasge-overlay) (eshell--stored-incomplete-input): New internal variables. (eshell-hist-mode-map): Bind 'M-r' to 'eshell-isearch-backward-regexp' and free 'M-s' binding for normal in-buffer search commands. (eshell-isearch-backward, eshell-isearch-forward): Use the new way to start searching. (eshell-hist-initialize): Use the new Isearch setup function. (eshell-previous-matching-input): Use 'eshell-goto-history'. Also inhibit messages when searching. (eshell-isearch-map, eshell-isearch-repeat-backward) (eshell-isearch-abort, eshell-isearch-delete-char) (eshell-isearch-return, eshell-isearch-cancel) (eshell-isearch-repeat-forward, eshell-test-imatch) (eshell-return-to-prompt, eshell-prepare-for-search): Remove. These are for the old history Isearch implementation. * doc/misc/eshell.texi (History): Document changes. * etc/NEWS: Annouce changes. --- doc/misc/eshell.texi | 15 +- etc/NEWS | 23 +++ lisp/eshell/em-hist.el | 322 ++++++++++++++++++++++++----------------- 3 files changed, 223 insertions(+), 137 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index ee4d0ca09c8..701137ea1b4 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -2661,10 +2661,10 @@ History @table @kbd @kindex M-r -@kindex M-s @item M-r -@itemx M-s -History I-search. +History I-search. @kbd{M-r} starts an incremental search in input +history. While searching, type @kbd{C-r} to move to the previous match, +and @kbd{C-s} to move to the next match in the input history. @kindex M-p @kindex M-n @@ -2675,6 +2675,15 @@ History previous or next line that begins with that string. @end table +@vindex eshell-history-isearch +If you would like to use the default Isearch key-bindings to search +through input history, you may customize @code{eshell-history-isearch} +to @code{t}. That makes, for example, @kbd{C-r} and @kbd{C-M-r} in an +Eshell buffer search in input history only. In addition, if the value +of @code{eshell-history-isearch} is @code{dwim}, those commands search +in the history when the point is after the last prompt, and search in +the buffer when the point is before or within the last prompt. + @node Extension modules @chapter Extension modules Eshell provides a facility for defining extension modules so that they diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..c1df6f78d9f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -288,6 +288,29 @@ This hook runs after an Eshell session has been fully initialized, immediately before running 'eshell-post-command-hook' for the first time. ++++ +*** Improved history Isearch. +History Isearch in Eshell is reworked. Two new commands +'eshell-isearch-backward-regexp' and 'eshell-isearch-forward-regexp' are +added for incrementally searching through the input history. +'eshell-isearch-backward-regexp' is bound to 'M-r' by default, and 'M-s' +is freed for normal search commands. If you would like to restore the +previous key-bindings for the non-incremental search commands, put in +your configuration: + + (keymap-set eshell-hist-mode-map "M-r" + #'eshell-previous-matching-input) + (keymap-set eshell-hist-mode-map "M-s" + #'eshell-next-matching-input) + ++++ +*** New user option 'eshell-history-isearch' +When 'eshell-history-isearch' is nil (the default), Isearch commands +search in the buffer contents. If you customize it to t, those commands +only search in input history. If you customize it to the symbol 'dwim', +those commands search in input history only when the point is after the +last prompt. + ** SHR +++ diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index fffd611c06f..de986b05f48 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -34,7 +34,6 @@ ;; Also, most of `comint-mode's keybindings are accepted: ;; ;; M-r ; search backward for a previous command by regexp -;; M-s ; search forward for a previous command by regexp ;; M-p ; access the last command entered, repeatable ;; M-n ; access the first command entered, repeatable ;; @@ -132,6 +131,17 @@ eshell-input-filter (function :tag "Other function")) :risky t) +(defcustom eshell-history-isearch nil + "Non-nil to Isearch in input history only. +If t, usual Isearch keys like \\[isearch-forward] in Eshell search in +the input history only. If `dwim', Isearch in the input history when +point is at the command line, otherwise search in the current Eshell +buffer." + :type '(choice (const :tag "Don't search in input history" nil) + (const :tag "Search histroy when point is on command line" dwim) + (const :tag "Always search in input history" t)) + :version "31.1") + (defun eshell-hist--update-keymap (symbol value) "Update `eshell-hist-mode-map' for `eshell-hist-match-partial'." ;; Don't try to set this before it is bound. See below. @@ -204,25 +214,17 @@ eshell-save-history-index (defvar eshell-hist--new-items nil "The number of new history items that have not been written to file. This variable is local in each eshell buffer.") - -(defvar-keymap eshell-isearch-map - :doc "Keymap used in isearch in Eshell." - :parent isearch-mode-map - "C-m" #'eshell-isearch-return - "C-r" #'eshell-isearch-repeat-backward - "C-s" #'eshell-isearch-repeat-forward - "C-g" #'eshell-isearch-abort - "" #'eshell-isearch-delete-char - "" #'eshell-isearch-delete-char - "C-c C-c" #'eshell-isearch-cancel) +(defvar-local eshell--history-isearch-messasge-overlay nil + "Overlay for Isearch message when searching through input history.") +(defvar-local eshell--stored-incomplete-input nil + "Stored input for history cycling.") (defvar-keymap eshell-hist-mode-map "" #'eshell-previous-matching-input-from-input "" #'eshell-next-matching-input-from-input "C-" #'eshell-previous-input "C-" #'eshell-next-input - "M-r" #'eshell-previous-matching-input - "M-s" #'eshell-next-matching-input + "M-r" #'eshell-isearch-backward-regexp "C-c M-r" #'eshell-previous-matching-input-from-input "C-c M-s" #'eshell-next-matching-input-from-input "C-c C-l" #'eshell-list-history @@ -261,20 +263,9 @@ eshell-hist-initialize (not eshell-non-interactive-p)) (let ((rebind-alist eshell-rebind-keys-alist)) (setq-local eshell-rebind-keys-alist - (append rebind-alist eshell-hist-rebind-keys-alist)) - (setq-local search-invisible t) - (setq-local search-exit-option t) - (add-hook 'isearch-mode-hook - (lambda () - (if (>= (point) eshell-last-output-end) - (setq overriding-terminal-local-map - eshell-isearch-map))) - nil t) - (add-hook 'isearch-mode-end-hook - (lambda () - (setq overriding-terminal-local-map nil)) - nil t)) + (append rebind-alist eshell-hist-rebind-keys-alist))) (eshell-hist-mode)) + (add-hook 'isearch-mode-hook #'eshell--isearch-setup nil t) (make-local-variable 'eshell-history-size) (or eshell-history-size @@ -384,6 +375,23 @@ eshell-get-history "Get an input line from the history ring." (ring-ref (or ring eshell-history-ring) index)) +(defun eshell-goto-history (pos) + "Replace command line with the element at POS of history ring. +Also update `eshell-history-index'. As a special case, if POS is nil +and `eshell--stored-incomplete-input' is a non-empty string, restore the +saved input." + (when (null eshell-history-index) + (setq eshell--stored-incomplete-input + (buffer-substring-no-properties eshell-last-output-end + (point-max)))) + (setq eshell-history-index pos) + ;; Can't use kill-region as it sets this-command + (delete-region eshell-last-output-end (point-max)) + (if (and pos (not (ring-empty-p eshell-history-ring))) + (insert-and-inherit (eshell-get-history pos)) + (when (> (length eshell--stored-incomplete-input) 0) + (insert-and-inherit eshell--stored-incomplete-input)))) + (defun eshell-add-input-to-history (input) "Add the string INPUT to the history ring. Input is entered into the input history ring, if the value of @@ -897,12 +905,12 @@ eshell-previous-matching-input ;; Has a match been found? (if (null pos) (error "Not found") - (setq eshell-history-index pos) - (unless (minibuffer-window-active-p (selected-window)) - (message "History item: %d" (- (ring-length eshell-history-ring) pos))) - ;; Can't use kill-region as it sets this-command - (delete-region eshell-last-output-end (point)) - (insert-and-inherit (eshell-get-history pos))))) + (eshell-goto-history pos) + (unless (or (minibuffer-window-active-p (selected-window)) + ;; No messages for Isearch because it will show the + ;; same messages (and more). + isearch-mode) + (message "History item: %d" (- (ring-length eshell-history-ring) pos)))))) (defun eshell-next-matching-input (regexp arg) "Search forwards through input history for match for REGEXP. @@ -937,114 +945,160 @@ eshell-next-matching-input-from-input (interactive "p") (eshell-previous-matching-input-from-input (- arg))) -(defun eshell-test-imatch () - "If isearch match good, put point at the beginning and return non-nil." - (if (get-text-property (point) 'history) - (progn (beginning-of-line) t) - (let ((before (point))) - (beginning-of-line) - (if (and (not (bolp)) - (<= (point) before)) - t - (if isearch-forward - (progn - (end-of-line) - (forward-char)) - (beginning-of-line) - (backward-char)))))) - -(defun eshell-return-to-prompt () - "Once a search string matches, insert it at the end and go there." - (setq isearch-other-end nil) - (let ((found (eshell-test-imatch)) before) - (while (and (not found) - (setq before - (funcall (if isearch-forward - 're-search-forward - 're-search-backward) - isearch-string nil t))) - (setq found (eshell-test-imatch))) - (if (not found) - (progn - (goto-char eshell-last-output-end) - (delete-region (point) (point-max))) - (setq before (point)) - (let ((text (buffer-substring-no-properties - (point) (line-end-position))) - (orig (marker-position eshell-last-output-end))) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (when (and text (> (length text) 0)) - (insert text) - (put-text-property (1- (point)) (point) - 'last-search-pos before) - (set-marker eshell-last-output-end orig) - (goto-char eshell-last-output-end)))))) - -(defun eshell-prepare-for-search () - "Make sure the old history file is at the beginning of the buffer." - (unless (get-text-property (point-min) 'history) - (save-excursion - (goto-char (point-min)) - (let ((end (copy-marker (point) t))) - (insert-file-contents eshell-history-file-name) - (set-text-properties (point-min) end - '(history t invisible t)))))) +(defun eshell--isearch-setup () + "Set up Isearch to search the input history. +Intended to be added to `isearch-mode-hook' in an Eshell buffer." + (when (and + ;; Eshell is busy running a foreground process + (not eshell-foreground-command) + (or (eq eshell-history-isearch t) + (and (eq eshell-history-isearch 'dwim) + (>= (point) eshell-last-output-end)))) + (setq isearch-message-prefix-add "history ") + (setq-local isearch-lazy-count nil) + (setq-local isearch-search-fun-function #'eshell-history-isearch-search + isearch-message-function #'eshell-history-isearch-message + isearch-wrap-function #'eshell-history-isearch-wrap + isearch-push-state-function #'eshell-history-isearch-push-state) + (add-hook 'isearch-mode-end-hook #'eshell-history-isearch-end nil t))) + +(defun eshell-history-isearch-end () + "Clean up after terminating history Isearch." + (when (overlayp eshell--history-isearch-messasge-overlay) + (delete-overlay eshell--history-isearch-messasge-overlay)) + (setq isearch-message-prefix-add nil) + (kill-local-variable 'isearch-lazy-count) + (setq-local isearch-search-fun-function #'isearch-search-fun-default + isearch-message-function nil + isearch-wrap-function nil + isearch-push-state-function nil) + (remove-hook 'isearch-mode-end-hook #'eshell-history-isearch-end t) + (setq isearch-opoint (point)) + (unless isearch-suspended + (custom-reevaluate-setting 'eshell-history-isearch))) + +(defun eshell-history-isearch-search () + "Return search function for Isearch in input history." + (lambda (string bound noerror) + (let ((search-fun (isearch-search-fun-default)) + (found nil)) + ;; Avoid highlighting matches in and before the last prompt + (when (and bound isearch-forward + (< (point) eshell-last-output-end)) + (goto-char eshell-last-output-end)) + (or + ;; First search in the initial input + (funcall search-fun string + (if isearch-forward bound eshell-last-output-end) + noerror) + ;; Then search in the input history: put next/previous history + ;; element in the command line successively, then search the + ;; string in the command line. Do this only when not + ;; lazy-highlighting (`bound' is nil). + (unless bound + (condition-case nil + (progn + (while (not found) + (cond (isearch-forward + ;; Signal an error explicitly to break + (when (or (null eshell-history-index) + (eq eshell-history-index 0)) + (error "End of history; no next item")) + (eshell-next-input 1) + (goto-char eshell-last-output-end)) + (t + ;; Signal an error explicitly to break + (when (eq eshell-history-index + (1- (ring-length eshell-history-ring))) + (error "Beginning of history; no preceding item")) + (eshell-previous-input 1) + (goto-char (point-max)))) + (setq isearch-barrier (point) + isearch-opoint (point)) + ;; After putting an history element in the command + ;; line, search the string in them. + (setq found (funcall search-fun string + (unless isearch-forward + eshell-last-output-end) + noerror))) + (point)) + ;; Return when no next/preceding element error signaled + (error nil))))))) + +(defun eshell-history-isearch-message (&optional c-q-hack ellipsis) + "Display the input history search prompt. +If there are no search errors, this function displays an overlay with +the Isearch prompt which replaces the original Eshell prompt. +Otherwise, it displays the standard Isearch message returned from the +function `isearch-message'." + (if (not (and isearch-success (not isearch-error))) + ;; Use standard message function (which displays a message in the + ;; echo area) when not in command line, or search fails or has + ;; errors (like incomplete regexp). + (isearch-message c-q-hack ellipsis) + ;; Otherwise, use an overlay over the Eshell prompt. + (if (overlayp eshell--history-isearch-messasge-overlay) + (move-overlay eshell--history-isearch-messasge-overlay + (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end) + (setq eshell--history-isearch-messasge-overlay + (make-overlay (save-excursion + (goto-char eshell-last-output-end) + (forward-line 0) + (point)) + eshell-last-output-end)) + (overlay-put eshell--history-isearch-messasge-overlay 'evaporate t)) + (overlay-put eshell--history-isearch-messasge-overlay + 'display (isearch-message-prefix ellipsis + isearch-nonincremental)) + (if (and eshell-history-index (not ellipsis)) + (message "History item: %d" (- (ring-length eshell-history-ring) + eshell-history-index)) + (message "")))) + +(defun eshell-history-isearch-wrap () + "Wrap the input history search." + (if isearch-forward + (eshell-goto-history (1- (ring-length eshell-history-ring))) + (eshell-goto-history nil)) + (goto-char (if isearch-forward eshell-last-output-end (point-max)))) + +(defun eshell-history-isearch-push-state () + "Save a function restoring the state of input history search. +Save `eshell-history-index' to the additional state parameter in the +search status stack." + (let ((index eshell-history-index)) + (lambda (_cmd) + (eshell-goto-history index)))) (defun eshell-isearch-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((inhibit-read-only t)) - (eshell-prepare-for-search) - (goto-char (point-max)) - (set-marker eshell-last-output-end (point)) - (delete-region (point) (point-max))) - (isearch-mode invert t 'eshell-return-to-prompt)) - -(defun eshell-isearch-repeat-backward (&optional invert) - "Do incremental regexp search backward through past commands." - (interactive) - (let ((old-pos (get-text-property (1- (point-max)) - 'last-search-pos))) - (when old-pos - (goto-char old-pos) - (if invert - (end-of-line) - (backward-char))) - (setq isearch-forward invert) - (isearch-search-and-update))) + "Do incremental search backward through past commands." + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward nil t) + (isearch-backward nil t))) (defun eshell-isearch-forward () - "Do incremental regexp search backward through past commands." - (interactive) + "Do incremental search forward through past commands." + (interactive nil eshell-mode) (eshell-isearch-backward t)) -(defun eshell-isearch-repeat-forward () +(defun eshell-isearch-backward-regexp (&optional invert) "Do incremental regexp search backward through past commands." - (interactive) - (eshell-isearch-repeat-backward t)) - -(defun eshell-isearch-cancel () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-cancel)) - -(defun eshell-isearch-abort () - (interactive) - (goto-char eshell-last-output-end) - (delete-region (point) (point-max)) - (call-interactively 'isearch-abort)) - -(defun eshell-isearch-delete-char () - (interactive) - (save-excursion - (isearch-delete-char))) - -(defun eshell-isearch-return () - (interactive) - (isearch-done) - (eshell-send-input)) + (interactive nil eshell-mode) + (setq eshell-history-isearch t) + (if invert + (isearch-forward-regexp nil t) + (isearch-backward-regexp nil t))) + +(defun eshell-isearch-forward-regexp () + "Do incremental regexp search forward through past commands." + (interactive nil eshell-mode) + (eshell-isearch-backward-regexp t)) (defun em-hist-unload-function () (remove-hook 'kill-emacs-hook 'eshell-save-some-history)) -- 2.47.0 --=-=-=-- ------------=_1733947263-10502-1--