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:15:38 -0700	[thread overview]
Message-ID: <a7f7eef4-35d3-8673-9db7-846a16b77465@revtera.com> (raw)
In-Reply-To: <83cztsxvb8.fsf@gnu.org>

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

Sorry for the delay in response!
Thank you (especially to Eli!) for your guidance.

I set :version to "28", but I don't see an issue with applying this 
patch to earlier versions.

All of the nits are I think fixed.

Please find enclosed new format-patch patch.

Thanks again!
-Jason

On 5/15/21 1:20 AM, Eli Zaretskii wrote:
>> Cc: emacs-devel@gnu.org, shivers@cs.cmu.edu, jason.kim@revtera.com
>> From: Jason Kim <jason.w.kim@icloud.com>
>> Date: Fri, 7 May 2021 09:51:08 -0700
>>
>> 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!
> 
> Applying these patches produces the following byte-compilation
> warnings:
> 
>     ELC      shell.elc
> 
>   In toplevel form:
>   shell.el:324:1: Warning: defcustom for `shell-has-auto-cd' fails to specify
>       type
>   shell.el:324:1: Warning: custom-declare-variable `shell-has-auto-cd' docstring
>       wider than 80 characters
> 
> In addition, please provide a :version tag for the new defcustom.
> 
> And finally, the commit log message should include ChangeLog-style
> description of the file(s) and functions/variables which were affected
> by the changes, see the existing log messages and the advice in
> CONTRIBUTE for more details.
> 
> Please fix those minor nits, and then we will be able to install the
> changes.
> 
> Thanks.
> 

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

From a49a4430a16e291409fedcc6f7529da496919b6e 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-mode
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:15 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 [this message]
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=a7f7eef4-35d3-8673-9db7-846a16b77465@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).