diff options
| author | Eric S. Raymond | 1993-04-25 06:14:06 +0000 |
|---|---|---|
| committer | Eric S. Raymond | 1993-04-25 06:14:06 +0000 |
| commit | 231c4e102b6f4376747d154c15e80cdea5ca3b3f (patch) | |
| tree | 381f223def9d9fd0aa5a46b29819aad387f2ac2f | |
| parent | 41dc743ded9ab4a149804d2f0ce3c6758c121cdb (diff) | |
| download | emacs-231c4e102b6f4376747d154c15e80cdea5ca3b3f.tar.gz emacs-231c4e102b6f4376747d154c15e80cdea5ca3b3f.zip | |
(cd): Changed to use to resolve relative cd calls.
(cd-absolute): Added. This is actually the old cd code with a changed
doc string.
(parse-colon-path): Added. Path-to-string exploder --- may be useful elsewhere.
| -rw-r--r-- | lisp/files.el | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/lisp/files.el b/lisp/files.el index b9515ddfc7d..2820c235a07 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -226,17 +226,32 @@ and ignores this variable.") | |||
| 226 | 226 | ||
| 227 | ;; Avoid losing in versions where CLASH_DETECTION is disabled. | 227 | ;; Avoid losing in versions where CLASH_DETECTION is disabled. |
| 228 | (or (fboundp 'lock-buffer) | 228 | (or (fboundp 'lock-buffer) |
| 229 | (fset 'lock-buffer 'ignore)) | 229 | (defalias 'lock-buffer 'ignore)) |
| 230 | (or (fboundp 'unlock-buffer) | 230 | (or (fboundp 'unlock-buffer) |
| 231 | (fset 'unlock-buffer 'ignore)) | 231 | (defalias 'unlock-buffer 'ignore)) |
| 232 | 232 | ||
| 233 | (defun pwd () | 233 | (defun pwd () |
| 234 | "Show the current default directory." | 234 | "Show the current default directory." |
| 235 | (interactive nil) | 235 | (interactive nil) |
| 236 | (message "Directory %s" default-directory)) | 236 | (message "Directory %s" default-directory)) |
| 237 | 237 | ||
| 238 | (defun cd (dir) | 238 | (defvar cd-path nil |
| 239 | "Make DIR become the current buffer's default directory." | 239 | "Value of the CDPATH environment variable, as a list. |
| 240 | Not actually set up until the first time you you use it.") | ||
| 241 | |||
| 242 | (defun parse-colon-path (cd-path) | ||
| 243 | "Explode a colon-separated list of paths into a string list." | ||
| 244 | (and cd-path | ||
| 245 | (let (cd-prefix cd-list (cd-start 0) cd-colon) | ||
| 246 | (setq cd-path (concat cd-path ":")) | ||
| 247 | (while (setq cd-colon (string-match ":" cd-path cd-start)) | ||
| 248 | (setq cd-list | ||
| 249 | (nconc cd-list (list (substitute-in-file-name (file-name-as-directory (substring cd-path cd-start cd-colon)))))) | ||
| 250 | (setq cd-start (+ cd-colon 1))) | ||
| 251 | cd-list))) | ||
| 252 | |||
| 253 | (defun cd-absolute (dir) | ||
| 254 | "Change current directory to given absolute path DIR." | ||
| 240 | (interactive "DChange default directory: ") | 255 | (interactive "DChange default directory: ") |
| 241 | (setq dir (expand-file-name dir)) | 256 | (setq dir (expand-file-name dir)) |
| 242 | (if (not (eq system-type 'vax-vms)) | 257 | (if (not (eq system-type 'vax-vms)) |
| @@ -246,11 +261,31 @@ and ignores this variable.") | |||
| 246 | (if (file-executable-p dir) | 261 | (if (file-executable-p dir) |
| 247 | (setq default-directory dir) | 262 | (setq default-directory dir) |
| 248 | (error "Cannot cd to %s: Permission denied" dir))) | 263 | (error "Cannot cd to %s: Permission denied" dir))) |
| 249 | ;; We used to call pwd at this point. That's not terribly helpful | ||
| 250 | ;; when we're invoking cd interactively, and the new cmushell-based | ||
| 251 | ;; shell has its own (better) facilities for this. | ||
| 252 | ) | 264 | ) |
| 253 | 265 | ||
| 266 | (defun cd (dir) | ||
| 267 | "Make DIR become the current buffer's default directory. | ||
| 268 | If your environment imcludes a $CDPATH variable, cd tries each one of that | ||
| 269 | colon-separated list of directories when resolving a relative cd." | ||
| 270 | (interactive "FChange default directory: ") | ||
| 271 | (if (= (aref dir 0) ?/) | ||
| 272 | (cd-absolute (expand-file-name dir)) | ||
| 273 | (if (null cd-path) | ||
| 274 | (let ((trypath (parse-colon-path (getenv "CDPATH")))) | ||
| 275 | (setq cd-path (or trypath "./")))) | ||
| 276 | (if (not (catch 'found | ||
| 277 | (mapcar | ||
| 278 | (function (lambda (x) | ||
| 279 | (let ((f (expand-file-name (concat x dir)))) | ||
| 280 | (if (file-directory-p f) | ||
| 281 | (progn | ||
| 282 | (cd-absolute f) | ||
| 283 | (throw 'found t)))))) | ||
| 284 | cd-path) | ||
| 285 | nil)) | ||
| 286 | (error "No such directory on your cd path."))) | ||
| 287 | ) | ||
| 288 | |||
| 254 | (defun load-file (file) | 289 | (defun load-file (file) |
| 255 | "Load the Lisp file named FILE." | 290 | "Load the Lisp file named FILE." |
| 256 | (interactive "fLoad file: ") | 291 | (interactive "fLoad file: ") |