(cvs-mode-add-change-log-entry-other-window):
[emacs.git] / lisp / w32-fns.el
blob0f30dd63bead1c8a2a5801d6ab561359b5273e56
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)
12 ;; any later version.
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.
24 ;;; Commentary:
26 ;; (August 12, 1993)
27 ;; Created.
29 ;; (November 21, 1994)
30 ;; [C-M-backspace] defined.
31 ;; mode-line-format defined to show buffer file type.
32 ;; audio bell initialized.
34 ;;; Code:
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
46 ;; same buffer.
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"
51 "ndos" "ndos.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)
61 (getenv "ESHELL")
62 (getenv "SHELL")
63 (and (w32-using-nt) "cmd.exe")
64 "command.com"))
66 (defun w32-system-shell-p (shell-name)
67 (and shell-name
68 (member (downcase (file-name-nondirectory shell-name))
69 w32-system-shells)))
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."
86 (interactive)
87 (let ((prev-buffer (current-buffer))
88 (buffer (get-buffer-create "*Shell Configuration*"))
89 (system-shell))
90 (set-buffer buffer)
91 (erase-buffer)
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"
95 (getenv "ESHELL"))))
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"
99 (getenv "SHELL"))))
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"
103 shell-file-name)))
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
115 (erase-buffer))
117 (cond (system-shell
118 ;; System shells.
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)))
149 (or (w32-using-nt)
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
167 ;;; built-in though.
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."
171 (let ((i 65535)
172 locales)
173 (while (> i 0)
174 (if (w32-get-locale-info i)
175 (setq locales (cons i locales)))
176 (setq i (1- i)))
177 locales)))
179 (defun w32-list-locales ()
180 "List the name and id of all locales supported by Windows."
181 (interactive)
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*"))
185 (erase-buffer)
186 (insert "LCID\tAbbrev\tFull name\n\n")
187 (insert (mapconcat
188 '(lambda (x)
189 (format "%d\t%s\t%s"
191 (w32-get-locale-info x)
192 (w32-get-locale-info x t)))
193 w32-valid-locales "\n"))
194 (insert "\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
227 ; '(lambda ()
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 (let ((filename (original-make-auto-save-file-name)))
241 ;; Don't modify remote (ange-ftp) filenames
242 (if (string-match "^/\\w+@[-A-Za-z0-9._]+:" filename)
243 filename
244 (convert-standard-filename filename))))
246 (defun convert-standard-filename (filename)
247 "Convert a standard file's name to something suitable for the current OS.
248 This function's standard definition is trivial; it just returns the argument.
249 However, on some systems, the function is redefined
250 with a definition that really does change some file names."
251 (let ((name (copy-sequence filename))
252 (start 0))
253 ;; leave ':' if part of drive specifier
254 (if (eq (aref name 1) ?:)
255 (setq start 2))
256 ;; destructively replace invalid filename characters with !
257 (while (string-match "[?*:<>|\"\000-\037]" name start)
258 (aset name (match-beginning 0) ?!)
259 (setq start (match-end 0)))
260 ;; convert directory separators to Windows format
261 ;; (but only if the shell in use requires it)
262 (if (w32-shell-dos-semantics)
263 (while (string-match "/" name start)
264 (aset name (match-beginning 0) ?\\)
265 (setq start (match-end 0))))
266 name))
268 ;;; Fix interface to (X-specific) mouse.el
269 (defun x-set-selection (type data)
270 (or type (setq type 'PRIMARY))
271 (put 'x-selections type data))
273 (defun x-get-selection (&optional type data-type)
274 (or type (setq type 'PRIMARY))
275 (get 'x-selections type))
277 (defun set-w32-system-coding-system (coding-system)
278 "Set the coding system used by the Windows System to CODING-SYSTEM.
279 This is used for things like passing font names with non-ASCII
280 characters in them to the system. For a list of possible values of
281 CODING-SYSTEM, use \\[list-coding-systems]."
282 (interactive
283 (list (let ((default w32-system-coding-system))
284 (read-coding-system
285 (format "Coding system for system calls (default, %s): "
286 default)
287 default))))
288 (check-coding-system coding-system)
289 (setq w32-system-coding-system coding-system))
290 ;; Set system coding system initially to iso-latin-1
291 (set-w32-system-coding-system 'iso-latin-1)
293 ;;; Set to a system sound if you want a fancy bell.
294 (set-message-beep nil)
296 ;;; The "Windows" keys on newer keyboards bring up the Start menu
297 ;;; whether you want it or not - make Emacs ignore these keystrokes
298 ;;; rather than beep.
299 (global-set-key [lwindow] 'ignore)
300 (global-set-key [rwindow] 'ignore)
302 ;; Map certain keypad keys into ASCII characters
303 ;; that people usually expect.
304 (define-key function-key-map [tab] [?\t])
305 (define-key function-key-map [linefeed] [?\n])
306 (define-key function-key-map [clear] [11])
307 (define-key function-key-map [return] [13])
308 (define-key function-key-map [escape] [?\e])
309 (define-key function-key-map [M-tab] [?\M-\t])
310 (define-key function-key-map [M-linefeed] [?\M-\n])
311 (define-key function-key-map [M-clear] [?\M-\013])
312 (define-key function-key-map [M-return] [?\M-\015])
313 (define-key function-key-map [M-escape] [?\M-\e])
315 ;; These don't do the right thing (voelker)
316 ;(define-key function-key-map [backspace] [127])
317 ;(define-key function-key-map [delete] [127])
318 ;(define-key function-key-map [M-backspace] [?\M-\d])
319 ;(define-key function-key-map [M-delete] [?\M-\d])
321 ;; These tell read-char how to convert
322 ;; these special chars to ASCII.
323 (put 'tab 'ascii-character ?\t)
324 (put 'linefeed 'ascii-character ?\n)
325 (put 'clear 'ascii-character 12)
326 (put 'return 'ascii-character 13)
327 (put 'escape 'ascii-character ?\e)
328 (put 'backspace 'ascii-character 127)
329 (put 'delete 'ascii-character 127)
331 ;; W32 uses different color indexes than standard:
333 (defvar w32-tty-standard-colors
334 '(("white" 15 65535 65535 65535)
335 ("yellow" 14 65535 65535 0) ; Yellow
336 ("lightmagenta" 13 65535 0 65535) ; Magenta
337 ("lightred" 12 65535 0 0) ; Red
338 ("lightcyan" 11 0 65535 65535) ; Cyan
339 ("lightgreen" 10 0 65535 0) ; Green
340 ("lightblue" 9 0 0 65535) ; Blue
341 ("darkgray" 8 26112 26112 26112) ; Gray40
342 ("lightgray" 7 48640 48640 48640) ; Gray
343 ("brown" 6 40960 20992 11520) ; Sienna
344 ("magenta" 5 35584 0 35584) ; DarkMagenta
345 ("red" 4 45568 8704 8704) ; FireBrick
346 ("cyan" 3 0 52736 53504) ; DarkTurquoise
347 ("green" 2 8704 35584 8704) ; ForestGreen
348 ("blue" 1 0 0 52480) ; MediumBlue
349 ("black" 0 0 0 0))
350 "A list of VGA console colors, their indices and 16-bit RGB values.")
352 ;; w32term.c sets this to nil, but if it has been overridden before we
353 ;; get here, we should not try to set it again.
354 (if (not w32-charset-info-alist)
355 (progn (setq w32-charset-info-alist
356 '(("iso8859-1" . (w32-charset-ansi . 1252))
357 ("jisx0208-sjis" . (w32-charset-shiftjis . 932))
358 ("jisx0201-latin" . (w32-charset-shiftjis . 932))
359 ("jisx0201-katakana" . (w32-charset-shiftjis . 932))
360 ("ksc5601.1987" . (w32-charset-hangul . 949))
361 ("big5" . (w32-charset-chinesebig5 . 950))
362 ("gb2312" . (w32-charset-gb2312 . 936))
363 ("ms-symbol" . (w32-charset-symbol . nil))
364 ("ms-oem" . (w32-charset-oem . 437))
365 ("ms-oemlatin" . (w32-charset-oem . 850))))
366 (if (boundp 'w32-extra-charsets-defined)
367 (progn
368 (add-to-list 'w32-charset-info-alist
369 '("iso8859-2" . (w32-charset-easteurope . 28592)))
370 (add-to-list 'w32-charset-info-alist
371 '("iso8859-3" . (w32-charset-turkish . 28593)))
372 (add-to-list 'w32-charset-info-alist
373 '("iso8859-4" . (w32-charset-baltic . 28594)))
374 (add-to-list 'w32-charset-info-alist
375 '("iso8859-5" . (w32-charset-russian . 28595)))
376 (add-to-list 'w32-charset-info-alist
377 '("iso8859-6" . (w32-charset-arabic . 28596)))
378 (add-to-list 'w32-charset-info-alist
379 '("iso8859-7" . (w32-charset-greek . 28597)))
380 (add-to-list 'w32-charset-info-alist
381 '("iso8859-8" . (w32-charset-hebrew . 1255)))
382 (add-to-list 'w32-charset-info-alist
383 '("iso8859-9" . (w32-charset-turkish . 1254)))
384 (add-to-list 'w32-charset-info-alist
385 '("iso8859-13" . (w32-charset-baltic . 1257)))
386 (add-to-list 'w32-charset-info-alist
387 '("koi8-r" . (w32-charset-russian . 20866)))
388 (add-to-list 'w32-charset-info-alist
389 '("tis620" . (w32-charset-thai . 874)))
390 (add-to-list 'w32-charset-info-alist
391 '("ksc5601.1992" . (w32-charset-johab . 1361)))
392 (add-to-list 'w32-charset-info-alist
393 '("mac" . (w32-charset-mac . nil))))))
394 (if (boundp 'w32-unicode-charset-defined)
395 (progn
396 (add-to-list 'w32-charset-info-alist
397 '("iso10646" . (w32-charset-unicode . t)))
398 (add-to-list 'w32-charset-info-alist
399 '("unicode" . (w32-charset-unicode . t))))))
401 (make-obsolete-variable 'w32-enable-italics 'w32-enable-synthesized-fonts)
402 (make-obsolete-variable 'w32-charset-to-codepage-alist
403 "w32-charset-to-codepage-alist has been replaced by the more extensive
404 w32-charset-info-alist")
406 ;;; w32-fns.el ends here