Subject: bug#64311: closed (Re: bug#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 08 Jul 2023 08:31:02 +0000

Your bug report

#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers

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 [email-masked].

-- 
64311: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64311
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers
From: Eli Zaretskii <[email-masked]>
To: Vladimir Sedach <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sat, 08 Jul 2023 11:30:25 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Vladimir Sedach <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>, [email-masked]
> Date: Thu, 06 Jul 2023 14:30:16 -0600
> 
> Attached is a patch that keeps defvaralias, and does not obsolete
> anything.

Thanks, I installed this, with slight changes, on the master branch,
and I'm therefore closing this bug.

Subject: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers
From: Vladimir Sedach <[email-masked]>
To: [email-masked]
Date: Mon, 26 Jun 2023 22:39:50 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

Fix shell-dirtrack-mode showing up as enabled in unrelated buffers

shell-dirtrack-mode always shows up in unrelated buffers.

Steps to reproduce:
1. emacs -q
2. M-x shell
3. describe-mode (C-h m) in *scratch* or *GNU Emacs*

This is because shell-dirtrack-mode is aliased to shell-dirtrackp,
which has default value t.

Changes in this patch:
mark shell-dirtrackp obsolete
replace existing occurrences of shell-dirtrackp with shell-dirtrack-mode
add :interactive (shell-mode) suggestion to shell-dirtrack-mode

shell-dirtrack-mode is still turned on by default. There is an
explicit call to (shell-dirtrack-mode 1) in the definition of
shell-mode.

Definition of shell-dirtrack-mode is moved to quiet warning about
reference to free variable ‘shell-dirtrack-mode’.

Note: I am not sure what to put for WHEN on the obsolete variable.
Does that get filled in when merging?

--
Vladimir Sedach

>From 4f803f5f2c3e4df48e6509cf238dc420cebc4a0a Mon Sep 17 00:00:00 2001
From: Vladimir Sedach <[email-masked]>
Date: Mon, 26 Jun 2023 22:30:25 -0600
Subject: [PATCH 1/2] ; * test/lisp/shell-tests.el: added tests for
 shell-dirtrack-mode

---
 test/lisp/shell-tests.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/test/lisp/shell-tests.el b/test/lisp/shell-tests.el
index db9124e2435..ddddfdb2e0f 100644
--- a/test/lisp/shell-tests.el
+++ b/test/lisp/shell-tests.el
@@ -64,4 +64,35 @@ shell-tests-split-string
     (should (equal (split-string-shell-command "ls /tmp/foo\\ bar")
                    '("ls" "/tmp/foo bar")))))
 
+(ert-deftest shell-dirtrack-on-by-default ()
+  (with-temp-buffer
+    (shell-mode)
+    (should shell-dirtrack-mode)))
+
+(ert-deftest shell-dirtrack-should-not-be-on-in-unrelated-modes ()
+  (with-temp-buffer
+    (should (not shell-dirtrack-mode))))
+
+(ert-deftest shell-dirtrack-sets-list-buffers-directory ()
+  (let ((start-dir default-directory))
+    (with-temp-buffer
+      (should-not list-buffers-directory)
+      (shell-mode)
+      (shell-cd "..")
+      (should list-buffers-directory)
+      (should (not (equal start-dir list-buffers-directory)))
+      (should (string-prefix-p list-buffers-directory start-dir)))))
+
+(ert-deftest shell-directory-tracker-cd ()
+  (let ((start-dir default-directory))
+    (with-temp-buffer
+      (should-not list-buffers-directory)
+      (shell-mode)
+      (cl-letf (((symbol-function 'shell-unquote-argument)
+                 (lambda (x) x)))
+        (shell-directory-tracker "cd .."))
+      (should list-buffers-directory)
+      (should (not (equal start-dir list-buffers-directory)))
+      (should (string-prefix-p list-buffers-directory start-dir)))))
+
 ;;; shell-tests.el ends here
-- 
2.20.1

>From 623704526b081c0d453a84d517f9d02035755504 Mon Sep 17 00:00:00 2001
From: Vladimir Sedach <[email-masked]>
Date: Mon, 26 Jun 2023 22:32:07 -0600
Subject: [PATCH 2/2] Fix shell-dirtrack-mode showing up as enabled in
 unrelated buffers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

; shell-dirtrack-mode always shows up in unrelated buffers.

; Steps to reproduce:
; 1. emacs -q
; 2. M-x shell
; 3. describe-mode (C-h m) in *scratch* or *GNU Emacs*

; This is because shell-dirtrack-mode is aliased to shell-dirtrackp,
; which has default value t.

; Changes in this patch:
; mark shell-dirtrackp obsolete
; replace existing occurrences of shell-dirtrackp with shell-dirtrack-mode
; add :interactive (shell-mode) suggestion to shell-dirtrack-mode

; shell-dirtrack-mode is still turned on by default. There is an
; explicit call to (shell-dirtrack-mode 1) in the definition of
; shell-mode.

; Definition of shell-dirtrack-mode is moved to quiet warning about
; reference to free variable ‘shell-dirtrack-mode’.
---
 lisp/shell.el | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/lisp/shell.el b/lisp/shell.el
index b74442f1961..39e12577280 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -346,10 +346,10 @@ shell-dirstack
   "List of directories saved by pushd in this buffer's shell.
 Thus, this does not include the shell's current directory.")
 
-(defvaralias 'shell-dirtrack-mode 'shell-dirtrackp)
-
-(defvar shell-dirtrackp t
-  "Non-nil in a shell buffer means directory tracking is enabled.")
+(define-obsolete-variable-alias 'shell-dirtrackp 'shell-dirtrack-mode
+  "???"
+  "Non-nil in a shell buffer means directory tracking is enabled.
+Use the minor mode variable `shell-dirtrack-mode' instead.")
 
 (defvar shell-last-dir nil
   "Keep track of last directory for ksh `cd -' command.")
@@ -997,6 +997,20 @@ shell
 ;; replace it with a process filter that watches for and strips out
 ;; these messages.
 
+(define-minor-mode shell-dirtrack-mode
+  "Toggle directory tracking in this shell buffer (Shell Dirtrack mode).
+
+The `dirtrack' package provides an alternative implementation of
+this feature; see the function `dirtrack-mode'.  Also see
+`comint-osc-directory-tracker' for an escape-sequence based
+solution."
+  :lighter nil
+  :interactive (shell-mode)
+  (setq list-buffers-directory (if shell-dirtrack-mode default-directory))
+  (if shell-dirtrack-mode
+      (add-hook 'comint-input-filter-functions #'shell-directory-tracker nil t)
+    (remove-hook 'comint-input-filter-functions #'shell-directory-tracker t)))
+
 (defun shell-directory-tracker (str)
   "Tracks cd, pushd and popd commands issued to the shell.
 This function is called on each input passed to the shell.
@@ -1013,7 +1027,7 @@ shell-directory-tracker
 and `shell-pushd-dunique' control the behavior of the relevant command.
 
 Environment variables are expanded, see function `substitute-in-file-name'."
-  (if shell-dirtrackp
+  (if shell-dirtrack-mode
       ;; We fail gracefully if we think the command will fail in the shell.
 ;;;      (with-demoted-errors "Directory tracker failure: %s"
       ;; This fails so often that it seems better to just ignore errors (?).
@@ -1167,23 +1181,10 @@ shell-extract-num
   (and (string-match "^\\+[1-9][0-9]*$" str)
        (string-to-number str)))
 
-(define-minor-mode shell-dirtrack-mode
-  "Toggle directory tracking in this shell buffer (Shell Dirtrack mode).
-
-The `dirtrack' package provides an alternative implementation of
-this feature; see the function `dirtrack-mode'.  Also see
-`comint-osc-directory-tracker' for an escape-sequence based
-solution."
-  :lighter nil
-  (setq list-buffers-directory (if shell-dirtrack-mode default-directory))
-  (if shell-dirtrack-mode
-      (add-hook 'comint-input-filter-functions #'shell-directory-tracker nil t)
-    (remove-hook 'comint-input-filter-functions #'shell-directory-tracker t)))
-
 (defun shell-cd (dir)
   "Do normal `cd' to DIR, and set `list-buffers-directory'."
   (cd dir)
-  (if shell-dirtrackp
+  (if shell-dirtrack-mode
       (setq list-buffers-directory default-directory)))
 
 (defun shell-resync-dirs ()
-- 
2.20.1