Currently, if you use find-file (C-x C-f) to find a file in a non- existant directory, mg (and emacs - coincidentally) suggest you create the directory manually with the make-directory command. This diff offers to create the missing directory by pressing 'y'. If mg cannot create the missing the directory for some reason, it behaves the same as before and opens a read-write buffer.
Another option would be having mg try and create the directory on the fly (without having to press 'y') and then giving a message on its success or failure. comments/oks? -lum Index: def.h =================================================================== RCS file: /cvs/src/usr.bin/mg/def.h,v retrieving revision 1.140 diff -u -p -u -p -r1.140 def.h --- def.h 22 Mar 2014 11:05:37 -0000 1.140 +++ def.h 1 Apr 2014 06:18:55 -0000 @@ -336,7 +336,8 @@ int changedir(int, int); int showcwdir(int, int); int getcwdir(char *, size_t); int makedir(int, int); -int do_makedir(void); +int do_makedir(char *); +int ask_makedir(void); /* dired.c */ struct buffer *dired_(char *); Index: dir.c =================================================================== RCS file: /cvs/src/usr.bin/mg/dir.c,v retrieving revision 1.26 diff -u -p -u -p -r1.26 dir.c --- dir.c 31 Mar 2014 18:00:58 -0000 1.26 +++ dir.c 1 Apr 2014 06:18:55 -0000 @@ -84,18 +84,15 @@ getcwdir(char *buf, size_t len) int makedir(int f, int n) { - return (do_makedir()); + return (ask_makedir()); } int -do_makedir(void) +ask_makedir(void) { - struct stat sb; - int finished, ishere; - mode_t dir_mode, mode, oumask; char bufc[NFILEN]; - char *slash, *path; + char *path; if (getbufcwd(bufc, sizeof(bufc)) != TRUE) return (ABORT); @@ -104,6 +101,17 @@ do_makedir(void) return (ABORT); else if (path[0] == '\0') return (FALSE); + + return (do_makedir(path)); +} + +int +do_makedir(char *path) +{ + struct stat sb; + int finished, ishere; + mode_t dir_mode, mode, oumask; + char *slash; if ((path = adjustname(path, TRUE)) == NULL) return (FALSE); Index: dired.c =================================================================== RCS file: /cvs/src/usr.bin/mg/dired.c,v retrieving revision 1.66 diff -u -p -u -p -r1.66 dired.c --- dired.c 20 Mar 2014 07:47:29 -0000 1.66 +++ dired.c 1 Apr 2014 06:18:55 -0000 @@ -648,7 +648,7 @@ d_create_directory(int f, int n) int ret; struct buffer *bp; - ret = do_makedir(); + ret = ask_makedir(); if (ret != TRUE) return(ret); Index: file.c =================================================================== RCS file: /cvs/src/usr.bin/mg/file.c,v retrieving revision 1.93 diff -u -p -u -p -r1.93 file.c --- file.c 31 Mar 2014 21:29:59 -0000 1.93 +++ file.c 1 Apr 2014 06:18:55 -0000 @@ -231,10 +231,10 @@ readin(char *fname) (void)xdirname(dp, fname, sizeof(dp)); (void)strlcat(dp, "/", sizeof(dp)); + /* Missing directory; keep buffer read-write, like emacs */ if (stat(dp, &statbuf) == -1 && errno == ENOENT) { - /* not read-only; like emacs */ - ewprintf("Use M-x make-directory RET RET to create the" - " directory and its parents"); + if (eyorn("Missing directory, create") == TRUE) + (void)do_makedir(dp); } else if (access(dp, W_OK) == -1 && errno == EACCES) { ewprintf("File not found and directory" " write-protected");