diff options
| author | Noah Friedman | 2020-08-19 15:59:59 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-08-19 15:59:59 +0200 |
| commit | 90e65c826fab2092ad2099d7763538194c93e021 (patch) | |
| tree | 2e5e49388d659926b5cd83ee959f6a114abed131 | |
| parent | 33a72465b53fd1dc71856ea4ad3376a05da35c73 (diff) | |
| download | emacs-90e65c826fab2092ad2099d7763538194c93e021.tar.gz emacs-90e65c826fab2092ad2099d7763538194c93e021.zip | |
Make shell-resync-dirs handle whitespace in directory names
* lisp/shell.el (shell-resync-dirs): Correctly handle
whitespace in directory names (bug#23324).
| -rw-r--r-- | lisp/shell.el | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/lisp/shell.el b/lisp/shell.el index 301a8cb0833..9667dab2afd 100644 --- a/lisp/shell.el +++ b/lisp/shell.el | |||
| @@ -1035,25 +1035,41 @@ command again." | |||
| 1035 | (accept-process-output proc) | 1035 | (accept-process-output proc) |
| 1036 | (goto-char pt))) | 1036 | (goto-char pt))) |
| 1037 | (goto-char pmark) (delete-char 1) ; remove the extra newline | 1037 | (goto-char pmark) (delete-char 1) ; remove the extra newline |
| 1038 | ;; That's the dirlist. grab it & parse it. | 1038 | ;; That's the dirlist. Grab it & parse it. |
| 1039 | (let* ((dl (buffer-substring (match-beginning 2) (1- (match-end 2)))) | 1039 | (let* ((dls (buffer-substring-no-properties |
| 1040 | (dl-len (length dl)) | 1040 | (match-beginning 0) (1- (match-end 0)))) |
| 1041 | (ds '()) ; new dir stack | 1041 | (dlsl nil) |
| 1042 | (i 0)) | 1042 | (pos 0) |
| 1043 | (while (< i dl-len) | 1043 | (ds nil)) |
| 1044 | ;; regexp = optional whitespace, (non-whitespace), optional whitespace | 1044 | ;; Split the dirlist into whitespace and non-whitespace chunks. |
| 1045 | (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir | 1045 | ;; dlsl will be a reversed list of tokens. |
| 1046 | (setq ds (cons (concat comint-file-name-prefix | 1046 | (while (string-match "\\(\\S-+\\|\\s-+\\)" dls pos) |
| 1047 | (substring dl (match-beginning 1) | 1047 | (push (match-string 1 dls) dlsl) |
| 1048 | (match-end 1))) | 1048 | (setq pos (match-end 1))) |
| 1049 | ds)) | 1049 | |
| 1050 | (setq i (match-end 0))) | 1050 | ;; Prepend trailing entries until they form an existing directory, |
| 1051 | (let ((ds (nreverse ds))) | 1051 | ;; whitespace and all. Discard the next whitespace and repeat. |
| 1052 | (with-demoted-errors "Couldn't cd: %s" | 1052 | (while dlsl |
| 1053 | (shell-cd (car ds)) | 1053 | (let ((newelt "") |
| 1054 | (setq shell-dirstack (cdr ds) | 1054 | tem1 tem2) |
| 1055 | shell-last-dir (car shell-dirstack)) | 1055 | (while newelt |
| 1056 | (shell-dirstack-message))))) | 1056 | ;; We need tem1 because we don't want to prepend |
| 1057 | ;; `comint-file-name-prefix' repeatedly into newelt via tem2. | ||
| 1058 | (setq tem1 (pop dlsl) | ||
| 1059 | tem2 (concat comint-file-name-prefix tem1 newelt)) | ||
| 1060 | (cond ((file-directory-p tem2) | ||
| 1061 | (push tem2 ds) | ||
| 1062 | (when (string= " " (car dlsl)) | ||
| 1063 | (pop dlsl)) | ||
| 1064 | (setq newelt nil)) | ||
| 1065 | (t | ||
| 1066 | (setq newelt (concat tem1 newelt))))))) | ||
| 1067 | |||
| 1068 | (with-demoted-errors "Couldn't cd: %s" | ||
| 1069 | (shell-cd (car ds)) | ||
| 1070 | (setq shell-dirstack (cdr ds) | ||
| 1071 | shell-last-dir (car shell-dirstack)) | ||
| 1072 | (shell-dirstack-message)))) | ||
| 1057 | (if started-at-pmark (goto-char (marker-position pmark))))) | 1073 | (if started-at-pmark (goto-char (marker-position pmark))))) |
| 1058 | 1074 | ||
| 1059 | ;; For your typing convenience: | 1075 | ;; For your typing convenience: |