unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jason Kim <jason.w.kim@icloud.com>
To: Eli Zaretskii <eliz@gnu.org>, michael.albinus@gmx.de
Cc: emacs-devel@gnu.org, shivers@cs.cmu.edu, jason.kim@revtera.com
Subject: Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh)
Date: Fri, 7 May 2021 09:51:08 -0700	[thread overview]
Message-ID: <6cb49320-ca9e-9212-13c8-78aa0a4f7dde@icloud.com> (raw)
In-Reply-To: <fb8c004a-5ec4-fa33-c1ba-0e5682a46530@icloud.com>

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

Hi, enclosed is what I hope is an acceptable git-format-patch for this 
tiny change.

If not, please let me know how to fix!

Thanks!
-Jason




[-- Attachment #2: 0001-Add-a-defcustom-to-shell-mode-to-handle-auto-cd-feat.patch --]
[-- Type: text/x-patch, Size: 2699 bytes --]

From 7dca68a6289abb1800b2dccfd26efe0e85aad6a4 Mon Sep 17 00:00:00 2001
From: Jason Kim <jason.kim@revtera.com>
Date: Fri, 7 May 2021 09:41:11 -0700
Subject: [PATCH] Add a defcustom to shell-mode to handle auto-cd feature (e.g.
 zsh)

shell-has-auto-cd is a new defcustom (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-mode
processes the command (which happens to be a directory) as if it
were prepended with "cd"
---
 lisp/shell.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/shell.el b/lisp/shell.el
index 3098d3a14d..8b3499ccb4 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -321,6 +321,13 @@ Thus, this does not include the shell's current directory.")
 (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' will automatically process implicit \"cd\" commands.
+Implicit \"cd\" is changing the directory if the command happens to be 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.")
+
+
 (defvar shell-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "\C-c\C-f" 'shell-forward-command)
@@ -836,13 +843,15 @@ Environment variables are expanded, see function `substitute-in-file-name'."
 			       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 +868,9 @@ Environment variables are expanded, see function `substitute-in-file-name'."
 			  (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-07 16:51 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 [this message]
2021-05-15  8:20       ` Eli Zaretskii
2021-05-24 17:15         ` Jason Kim
2021-05-24 17:20           ` Jason Kim
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=6cb49320-ca9e-9212-13c8-78aa0a4f7dde@icloud.com \
    --to=jason.w.kim@icloud.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=jason.kim@revtera.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).