1 ;;; w32-fns.el --- Lisp routines for Windows NT.
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
5 ;; Author: Geoff Voelker <voelker@cs.washington.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
29 ;; (November 21, 1994)
30 ;; [C-M-backspace] defined.
31 ;; mode-line-format defined to show buffer file type.
32 ;; audio bell initialized.
36 ;; Map delete and backspace
37 (define-key function-key-map
[backspace] "\177")
38 (define-key function-key-map [delete] "\C-d")
39 (define-key function-key-map [M-backspace] [?\M-\177])
40 (define-key function-key-map [C-M-backspace] [\C-\M-delete])
42 ;; Ignore case on file-name completion
43 (setq completion-ignore-case t)
45 ;; Map all versions of a filename (8.3, longname, mixed case) to the
47 (setq find-file-visit-truename t)
49 (defvar w32-system-shells '("cmd" "cmd.exe" "command" "command.com"
50 "4nt" "4nt.exe" "4dos" "4dos.exe"
52 "List of strings recognized as Windows NT/9X system shells.")
54 (defun w32-using-nt ()
55 "Return non-nil if literally running on Windows NT (i.e., not Windows 9X)."
56 (and (eq system-type 'windows-nt) (getenv "SystemRoot")))
58 (defun w32-shell-name ()
59 "Return the name of the shell being used."
60 (or (and (boundp 'explicit-shell-file-name) explicit-shell-file-name)
63 (and (w32-using-nt) "cmd.exe")
66 (defun w32-system-shell-p (shell-name)
68 (member (downcase (file-name-nondirectory shell-name))
71 (defun w32-shell-dos-semantics ()
72 "Return t if the interactive shell being used expects msdos shell semantics."
73 (or (w32-system-shell-p (w32-shell-name))
74 (and (member (downcase (file-name-nondirectory (w32-shell-name)))
75 '("cmdproxy" "cmdproxy.exe"))
76 (w32-system-shell-p (getenv "COMSPEC")))))
78 (defvar w32-allow-system-shell nil
79 "*Disable startup warning when using \"system\" shells.")
81 (defun w32-check-shell-configuration ()
82 "Check the configuration of shell variables on Windows NT/9X.
83 This function is invoked after loading the init files and processing
84 the command line arguments. It issues a warning if the user or site
85 has configured the shell with inappropriate settings."
87 (let ((prev-buffer (current-buffer))
88 (buffer (get-buffer-create "*Shell Configuration*"))
92 (if (w32-system-shell-p (getenv "ESHELL"))
93 (insert (format "Warning! The ESHELL environment variable uses %s.
94 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
96 (if (w32-system-shell-p (getenv "SHELL"))
97 (insert (format "Warning! The SHELL environment variable uses %s.
98 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
100 (if (w32-system-shell-p shell-file-name)
101 (insert (format "Warning! shell-file-name uses %s.
102 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
104 (if (and (boundp 'explicit-shell-file-name)
105 (w32-system-shell-p explicit-shell-file-name))
106 (insert (format "Warning! explicit-shell-file-name uses %s.
107 You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
108 explicit-shell-file-name)))
109 (setq system-shell (> (buffer-size) 0))
111 ;; Allow user to specify that they really do want to use one of the
112 ;; "system" shells, despite the drawbacks, but still warn if
113 ;; shell-command-switch doesn't match.
114 (if w32-allow-system-shell
119 (if (string-equal "-c" shell-command-switch)
120 (insert "Warning! shell-command-switch is \"-c\".
121 You should set this to \"/c\" when using a system shell.\n\n"))
122 (if w32-quote-process-args
123 (insert "Warning! w32-quote-process-args is t.
124 You should set this to nil when using a system shell.\n\n")))
125 ;; Non-system shells.
127 (if (string-equal "/c" shell-command-switch)
128 (insert "Warning! shell-command-switch is \"/c\".
129 You should set this to \"-c\" when using a non-system shell.\n\n"))
130 (if (not w32-quote-process-args)
131 (insert "Warning! w32-quote-process-args is nil.
132 You should set this to t when using a non-system shell.\n\n"))))
133 (if (> (buffer-size) 0)
134 (display-buffer buffer)
135 (kill-buffer buffer))
136 (set-buffer prev-buffer)))
138 (add-hook 'after-init-hook 'w32-check-shell-configuration)
140 ;;; Override setting chosen at startup.
141 (defun set-default-process-coding-system ()
142 ;; Most programs on Windows will accept Unix line endings on input
143 ;; (and some programs ported from Unix require it) but most will
144 ;; produce DOS line endings on output.
145 (setq default-process-coding-system
146 (if default-enable-multibyte-characters
147 '(undecided-dos . undecided-unix)
148 '(raw-text-dos . raw-text-unix)))
150 ;; On Windows 9x, make cmdproxy default to using DOS line endings
151 ;; for input, because command.com requires this.
152 (setq process-coding-system-alist
153 `(("[cC][mM][dD][pP][rR][oO][xX][yY]"
154 . ,(if default-enable-multibyte-characters
155 '(undecided-dos . undecided-dos)
156 '(raw-text-dos . raw-text-dos)))))))
158 (add-hook 'before-init-hook 'set-default-process-coding-system)
161 ;;; Basic support functions for managing Emacs' locale setting
163 (defvar w32-valid-locales nil
164 "List of locale ids known to be supported.")
166 ;;; This is the brute-force version; an efficient version is now
168 (if (not (fboundp 'w32-get-valid-locale-ids))
169 (defun w32-get-valid-locale-ids ()
170 "Return list of all valid Windows locale ids."
174 (if (w32-get-locale-info i)
175 (setq locales (cons i locales)))
179 (defun w32-list-locales ()
180 "List the name and id of all locales supported by Windows."
182 (if (null w32-valid-locales)
183 (setq w32-valid-locales (w32-get-valid-locale-ids)))
184 (switch-to-buffer-other-window (get-buffer-create "*Supported Locales*"))
186 (insert "LCID\tAbbrev\tFull name\n\n")
191 (w32-get-locale-info x)
192 (w32-get-locale-info x t)))
193 w32-valid-locales "\n"))
195 (goto-char (point-min)))
198 ;;; Setup Info-default-directory-list to include the info directory
199 ;;; near where Emacs executable was installed. We used to set INFOPATH,
200 ;;; but when this is set Info-default-directory-list is ignored. We
201 ;;; also cannot rely upon what is set in paths.el because they assume
202 ;;; that configuration during build time is correct for runtime.
203 (defun w32-init-info ()
204 (let* ((instdir (file-name-directory invocation-directory))
205 (dir1 (expand-file-name "../info/" instdir))
206 (dir2 (expand-file-name "../../../info/" instdir)))
207 (if (file-exists-p dir1)
208 (setq Info-default-directory-list
209 (append Info-default-directory-list (list dir1)))
210 (if (file-exists-p dir2)
211 (setq Info-default-directory-list
212 (append Info-default-directory-list (list dir2)))))))
214 (add-hook 'before-init-hook 'w32-init-info)
216 ;;; The variable source-directory is used to initialize Info-directory-list.
217 ;;; However, the common case is that Emacs is being used from a binary
218 ;;; distribution, and the value of source-directory is meaningless in that
219 ;;; case. Even worse, source-directory can refer to a directory on a drive
220 ;;; on the build machine that happens to be a removable drive on the user's
221 ;;; machine. When this happens, Emacs tries to access the removable drive
222 ;;; and produces the abort/retry/ignore dialog. Since we do not use
223 ;;; source-directory, set it to something that is a reasonable approximation
224 ;;; on the user's machine.
226 (add-hook 'before-init-hook
228 (setq source-directory (file-name-as-directory
229 (expand-file-name ".." exec-directory)))))
231 ;; Avoid creating auto-save file names containing invalid characters.
232 (fset 'original-make-auto-save-file-name
233 (symbol-function 'make-auto-save-file-name))
235 (defun make-auto-save-file-name ()
236 "Return file name to use for auto-saves of current buffer.
237 Does not consider `auto-save-visited-file-name' as that variable is checked
238 before calling this function. You can redefine this for customization.
239 See also `auto-save-file-name-p'."
240 (convert-standard-filename (original-make-auto-save-file-name)))
242 (defun convert-standard-filename (filename)
243 "Convert a standard file's name to something suitable for the current OS.
244 This function's standard definition is trivial; it just returns the argument.
245 However, on some systems, the function is redefined
246 with a definition that really does change some file names."
247 (let ((name (copy-sequence filename))
249 ;; leave ':' if part of drive specifier
250 (if (eq (aref name 1) ?:)
252 ;; destructively replace invalid filename characters with !
253 (while (string-match "[?*:<>|\"\000-\037]" name start)
254 (aset name (match-beginning 0) ?!)
255 (setq start (match-end 0)))
256 ;; convert directory separators to Windows format
257 ;; (but only if the shell in use requires it)
258 (if (w32-shell-dos-semantics)
259 (while (string-match "/" name start)
260 (aset name (match-beginning 0) ?\\)
261 (setq start (match-end 0))))
264 ;;; Fix interface to (X-specific) mouse.el
265 (defun x-set-selection (type data)
266 (or type (setq type 'PRIMARY))
267 (put 'x-selections type data))
269 (defun x-get-selection (&optional type data-type)
270 (or type (setq type 'PRIMARY))
271 (get 'x-selections type))
273 (defun set-w32-system-coding-system (coding-system)
274 "Set the coding system used by the Windows System to CODING-SYSTEM.
275 This is used for things like passing font names with non-ASCII
276 characters in them to the system. For a list of possible values of
277 CODING-SYSTEM, use \\[list-coding-systems]."
279 (list (let ((default w32-system-coding-system))
281 (format "Coding system for system calls (default, %s): "
284 (check-coding-system coding-system)
285 (setq w32-system-coding-system coding-system))
286 ;; Set system coding system initially to iso-latin-1
287 (set-w32-system-coding-system 'iso-latin-1)
289 ;;; Set to a system sound if you want a fancy bell.
290 (set-message-beep nil)
292 ;;; The "Windows" keys on newer keyboards bring up the Start menu
293 ;;; whether you want it or not - make Emacs ignore these keystrokes
294 ;;; rather than beep.
295 (global-set-key [lwindow] 'ignore)
296 (global-set-key [rwindow] 'ignore)
298 ;; Map certain keypad keys into ASCII characters
299 ;; that people usually expect.
300 (define-key function-key-map [tab] [?\t])
301 (define-key function-key-map [linefeed] [?\n])
302 (define-key function-key-map [clear] [11])
303 (define-key function-key-map [return] [13])
304 (define-key function-key-map [escape] [?\e])
305 (define-key function-key-map [M-tab] [?\M-\t])
306 (define-key function-key-map [M-linefeed] [?\M-\n])
307 (define-key function-key-map [M-clear] [?\M-\013])
308 (define-key function-key-map [M-return] [?\M-\015])
309 (define-key function-key-map [M-escape] [?\M-\e])
311 ;; These don't do the right thing (voelker)
312 ;(define-key function-key-map [backspace] [127])
313 ;(define-key function-key-map [delete] [127])
314 ;(define-key function-key-map [M-backspace] [?\M-\d])
315 ;(define-key function-key-map [M-delete] [?\M-\d])
317 ;; These tell read-char how to convert
318 ;; these special chars to ASCII.
319 (put 'tab
'ascii-character ?
\t)
320 (put 'linefeed
'ascii-character ?
\n)
321 (put 'clear
'ascii-character
12)
322 (put 'return
'ascii-character
13)
323 (put 'escape
'ascii-character ?\e
)
324 (put 'backspace
'ascii-character
127)
325 (put 'delete
'ascii-character
127)
327 ;; W32 uses different color indexes than standard:
329 (defvar w32-tty-standard-colors
330 '(("white" 15 65535 65535 65535)
331 ("yellow" 14 65535 65535 0) ; Yellow
332 ("lightmagenta" 13 65535 0 65535) ; Magenta
333 ("lightred" 12 65535 0 0) ; Red
334 ("lightcyan" 11 0 65535 65535) ; Cyan
335 ("lightgreen" 10 0 65535 0) ; Green
336 ("lightblue" 9 0 0 65535) ; Blue
337 ("darkgray" 8 26112 26112 26112) ; Gray40
338 ("lightgray" 7 48640 48640 48640) ; Gray
339 ("brown" 6 40960 20992 11520) ; Sienna
340 ("magenta" 5 35584 0 35584) ; DarkMagenta
341 ("red" 4 45568 8704 8704) ; FireBrick
342 ("cyan" 3 0 52736 53504) ; DarkTurquoise
343 ("green" 2 8704 35584 8704) ; ForestGreen
344 ("blue" 1 0 0 52480) ; MediumBlue
346 "A list of VGA console colors, their indices and 16-bit RGB values.")
348 ;; w32term.c sets this to nil, but if it has been overridden before we
349 ;; get here, we should not try to set it again.
350 (if (not w32-charset-info-alist
)
351 (progn (setq w32-charset-info-alist
352 '(("iso8859-1" .
(w32-charset-ansi .
1252))
353 ("jisx0208-sjis" .
(w32-charset-shiftjis .
932))
354 ("jisx0201-latin" .
(w32-charset-shiftjis .
932))
355 ("jisx0201-katakana" .
(w32-charset-shiftjis .
932))
356 ("ksc5601.1987" .
(w32-charset-hangul .
949))
357 ("big5" .
(w32-charset-chinesebig5 .
950))
358 ("gb2312" .
(w32-charset-gb2312 .
936))
359 ("ms-symbol" .
(w32-charset-symbol . nil
))
360 ("ms-oem" .
(w32-charset-oem .
437))
361 ("ms-oemlatin" .
(w32-charset-oem .
850))))
362 (if (boundp 'w32-extra-charsets-defined
)
364 (add-to-list 'w32-charset-info-alist
365 '("iso8859-2" .
(w32-charset-easteurope .
28592)))
366 (add-to-list 'w32-charset-info-alist
367 '("iso8859-3" .
(w32-charset-turkish .
28593)))
368 (add-to-list 'w32-charset-info-alist
369 '("iso8859-4" .
(w32-charset-baltic .
28594)))
370 (add-to-list 'w32-charset-info-alist
371 '("iso8859-5" .
(w32-charset-russian .
28595)))
372 (add-to-list 'w32-charset-info-alist
373 '("iso8859-6" .
(w32-charset-arabic .
28596)))
374 (add-to-list 'w32-charset-info-alist
375 '("iso8859-7" .
(w32-charset-greek .
28597)))
376 (add-to-list 'w32-charset-info-alist
377 '("iso8859-8" .
(w32-charset-hebrew .
1255)))
378 (add-to-list 'w32-charset-info-alist
379 '("iso8859-9" .
(w32-charset-turkish .
1254)))
380 (add-to-list 'w32-charset-info-alist
381 '("iso8859-13" .
(w32-charset-baltic .
1257)))
382 (add-to-list 'w32-charset-info-alist
383 '("koi8-r" .
(w32-charset-russian .
20866)))
384 (add-to-list 'w32-charset-info-alist
385 '("tis620" .
(w32-charset-thai .
874)))
386 (add-to-list 'w32-charset-info-alist
387 '("ksc5601.1992" .
(w32-charset-johab .
1361)))
388 (add-to-list 'w32-charset-info-alist
389 '("mac" .
(w32-charset-mac . nil
))))))
390 (if (boundp 'w32-unicode-charset-defined
)
392 (add-to-list 'w32-charset-info-alist
393 '("iso10646" .
(w32-charset-unicode . t
)))
394 (add-to-list 'w32-charset-info-alist
395 '("unicode" .
(w32-charset-unicode . t
))))))
397 (make-obsolete-variable 'w32-enable-italics
'w32-enable-synthesized-fonts
)
398 (make-obsolete-variable 'w32-charset-to-codepage-alist
399 "w32-charset-to-codepage-alist has been replaced by the more extensive
400 w32-charset-info-alist")
402 ;;; w32-fns.el ends here