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

From: Stefan Monnier <[email-masked]>
Date: Mon, 03 Jul 2023 23:32:49 -0400

> 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.")

Indeed `shell-dirtrackp` should not be defvar'd.
The above looks good to me.

> @@ -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)))

You can make the patch smaller by keeping this definition where it is
and just add a (defvar shell-dirtrack-mode) here instead to silence the
compiler warnings.

        Stefan