From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jason Kim Newsgroups: gmane.emacs.devel Subject: Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) Date: Thu, 27 May 2021 10:09:25 -0700 Message-ID: <50594491-8781-dee6-4a7e-544a1eeb7a3e@revtera.com> References: <83v97we0ey.fsf@gnu.org> <6cb49320-ca9e-9212-13c8-78aa0a4f7dde@icloud.com> <83cztsxvb8.fsf@gnu.org> <874kerntyl.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------E05C9E4953DF17BF722AF90B" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1590"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 Cc: Eli Zaretskii , Jason Kim , shivers@cs.cmu.edu, emacs-devel@gnu.org To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 27 19:11:06 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lmJXG-0000Cb-82 for ged-emacs-devel@m.gmane-mx.org; Thu, 27 May 2021 19:11:06 +0200 Original-Received: from localhost ([::1]:39678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmJXF-0000EM-A8 for ged-emacs-devel@m.gmane-mx.org; Thu, 27 May 2021 13:11:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmJW5-0007v8-6e for emacs-devel@gnu.org; Thu, 27 May 2021 13:09:53 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:38515) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmJW2-0007DE-Pd; Thu, 27 May 2021 13:09:52 -0400 Original-Received: (Authenticated sender: jason.kim@revtera.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id E8BF340004; Thu, 27 May 2021 17:09:38 +0000 (UTC) In-Reply-To: <874kerntyl.fsf@gmx.de> Content-Language: en-US Received-SPF: pass client-ip=217.70.183.194; envelope-from=jason.kim@revtera.com; helo=relay2-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269953 Archived-At: This is a multi-part message in MIME format. --------------E05C9E4953DF17BF722AF90B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Woops is all I can say. After reading the CONTRIBUTE more carefully (and trying out git am locally and comparing to existing commit logs, I think I finally get it :-) Profuse apologies for wasted bandwidth. Updated :version to 28.1 as requested, and now I believe the commit log is finally up to snuff. Thanks again! On 5/25/21 12:38 AM, Michael Albinus wrote: > Jason Kim writes: > > Hi Jason, > >> From bbdd6f2665c70e15ccc23f48d664eb6e20df7fa6 Mon Sep 17 00:00:00 2001 >> From: Jason Kim >> 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" > > FTR, the commit message shall have a ChangeLog style. > >> +(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") > > This should be "28.1". > >> Thanks! >> -Jason > > Best regards, Michael. > --------------E05C9E4953DF17BF722AF90B Content-Type: text/x-patch; charset=UTF-8; name="0001-Auto-cd-support-for-shells-like-zsh.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Auto-cd-support-for-shells-like-zsh.patch" >From 178d645a572a4a8a495930348ba07aea134b8617 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Mon, 24 May 2021 10:04:54 -0700 Subject: [PATCH] Auto-cd support for shells like zsh Added a new defcustom shell-has-auto-cd (default: nil) For shells like zsh that can auto-cd into a directory without typing in the "cd" command, this change adds completion support for directory contents. * lisp/shell.el (shell-directory-tracker): handle implict "cd" --- lisp/shell.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lisp/shell.el b/lisp/shell.el index 3098d3a14d..49725f7310 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.1") + + (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 --------------E05C9E4953DF17BF722AF90B--