aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1993-03-28 08:29:21 +0000
committerRichard M. Stallman1993-03-28 08:29:21 +0000
commit4ad827c5ef13e13c37f26bad608cb7f4971a9d70 (patch)
treef6ac768f5d419725b016c69a7cfa892a0e00d6ed /src
parent75c0b143920f3facc1e1b44b69f4a6a53ae7d87f (diff)
downloademacs-4ad827c5ef13e13c37f26bad608cb7f4971a9d70.tar.gz
emacs-4ad827c5ef13e13c37f26bad608cb7f4971a9d70.zip
(Fexpand_file_name): Default DEFALT at beginning,
before expanding it. But avoid unneeded or infinite recursive expand. (Fwrite_region): Set visit_file after expanding file arg. Also expand VISIT arg if specified.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 049eb83af08..69ad679fbf5 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -623,6 +623,11 @@ See also the function `substitute-in-file-name'.")
623 if (!NILP (handler)) 623 if (!NILP (handler))
624 return call3 (handler, Qexpand_file_name, name, defalt); 624 return call3 (handler, Qexpand_file_name, name, defalt);
625 625
626 /* Use the buffer's default-directory if DEFALT is omitted. */
627 if (NILP (defalt))
628 defalt = current_buffer->directory;
629 CHECK_STRING (defalt, 1);
630
626 /* Make sure DEFALT is properly expanded. 631 /* Make sure DEFALT is properly expanded.
627 It would be better to do this down below where we actually use 632 It would be better to do this down below where we actually use
628 defalt. Unfortunately, calling Fexpand_file_name recursively 633 defalt. Unfortunately, calling Fexpand_file_name recursively
@@ -630,8 +635,12 @@ See also the function `substitute-in-file-name'.")
630 be annoying because we have pointers into strings lying around 635 be annoying because we have pointers into strings lying around
631 that would need adjusting, and people would add new pointers to 636 that would need adjusting, and people would add new pointers to
632 the code and forget to adjust them, resulting in intermittent bugs. 637 the code and forget to adjust them, resulting in intermittent bugs.
633 Putting this call here avoids all that crud. */ 638 Putting this call here avoids all that crud.
634 if (! NILP (defalt)) 639
640 The EQ test avoids infinite recursion. */
641 if (! NILP (defalt) && !EQ (defalt, name)
642 /* This saves time in a common case. */
643 && XSTRING (defalt)->data[0] != '/')
635 { 644 {
636 struct gcpro gcpro1; 645 struct gcpro gcpro1;
637 646
@@ -831,9 +840,6 @@ See also the function `substitute-in-file-name'.")
831#endif /* not VMS */ 840#endif /* not VMS */
832 && !newdir) 841 && !newdir)
833 { 842 {
834 if (NILP (defalt))
835 defalt = current_buffer->directory;
836 CHECK_STRING (defalt, 1);
837 newdir = XSTRING (defalt)->data; 843 newdir = XSTRING (defalt)->data;
838 } 844 }
839 845
@@ -2486,7 +2492,7 @@ to the file, instead of any buffer contents, and END is ignored.")
2486 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ 2492 unsigned char *fname = 0; /* If non-0, original filename (must rename) */
2487#endif /* VMS */ 2493#endif /* VMS */
2488 Lisp_Object handler; 2494 Lisp_Object handler;
2489 Lisp_Object visit_file = XTYPE (visit) == Lisp_String ? visit : filename; 2495 Lisp_Object visit_file;
2490 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 2496 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2491 2497
2492 /* Special kludge to simplify auto-saving */ 2498 /* Special kludge to simplify auto-saving */
@@ -2498,8 +2504,13 @@ to the file, instead of any buffer contents, and END is ignored.")
2498 else if (XTYPE (start) != Lisp_String) 2504 else if (XTYPE (start) != Lisp_String)
2499 validate_region (&start, &end); 2505 validate_region (&start, &end);
2500 2506
2501 GCPRO4 (start, filename, visit, visit_file);
2502 filename = Fexpand_file_name (filename, Qnil); 2507 filename = Fexpand_file_name (filename, Qnil);
2508 if (XTYPE (visit) == Lisp_String)
2509 visit = Fexpand_file_name (visit, Qnil);
2510 else
2511 visit_file = filename;
2512
2513 GCPRO4 (start, filename, visit, visit_file);
2503 2514
2504 /* If the file name has special constructs in it, 2515 /* If the file name has special constructs in it,
2505 call the corresponding file handler. */ 2516 call the corresponding file handler. */