GNU bug report logs - #79441
shell-resync-dirs breaks on PS1 with newline

Previous Next

Package: emacs;

Reported by: Janneke Nieuwenhuizen <janneke <at> gnu.org>

Date: Sat, 13 Sep 2025 06:53:02 UTC

Severity: normal

Full log


Message #14 received at 79441 <at> debbugs.gnu.org (full text, mbox):

From: Janneke Nieuwenhuizen <janneke <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 79441 <at> debbugs.gnu.org
Subject: Re: bug#79441: [PATCH v2] Re: bug#79441: shell-resync-dirs breaks
 on PS1 with newline
Date: Sun, 14 Sep 2025 07:50:38 +0200
[Message part 1 (text/plain, inline)]
Janneke Nieuwenhuizen writes:

Hello!

> [.]
>
>>> To reproduce, a
>>> single character (that is not '.') and a newline suffices, typing
>>> something like:
>>> 
>>>     PS1='0\n$ '
>>> 
>>> in an emacs shell and typing M-RET reproduces the problem.
>>
>> Can you suggest how to solve this?
>
> Good question!  When I tried to add (message ...) debugging this
> morning, it started (and kept) looping; so I had no idea how to proceed.
> However, I tried again and got better results this time and have created
> a patch that "works for me" (see attached).

[..]  Snip rationale that still holds...but

...initially I only used `seq-filter' in my patch, so I removed the
stripping of the optional final newline.  When I added the fall-back to
takk the last element of the list, we'd need to bring back that final
newline removal.  Version 2 attached.

Greetings,
Janneke

[v2-0001-Fix-shell-resync-dirs-for-multi-line-prompt.patch (text/x-patch, inline)]
From a08fc315b30044c7feb86a04a135ea7de434bf11 Mon Sep 17 00:00:00 2001
From: Janneke Nieuwenhuizen <janneke <at> gnu.org>
Date: Sat, 13 Sep 2025 16:30:42 +0200
Subject: [PATCH v2] Fix 'shell-resync-dirs' for multi-line prompt.

* lisp/shell.el (shell-eval-command): Instead of always taking the last
element from the shell-dirtrack-query command, first try selecting the
last directory.  (Bug#79441)
---
 lisp/shell.el | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lisp/shell.el b/lisp/shell.el
index 09d4161ba7a..a9c71488f2d 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -1236,11 +1236,12 @@ shell-resync-dirs
 `shell-dirstack-query' (default \"dirs\"), reads the next
 line output and parses it to form the new directory stack."
   (interactive)
-  (let* ((dls (car
-               (last
-                (string-lines
-                 (string-chop-newline
-                  (shell-eval-command (concat shell-dirstack-query "\n")))))))
+  (let* ((lines (nreverse
+                 (string-lines
+                  (string-chop-newline
+                   (shell-eval-command (concat shell-dirstack-query "\n"))))))
+         (dls (or (seq-find #'file-directory-p lines)
+                  (car lines)))
          (dlsl nil)
          (pos 0)
          (ds nil))
-- 
2.51.0

[Message part 3 (text/plain, inline)]
-- 
Janneke Nieuwenhuizen <janneke <at> gnu.org>  | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | AvatarĀ® https://AvatarAcademy.com

This bug report was last modified 4 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.