/* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */
if (NILP (default_directory))
- default_directory = BVAR (current_buffer, directory);
+ {
+ Lisp_Object dir = BVAR (current_buffer, directory);
+ /* The buffer's default-directory should be absolute. If it
+ isn't, try to expand it relative to invocation-directory.
+ But we have to be careful to avoid an infinite loop, because
+ the code in emacs.c that sets Vinvocation_directory might
+ call Fexpand_file_name. */
+ if (STRINGP (dir))
+ {
+ if (!NILP (Ffile_name_absolute_p (dir)))
+ default_directory = dir;
+ else if (STRINGP (Vinvocation_directory)
+ && !NILP (Ffile_name_absolute_p (Vinvocation_directory)))
+ default_directory = Fexpand_file_name (dir, Vinvocation_directory);
+ }
+ }
if (! STRINGP (default_directory))
{
#ifdef DOS_NT
(should (equal c1 (char-before)))
(should (equal c1 (char-after))))))
(if f (delete-file f)))))
+
+(ert-deftest fileio-tests--relative-default-directory ()
+ "Test expand-file-name when default-directory is relative."
+ (let ((default-directory "some/relative/name"))
+ (should (file-name-absolute-p (expand-file-name "foo")))))