To: Gregory Margo Cc: Vim Dev Mailing List Subject: patch 5.4.34 (was: vim and full pathnames) In-Reply-To: <19990817090747.A17050@wenet.net> Fcc: outbox From: Bram Moolenaar ------------ Gregory Margo wrote: > One thing that frequently bugs me about vim is vim's preference for > full pathnames over relative pathnames. Strange that you say this. The intention has always been to use short, relative path names when possible. > I'm speaking about the Unix version, although it may be a problem in > other versions as well. It looks like it applies to all versions. > If I invoke vim with a relative pathname (starting with ../), not under > my home directory, vim references the file by a full pathname instead > of a (vi-compatible) relative pathname. > > Simple example: [...] Indeed, when starting vim with "vim ../*/command", the result is editing two files with an absolute path name. There are two strange things I notice: - While reading the file it does show the relative path name. - When using ":next ../*/command" the relative path names are kept. After a little bit of digging, I found the problem: shorten_fnames() is used in main() to try to make the file names shorter. But what actually happens is that a path which starts with "../" is made absolute. This can be fixed. Note: One changed file is from the extra archive. Therefore there are two patches for this: 5.4.34 for the main code, 5.4.x5 for the extra archive. I'll send 5.4.x5 in another message. Patch 5.4.34 (also see 5.4.x5) Problem: When editing a file, and the file name is relative to a directory above the current directory, the file name was made absolute. (Gregory Margo) Solution: Add an argument to shorten_fnames() which indicates if all file names should be shortened, or only absolute names. In main() only use shorten_fnames() to shorten absolute names. Files: src/ex_docmd.c, src/fileio.c, src/main.c, src/proto/fileio.pro *** ../vim-5.4.33/src/ex_docmd.c Fri Jul 9 10:47:59 1999 --- src/ex_docmd.c Wed Aug 18 10:29:11 1999 *************** *** 6412,6418 **** if (new_dir == NULL || mch_chdir((char *)new_dir)) emsg(e_failed); else ! shorten_fnames(); vim_free(tofree); } } --- 6412,6418 ---- if (new_dir == NULL || mch_chdir((char *)new_dir)) emsg(e_failed); else ! shorten_fnames(TRUE); vim_free(tofree); } } *************** *** 6852,6858 **** * Change to session file's dir. */ (void)vim_chdirfile(eap->arg); ! shorten_fnames(); failed |= (makeopens(fd) == FAIL); --- 6852,6858 ---- * Change to session file's dir. */ (void)vim_chdirfile(eap->arg); ! shorten_fnames(TRUE); failed |= (makeopens(fd) == FAIL); *************** *** 6860,6866 **** if (*dirnow) { (void)mch_chdir((char *)dirnow); ! shorten_fnames(); } } #endif --- 6860,6866 ---- if (*dirnow) { (void)mch_chdir((char *)dirnow); ! shorten_fnames(TRUE); } } #endif *** ../vim-5.4.33/src/fileio.c Mon Aug 16 11:17:31 1999 --- src/fileio.c Wed Aug 18 10:50:30 1999 *************** *** 2354,2365 **** } /* ! * Use full path from now on for files currently being edited, both for file ! * name and swap file name. Try to shorten the file names a bit if safe to do ! * so. */ void ! shorten_fnames() { char_u dirname[MAXPATHL]; BUF *buf; --- 2354,2367 ---- } /* ! * When "force" is TRUE: Use full path from now on for files currently being ! * edited, both for file name and swap file name. Try to shorten the file ! * names a bit, if safe to do so. ! * When "force" is FALSE: Only try to shorten absolute file names. */ void ! shorten_fnames(force) ! int force; { char_u dirname[MAXPATHL]; BUF *buf; *************** *** 2368,2374 **** mch_dirname(dirname, MAXPATHL); for (buf = firstbuf; buf != NULL; buf = buf->b_next) { ! if (buf->b_fname != NULL) { vim_free(buf->b_sfname); buf->b_sfname = NULL; --- 2370,2379 ---- mch_dirname(dirname, MAXPATHL); for (buf = firstbuf; buf != NULL; buf = buf->b_next) { ! if (buf->b_fname != NULL ! && (force ! || buf->b_sfname == NULL ! || mch_isFullName(buf->b_sfname))) { vim_free(buf->b_sfname); buf->b_sfname = NULL; *** ../vim-5.4.33/src/main.c Tue Aug 10 16:10:46 1999 --- src/main.c Wed Aug 18 10:46:34 1999 *************** *** 1376,1384 **** (void)buflist_add(arg_files[arg_idx++]); /* ! * Now shorten any of the filenames if possible */ ! shorten_fnames(); /* * Need to jump to the tag before executing the '-c command'. --- 1377,1385 ---- (void)buflist_add(arg_files[arg_idx++]); /* ! * Shorten any of the filenames, but only when absolute. */ ! shorten_fnames(FALSE); /* * Need to jump to the tag before executing the '-c command'. *** ../vim-5.4.33/src/proto/fileio.pro Sun Jul 25 13:08:18 1999 --- src/proto/fileio.pro Wed Aug 18 10:35:37 1999 *************** *** 3,9 **** int readfile __ARGS((char_u *fname, char_u *sfname, linenr_t from, linenr_t lines_to_skip, linenr_t lines_to_read, int flags)); int buf_write __ARGS((BUF *buf, char_u *fname, char_u *sfname, linenr_t start, linenr_t end, int append, int forceit, int reset_changed, int filtering)); char_u *shorten_fname __ARGS((char_u *full_path, char_u *dir_name)); ! void shorten_fnames __ARGS((void)); char_u *modname __ARGS((char_u *fname, char_u *ext, int prepend_dot)); char_u *buf_modname __ARGS((int shortname, char_u *fname, char_u *ext, int prepend_dot)); int vim_fgets __ARGS((char_u *buf, int size, FILE *fp)); --- 3,9 ---- int readfile __ARGS((char_u *fname, char_u *sfname, linenr_t from, linenr_t lines_to_skip, linenr_t lines_to_read, int flags)); int buf_write __ARGS((BUF *buf, char_u *fname, char_u *sfname, linenr_t start, linenr_t end, int append, int forceit, int reset_changed, int filtering)); char_u *shorten_fname __ARGS((char_u *full_path, char_u *dir_name)); ! void shorten_fnames __ARGS((int force)); char_u *modname __ARGS((char_u *fname, char_u *ext, int prepend_dot)); char_u *buf_modname __ARGS((int shortname, char_u *fname, char_u *ext, int prepend_dot)); int vim_fgets __ARGS((char_u *buf, int size, FILE *fp)); *** ../vim-5.4.33/src/version.h Wed Aug 18 10:54:13 1999 --- src/version.h Wed Aug 18 10:53:51 1999 *************** *** 19,26 **** #define VIM_VERSION_MINOR_STR "4" #define VIM_VERSION_BUILD 57 #define VIM_VERSION_BUILD_STR "57" ! #define VIM_VERSION_PATCHLEVEL 33 ! #define VIM_VERSION_PATCHLEVEL_STR "33" /* * VIM_VERSION_NODOT is used for the runtime directory name. --- 19,26 ---- #define VIM_VERSION_MINOR_STR "4" #define VIM_VERSION_BUILD 57 #define VIM_VERSION_BUILD_STR "57" ! #define VIM_VERSION_PATCHLEVEL 34 ! #define VIM_VERSION_PATCHLEVEL_STR "34" /* * VIM_VERSION_NODOT is used for the runtime directory name. *************** *** 30,35 **** */ #define VIM_VERSION_NODOT "vim54" #define VIM_VERSION_SHORT "5.4" ! #define VIM_VERSION_MEDIUM "5.4.33" ! #define VIM_VERSION_LONG "VIM - Vi IMproved 5.4.33 (1999 Aug 17)" ! #define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 5.4.33 (1999 Aug 17, compiled " --- 30,35 ---- */ #define VIM_VERSION_NODOT "vim54" #define VIM_VERSION_SHORT "5.4" ! #define VIM_VERSION_MEDIUM "5.4.34" ! #define VIM_VERSION_LONG "VIM - Vi IMproved 5.4.34 (1999 Aug 18)" ! #define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 5.4.34 (1999 Aug 18, compiled " -- ~ ~ ~ ".signature" 4 lines, 50 characters written --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /