Mercurial > emacs
comparison lisp/files.el @ 2575:1c5dca7628cb
(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.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Sun, 25 Apr 1993 06:14:06 +0000 |
parents | 61e4e09e7243 |
children | d22e01f5ab0c |
comparison
equal
deleted
inserted
replaced
2574:c782b69b60a4 | 2575:1c5dca7628cb |
---|---|
224 The command \\[normal-mode] always obeys local-variables lists | 224 The command \\[normal-mode] always obeys local-variables lists |
225 and ignores this variable.") | 225 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)) |
243 (setq dir (file-name-as-directory dir))) | 258 (setq dir (file-name-as-directory dir))) |
244 (if (not (file-directory-p dir)) | 259 (if (not (file-directory-p dir)) |
245 (error "%s is not a directory" dir) | 260 (error "%s is not a directory" dir) |
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 ) |
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 ) | |
253 | 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: ") |
257 (load (expand-file-name file) nil nil t)) | 292 (load (expand-file-name file) nil nil t)) |