Mercurial > emacs
comparison lisp/shell.el @ 78770:6db70c3a1837
Chris Moore <dooglus at gmail.com>
(shell-resync-dirs): Don't move the cursor relative to the command
being edited.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 13 Sep 2007 07:26:32 +0000 |
parents | 9355f9b7bbff |
children | 73661ddc7ac7 |
comparison
equal
deleted
inserted
replaced
78769:ca61e14e02a6 | 78770:6db70c3a1837 |
---|---|
800 immediately after the query, its output will be taken as the | 800 immediately after the query, its output will be taken as the |
801 new directory stack -- you lose. If this happens, just do the | 801 new directory stack -- you lose. If this happens, just do the |
802 command again." | 802 command again." |
803 (interactive) | 803 (interactive) |
804 (let* ((proc (get-buffer-process (current-buffer))) | 804 (let* ((proc (get-buffer-process (current-buffer))) |
805 (pmark (process-mark proc))) | 805 (pmark (process-mark proc)) |
806 (goto-char pmark) | 806 (started-at-pmark (= (point) (marker-position pmark)))) |
807 ;; If the process echoes commands, don't insert a fake command in | 807 (save-excursion |
808 ;; the buffer or it will appear twice. | 808 (goto-char pmark) |
809 (unless comint-process-echoes | 809 ;; If the process echoes commands, don't insert a fake command in |
810 (insert shell-dirstack-query) (insert "\n")) | 810 ;; the buffer or it will appear twice. |
811 (sit-for 0) ; force redisplay | 811 (unless comint-process-echoes |
812 (comint-send-string proc shell-dirstack-query) | 812 (insert shell-dirstack-query) (insert "\n")) |
813 (comint-send-string proc "\n") | 813 (sit-for 0) ; force redisplay |
814 (set-marker pmark (point)) | 814 (comint-send-string proc shell-dirstack-query) |
815 (let ((pt (point)) | 815 (comint-send-string proc "\n") |
816 (regexp | 816 (set-marker pmark (point)) |
817 (concat | 817 (let ((pt (point)) |
818 (if comint-process-echoes | 818 (regexp |
819 ;; Skip command echo if the process echoes | 819 (concat |
820 (concat "\\(" (regexp-quote shell-dirstack-query) "\n\\)") | 820 (if comint-process-echoes |
821 "\\(\\)") | 821 ;; Skip command echo if the process echoes |
822 "\\(.+\n\\)"))) | 822 (concat "\\(" (regexp-quote shell-dirstack-query) "\n\\)") |
823 ;; This extra newline prevents the user's pending input from spoofing us. | 823 "\\(\\)") |
824 (insert "\n") (backward-char 1) | 824 "\\(.+\n\\)"))) |
825 ;; Wait for one line. | 825 ;; This extra newline prevents the user's pending input from spoofing us. |
826 (while (not (looking-at regexp)) | 826 (insert "\n") (backward-char 1) |
827 (accept-process-output proc) | 827 ;; Wait for one line. |
828 (goto-char pt))) | 828 (while (not (looking-at regexp)) |
829 (goto-char pmark) (delete-char 1) ; remove the extra newline | 829 (accept-process-output proc) |
830 ;; That's the dirlist. grab it & parse it. | 830 (goto-char pt))) |
831 (let* ((dl (buffer-substring (match-beginning 2) (1- (match-end 2)))) | 831 (goto-char pmark) (delete-char 1) ; remove the extra newline |
832 (dl-len (length dl)) | 832 ;; That's the dirlist. grab it & parse it. |
833 (ds '()) ; new dir stack | 833 (let* ((dl (buffer-substring (match-beginning 2) (1- (match-end 2)))) |
834 (i 0)) | 834 (dl-len (length dl)) |
835 (while (< i dl-len) | 835 (ds '()) ; new dir stack |
836 ;; regexp = optional whitespace, (non-whitespace), optional whitespace | 836 (i 0)) |
837 (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir | 837 (while (< i dl-len) |
838 (setq ds (cons (concat comint-file-name-prefix | 838 ;; regexp = optional whitespace, (non-whitespace), optional whitespace |
839 (substring dl (match-beginning 1) | 839 (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir |
840 (match-end 1))) | 840 (setq ds (cons (concat comint-file-name-prefix |
841 ds)) | 841 (substring dl (match-beginning 1) |
842 (setq i (match-end 0))) | 842 (match-end 1))) |
843 (let ((ds (nreverse ds))) | 843 ds)) |
844 (condition-case nil | 844 (setq i (match-end 0))) |
845 (progn (shell-cd (car ds)) | 845 (let ((ds (nreverse ds))) |
846 (setq shell-dirstack (cdr ds) | 846 (condition-case nil |
847 shell-last-dir (car shell-dirstack)) | 847 (progn (shell-cd (car ds)) |
848 (shell-dirstack-message)) | 848 (setq shell-dirstack (cdr ds) |
849 (error (message "Couldn't cd"))))))) | 849 shell-last-dir (car shell-dirstack)) |
850 (shell-dirstack-message)) | |
851 (error (message "Couldn't cd")))))) | |
852 (if started-at-pmark (goto-char (marker-position pmark))))) | |
850 | 853 |
851 ;; For your typing convenience: | 854 ;; For your typing convenience: |
852 (defalias 'dirs 'shell-resync-dirs) | 855 (defalias 'dirs 'shell-resync-dirs) |
853 | 856 |
854 | 857 |