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: Sat, 03 Jun 2023 15:27:30 +0200 Message-ID: <87bkhwllq5.fsf@hyperspace> References: <87ilcew4ng.fsf@hyperspace> <14785aa0-e1a5-6f69-9d1f-fccdaac9a7fc@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="37013"; 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 Sat Jun 03 15:28:18 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 1q5RIm-0009NR-JQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Jun 2023 15:28:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q5RId-0007up-6v; Sat, 03 Jun 2023 09:28:07 -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 1q5RIZ-0007ue-Tx for bug-gnu-emacs@gnu.org; Sat, 03 Jun 2023 09:28:05 -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 1q5RIZ-0000uD-Gl for bug-gnu-emacs@gnu.org; Sat, 03 Jun 2023 09:28:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q5RIY-0002TJ-Cn for bug-gnu-emacs@gnu.org; Sat, 03 Jun 2023 09:28: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: Sat, 03 Jun 2023 13:28: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.16857988659475 (code B ref 63748); Sat, 03 Jun 2023 13:28:02 +0000 Original-Received: (at 63748) by debbugs.gnu.org; 3 Jun 2023 13:27:45 +0000 Original-Received: from localhost ([127.0.0.1]:41821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q5RIG-0002Sk-Cf for submit@debbugs.gnu.org; Sat, 03 Jun 2023 09:27:44 -0400 Original-Received: from mout-p-101.mailbox.org ([80.241.56.151]:51542) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q5RIC-0002ST-GV for 63748@debbugs.gnu.org; Sat, 03 Jun 2023 09:27:42 -0400 Original-Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4QYLJh4PTzz9sVt; Sat, 3 Jun 2023 15:27:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1685798852; 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=OJrm/SUtCZUDlSs+glE2fuUv9qBfEOquENYwFRJo8OQ=; b=kJCbJSS/ylL5+C57+20dmy23ShkiU1bJl0ATiqvojiMh3yfXhKVKAnnO89ni41l9hLx8N3 eK94go7c5QYzLIyAnkJPqItjTr49FD2bCMxqcoWWi4P/6Ik1jhd7I2CYcK2LUJ4LbX3PLy Jz+HPawPQ8JeLrEjzLBsTDPg/P3bApGn9GqAc1uylII5bYatucn8IHIjyyURDGZvAtvCHZ mqcuTvs4dZ5AJO7vI+Ge9IdZlaBBBeSdVQQjP8r8wp+iKafxNxlJgaz6otnAapNRCWzD2f hQz4/HGNqaSO79hhigpS1G9xcIV5ndLvg0NSUNKpWc/LGwJ0sp+h3bNuqTVxGg== In-Reply-To: <14785aa0-e1a5-6f69-9d1f-fccdaac9a7fc@gmail.com> X-MBO-RS-META: ztnesm3ozwixwocy7p1f8hcftoq13qcc X-MBO-RS-ID: 86dfef5a299a8dff107 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:262837 Archived-At: --=-=-= Content-Type: text/plain On Mon, May 29 2023 22:02, Jim Porter wrote: > A test would be great. See "test/lisp/eshell/em-prompt-tests.el": > another test based on 'em-prompt-test/next-previous-prompt' (and > possibly 'em-prompt-test/forward-backward-matching-input' too) should be > sufficient, I think. > > If you want to add a test yourself, go for it, and let me know if you > run into any issues. Otherwise if you prefer, I can write a test case > for this. Okay, I now added some hopefully sufficient tests for this based on both next-previous-prompt and forward-backward-matching-input (if that's not too overkill). Let me know what you think. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-eshell-next-prompt-More-precisely-navigate-to-the-pr.patch Content-Transfer-Encoding: quoted-printable >From 45b4e788fb60138516ed8e58a368d72d994da4c0 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/multiline): Test a given function 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 | 45 ++++++++++++++++++++++++++--- 2 files changed, 43 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-prom= pt-tests.el index 257549e40f..7e3454a4d3 100644 --- a/test/lisp/eshell/em-prompt-tests.el +++ b/test/lisp/eshell/em-prompt-tests.el @@ -80,9 +80,27 @@ em-prompt-test/field-properties/no-highlight (apply #'propertize "hello\n" eshell-command-output-properties))))))) =20 -(ert-deftest em-prompt-test/next-previous-prompt () - "Check that navigating forward/backward through old prompts works correc= tly." +(defun em-prompt-test/multiline (test-fun) + "Execute TEST-FUN with a multiline prompt." + (funcall + test-fun + '(progn + (setq eshell-prompt-function + (lambda () + (concat "=E2=94=8C=E2=94=80" + (user-login-name) "@" (system-name) + " " (abbreviate-file-name (eshell/pwd)) " \n" + "=E2=94=94=E2=94=80" + (if (zerop (user-uid)) "#" "$") + " "))) + (setq eshell-prompt-regexp "=E2=94=94=E2=94=80[$#] ")))) + +(defun em-prompt-test/next-previous-prompt-with (&optional more) + "Helper for checking forward/backward navigation of old prompts. +Accepts an additional argument, to be executed inside of a +temporary eshell buffer." (with-temp-eshell + (eval more) (eshell-insert-command "echo one") (eshell-insert-command "echo two") (eshell-insert-command "echo three") @@ -98,9 +116,20 @@ em-prompt-test/next-previous-prompt (eshell-next-prompt 3) (should (equal (eshell-get-old-input) "echo fou")))) =20 -(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 correc= tly." + (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/multiline #'em-prompt-test/next-previous-prompt-with)) + +(defun em-prompt-test/forward-backward-matching-input-with (&optional more) + "Helper for checking forward/backward navigation via regexps. +Accepts an additional argument, to be executed inside of a +temporary eshell buffer." (with-temp-eshell + (eval more) (eshell-insert-command "echo one") (eshell-insert-command "printnl something else") (eshell-insert-command "echo two") @@ -117,4 +146,12 @@ em-prompt-test/forward-backward-matching-input (eshell-forward-matching-input "echo" 3) (should (equal (eshell-get-old-input) "echo fou")))) =20 +(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/multiline #'em-prompt-test/forward-backward-matching-inp= ut-with)) + ;;; em-prompt-tests.el ends here --=20 2.40.1 --=-=-= Content-Type: text/plain -- Tony Zorman | https://tony-zorman.com/ --=-=-=--