diff options
| author | Glenn Morris | 2015-06-11 20:34:54 -0400 |
|---|---|---|
| committer | Glenn Morris | 2015-06-11 20:34:54 -0400 |
| commit | ebbc6a4782c279527c52d6b1d8b379517aeec2d5 (patch) | |
| tree | 13294b8212776555f38defad43d82c8e0020510f | |
| parent | 32e53667a91ed479743175d5698a89b163c8be94 (diff) | |
| download | emacs-ebbc6a4782c279527c52d6b1d8b379517aeec2d5.tar.gz emacs-ebbc6a4782c279527c52d6b1d8b379517aeec2d5.zip | |
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.
| -rw-r--r-- | lisp/minibuffer.el | 2 | ||||
| -rw-r--r-- | lisp/startup.el | 47 | ||||
| -rw-r--r-- | src/buffer.c | 69 |
3 files changed, 69 insertions, 49 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 60b89b6d521..bf18adf361b 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -2572,7 +2572,7 @@ and `read-file-name-function'." | |||
| 2572 | (defun read-file-name-default (prompt &optional dir default-filename mustmatch initial predicate) | 2572 | (defun read-file-name-default (prompt &optional dir default-filename mustmatch initial predicate) |
| 2573 | "Default method for reading file names. | 2573 | "Default method for reading file names. |
| 2574 | See `read-file-name' for the meaning of the arguments." | 2574 | See `read-file-name' for the meaning of the arguments." |
| 2575 | (unless dir (setq dir default-directory)) | 2575 | (unless dir (setq dir (or default-directory "~/"))) |
| 2576 | (unless (file-name-absolute-p dir) (setq dir (expand-file-name dir))) | 2576 | (unless (file-name-absolute-p dir) (setq dir (expand-file-name dir))) |
| 2577 | (unless default-filename | 2577 | (unless default-filename |
| 2578 | (setq default-filename (if initial (expand-file-name initial dir) | 2578 | (setq default-filename (if initial (expand-file-name initial dir) |
diff --git a/lisp/startup.el b/lisp/startup.el index 3c9ada682d3..b638ed50cc6 100644 --- a/lisp/startup.el +++ b/lisp/startup.el | |||
| @@ -592,9 +592,10 @@ It is the default value of the variable `top-level'." | |||
| 592 | ;; describes the directory linked to, not FOO itself. | 592 | ;; describes the directory linked to, not FOO itself. |
| 593 | (or (equal (file-attributes | 593 | (or (equal (file-attributes |
| 594 | (concat (file-name-as-directory pwd) ".")) | 594 | (concat (file-name-as-directory pwd) ".")) |
| 595 | (file-attributes | 595 | (if default-directory |
| 596 | (concat (file-name-as-directory default-directory) | 596 | (file-attributes |
| 597 | "."))) | 597 | (concat (file-name-as-directory default-directory) |
| 598 | ".")))) | ||
| 598 | (setq process-environment | 599 | (setq process-environment |
| 599 | (delete (concat "PWD=" pwd) | 600 | (delete (concat "PWD=" pwd) |
| 600 | process-environment))))) | 601 | process-environment))))) |
| @@ -609,12 +610,19 @@ It is the default value of the variable `top-level'." | |||
| 609 | (mapcar (lambda (dir) | 610 | (mapcar (lambda (dir) |
| 610 | (decode-coding-string dir coding t)) | 611 | (decode-coding-string dir coding t)) |
| 611 | charset-map-path)))) | 612 | charset-map-path)))) |
| 612 | (setq default-directory (abbreviate-file-name default-directory)) | 613 | (if default-directory |
| 614 | (setq default-directory (abbreviate-file-name default-directory)) | ||
| 615 | ;; FIXME this does not get shown. | ||
| 616 | ;; If after (command-line), it is shown, but if command-line | ||
| 617 | ;; changed the buffer (eg found a file), it applies to that | ||
| 618 | ;; buffer, not *scratch*. | ||
| 619 | (display-warning 'initialization "Error setting default-directory")) | ||
| 613 | (let ((old-face-font-rescale-alist face-font-rescale-alist)) | 620 | (let ((old-face-font-rescale-alist face-font-rescale-alist)) |
| 614 | (unwind-protect | 621 | (unwind-protect |
| 615 | (command-line) | 622 | (command-line) |
| 616 | ;; Do this again, in case .emacs defined more abbreviations. | 623 | ;; Do this again, in case .emacs defined more abbreviations. |
| 617 | (setq default-directory (abbreviate-file-name default-directory)) | 624 | (if default-directory |
| 625 | (setq default-directory (abbreviate-file-name default-directory))) | ||
| 618 | ;; Specify the file for recording all the auto save files of this session. | 626 | ;; Specify the file for recording all the auto save files of this session. |
| 619 | ;; This is used by recover-session. | 627 | ;; This is used by recover-session. |
| 620 | (or auto-save-list-file-name | 628 | (or auto-save-list-file-name |
| @@ -2193,19 +2201,26 @@ A fancy display is used on graphic displays, normal otherwise." | |||
| 2193 | ;; to zero when `process-file-arg' returns. | 2201 | ;; to zero when `process-file-arg' returns. |
| 2194 | (process-file-arg | 2202 | (process-file-arg |
| 2195 | (lambda (name) | 2203 | (lambda (name) |
| 2196 | (let* ((file (expand-file-name | 2204 | ;; If a relative filename was specified and |
| 2205 | ;; command-line-default-directory is nil, | ||
| 2206 | ;; silently drop that argument. | ||
| 2207 | ;; This can only happen if PWD is deleted. | ||
| 2208 | ;; The warning about setting default-directory will | ||
| 2209 | ;; clue you in. | ||
| 2210 | (when (and (or dir (file-name-absolute-p name)) | ||
| 2211 | (let* ((file (expand-file-name | ||
| 2197 | (command-line-normalize-file-name name) | 2212 | (command-line-normalize-file-name name) |
| 2198 | dir)) | 2213 | dir)) |
| 2199 | (buf (find-file-noselect file))) | 2214 | (buf (find-file-noselect file))) |
| 2200 | (setq displayable-buffers (cons buf displayable-buffers)) | 2215 | (setq displayable-buffers (cons buf displayable-buffers)) |
| 2201 | (with-current-buffer buf | 2216 | (with-current-buffer buf |
| 2202 | (unless (zerop line) | 2217 | (unless (zerop line) |
| 2203 | (goto-char (point-min)) | 2218 | (goto-char (point-min)) |
| 2204 | (forward-line (1- line))) | 2219 | (forward-line (1- line))) |
| 2205 | (setq line 0) | 2220 | (setq line 0) |
| 2206 | (unless (< column 1) | 2221 | (unless (< column 1) |
| 2207 | (move-to-column (1- column))) | 2222 | (move-to-column (1- column))) |
| 2208 | (setq column 0)))))) | 2223 | (setq column 0)))))))) |
| 2209 | 2224 | ||
| 2210 | ;; Add the long X options to longopts. | 2225 | ;; Add the long X options to longopts. |
| 2211 | (dolist (tem command-line-x-option-alist) | 2226 | (dolist (tem command-line-x-option-alist) |
diff --git a/src/buffer.c b/src/buffer.c index 0b98431eb0e..75a00f0d337 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -5285,41 +5285,46 @@ init_buffer (int initialized) | |||
| 5285 | pwd = get_current_dir_name (); | 5285 | pwd = get_current_dir_name (); |
| 5286 | 5286 | ||
| 5287 | if (!pwd) | 5287 | if (!pwd) |
| 5288 | fatal ("get_current_dir_name: %s\n", strerror (errno)); | ||
| 5289 | |||
| 5290 | /* Maybe this should really use some standard subroutine | ||
| 5291 | whose definition is filename syntax dependent. */ | ||
| 5292 | len = strlen (pwd); | ||
| 5293 | if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) | ||
| 5294 | { | 5288 | { |
| 5295 | /* Grow buffer to add directory separator and '\0'. */ | 5289 | fprintf (stderr, "Error getting directory: %s", emacs_strerror (errno)); |
| 5296 | pwd = realloc (pwd, len + 2); | 5290 | bset_directory (current_buffer, Qnil); |
| 5297 | if (!pwd) | ||
| 5298 | fatal ("get_current_dir_name: %s\n", strerror (errno)); | ||
| 5299 | pwd[len] = DIRECTORY_SEP; | ||
| 5300 | pwd[len + 1] = '\0'; | ||
| 5301 | len++; | ||
| 5302 | } | 5291 | } |
| 5303 | 5292 | else | |
| 5304 | /* At this moment, we still don't know how to decode the directory | ||
| 5305 | name. So, we keep the bytes in unibyte form so that file I/O | ||
| 5306 | routines correctly get the original bytes. */ | ||
| 5307 | bset_directory (current_buffer, make_unibyte_string (pwd, len)); | ||
| 5308 | |||
| 5309 | /* Add /: to the front of the name | ||
| 5310 | if it would otherwise be treated as magic. */ | ||
| 5311 | temp = Ffind_file_name_handler (BVAR (current_buffer, directory), Qt); | ||
| 5312 | if (! NILP (temp) | ||
| 5313 | /* If the default dir is just /, TEMP is non-nil | ||
| 5314 | because of the ange-ftp completion handler. | ||
| 5315 | However, it is not necessary to turn / into /:/. | ||
| 5316 | So avoid doing that. */ | ||
| 5317 | && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) | ||
| 5318 | { | 5293 | { |
| 5319 | AUTO_STRING (slash_colon, "/:"); | 5294 | /* Maybe this should really use some standard subroutine |
| 5320 | bset_directory (current_buffer, | 5295 | whose definition is filename syntax dependent. */ |
| 5321 | concat2 (slash_colon, | 5296 | len = strlen (pwd); |
| 5322 | BVAR (current_buffer, directory))); | 5297 | if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) |
| 5298 | { | ||
| 5299 | /* Grow buffer to add directory separator and '\0'. */ | ||
| 5300 | pwd = realloc (pwd, len + 2); | ||
| 5301 | if (!pwd) | ||
| 5302 | fatal ("get_current_dir_name: %s\n", strerror (errno)); | ||
| 5303 | pwd[len] = DIRECTORY_SEP; | ||
| 5304 | pwd[len + 1] = '\0'; | ||
| 5305 | len++; | ||
| 5306 | } | ||
| 5307 | |||
| 5308 | /* At this moment, we still don't know how to decode the directory | ||
| 5309 | name. So, we keep the bytes in unibyte form so that file I/O | ||
| 5310 | routines correctly get the original bytes. */ | ||
| 5311 | bset_directory (current_buffer, make_unibyte_string (pwd, len)); | ||
| 5312 | |||
| 5313 | /* Add /: to the front of the name | ||
| 5314 | if it would otherwise be treated as magic. */ | ||
| 5315 | temp = Ffind_file_name_handler (BVAR (current_buffer, directory), Qt); | ||
| 5316 | if (! NILP (temp) | ||
| 5317 | /* If the default dir is just /, TEMP is non-nil | ||
| 5318 | because of the ange-ftp completion handler. | ||
| 5319 | However, it is not necessary to turn / into /:/. | ||
| 5320 | So avoid doing that. */ | ||
| 5321 | && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) | ||
| 5322 | { | ||
| 5323 | AUTO_STRING (slash_colon, "/:"); | ||
| 5324 | bset_directory (current_buffer, | ||
| 5325 | concat2 (slash_colon, | ||
| 5326 | BVAR (current_buffer, directory))); | ||
| 5327 | } | ||
| 5323 | } | 5328 | } |
| 5324 | 5329 | ||
| 5325 | temp = get_minibuffer (0); | 5330 | temp = get_minibuffer (0); |