Mercurial > emacs
comparison lisp/shell.el @ 5474:239620e1795d
(shell-cd): Function removed.
(shell-prefixed-directory-name): New defsubst.
(shell-process-popd, shell-process-pushd, shell-process-cd,
shell-resync-dirs): Apply it to ARG when it's a directory name.
Use (concat comint-file-name-prefix "~") in place of (getenv "HOME") or "~".
Call cd instead of shell-cd.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Thu, 06 Jan 1994 17:02:00 +0000 |
parents | abf0d4d01681 |
children | 9d84549e89b4 |
comparison
equal
deleted
inserted
replaced
5473:e080a27c1dd6 | 5474:239620e1795d |
---|---|
414 (shell-process-cd (substitute-in-file-name arg1)))) | 414 (shell-process-cd (substitute-in-file-name arg1)))) |
415 (setq start (progn (string-match "[;\\s ]*" str end) ; skip again | 415 (setq start (progn (string-match "[;\\s ]*" str end) ; skip again |
416 (match-end 0))))) | 416 (match-end 0))))) |
417 (error (message "Couldn't cd"))))) | 417 (error (message "Couldn't cd"))))) |
418 | 418 |
419 | |
420 ;; Like `cd', but prepends comint-file-name-prefix to absolute names. | |
421 (defsubst shell-cd (directory) | |
422 (if (file-name-absolute-p directory) | |
423 (cd-absolute (concat comint-file-name-prefix directory)) | |
424 (cd directory))) | |
425 | |
426 ;;; popd [+n] | 419 ;;; popd [+n] |
427 (defun shell-process-popd (arg) | 420 (defun shell-process-popd (arg) |
428 (let ((num (or (shell-extract-num arg) 0))) | 421 (let ((num (or (shell-extract-num arg) 0))) |
429 (cond ((and num (= num 0) shell-dirstack) | 422 (cond ((and num (= num 0) shell-dirstack) |
430 (shell-cd (car shell-dirstack)) | 423 (cd (car shell-dirstack)) |
431 (setq shell-dirstack (cdr shell-dirstack)) | 424 (setq shell-dirstack (cdr shell-dirstack)) |
432 (shell-dirstack-message)) | 425 (shell-dirstack-message)) |
433 ((and num (> num 0) (<= num (length shell-dirstack))) | 426 ((and num (> num 0) (<= num (length shell-dirstack))) |
434 (let* ((ds (cons nil shell-dirstack)) | 427 (let* ((ds (cons nil shell-dirstack)) |
435 (cell (nthcdr (1- num) ds))) | 428 (cell (nthcdr (1- num) ds))) |
437 (setq shell-dirstack (cdr ds)) | 430 (setq shell-dirstack (cdr ds)) |
438 (shell-dirstack-message))) | 431 (shell-dirstack-message))) |
439 (t | 432 (t |
440 (error (message "Couldn't popd.")))))) | 433 (error (message "Couldn't popd.")))))) |
441 | 434 |
435 ;; Return DIR prefixed with comint-file-name-prefix as appropriate. | |
436 (defsubst shell-prefixed-directory-name (dir) | |
437 (if (file-name-absolute-p dir) | |
438 ;; The name is absolute, so prepend the prefix. | |
439 (concat comint-file-name-prefix dir) | |
440 ;; For a relative name we assume default-directory already has the prefix. | |
441 (expand-file-name dir))) | |
442 | |
442 ;;; cd [dir] | 443 ;;; cd [dir] |
443 (defun shell-process-cd (arg) | 444 (defun shell-process-cd (arg) |
444 (let ((new-dir (cond ((zerop (length arg)) (getenv "HOME")) | 445 (let ((new-dir (cond ((zerop (length arg)) (concat comint-file-name-prefix |
446 "~")) | |
445 ((string-equal "-" arg) shell-last-dir) | 447 ((string-equal "-" arg) shell-last-dir) |
446 (t arg)))) | 448 (t (shell-prefixed-directory-name arg))))) |
447 (setq shell-last-dir default-directory) | 449 (setq shell-last-dir default-directory) |
448 (shell-cd new-dir) | 450 (cd new-dir) |
449 (shell-dirstack-message))) | 451 (shell-dirstack-message))) |
450 | 452 |
451 ;;; pushd [+n | dir] | 453 ;;; pushd [+n | dir] |
452 (defun shell-process-pushd (arg) | 454 (defun shell-process-pushd (arg) |
453 (let ((num (shell-extract-num arg))) | 455 (let ((num (shell-extract-num arg))) |
454 (cond ((zerop (length arg)) | 456 (cond ((zerop (length arg)) |
455 ;; no arg -- swap pwd and car of stack unless shell-pushd-tohome | 457 ;; no arg -- swap pwd and car of stack unless shell-pushd-tohome |
456 (cond (shell-pushd-tohome | 458 (cond (shell-pushd-tohome |
457 (shell-process-pushd "~")) | 459 (shell-process-pushd (concat comint-file-name-prefix "~"))) |
458 (shell-dirstack | 460 (shell-dirstack |
459 (let ((old default-directory)) | 461 (let ((old default-directory)) |
460 (shell-cd (car shell-dirstack)) | 462 (cd (car shell-dirstack)) |
461 (setq shell-dirstack | 463 (setq shell-dirstack |
462 (cons old (cdr shell-dirstack))) | 464 (cons old (cdr shell-dirstack))) |
463 (shell-dirstack-message))) | 465 (shell-dirstack-message))) |
464 (t | 466 (t |
465 (message "Directory stack empty.")))) | 467 (message "Directory stack empty.")))) |
471 (error (message "Couldn't cd."))) | 473 (error (message "Couldn't cd."))) |
472 (shell-pushd-dextract | 474 (shell-pushd-dextract |
473 (let ((dir (nth (1- num) shell-dirstack))) | 475 (let ((dir (nth (1- num) shell-dirstack))) |
474 (shell-process-popd arg) | 476 (shell-process-popd arg) |
475 (shell-process-pushd default-directory) | 477 (shell-process-pushd default-directory) |
476 (shell-cd dir) | 478 (cd dir) |
477 (shell-dirstack-message))) | 479 (shell-dirstack-message))) |
478 (t | 480 (t |
479 (let* ((ds (cons default-directory shell-dirstack)) | 481 (let* ((ds (cons default-directory shell-dirstack)) |
480 (dslen (length ds)) | 482 (dslen (length ds)) |
481 (front (nthcdr num ds)) | 483 (front (nthcdr num ds)) |
482 (back (reverse (nthcdr (- dslen num) (reverse ds)))) | 484 (back (reverse (nthcdr (- dslen num) (reverse ds)))) |
483 (new-ds (append front back))) | 485 (new-ds (append front back))) |
484 (shell-cd (car new-ds)) | 486 (cd (car new-ds)) |
485 (setq shell-dirstack (cdr new-ds)) | 487 (setq shell-dirstack (cdr new-ds)) |
486 (shell-dirstack-message))))) | 488 (shell-dirstack-message))))) |
487 (t | 489 (t |
488 ;; pushd <dir> | 490 ;; pushd <dir> |
489 (let ((old-wd default-directory)) | 491 (let ((old-wd default-directory)) |
490 (shell-cd arg) | 492 (cd (shell-prefixed-directory-name arg)) |
491 (if (or (null shell-pushd-dunique) | 493 (if (or (null shell-pushd-dunique) |
492 (not (member old-wd shell-dirstack))) | 494 (not (member old-wd shell-dirstack))) |
493 (setq shell-dirstack (cons old-wd shell-dirstack))) | 495 (setq shell-dirstack (cons old-wd shell-dirstack))) |
494 (shell-dirstack-message)))))) | 496 (shell-dirstack-message)))))) |
495 | 497 |
541 (ds '()) ; new dir stack | 543 (ds '()) ; new dir stack |
542 (i 0)) | 544 (i 0)) |
543 (while (< i dl-len) | 545 (while (< i dl-len) |
544 ;; regexp = optional whitespace, (non-whitespace), optional whitespace | 546 ;; regexp = optional whitespace, (non-whitespace), optional whitespace |
545 (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir | 547 (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir |
546 (setq ds (cons (substring dl (match-beginning 1) (match-end 1)) | 548 (setq ds (cons (concat comint-file-name-prefix |
549 (substring dl (match-beginning 1) | |
550 (match-end 1))) | |
547 ds)) | 551 ds)) |
548 (setq i (match-end 0))) | 552 (setq i (match-end 0))) |
549 (let ((ds (reverse ds))) | 553 (let ((ds (nreverse ds))) |
550 (condition-case nil | 554 (condition-case nil |
551 (progn (cd (car ds)) | 555 (progn (cd (car ds)) |
552 (setq shell-dirstack (cdr ds)) | 556 (setq shell-dirstack (cdr ds)) |
553 (shell-dirstack-message)) | 557 (shell-dirstack-message)) |
554 (error (message "Couldn't cd."))))))) | 558 (error (message "Couldn't cd."))))))) |