1 ;;; w32-fns.el --- Lisp routines for 32-bit Windows
3 ;; Copyright (C) 1994, 2001-2017 Free Software Foundation, Inc.
5 ;; Author: Geoff Voelker <voelker@cs.washington.edu>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
30 (defvar explicit-shell-file-name
)
34 (declare-function set-message-beep
"w32fns.c" (sound))
35 (declare-function w32-get-locale-info
"w32proc.c" (lcid &optional longform
))
36 (declare-function w32-get-valid-locale-ids
"w32proc.c" ())
38 ;; Map all versions of a filename (8.3, longname, mixed case) to the
40 (setq find-file-visit-truename t
)
42 (defun w32-shell-name ()
43 "Return the name of the shell being used."
44 (or (bound-and-true-p shell-file-name
)
47 (and (fboundp 'w32-using-nt
) (w32-using-nt) "cmd.exe")
50 (defun w32-system-shell-p (shell-name)
52 (member (downcase (file-name-nondirectory shell-name
))
55 (defun w32-shell-dos-semantics ()
56 "Return non-nil if the interactive shell being used expects MS-DOS shell semantics."
57 (or (w32-system-shell-p (w32-shell-name))
58 (and (member (downcase (file-name-nondirectory (w32-shell-name)))
59 '("cmdproxy" "cmdproxy.exe"))
60 (w32-system-shell-p (getenv "COMSPEC")))))
62 (defvar w32-quote-process-args
) ;; defined in w32proc.c
64 (defun w32-check-shell-configuration ()
65 "Check the configuration of shell variables on Windows.
66 This function is invoked after loading the init files and processing
67 the command line arguments. It issues a warning if the user or site
68 has configured the shell with inappropriate settings."
70 (let ((prev-buffer (current-buffer))
71 (buffer (get-buffer-create "*Shell Configuration*"))
75 (if (w32-system-shell-p (getenv "ESHELL"))
76 (insert (format "Warning! The ESHELL environment variable uses %s.
77 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
79 (if (w32-system-shell-p (getenv "SHELL"))
80 (insert (format "Warning! The SHELL environment variable uses %s.
81 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
83 (if (w32-system-shell-p shell-file-name
)
84 (insert (format "Warning! shell-file-name uses %s.
85 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
87 (if (and (boundp 'explicit-shell-file-name
)
88 (w32-system-shell-p explicit-shell-file-name
))
89 (insert (format "Warning! explicit-shell-file-name uses %s.
90 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
91 explicit-shell-file-name
)))
92 (setq system-shell
(> (buffer-size) 0))
94 ;; Allow user to specify that they really do want to use one of the
95 ;; "system" shells, despite the drawbacks, but still warn if
96 ;; shell-command-switch doesn't match.
97 (if w32-allow-system-shell
102 (if (string-equal "-c" shell-command-switch
)
103 (insert "Warning! shell-command-switch is \"-c\".
104 You should set this to \"/c\" when using a system shell.\n\n"))
105 (if w32-quote-process-args
106 (insert "Warning! w32-quote-process-args is t.
107 You should set this to nil when using a system shell.\n\n")))
108 ;; Non-system shells.
110 (if (string-equal "/c" shell-command-switch
)
111 (insert "Warning! shell-command-switch is \"/c\".
112 You should set this to \"-c\" when using a non-system shell.\n\n"))
113 (if (not w32-quote-process-args
)
114 (insert "Warning! w32-quote-process-args is nil.
115 You should set this to t when using a non-system shell.\n\n"))))
116 (if (> (buffer-size) 0)
117 (display-buffer buffer
)
118 (kill-buffer buffer
))
119 (set-buffer prev-buffer
)))
121 (add-hook 'after-init-hook
'w32-check-shell-configuration
)
123 ;; Override setting chosen at startup.
124 (defun w32-set-default-process-coding-system ()
125 ;; Most programs on Windows will accept Unix line endings on input
126 ;; (and some programs ported from Unix require it) but most will
127 ;; produce DOS line endings on output.
128 (setq default-process-coding-system
129 (if (default-value 'enable-multibyte-characters
)
130 '(undecided-dos . undecided-unix
)
131 '(raw-text-dos . raw-text-unix
)))
132 ;; Make cmdproxy default to using DOS line endings for input,
133 ;; because some Windows programs (including command.com) require it.
134 (add-to-list 'process-coding-system-alist
135 `("[cC][mM][dD][pP][rR][oO][xX][yY]"
136 .
,(if (default-value 'enable-multibyte-characters
)
137 '(undecided-dos . undecided-dos
)
138 '(raw-text-dos . raw-text-dos
))))
139 ;; plink needs DOS input when entering the password.
140 (add-to-list 'process-coding-system-alist
141 `("[pP][lL][iI][nN][kK]"
142 .
,(if (default-value 'enable-multibyte-characters
)
143 '(undecided-dos . undecided-dos
)
144 '(raw-text-dos . raw-text-dos
)))))
145 (define-obsolete-function-alias 'set-default-process-coding-system
146 #'w32-set-default-process-coding-system
"26.1")
147 (add-hook 'before-init-hook
#'w32-set-default-process-coding-system
)
150 ;;; Basic support functions for managing Emacs's locale setting
152 (defvar w32-valid-locales nil
153 "List of locale ids known to be supported.")
155 ;; This is the brute-force version; an efficient version is now
157 (if (not (fboundp 'w32-get-valid-locale-ids
))
158 (defun w32-get-valid-locale-ids ()
159 "Return list of all valid Windows locale ids."
163 (if (w32-get-locale-info i
)
164 (setq locales
(cons i locales
)))
168 (defun w32-list-locales ()
169 "List the name and id of all locales supported by Windows."
171 (when (null w32-valid-locales
)
172 (setq w32-valid-locales
(sort (w32-get-valid-locale-ids) #'<)))
173 (with-output-to-temp-buffer "*Supported Locales*"
174 (princ "LCID\tAbbrev\tFull name\n\n")
175 (dolist (locale w32-valid-locales
)
176 (princ (format "%d\t%s\t%s\n"
178 (w32-get-locale-info locale
)
179 (w32-get-locale-info locale t
))))))
181 ;; The variable source-directory is used to initialize Info-directory-list.
182 ;; However, the common case is that Emacs is being used from a binary
183 ;; distribution, and the value of source-directory is meaningless in that
184 ;; case. Even worse, source-directory can refer to a directory on a drive
185 ;; on the build machine that happens to be a removable drive on the user's
186 ;; machine. When this happens, Emacs tries to access the removable drive
187 ;; and produces the abort/retry/ignore dialog. Since we do not use
188 ;; source-directory, set it to something that is a reasonable approximation
189 ;; on the user's machine.
191 ;;(add-hook 'before-init-hook
193 ;; (setq source-directory (file-name-as-directory
194 ;; (expand-file-name ".." exec-directory)))))
196 (defun w32-convert-standard-filename (filename)
197 "Convert a standard file's name to something suitable for MS-Windows.
198 This means to guarantee valid names and perhaps to canonicalize
201 This function is called by `convert-standard-filename'.
203 Replace invalid characters and turn Cygwin names into native
207 (if (string-match "\\`/cygdrive/\\([a-zA-Z]\\)/" filename
)
208 (replace-match "\\1:/" t nil filename
)
209 (copy-sequence filename
)))
211 ;; leave ':' if part of drive specifier
212 (if (and (> (length name
) 1)
213 (eq (aref name
1) ?
:))
215 ;; destructively replace invalid filename characters with !
216 (while (string-match "[?*:<>|\"\000-\037]" name start
)
217 (aset name
(match-beginning 0) ?
!)
218 (setq start
(match-end 0)))
221 (defun w32-set-system-coding-system (coding-system)
222 "Set the coding system used by the Windows system to CODING-SYSTEM.
223 This is used for things like passing font names with non-ASCII
224 characters in them to the system. For a list of possible values of
225 CODING-SYSTEM, use \\[list-coding-systems].
227 This function is provided for backward compatibility, since
228 `w32-system-coding-system' is now an alias for `locale-coding-system'."
230 (list (let ((default locale-coding-system
))
232 (format "Coding system for system calls (default %s): "
235 (check-coding-system coding-system
)
236 (setq locale-coding-system coding-system
))
237 (define-obsolete-function-alias 'set-w32-system-coding-system
238 #'w32-set-system-coding-system
"26.1")
240 ;; locale-coding-system was introduced to do the same thing as
241 ;; w32-system-coding-system. Use that instead.
242 (defvaralias 'w32-system-coding-system
'locale-coding-system
)
244 ;; Set to a system sound if you want a fancy bell.
245 (set-message-beep nil
)
247 (defvar w32-charset-info-alist
) ; w32font.c
249 (defun w32-add-charset-info (xlfd-charset windows-charset codepage
)
250 "Function to add character sets to display with Windows fonts.
251 Creates entries in `w32-charset-info-alist'.
252 XLFD-CHARSET is a string which will appear in the XLFD font name to
253 identify the character set. WINDOWS-CHARSET is a symbol identifying
254 the Windows character set this maps to. For the list of possible
255 values, see the documentation for `w32-charset-info-alist'. CODEPAGE
256 can be a numeric codepage that Windows uses to display the character
257 set, t for Unicode output with no codepage translation or nil for 8
258 bit output with no translation."
259 (add-to-list 'w32-charset-info-alist
260 (cons xlfd-charset
(cons windows-charset codepage
))))
262 ;; The last charset we add becomes the "preferred" charset for the return
263 ;; value from w32-select-font etc, so list the most important charsets last.
264 (w32-add-charset-info "iso8859-14" 'w32-charset-ansi
28604)
265 (w32-add-charset-info "iso8859-15" 'w32-charset-ansi
28605)
266 ;; The following two are included for pattern matching.
267 (w32-add-charset-info "jisx0201" 'w32-charset-shiftjis
932)
268 (w32-add-charset-info "jisx0208" 'w32-charset-shiftjis
932)
269 (w32-add-charset-info "jisx0201-latin" 'w32-charset-shiftjis
932)
270 (w32-add-charset-info "jisx0201-katakana" 'w32-charset-shiftjis
932)
271 (w32-add-charset-info "ksc5601.1989" 'w32-charset-hangeul
949)
272 (w32-add-charset-info "big5" 'w32-charset-chinesebig5
950)
273 (w32-add-charset-info "gb2312.1980" 'w32-charset-gb2312
936)
274 (w32-add-charset-info "ms-symbol" 'w32-charset-symbol nil
)
275 (w32-add-charset-info "ms-oem" 'w32-charset-oem
437)
276 (w32-add-charset-info "ms-oemlatin" 'w32-charset-oem
850)
277 (w32-add-charset-info "iso8859-2" 'w32-charset-easteurope
28592)
278 (w32-add-charset-info "iso8859-3" 'w32-charset-turkish
28593)
279 (w32-add-charset-info "iso8859-4" 'w32-charset-baltic
28594)
280 (w32-add-charset-info "iso8859-6" 'w32-charset-arabic
28596)
281 (w32-add-charset-info "iso8859-7" 'w32-charset-greek
28597)
282 (w32-add-charset-info "iso8859-8" 'w32-charset-hebrew
1255)
283 (w32-add-charset-info "iso8859-9" 'w32-charset-turkish
1254)
284 (w32-add-charset-info "iso8859-13" 'w32-charset-baltic
1257)
285 (w32-add-charset-info "koi8-r" 'w32-charset-russian
20866)
286 (w32-add-charset-info "iso8859-5" 'w32-charset-russian
28595)
287 (w32-add-charset-info "tis620-2533" 'w32-charset-thai
874)
288 (w32-add-charset-info "windows-1258" 'w32-charset-vietnamese
1258)
289 (w32-add-charset-info "ksc5601.1992" 'w32-charset-johab
1361)
290 (w32-add-charset-info "mac-roman" 'w32-charset-mac
10000)
291 (w32-add-charset-info "iso10646-1" 'w32-charset-default t
)
293 ;; ;; If Unicode Windows charset is not defined, use ansi fonts.
294 ;; (w32-add-charset-info "iso10646-1" 'w32-charset-ansi t))
297 (w32-add-charset-info "big5-0" 'w32-charset-chinesebig5
950)
298 (w32-add-charset-info "gb2312.1980-0" 'w32-charset-gb2312
936)
299 (w32-add-charset-info "jisx0208-sjis" 'w32-charset-shiftjis
932)
300 (w32-add-charset-info "ksc5601.1987-0" 'w32-charset-hangeul
949)
301 (w32-add-charset-info "tis620-0" 'w32-charset-thai
874)
302 (w32-add-charset-info "iso8859-1" 'w32-charset-ansi
1252)
305 ;;;; Support for build process
308 (defvar autoload-make-program
)
309 (defvar generated-autoload-file
)
311 (defun w32-batch-update-autoloads ()
312 "Like `batch-update-autoloads', but takes the name of the autoloads file
313 from the command line.
315 This is required because some Windows build environments, such as MSYS,
316 munge command-line arguments that include file names to a horrible mess
317 that Emacs is unable to cope with."
318 (let ((generated-autoload-file
319 (expand-file-name (pop command-line-args-left
)))
320 ;; I can only assume the same considerations may apply here...
321 (autoload-make-program (pop command-line-args-left
)))
322 (batch-update-autoloads)))
324 (defun w32-append-code-lines (orig extra
)
325 "Append non-empty non-comment lines in the file EXTRA to the file ORIG.
327 This function saves all buffers and kills the Emacs session, without asking
330 This is required because the Windows build environment is not required
331 to include Sed, which is used by leim/Makefile.in to do the job."
333 (goto-char (point-max))
334 (insert-file-contents extra
)
335 (delete-matching-lines "^$\\|^;")
336 (save-buffers-kill-emacs t
))
338 ;;; w32-fns.el ends here