unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Vladimir Sedach <vas@oneofus.la>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 64311@debbugs.gnu.org
Subject: bug#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers
Date: Tue, 27 Jun 2023 08:09:22 -0600	[thread overview]
Message-ID: <87wmzp2e0d.fsf@t510.orion.oneofus.la> (raw)
In-Reply-To: <83h6qtw3tq.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]


Eli Zaretskii <eliz@gnu.org> writes:
> In what version of Emacs do you see this?  (You didn't include in your
> report the information collected by "M-x report-emacs-bug", so I
> cannot know what version and on what OS are you using.)  I cannot
> reproduce this in Emacs 29: "C-h m" after "M-x shell" shows
> shell-dirtrack-mode only in the *shell* buffer.  I do see it in
> *scratch* in Emacs 28, so I guess we already fixed this?

You are right about the steps to reproduce. What changed in Emacs 29
was describe-mode no longer using minor-mode-list, but
(buffer-local-value 'local-minor-modes buffer) instead.

This changed in commit 3c059f269e0182bd19df37871585e0b0bf1d47e5
Redo `C-h m' output
Wed Apr 13 03:50:06 2022 +0200

This only hides the problem, which is: the default value of
shell-dirtrack-mode being t.

Revised steps to reproduce:

1. emacs -q
2. M-x shell
3. M-: shell-dirtrack-mode in *scratch* or *GNU Emacs*

This is also demonstrated in the test
shell-dirtrack-should-not-be-on-in-unrelated-modes
from the first patch, which fails without the fix being applied.

Attached is a revised patch for the fix, with the obsolete variable
version filled in, and updated commit message.

Thank you for looking at this.

--
Vladimir Sedach


[-- Attachment #2: 0002-Fix-shell-dirtrack-mode-showing-up-as-enabled-in-unr.patch --]
[-- Type: text/x-diff, Size: 4360 bytes --]

From 971ac829043c6659acf7b315c0d610de1c7b0d10 Mon Sep 17 00:00:00 2001
From: Vladimir Sedach <vas@oneofus.la>
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. M-: shell-dirtrack-mode 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..e6f1c2629f3 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
+  "30.1"
+  "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


  reply	other threads:[~2023-06-27 14:09 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27  4:39 bug#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers Vladimir Sedach
2023-06-27 11:18 ` Eli Zaretskii
2023-06-27 14:09   ` Vladimir Sedach [this message]
2023-06-27 15:52     ` Eli Zaretskii
2023-06-28  0:07       ` Vladimir Sedach
2023-06-28 11:46         ` Eli Zaretskii
2023-06-28 16:43           ` Vladimir Sedach
2023-06-28 18:31             ` Eli Zaretskii
2023-06-28 20:14               ` Vladimir Sedach
2023-06-29  4:57                 ` Eli Zaretskii
2023-06-29 16:26                   ` Vladimir Sedach
2023-06-29 18:10                     ` Eli Zaretskii
2023-06-29 19:24                       ` Vladimir Sedach
2023-06-30  5:40                         ` Eli Zaretskii
2023-06-30 16:47                           ` Vladimir Sedach
2023-07-02  6:39                             ` Eli Zaretskii
2023-07-03 17:03                               ` Vladimir Sedach
2023-07-03 17:17                                 ` Eli Zaretskii
2023-07-04 14:28                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-04 16:05                                 ` Eli Zaretskii
2023-07-04 18:34                                   ` Vladimir Sedach
2023-07-04 20:36                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-04 22:27                                     ` Vladimir Sedach
2023-07-04 23:42                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-06 20:30                                         ` Vladimir Sedach
2023-07-08  8:30                                           ` Eli Zaretskii
2023-07-08 16:18                                             ` Vladimir Sedach
2023-07-08 16:31                                               ` Eli Zaretskii
2023-07-04  3:32 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-04 11:21   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wmzp2e0d.fsf@t510.orion.oneofus.la \
    --to=vas@oneofus.la \
    --cc=64311@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).