From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vladimir Sedach Newsgroups: gmane.emacs.bugs Subject: bug#64311: [PATCH] Fix shell-dirtrack-mode showing up as enabled in unrelated buffers Date: Mon, 26 Jun 2023 22:39:50 -0600 Message-ID: <87pm5h4iy1.fsf@t510.orion.oneofus.la> 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="17082"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.2 To: 64311@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 27 08:30:20 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 1qE2DT-0004JC-4U for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Jun 2023 08:30:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qE2DF-00012w-Vc; Tue, 27 Jun 2023 02:30:06 -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 1qE2DD-00012H-8t for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2023 02:30:03 -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 1qE2DC-0003RJ-U0 for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2023 02:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qE2DC-0006C3-9E for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2023 02:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vladimir Sedach Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Jun 2023 06:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64311 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168784739223762 (code B ref -1); Tue, 27 Jun 2023 06:30:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Jun 2023 06:29:52 +0000 Original-Received: from localhost ([127.0.0.1]:47457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qE2D2-0006B8-2M for submit@debbugs.gnu.org; Tue, 27 Jun 2023 02:29:52 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:43446) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qE0Uk-00032s-CP for submit@debbugs.gnu.org; Tue, 27 Jun 2023 00:40:03 -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 1qE0Ug-0005Km-0E for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2023 00:40:01 -0400 Original-Received: from robust-software.ca ([2607:f2f8:a680:0:582c:1928:cb2b:1a91]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qE0Ud-0000Wo-Kv for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2023 00:39:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=virgo1; bh=/FRUB+xrvC/bZ fwLo0e1qUQQUqn9kq1tAh+OuzQtej8=; h=date:subject:to:from; d=oneofus.la; b=tY+rYbu4nxG27elhVCM942ekcEDJl9fzzWMH7q8+QmLk5ZqT4QhPXfh6JQqdwiBg5Ad+ cOuAxP7vtFBDjbAP4/ZoejwdEDi+6yBQ6SRcfawr+PQA1aqPuWKNsm/v/lVq1tJRQ5yVbE OlJ8vpfqWkaUjVkeJ4rv3NRTsRv/sVim4= Original-Received: from t510.orion.oneofus.la (node-1w7jra28qzk6wbxvh8blpivjl.ipv6.telus.net [2001:56a:f913:3c01:117c:4f07:9ae2:4d31]) by virgo1.oneofus.la (OpenSMTPD) with ESMTPSA id 3b1bb257 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 26 Jun 2023 21:39:52 -0700 (PDT) Received-SPF: pass client-ip=2607:f2f8:a680:0:582c:1928:cb2b:1a91; envelope-from=vas@oneofus.la; helo=robust-software.ca X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 27 Jun 2023 02:29:50 -0400 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:264123 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 =E2=80=98shell-dirtrack-mode=E2=80=99. Note: I am not sure what to put for WHEN on the obsolete variable. Does that get filled in when merging? -- Vladimir Sedach --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-test-lisp-shell-tests.el-added-tests-for-shell-dirtr.patch >From 4f803f5f2c3e4df48e6509cf238dc420cebc4a0a Mon Sep 17 00:00:00 2001 From: Vladimir Sedach 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 --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0002-Fix-shell-dirtrack-mode-showing-up-as-enabled-in-unr.patch Content-Transfer-Encoding: quoted-printable >From 623704526b081c0d453a84d517f9d02035755504 Mon Sep 17 00:00:00 2001 From: Vladimir Sedach 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=3DUTF-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 =E2=80=98shell-dirtrack-mode=E2=80=99. --- 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.") =20 -(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.") =20 (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. =20 +(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 n= il 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. =20 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))) =20 -(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 n= il 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))) =20 (defun shell-resync-dirs () --=20 2.20.1 --=-=-=--