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: Mon, 24 May 2021 10:15:38 -0700 Message-ID: References: <83v97we0ey.fsf@gnu.org> <6cb49320-ca9e-9212-13c8-78aa0a4f7dde@icloud.com> <83cztsxvb8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------A3F9713A69910662C541D6A1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3941"; 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: Jason Kim , michael.albinus@gmx.de, shivers@cs.cmu.edu, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 24 19:27:35 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 1llEMX-0000km-Ov for ged-emacs-devel@m.gmane-mx.org; Mon, 24 May 2021 19:27:33 +0200 Original-Received: from localhost ([::1]:52584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llEMW-00058r-BO for ged-emacs-devel@m.gmane-mx.org; Mon, 24 May 2021 13:27:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llEBW-0004Qg-PY for emacs-devel@gnu.org; Mon, 24 May 2021 13:16:12 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:38939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llEBL-0000Ac-UW; Mon, 24 May 2021 13:16:10 -0400 Original-Received: (Authenticated sender: jason.kim@revtera.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id E8133C0003; Mon, 24 May 2021 17:15:44 +0000 (UTC) In-Reply-To: <83cztsxvb8.fsf@gnu.org> Content-Language: en-US Received-SPF: pass client-ip=217.70.183.198; envelope-from=jason.kim@revtera.com; helo=relay6-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, 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:269782 Archived-At: This is a multi-part message in MIME format. --------------A3F9713A69910662C541D6A1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 >> 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. > --------------A3F9713A69910662C541D6A1 Content-Type: text/x-patch; charset=UTF-8; name="0001-Auto-cd-support-for-lisp-shell.el.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Auto-cd-support-for-lisp-shell.el.patch" >From a49a4430a16e291409fedcc6f7529da496919b6e 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-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 --------------A3F9713A69910662C541D6A1--