unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jason Kim <jason.kim@revtera.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Jason Kim <jason.w.kim@icloud.com>,
	michael.albinus@gmx.de, shivers@cs.cmu.edu, emacs-devel@gnu.org
Subject: Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh)
Date: Mon, 24 May 2021 10:20:15 -0700	[thread overview]
Message-ID: <fb245856-9114-bc7e-262b-8c8c9ec02baf@revtera.com> (raw)
In-Reply-To: <a7f7eef4-35d3-8673-9db7-846a16b77465@revtera.com>

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

Wooops sent too soon.

changed: identified the function touched in shell.el in commitlog


Thanks!
-Jason


[-- Attachment #2: 0001-Auto-cd-support-for-lisp-shell.el.patch --]
[-- Type: text/x-patch, Size: 2567 bytes --]

From bbdd6f2665c70e15ccc23f48d664eb6e20df7fa6 Mon Sep 17 00:00:00 2001
From: Jason Kim <jason.kim@revtera.com>
Date: Mon, 24 May 2021 10:04:54 -0700
Subject: [PATCH] Auto-cd support for lisp/shell.el

Added a new defcustom shell-has-auto-cd (default: nil) for
users with shells like zsh that can auto-cd into a directory
without typing in the "cd" command.
If set to true and the command is a directory, then
shell-directory-tracker processes the command (which happens to be a
directory) as if it were prepended with "cd"
---
 lisp/shell.el | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lisp/shell.el b/lisp/shell.el
index 3098d3a14d..8ea6176896 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -321,6 +321,16 @@ shell-last-dir
 (defvar shell-dirstack-query nil
   "Command used by `shell-resync-dirs' to query the shell.")
 
+(defcustom shell-has-auto-cd nil
+  "If non-nil, `shell-mode' handles implicit \"cd\" commands.
+Implicit \"cd\" is changing the directory if the command is a directory.
+You can make this variable buffer-local to change it, per shell-mode instance
+Useful for shells like zsh that has this feature."
+  :type 'boolean
+  :group 'shell-directories
+  :version "28")
+
+
 (defvar shell-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "\C-c\C-f" 'shell-forward-command)
@@ -836,13 +846,15 @@ shell-directory-tracker
 			       str) ; skip whitespace
 			      (match-end 0)))
 		(case-fold-search)
-		end cmd arg1)
+		end cmd arg1 cmd-subst-fn)
 	    (while (string-match shell-command-regexp str start)
 	      (setq end (match-end 0)
 		    cmd (comint-arguments (substring str start end) 0 0)
 		    arg1 (comint-arguments (substring str start end) 1 1))
 	      (if arg1
 		  (setq arg1 (shell-unquote-argument arg1)))
+              (if shell-has-auto-cd
+                  (setq cmd-subst-fn (comint-substitute-in-file-name cmd)))
 	      (cond ((string-match (concat "\\`\\(" shell-popd-regexp
 					   "\\)\\($\\|[ \t]\\)")
 				   cmd)
@@ -859,7 +871,9 @@ shell-directory-tracker
 			  (string-match (concat "\\`\\(" shell-chdrive-regexp
 						"\\)\\($\\|[ \t]\\)")
 					cmd))
-		     (shell-process-cd (comint-substitute-in-file-name cmd))))
+		     (shell-process-cd (comint-substitute-in-file-name cmd)))
+                    ((and shell-has-auto-cd (file-directory-p cmd-subst-fn))
+                     (shell-process-cd cmd-subst-fn)))
 	      (setq start (progn (string-match shell-command-separator-regexp
 					       str end)
 				 ;; skip again
-- 
2.25.1


  reply	other threads:[~2021-05-24 17:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 19:55 Small shell-mode patch to handle auto-cd (e.g. shells like zsh) Jason Kim
2021-05-06  8:10 ` Michael Albinus
2021-05-06  8:23 ` Eli Zaretskii
2021-05-07 16:35   ` Jason Kim
2021-05-07 16:51     ` Jason Kim
2021-05-15  8:20       ` Eli Zaretskii
2021-05-24 17:15         ` Jason Kim
2021-05-24 17:20           ` Jason Kim [this message]
2021-05-25  7:38             ` Michael Albinus
2021-05-27 17:09               ` Jason Kim
2021-06-09 11:03                 ` Michael Albinus
2021-05-07 17:39     ` Michael Albinus
2021-05-08  6:36     ` Eli Zaretskii
2021-05-08 16:39       ` Jason Kim
2021-05-08 16:48         ` Eli Zaretskii
2021-05-08 17:19           ` Jason Kim
2021-05-08 17:58             ` Jason Kim

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=fb245856-9114-bc7e-262b-8c8c9ec02baf@revtera.com \
    --to=jason.kim@revtera.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=jason.w.kim@icloud.com \
    --cc=michael.albinus@gmx.de \
    --cc=shivers@cs.cmu.edu \
    /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).