aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Kim2021-06-09 11:44:34 +0200
committerMichael Albinus2021-06-09 11:44:34 +0200
commite67883bc2b99f48a3c46c3d8a00123306a62b27d (patch)
tree82f05c626d897f2d3fe642eaaf1960facf73df85
parent4a1e97bea96a3ed075cfbc09f4268ba5be9e44fd (diff)
downloademacs-e67883bc2b99f48a3c46c3d8a00123306a62b27d.tar.gz
emacs-e67883bc2b99f48a3c46c3d8a00123306a62b27d.zip
Handle auto-cd in shell-mode
* lisp/shell.el (shell-has-auto-cd): New defcustom. (shell-directory-tracker): Handle implicit "cd". Copyright-paperwork-exempt: yes
-rw-r--r--lisp/shell.el17
1 files changed, 15 insertions, 2 deletions
diff --git a/lisp/shell.el b/lisp/shell.el
index 3098d3a14da..62de5be8172 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -321,6 +321,15 @@ Thus, this does not include the shell's current directory.")
321(defvar shell-dirstack-query nil 321(defvar shell-dirstack-query nil
322 "Command used by `shell-resync-dirs' to query the shell.") 322 "Command used by `shell-resync-dirs' to query the shell.")
323 323
324(defcustom shell-has-auto-cd nil
325 "If non-nil, `shell-mode' handles implicit \"cd\" commands.
326Implicit \"cd\" is changing the directory if the command is a directory.
327You can make this variable buffer-local to change it, per shell-mode instance.
328Useful for shells like zsh that has this feature."
329 :type 'boolean
330 :group 'shell-directories
331 :version "28.1")
332
324(defvar shell-mode-map 333(defvar shell-mode-map
325 (let ((map (make-sparse-keymap))) 334 (let ((map (make-sparse-keymap)))
326 (define-key map "\C-c\C-f" 'shell-forward-command) 335 (define-key map "\C-c\C-f" 'shell-forward-command)
@@ -836,13 +845,15 @@ Environment variables are expanded, see function `substitute-in-file-name'."
836 str) ; skip whitespace 845 str) ; skip whitespace
837 (match-end 0))) 846 (match-end 0)))
838 (case-fold-search) 847 (case-fold-search)
839 end cmd arg1) 848 end cmd arg1 cmd-subst-fn)
840 (while (string-match shell-command-regexp str start) 849 (while (string-match shell-command-regexp str start)
841 (setq end (match-end 0) 850 (setq end (match-end 0)
842 cmd (comint-arguments (substring str start end) 0 0) 851 cmd (comint-arguments (substring str start end) 0 0)
843 arg1 (comint-arguments (substring str start end) 1 1)) 852 arg1 (comint-arguments (substring str start end) 1 1))
844 (if arg1 853 (if arg1
845 (setq arg1 (shell-unquote-argument arg1))) 854 (setq arg1 (shell-unquote-argument arg1)))
855 (if shell-has-auto-cd
856 (setq cmd-subst-fn (comint-substitute-in-file-name cmd)))
846 (cond ((string-match (concat "\\`\\(" shell-popd-regexp 857 (cond ((string-match (concat "\\`\\(" shell-popd-regexp
847 "\\)\\($\\|[ \t]\\)") 858 "\\)\\($\\|[ \t]\\)")
848 cmd) 859 cmd)
@@ -859,7 +870,9 @@ Environment variables are expanded, see function `substitute-in-file-name'."
859 (string-match (concat "\\`\\(" shell-chdrive-regexp 870 (string-match (concat "\\`\\(" shell-chdrive-regexp
860 "\\)\\($\\|[ \t]\\)") 871 "\\)\\($\\|[ \t]\\)")
861 cmd)) 872 cmd))
862 (shell-process-cd (comint-substitute-in-file-name cmd)))) 873 (shell-process-cd (comint-substitute-in-file-name cmd)))
874 ((and shell-has-auto-cd (file-directory-p cmd-subst-fn))
875 (shell-process-cd cmd-subst-fn)))
863 (setq start (progn (string-match shell-command-separator-regexp 876 (setq start (progn (string-match shell-command-separator-regexp
864 str end) 877 str end)
865 ;; skip again 878 ;; skip again