emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master ebbc6a4: Some progress towards starting with PWD de


From: Glenn Morris
Subject: [Emacs-diffs] master ebbc6a4: Some progress towards starting with PWD deleted. (Bug#18851)
Date: Fri, 12 Jun 2015 00:34:59 +0000

branch: master
commit ebbc6a4782c279527c52d6b1d8b379517aeec2d5
Author: Glenn Morris <address@hidden>
Commit: Glenn Morris <address@hidden>

    Some progress towards starting with PWD deleted.  (Bug#18851)
    
    * src/buffer.c (init_buffer): Handle get_current_dir_name failures.
    
    * lisp/startup.el (normal-top-level, command-line-1):
    * lisp/minibuffer.el (read-file-name-default):
    Handle default-directory being nil.
---
 lisp/minibuffer.el |    2 +-
 lisp/startup.el    |   47 +++++++++++++++++++++++------------
 src/buffer.c       |   69 ++++++++++++++++++++++++++++------------------------
 3 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 60b89b6..bf18adf 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2572,7 +2572,7 @@ and `read-file-name-function'."
 (defun read-file-name-default (prompt &optional dir default-filename mustmatch 
initial predicate)
   "Default method for reading file names.
 See `read-file-name' for the meaning of the arguments."
-  (unless dir (setq dir default-directory))
+  (unless dir (setq dir (or default-directory "~/")))
   (unless (file-name-absolute-p dir) (setq dir (expand-file-name dir)))
   (unless default-filename
     (setq default-filename (if initial (expand-file-name initial dir)
diff --git a/lisp/startup.el b/lisp/startup.el
index 3c9ada6..b638ed5 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -592,9 +592,10 @@ It is the default value of the variable `top-level'."
           ;; describes the directory linked to, not FOO itself.
           (or (equal (file-attributes
                       (concat (file-name-as-directory pwd) "."))
-                     (file-attributes
-                      (concat (file-name-as-directory default-directory)
-                              ".")))
+                     (if default-directory
+                         (file-attributes
+                          (concat (file-name-as-directory default-directory)
+                                  "."))))
               (setq process-environment
                     (delete (concat "PWD=" pwd)
                             process-environment)))))
@@ -609,12 +610,19 @@ It is the default value of the variable `top-level'."
                (mapcar (lambda (dir)
                          (decode-coding-string dir coding t))
                        charset-map-path))))
-    (setq default-directory (abbreviate-file-name default-directory))
+    (if default-directory
+       (setq default-directory (abbreviate-file-name default-directory))
+      ;; FIXME this does not get shown.
+      ;; If after (command-line), it is shown, but if command-line
+      ;; changed the buffer (eg found a file), it applies to that
+      ;; buffer, not *scratch*.
+      (display-warning 'initialization "Error setting default-directory"))
     (let ((old-face-font-rescale-alist face-font-rescale-alist))
       (unwind-protect
          (command-line)
        ;; Do this again, in case .emacs defined more abbreviations.
-       (setq default-directory (abbreviate-file-name default-directory))
+       (if default-directory
+           (setq default-directory (abbreviate-file-name default-directory)))
        ;; Specify the file for recording all the auto save files of this 
session.
        ;; This is used by recover-session.
        (or auto-save-list-file-name
@@ -2193,19 +2201,26 @@ A fancy display is used on graphic displays, normal 
otherwise."
                ;; to zero when `process-file-arg' returns.
                (process-file-arg
                 (lambda (name)
-                  (let* ((file (expand-file-name
+                 ;; If a relative filename was specified and
+                 ;; command-line-default-directory is nil,
+                 ;; silently drop that argument.
+                 ;; This can only happen if PWD is deleted.
+                 ;; The warning about setting default-directory will
+                 ;; clue you in.
+                 (when (and (or dir (file-name-absolute-p name))
+                   (let* ((file (expand-file-name
                                 (command-line-normalize-file-name name)
                                 dir))
-                         (buf (find-file-noselect file)))
-                    (setq displayable-buffers (cons buf displayable-buffers))
-                    (with-current-buffer buf
-                      (unless (zerop line)
-                        (goto-char (point-min))
-                        (forward-line (1- line)))
-                      (setq line 0)
-                      (unless (< column 1)
-                        (move-to-column (1- column)))
-                      (setq column 0))))))
+                          (buf (find-file-noselect file)))
+                     (setq displayable-buffers (cons buf displayable-buffers))
+                     (with-current-buffer buf
+                       (unless (zerop line)
+                         (goto-char (point-min))
+                         (forward-line (1- line)))
+                       (setq line 0)
+                       (unless (< column 1)
+                         (move-to-column (1- column)))
+                       (setq column 0))))))))
 
           ;; Add the long X options to longopts.
           (dolist (tem command-line-x-option-alist)
diff --git a/src/buffer.c b/src/buffer.c
index 0b98431..75a00f0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5285,41 +5285,46 @@ init_buffer (int initialized)
   pwd = get_current_dir_name ();
 
   if (!pwd)
-    fatal ("get_current_dir_name: %s\n", strerror (errno));
-
-  /* Maybe this should really use some standard subroutine
-     whose definition is filename syntax dependent.  */
-  len = strlen (pwd);
-  if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
     {
-      /* Grow buffer to add directory separator and '\0'.  */
-      pwd = realloc (pwd, len + 2);
-      if (!pwd)
-       fatal ("get_current_dir_name: %s\n", strerror (errno));
-      pwd[len] = DIRECTORY_SEP;
-      pwd[len + 1] = '\0';
-      len++;
+      fprintf (stderr, "Error getting directory: %s", emacs_strerror (errno));
+      bset_directory (current_buffer, Qnil);
     }
-
-  /* At this moment, we still don't know how to decode the directory
-     name.  So, we keep the bytes in unibyte form so that file I/O
-     routines correctly get the original bytes.  */
-  bset_directory (current_buffer, make_unibyte_string (pwd, len));
-
-  /* Add /: to the front of the name
-     if it would otherwise be treated as magic.  */
-  temp = Ffind_file_name_handler (BVAR (current_buffer, directory), Qt);
-  if (! NILP (temp)
-      /* If the default dir is just /, TEMP is non-nil
-        because of the ange-ftp completion handler.
-        However, it is not necessary to turn / into /:/.
-        So avoid doing that.  */
-      && strcmp ("/", SSDATA (BVAR (current_buffer, directory))))
+  else
     {
-      AUTO_STRING (slash_colon, "/:");
-      bset_directory (current_buffer,
-                     concat2 (slash_colon,
-                              BVAR (current_buffer, directory)));
+      /* Maybe this should really use some standard subroutine
+         whose definition is filename syntax dependent.  */
+      len = strlen (pwd);
+      if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
+        {
+          /* Grow buffer to add directory separator and '\0'.  */
+          pwd = realloc (pwd, len + 2);
+          if (!pwd)
+            fatal ("get_current_dir_name: %s\n", strerror (errno));
+          pwd[len] = DIRECTORY_SEP;
+          pwd[len + 1] = '\0';
+          len++;
+        }
+
+      /* At this moment, we still don't know how to decode the directory
+         name.  So, we keep the bytes in unibyte form so that file I/O
+         routines correctly get the original bytes.  */
+      bset_directory (current_buffer, make_unibyte_string (pwd, len));
+
+      /* Add /: to the front of the name
+         if it would otherwise be treated as magic.  */
+      temp = Ffind_file_name_handler (BVAR (current_buffer, directory), Qt);
+      if (! NILP (temp)
+          /* If the default dir is just /, TEMP is non-nil
+             because of the ange-ftp completion handler.
+             However, it is not necessary to turn / into /:/.
+             So avoid doing that.  */
+          && strcmp ("/", SSDATA (BVAR (current_buffer, directory))))
+        {
+          AUTO_STRING (slash_colon, "/:");
+          bset_directory (current_buffer,
+                          concat2 (slash_colon,
+                                   BVAR (current_buffer, directory)));
+        }
     }
 
   temp = get_minibuffer (0);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]