* Small shell-mode patch to handle auto-cd (e.g. shells like zsh) @ 2021-05-05 19:55 Jason Kim 2021-05-06 8:10 ` Michael Albinus 2021-05-06 8:23 ` Eli Zaretskii 0 siblings, 2 replies; 17+ messages in thread From: Jason Kim @ 2021-05-05 19:55 UTC (permalink / raw) To: emacs-devel, shivers, emacs-devel, jason.kim [-- Attachment #1: Type: text/plain, Size: 493 bytes --] Hi, Please find enclosed a small patch against emacs-lisp (packaged with emacs 26.3 on recent emacsen on recent ubuntu (20.4.0.2 ?) I'd be more than happy to do the leg work to get it "install ready" but may need some advice on how to do that. This patch works in live emacs after eval-region of the changes. I have no idea who to contact on ubuntu side to get it accelerated in. Thanks for reading. Please let me know if you need any additional reformatting etc... Thank you -Jason [-- Attachment #2: emacs-lisp.shell.track.auto-cd.patch.gz --] [-- Type: application/gzip, Size: 776 bytes --] ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 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 1 sibling, 0 replies; 17+ messages in thread From: Michael Albinus @ 2021-05-06 8:10 UTC (permalink / raw) To: Jason Kim; +Cc: jason.kim, shivers, emacs-devel Jason Kim <jason.w.kim@icloud.com> writes: Hi Jason, > Hi, Please find enclosed a small patch against emacs-lisp (packaged > with emacs 26.3 on recent emacsen on recent ubuntu (20.4.0.2 ?) Thanks for this proposal. I don't use shell-process-cd myself, at least not explicitly, but I have some few comments: +(defvar shell-has-auto-cd nil + "if set to true, shell-mode assumes that a command that resolves to a directory +is an implicit cd command. Useful for shells like zsh that has this feature.") - The docstring must be a complete sentence in the first line, starting with a capital letter, and finishing with a period. The separator between two sentences are newline or two (!) spaces. See the emacs documentation standards (info "(elisp) Documentation Tips") - I suppose you want to let people change this. So it should be rather a defcustom but a defvar. - The initial value could be more intelligent. Instead of using nil, you might check the used shell file name whether it matches, for example, "zsh$". - Several different shells could be used in an Emacs session, depending where you run the shell, locally or on a remote host. So it might be problematic to have just one fixed global value. > Thank you > -Jason Best regards, Michael. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 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 1 sibling, 1 reply; 17+ messages in thread From: Eli Zaretskii @ 2021-05-06 8:23 UTC (permalink / raw) To: Jason Kim; +Cc: shivers, emacs-devel > From: Jason Kim <jason.w.kim@icloud.com> > Date: Wed, 5 May 2021 12:55:07 -0700 > > Hi, Please find enclosed a small patch against emacs-lisp (packaged with > emacs 26.3 on recent emacsen on recent ubuntu (20.4.0.2 ?) > > I'd be more than happy to do the leg work to get it "install ready" but > may need some advice on how to do that. Thanks. Some comments on your patch: . We prefer patches relative to the current development sources on the master branch of the Emacs Git repository. Would it be possible for you to update the patch so it is relative to the latest sources? If so, please also send the diffs using the command "git format-patch", as it makes it easier to apply the diffs. . Please accompany the changeset with a ChangeLog-style commit log message; see the file CONTRIBUTE for the details of how to format the log message according to our conventions. . A few comments on the code itself: > +(defvar shell-has-auto-cd nil > + "if set to true, shell-mode assumes that a command that resolves to a directory > +is an implicit cd command. Useful for shells like zsh that has this feature.") This should be a defcustom, so that users could customize it easily. The first line of the doc string should be a single complete sentence. Something like this: If non-nil, `shell-mode' will automatically process implicit \"cd\" commands. (Then in the following text of the doc string explain what does "implicit cd command" mean in this context.) Should this variable's value be computed automatically based on the shell's name? > - end cmd arg1) > + end cmd arg1 cmdS) I wonder if you could find a more descriptive name for the cmdS variable. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-06 8:23 ` Eli Zaretskii @ 2021-05-07 16:35 ` Jason Kim 2021-05-07 16:51 ` Jason Kim ` (2 more replies) 0 siblings, 3 replies; 17+ messages in thread From: Jason Kim @ 2021-05-07 16:35 UTC (permalink / raw) To: Eli Zaretskii, michael.albinus; +Cc: emacs-devel, shivers, jason.kim Working on it now, Expect the git format-patch shortly But just to set the stage.... a few comments. On 5/6/21 1:23 AM, Eli Zaretskii wrote: > > . A few comments on the code itself: > >> +(defvar shell-has-auto-cd nil >> + "if set to true, shell-mode assumes that a command that resolves to a directory >> +is an implicit cd command. Useful for shells like zsh that has this feature.") > > This should be a defcustom, so that users could customize it easily. > done. > The first line of the doc string should be a single complete > sentence. Something like this: > > If non-nil, `shell-mode' will automatically process implicit \"cd\" commands. Yep that's lot better :-) thanks! > > (Then in the following text of the doc string explain what does > "implicit cd command" mean in this context.) > > Should this variable's value be computed automatically based on the > shell's name? I don't think so... If only because its an option that needs enabling in zsh as well? > >> - end cmd arg1) >> + end cmd arg1 cmdS) > > I wonder if you could find a more descriptive name for the cmdS > variable. cmdS --> cmd-subst-fn > michael.albinus@gmx.de writes >- Several different shells could be used in an Emacs session, depending > where you run the shell, locally or on a remote host. So it might be > problematic to have just one fixed global value. I'm confused...? Would making the variable buffer-local in a user's .emacs address this? dir tracking (for things like auto completion) never worked for me if I ssh into a different host from emacs-shell. (maybe because pattern globbing rules are more complex (optionally) in zsh?) What am I missing here? Can we skip this issue for now? (or does making the var buffer-local get around it?) Thank!!! -jason ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-07 16:35 ` Jason Kim @ 2021-05-07 16:51 ` Jason Kim 2021-05-15 8:20 ` Eli Zaretskii 2021-05-07 17:39 ` Michael Albinus 2021-05-08 6:36 ` Eli Zaretskii 2 siblings, 1 reply; 17+ messages in thread From: Jason Kim @ 2021-05-07 16:51 UTC (permalink / raw) To: Eli Zaretskii, michael.albinus; +Cc: emacs-devel, shivers, jason.kim [-- 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 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-07 16:51 ` Jason Kim @ 2021-05-15 8:20 ` Eli Zaretskii 2021-05-24 17:15 ` Jason Kim 0 siblings, 1 reply; 17+ messages in thread From: Eli Zaretskii @ 2021-05-15 8:20 UTC (permalink / raw) To: Jason Kim; +Cc: jason.kim, michael.albinus, shivers, emacs-devel > 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. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-15 8:20 ` Eli Zaretskii @ 2021-05-24 17:15 ` Jason Kim 2021-05-24 17:20 ` Jason Kim 0 siblings, 1 reply; 17+ messages in thread From: Jason Kim @ 2021-05-24 17:15 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Jason Kim, michael.albinus, shivers, emacs-devel [-- 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 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-24 17:15 ` Jason Kim @ 2021-05-24 17:20 ` Jason Kim 2021-05-25 7:38 ` Michael Albinus 0 siblings, 1 reply; 17+ messages in thread From: Jason Kim @ 2021-05-24 17:20 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Jason Kim, michael.albinus, shivers, emacs-devel [-- 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 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-24 17:20 ` Jason Kim @ 2021-05-25 7:38 ` Michael Albinus 2021-05-27 17:09 ` Jason Kim 0 siblings, 1 reply; 17+ messages in thread From: Michael Albinus @ 2021-05-25 7:38 UTC (permalink / raw) To: Jason Kim; +Cc: Eli Zaretskii, Jason Kim, shivers, emacs-devel Jason Kim <jason.kim@revtera.com> writes: Hi Jason, > 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" 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. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-25 7:38 ` Michael Albinus @ 2021-05-27 17:09 ` Jason Kim 2021-06-09 11:03 ` Michael Albinus 0 siblings, 1 reply; 17+ messages in thread From: Jason Kim @ 2021-05-27 17:09 UTC (permalink / raw) To: Michael Albinus; +Cc: Eli Zaretskii, Jason Kim, shivers, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1522 bytes --] 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 <jason.kim@revtera.com> writes: > > Hi Jason, > >> 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" > > 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. > [-- Attachment #2: 0001-Auto-cd-support-for-shells-like-zsh.patch --] [-- Type: text/x-patch, Size: 2518 bytes --] From 178d645a572a4a8a495930348ba07aea134b8617 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 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 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-27 17:09 ` Jason Kim @ 2021-06-09 11:03 ` Michael Albinus 0 siblings, 0 replies; 17+ messages in thread From: Michael Albinus @ 2021-06-09 11:03 UTC (permalink / raw) To: Jason Kim; +Cc: Eli Zaretskii, emacs-devel, Jason Kim, shivers Jason Kim <jason.kim@revtera.com> writes: Hi Jason, > Updated :version to 28.1 as requested, and now I believe the commit > log is finally up to snuff. There were still some minor nits, but I have fixed them silently. Committed to master, and also an entry in etc/NEWS. > Thanks again! Best regards, Michael. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-07 16:35 ` Jason Kim 2021-05-07 16:51 ` Jason Kim @ 2021-05-07 17:39 ` Michael Albinus 2021-05-08 6:36 ` Eli Zaretskii 2 siblings, 0 replies; 17+ messages in thread From: Michael Albinus @ 2021-05-07 17:39 UTC (permalink / raw) To: Jason Kim; +Cc: Eli Zaretskii, jason.kim, shivers, emacs-devel Jason Kim <jason.w.kim@icloud.com> writes: Hi Jason, >> michael.albinus@gmx.de writes >>- Several different shells could be used in an Emacs session, depending >> where you run the shell, locally or on a remote host. So it might be >> problematic to have just one fixed global value. > > I'm confused...? > Would making the variable buffer-local in a user's .emacs address this? No. I'm rather thinking about connection-local values. > dir tracking (for things like auto completion) never worked for me if > I ssh into a different host from emacs-shell. > (maybe because pattern globbing rules are more complex (optionally) in zsh?) > What am I missing here? I'm speaking about Tramp. That is, if your current buffer has a remote default-directory, and you start "M-x shell". > Can we skip this issue for now? (or does making the var buffer-local > get around it?) Sure. > Thank!!! > -jason Best regards, Michael. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-07 16:35 ` Jason Kim 2021-05-07 16:51 ` Jason Kim 2021-05-07 17:39 ` Michael Albinus @ 2021-05-08 6:36 ` Eli Zaretskii 2021-05-08 16:39 ` Jason Kim 2 siblings, 1 reply; 17+ messages in thread From: Eli Zaretskii @ 2021-05-08 6:36 UTC (permalink / raw) To: Jason Kim; +Cc: jason.kim, michael.albinus, shivers, emacs-devel > 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:35:16 -0700 > > > Should this variable's value be computed automatically based on the > > shell's name? > > I don't think so... If only because its an option that needs enabling in > zsh as well? Sorry, I don't think I understand. My understanding was that this feature is supported by some shells whose names are known in advance (like zsh), so Emacs could compute the value as appropriate for that shell without asking the user to set it. If this is not a good idea, can you explain why? Thanks. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-08 6:36 ` Eli Zaretskii @ 2021-05-08 16:39 ` Jason Kim 2021-05-08 16:48 ` Eli Zaretskii 0 siblings, 1 reply; 17+ messages in thread From: Jason Kim @ 2021-05-08 16:39 UTC (permalink / raw) To: Eli Zaretskii; +Cc: michael.albinus, emacs-devel, shivers, jason.kim On 5/7/21 11:36 PM, 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:35:16 -0700 >> >>> Should this variable's value be computed automatically based on the >>> shell's name? >> >> I don't think so... If only because its an option that needs enabling in >> zsh as well? > > Sorry, I don't think I understand. My understanding was that this > feature is supported by some shells whose names are known in advance > (like zsh), so Emacs could compute the value as appropriate for that > shell without asking the user to set it. If this is not a good idea, > can you explain why? > Hi, sorry for the confusion - auto-cd feature in zsh is optional. It is not on by default, and I don't know of a good way to detect whether a zsh process tied to a shell buffer has that option turned on. I think having this as a switch that individual users can set is probably the simplest way to handle this. AFAIK other common shells (bash, csh) doesn't yet have this feature either. In other words, it's the user's choice to use zsh, and the user's choice whether to turn that feature on. I do cd's all the time (prolly same for most folks), and I hate repeatedly typing a command to do it, so it's a neat feature in zsh that would be nice to support within emacs shell mode. Thanks for reading. I hope I made it clear. Thank you! -Jason > Thanks. > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-08 16:39 ` Jason Kim @ 2021-05-08 16:48 ` Eli Zaretskii 2021-05-08 17:19 ` Jason Kim 0 siblings, 1 reply; 17+ messages in thread From: Eli Zaretskii @ 2021-05-08 16:48 UTC (permalink / raw) To: Jason Kim; +Cc: jason.kim, michael.albinus, shivers, emacs-devel > Cc: michael.albinus@gmx.de, emacs-devel@gnu.org, shivers@cs.cmu.edu, > jason.kim@revtera.com > From: Jason Kim <jason.w.kim@icloud.com> > Date: Sat, 8 May 2021 09:39:48 -0700 > > > Sorry, I don't think I understand. My understanding was that this > > feature is supported by some shells whose names are known in advance > > (like zsh), so Emacs could compute the value as appropriate for that > > shell without asking the user to set it. If this is not a good idea, > > can you explain why? > > > > Hi, sorry for the confusion - > auto-cd feature in zsh is optional. It is not on by default, and I don't > know of a good way to detect whether a zsh process tied to a shell > buffer has that option turned on. Can't you ask zsh itself, by running some command once, when the mode is turned on? ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-08 16:48 ` Eli Zaretskii @ 2021-05-08 17:19 ` Jason Kim 2021-05-08 17:58 ` Jason Kim 0 siblings, 1 reply; 17+ messages in thread From: Jason Kim @ 2021-05-08 17:19 UTC (permalink / raw) To: Eli Zaretskii; +Cc: michael.albinus, emacs-devel, shivers, jason.kim On 5/8/21 9:48 AM, Eli Zaretskii wrote: >> Cc: michael.albinus@gmx.de, emacs-devel@gnu.org, shivers@cs.cmu.edu, >> jason.kim@revtera.com >> From: Jason Kim <jason.w.kim@icloud.com> >> Date: Sat, 8 May 2021 09:39:48 -0700 >> >>> Sorry, I don't think I understand. My understanding was that this >>> feature is supported by some shells whose names are known in advance >>> (like zsh), so Emacs could compute the value as appropriate for that >>> shell without asking the user to set it. If this is not a good idea, >>> can you explain why? >>> >> >> Hi, sorry for the confusion - >> auto-cd feature in zsh is optional. It is not on by default, and I don't >> know of a good way to detect whether a zsh process tied to a shell >> buffer has that option turned on. > > Can't you ask zsh itself, by running some command once, when the mode > is turned on? > Sure, I suppose, but why do it? I'm a zsh user and I'm perfectly fine with it as a switch that I can put in my .emacs :-) and hijacking comint like that can add glitches, and introduce irreproducibility (I automate creation of shells, pasting commands to comint etc..). Auto injecting commands to what should be a user-input space seems a bit wierd just to support this feature, and may not be optimal, because it is unexpected I'd be happy to help with this improvement, if that's REALLY what you want but it can add glitches to user's automation of shells, but I don't think its necessary (for now), and I humbly request we punt on it. Thanks! -Jason ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Small shell-mode patch to handle auto-cd (e.g. shells like zsh) 2021-05-08 17:19 ` Jason Kim @ 2021-05-08 17:58 ` Jason Kim 0 siblings, 0 replies; 17+ messages in thread From: Jason Kim @ 2021-05-08 17:58 UTC (permalink / raw) To: Jason Kim, Eli Zaretskii; +Cc: michael.albinus, shivers, emacs-devel On 5/8/21 10:19 AM, Jason Kim wrote: Eli, Hi, I'd like to walk back anything that may seem like a criticism. I did not mean to imply any such, and apologies if you were taken aback. The main point here simply is that AFAIK, the switch is the simplest, least intrusive way to get this very small support capability in to shell mode, and that additional upgrades are perfectly possible, but IMHO not apropos at the moment. Thanks again, and hopefully you guys are ok with it. -Jason > Sure, I suppose, but why do it? I'm a zsh user and I'm perfectly fine > with it as a switch that I can put in my .emacs :-) > > and hijacking comint like that can add glitches, and introduce > irreproducibility (I automate creation of shells, pasting commands to > comint etc..). > > Auto injecting commands to what should be a user-input space seems a bit > wierd just to support this feature, and may not be optimal, because it > is unexpected > > I'd be happy to help with this improvement, if that's REALLY what you > want but it can add glitches to user's automation of shells, but I don't > think its necessary (for now), and I humbly request we punt on it. > > Thanks! > -Jason > ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2021-06-09 11:03 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.