Fix 'expand-file-name' during startup on MS-Windows

* src/w32.c (w32_init_file_name_codepage): New function, resets
file_name_codepage and w32_ansi_code_page to undo the values
recorded during dumping.
(codepage_for_filenames): Fix an embarrassing typo.  Ignore the
cached value of file-name encoding if it is nil, i.e. not
initialized yet.  Actually cache the last used file-name encoding
to avoid calling APIs when not necessary.

* src/w32.h (w32_init_file_name_codepage): Add prototype.

* src/w32term.c (syms_of_w32term): Set the value of
w32_unicode_filenames according to the OS version.  This avoids
resetting it during startup, which then causes temacs to run with
the incorrect value.

* src/emacs.c (main): Call w32_init_file_name_codepage early
during the startup.

* src/fileio.c (Fexpand_file_name) [WINDOWSNT]: Update 'newdir'
after converting $HOME to a UTF-8 string, so that 'newdirlim' is
consistent with it.  (Bug#25038)

* lisp/international/mule-cmds.el (set-locale-environment): Set
'default-file-name-coding-system' to the ANSI codepage even in
non-interactive sessions.

* lisp/files.el (directory-abbrev-alist, abbreviated-home-dir):
Doc fix.
(abbreviate-file-name): Decode 'abbreviated-home-dir' if it is a
unibyte string.

* doc/lispref/files.texi (Directory Names): Index
'directory-abbrev-alist'.
This commit is contained in:
Eli Zaretskii 2016-11-28 17:43:25 +02:00
parent 46065291fa
commit 5878abf87b
8 changed files with 64 additions and 23 deletions

View file

@ -51,20 +51,21 @@ when it has unsaved changes."
nil
"Alist of abbreviations for file directories.
A list of elements of the form (FROM . TO), each meaning to replace
FROM with TO when it appears in a directory name. This replacement is
done when setting up the default directory of a newly visited file.
a match for FROM with TO when a directory name matches FROM. This
replacement is done when setting up the default directory of a
newly visited file buffer.
FROM is matched against directory names anchored at the first
character, so it should start with a \"\\\\\\=`\", or, if directory
names cannot have embedded newlines, with a \"^\".
FROM is a regexp that is matched against directory names anchored at
the first character, so it should start with a \"\\\\\\=`\", or, if
directory names cannot have embedded newlines, with a \"^\".
FROM and TO should be equivalent names, which refer to the
same directory. Do not use `~' in the TO strings;
they should be ordinary absolute directory names.
same directory. TO should be an absolute directory name.
Do not use `~' in the TO strings.
Use this feature when you have directories which you normally refer to
via absolute symbolic links. Make TO the name of the link, and FROM
the name it is linked to."
a regexp matching the name it is linked to."
:type '(repeat (cons :format "%v"
:value ("\\`" . "")
(regexp :tag "From")
@ -1736,7 +1737,8 @@ Choose the buffer's name using `generate-new-buffer-name'."
(make-obsolete-variable 'automount-dir-prefix 'directory-abbrev-alist "24.3")
(defvar abbreviated-home-dir nil
"The user's homedir abbreviated according to `directory-abbrev-alist'.")
"Regexp matching the user's homedir at the beginning of file name.
The value includes abbreviation according to `directory-abbrev-alist'.")
(defun abbreviate-file-name (filename)
"Return a version of FILENAME shortened using `directory-abbrev-alist'.
@ -1770,8 +1772,23 @@ home directory is a root directory) and removes automounter prefixes
(or abbreviated-home-dir
(setq abbreviated-home-dir
(let ((abbreviated-home-dir "$foo"))
(concat "\\`" (abbreviate-file-name (expand-file-name "~"))
"\\(/\\|\\'\\)"))))
(setq abbreviated-home-dir
(concat "\\`"
(abbreviate-file-name (expand-file-name "~"))
"\\(/\\|\\'\\)"))
;; Depending on whether default-directory does or
;; doesn't include non-ASCII characters, the value
;; of abbreviated-home-dir could be multibyte or
;; unibyte. In the latter case, we need to decode
;; it. Note that this function is called for the
;; first time (from startup.el) when
;; locale-coding-system is already set up.
(if (multibyte-string-p abbreviated-home-dir)
abbreviated-home-dir
(decode-coding-string abbreviated-home-dir
(if (eq system-type 'windows-nt)
'utf-8
locale-coding-system))))))
;; If FILENAME starts with the abbreviated homedir,
;; make it start with `~' instead.