]> git.eshelyaron.com Git - emacs.git/commitdiff
Some progress towards starting with PWD deleted. (Bug#18851)
authorGlenn Morris <rgm@gnu.org>
Fri, 12 Jun 2015 00:34:54 +0000 (20:34 -0400)
committerGlenn Morris <rgm@gnu.org>
Fri, 12 Jun 2015 00:34:54 +0000 (20:34 -0400)
* 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
lisp/startup.el
src/buffer.c

index 60b89b6d5212004eed23072c8f7297f0a0eaa0c9..bf18adf361bc7d4ff7278dd6c051e562a7223c70 100644 (file)
@@ -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)
index 3c9ada682d3d385006015eb6e981049fccab33db..b638ed50cc668d9585b95e333a4442f0f4308f49 100644 (file)
@@ -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)
index 0b98431eb0ed54f7c8244db653be63eee299c2d3..75a00f0d33774cb3287f54cbc65ede120f5a2560 100644 (file)
@@ -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);