comparison src/buffer.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents 972bbb6d6ca2
children 6240c7796c7a
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
123 buffers and as a reset-value when local-vars are killed. */ 123 buffers and as a reset-value when local-vars are killed. */
124 struct buffer buffer_local_flags; 124 struct buffer buffer_local_flags;
125 125
126 /* This is the initial (startup) directory, as used for the *scratch* buffer. 126 /* This is the initial (startup) directory, as used for the *scratch* buffer.
127 We're making this a global to make others aware of the startup directory. 127 We're making this a global to make others aware of the startup directory.
128 `initial_directory' is stored in external format.
129 */ 128 */
130 char initial_directory[MAXPATHLEN+1]; 129 char initial_directory[MAXPATHLEN+1];
131 130
132 /* This structure holds the names of symbols whose values may be 131 /* This structure holds the names of symbols whose values may be
133 buffer-local. It is indexed and accessed in the same way as the above. */ 132 buffer-local. It is indexed and accessed in the same way as the above. */
431 FILENAME will be converted to its truename and used for searching, but 430 FILENAME will be converted to its truename and used for searching, but
432 the search will still be done on `buffer-file-name'. 431 the search will still be done on `buffer-file-name'.
433 */ 432 */
434 (filename)) 433 (filename))
435 { 434 {
436 /* This function can GC. GC checked and fixed 7-11-2000 ben. */ 435 /* This function can GC. GC checked 1997.04.06. */
437 REGISTER Lisp_Object tail, buf, tem; 436 REGISTER Lisp_Object tail, buf, tem;
438 struct gcpro gcpro1; 437 struct gcpro gcpro1;
439 438
440 #ifdef I18N3 439 #ifdef I18N3
441 /* DO NOT translate the filename. */ 440 /* DO NOT translate the filename. */
466 if (NILP (fn)) 465 if (NILP (fn))
467 { 466 {
468 dn = Ffile_name_directory (filename); 467 dn = Ffile_name_directory (filename);
469 fn = Ffile_truename (dn, Qnil); 468 fn = Ffile_truename (dn, Qnil);
470 if (! NILP (fn)) dn = fn; 469 if (! NILP (fn)) dn = fn;
471 /* Formerly the two calls below were combined, but that is 470 fn = Fexpand_file_name (Ffile_name_nondirectory (filename),
472 not GC-safe because the first call returns unprotected 471 dn);
473 data and the second call can GC. --ben */
474 fn = Ffile_name_nondirectory (filename);
475 fn = Fexpand_file_name (fn, dn);
476 } 472 }
477 filename = fn; 473 filename = fn;
478 NUNGCPRO; 474 NUNGCPRO;
479 } 475 }
480 476
527 } 523 }
528 524
529 Lisp_Object 525 Lisp_Object
530 get_truename_buffer (REGISTER Lisp_Object filename) 526 get_truename_buffer (REGISTER Lisp_Object filename)
531 { 527 {
532 /* This function can GC. GC correct 7-11-00 ben */
533 /* FSFmacs has its own code here and doesn't call get-file-buffer. 528 /* FSFmacs has its own code here and doesn't call get-file-buffer.
534 That's because their equivalent of find-file-compare-truenames 529 That's because their equivalent of find-file-compare-truenames
535 (find-file-existing-other-name) isn't looked at in get-file-buffer. 530 (find-file-existing-other-name) isn't looked at in get-file-buffer.
536 This way is more correct. */ 531 This way is more correct. */
537 int count = specpdl_depth (); 532 int count = specpdl_depth ();
1655 There it is the least likely candidate for `other-buffer' to return; 1650 There it is the least likely candidate for `other-buffer' to return;
1656 thus, the least likely buffer for \\[switch-to-buffer] to select by default. 1651 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
1657 If BUFFER is nil or omitted, bury the current buffer. 1652 If BUFFER is nil or omitted, bury the current buffer.
1658 Also, if BUFFER is nil or omitted, remove the current buffer from the 1653 Also, if BUFFER is nil or omitted, remove the current buffer from the
1659 selected window if it is displayed there. 1654 selected window if it is displayed there.
1660 Because of this, you may need to specify (current-buffer) as
1661 BUFFER when calling from minibuffer.
1662 If BEFORE is non-nil, it specifies a buffer before which BUFFER 1655 If BEFORE is non-nil, it specifies a buffer before which BUFFER
1663 will be placed, instead of being placed at the end. 1656 will be placed, instead of being placed at the end.
1664 */ 1657 */
1665 (buffer, before)) 1658 (buffer, before))
1666 { 1659 {
2752 /* Want no undo records for *scratch* until after Emacs is dumped */ 2745 /* Want no undo records for *scratch* until after Emacs is dumped */
2753 Fbuffer_disable_undo (scratch); 2746 Fbuffer_disable_undo (scratch);
2754 } 2747 }
2755 } 2748 }
2756 2749
2757 /* Is PWD another name for `.' ? */
2758 static int
2759 directory_is_current_directory (char *pwd)
2760 {
2761 Bufbyte *pwd_internal;
2762 struct stat dotstat, pwdstat;
2763
2764 GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA (pwd, pwd_internal);
2765
2766 return (IS_DIRECTORY_SEP (*pwd_internal)
2767 && stat ((char *) pwd_internal, &pwdstat) == 0
2768 && stat (".", &dotstat) == 0
2769 && dotstat.st_ino == pwdstat.st_ino
2770 && dotstat.st_dev == pwdstat.st_dev
2771 && (int) strlen ((char *) pwd_internal) < MAXPATHLEN);
2772 }
2773
2774 void 2750 void
2775 init_initial_directory (void) 2751 init_initial_directory (void)
2776 { 2752 {
2777 /* This function can GC */ 2753 /* This function can GC */
2778 2754
2779 char *pwd; 2755 char *pwd;
2756 struct stat dotstat, pwdstat;
2757 int rc;
2780 2758
2781 initial_directory[0] = 0; 2759 initial_directory[0] = 0;
2782 2760
2783 /* If PWD is accurate, use it instead of calling getcwd. This is faster 2761 /* If PWD is accurate, use it instead of calling getcwd. This is faster
2784 when PWD is right, and may avoid a fatal error. */ 2762 when PWD is right, and may avoid a fatal error. */
2785 if ((pwd = getenv ("PWD")) != NULL 2763 if ((pwd = getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd)
2786 && directory_is_current_directory (pwd)) 2764 && stat (pwd, &pwdstat) == 0
2765 && stat (".", &dotstat) == 0
2766 && dotstat.st_ino == pwdstat.st_ino
2767 && dotstat.st_dev == pwdstat.st_dev
2768 && (int) strlen (pwd) < MAXPATHLEN)
2787 strcpy (initial_directory, pwd); 2769 strcpy (initial_directory, pwd);
2788 else if (getcwd (initial_directory, MAXPATHLEN) == NULL) 2770 else if (getcwd (initial_directory, MAXPATHLEN) == NULL)
2789 fatal ("`getcwd' failed: %s\n", strerror (errno)); 2771 fatal ("`getcwd' failed: %s\n", strerror (errno));
2790 2772
2791 /* Make sure pwd is DIRECTORY_SEP-terminated. 2773 /* Maybe this should really use some standard subroutine
2792 Maybe this should really use some standard subroutine
2793 whose definition is filename syntax dependent. */ 2774 whose definition is filename syntax dependent. */
2794 { 2775 rc = strlen (initial_directory);
2795 int len = strlen (initial_directory); 2776 if (!(IS_DIRECTORY_SEP (initial_directory[rc - 1])))
2796 2777 {
2797 if (! IS_DIRECTORY_SEP (initial_directory[len - 1])) 2778 initial_directory[rc] = DIRECTORY_SEP;
2798 { 2779 initial_directory[rc + 1] = '\0';
2799 initial_directory[len] = DIRECTORY_SEP; 2780 }
2800 initial_directory[len + 1] = '\0';
2801 }
2802 }
2803
2804 /* XEmacs change: store buffer's default directory 2781 /* XEmacs change: store buffer's default directory
2805 using prefered (i.e. as defined at compile-time) 2782 using prefered (i.e. as defined at compile-time)
2806 directory separator. --marcpa */ 2783 directory separator. --marcpa */
2807 #ifdef DOS_NT 2784 #ifdef DOS_NT
2808 #define CORRECT_DIR_SEPS(s) \ 2785 #define CORRECT_DIR_SEPS(s) \
2819 { 2796 {
2820 /* This function can GC */ 2797 /* This function can GC */
2821 2798
2822 Fset_buffer (Fget_buffer_create (QSscratch)); 2799 Fset_buffer (Fget_buffer_create (QSscratch));
2823 2800
2824 current_buffer->directory = 2801 current_buffer->directory = build_string (initial_directory);
2825 build_ext_string (initial_directory, FORMAT_FILENAME);
2826 2802
2827 #if 0 /* FSFmacs */ 2803 #if 0 /* FSFmacs */
2828 /* #### is this correct? */ 2804 /* #### is this correct? */
2829 temp = get_minibuffer (0); 2805 temp = get_minibuffer (0);
2830 XBUFFER (temp)->directory = current_buffer->directory; 2806 XBUFFER (temp)->directory = current_buffer->directory;