>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=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