Commit 4e43240a authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(make-directory): Renamed from make-directory-path.

Optional argument says whether to create parent dirs.
Invoke file-name handler here.
(after-find-file): Delete code that offers to create dir.
Instead, just print a message.
parent 353cfc19
...@@ -557,20 +557,13 @@ Finishes by calling the functions in `find-file-hooks'." ...@@ -557,20 +557,13 @@ Finishes by calling the functions in `find-file-hooks'."
"Note: file is write protected") "Note: file is write protected")
((file-attributes (directory-file-name default-directory)) ((file-attributes (directory-file-name default-directory))
"File not found and directory write-protected") "File not found and directory write-protected")
((file-exists-p (file-name-directory buffer-file-name))
(setq buffer-read-only nil))
(t (t
;; If the directory the buffer is in doesn't exist,
;; offer to create it. It's better to do this now
;; than when we save the buffer, because we want
;; autosaving to work.
(setq buffer-read-only nil) (setq buffer-read-only nil)
(or (file-exists-p (file-name-directory buffer-file-name)) (if (file-exists-p (file-name-directory (directory-file-name (file-name-directory buffer-file-name))))
(if (yes-or-no-p "Use M-x make-dir RET RET to create the directory"
(format "Use C-u M-x make-dir RET RET to create directory and its parents")))))
"The directory containing %s does not exist. Create? "
(abbreviate-file-name buffer-file-name)))
(file-name-directory buffer-file-name))))
(if msg (if msg
(progn (progn
(message msg) (message msg)
...@@ -1411,18 +1404,29 @@ or multiple mail buffers, etc." ...@@ -1411,18 +1404,29 @@ or multiple mail buffers, etc."
(rename-buffer name) (rename-buffer name)
(set-buffer-modified-p (buffer-modified-p)))) ; force mode line update (set-buffer-modified-p (buffer-modified-p)))) ; force mode line update
(defun make-directory-path (path) (defun make-directory (dir &optional parents)
"Create all the directories along path that don't exist yet." "Create the directory DIR and any nonexistent parent dirs."
(interactive "Fdirectory path to create: ") (interactive "FMake directory: \nP")
(let ((path (directory-file-name (expand-file-name path))) (let (handler (handlers file-name-handler-alist))
create-list) (save-match-data
(while (not (file-exists-p path)) (while (and (consp handlers) (null handler))
(setq create-list (cons path create-list) (if (and (consp (car handlers))
path (directory-file-name (file-name-directory path)))) (stringp (car (car handlers)))
(while create-list (string-match (car (car handlers)) file))
(make-directory (car create-list)) (setq handler (cdr (car handlers))))
(setq create-list (cdr create-list))))) (setq handlers (cdr handlers))))
(if handler
(funcall handler 'make-directory dir parents)
(if (not parents)
(make-directory-internal dir)
(let ((dir (directory-file-name (expand-file-name dir)))
(while (not (file-exists-p dir))
(setq create-list (cons dir create-list)
dir (directory-file-name (file-name-directory dir))))
(while create-list
(make-directory-internal (car create-list))
(setq create-list (cdr create-list))))))))
(put 'revert-buffer-function 'permanent-local t) (put 'revert-buffer-function 'permanent-local t)
(defvar revert-buffer-function nil (defvar revert-buffer-function nil
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment