From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tony Zorman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63748: [PATCH] bug#63748: 30.0.50; eshell-previous-prompt doesn't work for multiline prompts Date: Thu, 08 Jun 2023 17:11:49 +0200 Message-ID: <878rcu0z0q.fsf@hyperspace> References: <87ilcew4ng.fsf@hyperspace> <14785aa0-e1a5-6f69-9d1f-fccdaac9a7fc@gmail.com> <87bkhwllq5.fsf@hyperspace> <88ae9a36-c9f9-fe0a-80a2-d90ff1b3837a@gmail.com> Reply-To: Tony Zorman Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7450"; mail-complaints-to="usenet@ciao.gmane.io" To: Jim Porter , 63748@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 08 17:13:27 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q7HKJ-0001kN-NJ for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 08 Jun 2023 17:13:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7HJx-0006hJ-6X; Thu, 08 Jun 2023 11:13:05 -0400 Original-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 1q7HJu-0006gY-TO for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 11:13:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7HJu-0007XO-KE for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 11:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q7HJu-0002aa-3o for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 11:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tony Zorman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 Jun 2023 15:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63748 X-GNU-PR-Package: emacs Original-Received: via spool by 63748-submit@debbugs.gnu.org id=B63748.16862371249887 (code B ref 63748); Thu, 08 Jun 2023 15:13:02 +0000 Original-Received: (at 63748) by debbugs.gnu.org; 8 Jun 2023 15:12:04 +0000 Original-Received: from localhost ([127.0.0.1]:57202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7HIx-0002ZO-N8 for submit@debbugs.gnu.org; Thu, 08 Jun 2023 11:12:04 -0400 Original-Received: from mout-p-101.mailbox.org ([80.241.56.151]:54640) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7HIt-0002Yr-TZ for 63748@debbugs.gnu.org; Thu, 08 Jun 2023 11:12:02 -0400 Original-Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4QcSNl5GNYz9snN; Thu, 8 Jun 2023 17:11:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1686237111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=K+700GKEgzh6Y3cjoyudAfI4Z+jhM7aq+HhvG/Op2xc=; b=j68fGqxE47QNUz2dEQ52L3bRWkEaaP1ZV0LH8re9YctDq3RA2gBKgFiiHtU/rCgh20sx/1 tqeUpHHorHccIAoBxAtRZkoPrNhE2sb7Ic8oL5gmekdJYjwZDBruOF7UPKIcL0cKbPGJPM DwzXQlEdZUkg5FUtrSUm+Mt3nxAnJxOeaXU2XOH7gd8TaZQF4CPytjqmhcXcstVjnBfjbC MXFMhV6Jf5lP6tER2oaTZP96CZlSaHSLy0XL/SIvBy9agVjsWQJqNej22XF5H2TIBQVX4C 6HobI/V3oLwaSP9JAba0ejJoSnkxDQiW/l78sHcFlae+K6sSpQ/c/2/ogYwGsQ== In-Reply-To: <88ae9a36-c9f9-fe0a-80a2-d90ff1b3837a@gmail.com> X-MBO-RS-ID: 953a708f360f1e5d0f4 X-MBO-RS-META: 5k6hxxsticfjheqwkrscgxqeghsfx79f X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263129 Archived-At: --=-=-= Content-Type: text/plain On Sat, Jun 03 2023 12:35, Jim Porter wrote: > You can probably simplify the multiline wrapper in your test to > something like this: > > (defmacro em-prompt-test--with-multiline (&rest body) > "Execute BODY with a multiline Eshell prompt." > `(let ((eshell-prompt-function (lambda () "multiline prompt\n$ "))) > ,@body)) > > Then use it like so: > > ;; Note: no arguments necessary. > (defun em-prompt-test/forward-backward-matching-input-with () > ;; ... > ) > > (ert-deftest em-prompt-test/forward-backward-matching-input-multiline () > (em-prompt-test--with-multiline > (em-prompt-test/forward-backward-matching-input-with))) > > That should be safer than setq'ing the prompt function. (You also don't > need to set the prompt regexp, since that's only useful if you want to > navigate via '(forward|backward)-paragraph', and we don't test that here.) oh, this is pretty neat, thanks! Sorry for the slow response; I have attached the (hopefully properly) corrected patch now. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-eshell-next-prompt-More-precisely-navigate-to-the-pr.patch >From 37988ca00beb26c0ce22f1c5f0d16cc4df56662c Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Sat, 3 Jun 2023 14:23:19 +0200 Subject: [PATCH] eshell-next-prompt: More precisely navigate to the prompt (bug#63748) * lisp/eshell/em-prompt.el (eshell-next-prompt): Navigate to the current prompt more accurately by using text properties instead of going to the beginning of the line. This is important for multiline prompts, as they don't necessarily start at the beginning of the current line. * test/lisp/eshell/em-prompt-tests.el (em-prompt-test--with-multiline): Execute a given body with a multiline prompt. (em-prompt-test/next-previous-prompt-with): (em-prompt-test/forward-backward-matching-input-with): Helper functions for code reuse. (em-prompt-test/forward-backward-matching-input): (em-prompt-test/next-previous-prompt): Rewrite in terms of the appropriate helper functions. (em-prompt-test/next-previous-prompt-multiline): (em-prompt-test/forward-backward-matching-input-multiline): Add multiline variants of existing tests. --- lisp/eshell/em-prompt.el | 3 ++- test/lisp/eshell/em-prompt-tests.el | 31 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lisp/eshell/em-prompt.el b/lisp/eshell/em-prompt.el index 9f9e58e83d..42f8f273b5 100644 --- a/lisp/eshell/em-prompt.el +++ b/lisp/eshell/em-prompt.el @@ -180,7 +180,8 @@ eshell-next-prompt (text-property-search-forward 'field 'prompt t)) (setq n (1- n))) (let (match this-match) - (forward-line 0) ; Don't count prompt on current line. + ;; Don't count the current prompt. + (text-property-search-backward 'field 'prompt t) (while (and (< n 0) (setq this-match (text-property-search-backward 'field 'prompt t))) diff --git a/test/lisp/eshell/em-prompt-tests.el b/test/lisp/eshell/em-prompt-tests.el index 257549e40f..93bf9d84ab 100644 --- a/test/lisp/eshell/em-prompt-tests.el +++ b/test/lisp/eshell/em-prompt-tests.el @@ -80,8 +80,13 @@ em-prompt-test/field-properties/no-highlight (apply #'propertize "hello\n" eshell-command-output-properties))))))) -(ert-deftest em-prompt-test/next-previous-prompt () - "Check that navigating forward/backward through old prompts works correctly." +(defmacro em-prompt-test--with-multiline (&rest body) + "Execute BODY with a multiline Eshell prompt." + `(let ((eshell-prompt-function (lambda () "multiline prompt\n$ "))) + ,@body)) + +(defun em-prompt-test/next-previous-prompt-with () + "Helper for checking forward/backward navigation of old prompts." (with-temp-eshell (eshell-insert-command "echo one") (eshell-insert-command "echo two") @@ -98,8 +103,17 @@ em-prompt-test/next-previous-prompt (eshell-next-prompt 3) (should (equal (eshell-get-old-input) "echo fou")))) -(ert-deftest em-prompt-test/forward-backward-matching-input () - "Check that navigating forward/backward via regexps works correctly." +(ert-deftest em-prompt-test/next-previous-prompt () + "Check that navigating forward/backward through old prompts works correctly." + (em-prompt-test/next-previous-prompt-with)) + +(ert-deftest em-prompt-test/next-previous-prompt-multiline () + "Check old prompt forward/backward navigation for multiline prompts." + (em-prompt-test--with-multiline + (em-prompt-test/next-previous-prompt-with))) + +(defun em-prompt-test/forward-backward-matching-input-with () + "Helper for checking forward/backward navigation via regexps." (with-temp-eshell (eshell-insert-command "echo one") (eshell-insert-command "printnl something else") @@ -117,4 +131,13 @@ em-prompt-test/forward-backward-matching-input (eshell-forward-matching-input "echo" 3) (should (equal (eshell-get-old-input) "echo fou")))) +(ert-deftest em-prompt-test/forward-backward-matching-input () + "Check that navigating forward/backward via regexps works correctly." + (em-prompt-test/forward-backward-matching-input-with)) + +(ert-deftest em-prompt-test/forward-backward-matching-input-multiline () + "Check forward/backward regexp navigation for multiline prompts." + (em-prompt-test--with-multiline + (em-prompt-test/forward-backward-matching-input-with))) + ;;; em-prompt-tests.el ends here -- 2.41.0 --=-=-= Content-Type: text/plain -- Tony Zorman | https://tony-zorman.com/ --=-=-=--