Commit | Line | Data |
---|---|---|
a0d14345 | 1 | ;;; w32-fns.el --- Lisp routines for Windows NT. |
b578f267 | 2 | |
95ed0025 RS |
3 | ;; Copyright (C) 1994 Free Software Foundation, Inc. |
4 | ||
68429d86 | 5 | ;; Author: Geoff Voelker <voelker@cs.washington.edu> |
95ed0025 RS |
6 | |
7 | ;; This file is part of GNU Emacs. | |
8 | ||
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. | |
13 | ||
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. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
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. | |
95ed0025 RS |
23 | |
24 | ;;; Commentary: | |
25 | ||
26 | ;; (August 12, 1993) | |
81b38822 | 27 | ;; Created. |
95ed0025 | 28 | |
81b38822 KH |
29 | ;; (November 21, 1994) |
30 | ;; [C-M-backspace] defined. | |
31 | ;; mode-line-format defined to show buffer file type. | |
32 | ;; audio bell initialized. | |
95ed0025 RS |
33 | |
34 | ;;; Code: | |
35 | ||
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]) | |
81b38822 KH |
40 | (define-key function-key-map [C-M-backspace] [\C-\M-delete]) |
41 | ||
95ed0025 RS |
42 | ;; Ignore case on file-name completion |
43 | (setq completion-ignore-case t) | |
44 | ||
d234707d GV |
45 | ;; Map all versions of a filename (8.3, longname, mixed case) to the |
46 | ;; same buffer. | |
47 | (setq find-file-visit-truename t) | |
48 | ||
85f568ec GV |
49 | (defvar w32-system-shells '("cmd" "cmd.exe" "command" "command.com" |
50 | "4nt" "4nt.exe" "4dos" "4dos.exe" | |
51 | "ndos" "ndos.exe") | |
d234707d | 52 | "List of strings recognized as Windows NT/9X system shells.") |
ee82af56 GV |
53 | |
54 | (defun w32-using-nt () | |
d234707d | 55 | "Return t if literally running on Windows NT (i.e., not Windows 9X)." |
ee82af56 GV |
56 | (and (eq system-type 'windows-nt) (getenv "SystemRoot"))) |
57 | ||
58 | (defun w32-shell-name () | |
d234707d | 59 | "Return the name of the shell being used." |
ee82af56 GV |
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")) | |
65 | ||
d234707d GV |
66 | (defun w32-system-shell-p (shell-name) |
67 | (and shell-name | |
68 | (member (downcase (file-name-nondirectory shell-name)) | |
69 | w32-system-shells))) | |
ee82af56 | 70 | |
f3e62da2 GV |
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"))))) | |
77 | ||
85f568ec GV |
78 | (defvar w32-allow-system-shell nil |
79 | "*Disable startup warning when using \"system\" shells.") | |
80 | ||
d234707d GV |
81 | (defun w32-check-shell-configuration () |
82 | "Check the configuration of shell variables on Windows NT/9X. | |
ee82af56 | 83 | This function is invoked after loading the init files and processing |
d234707d GV |
84 | the command line arguments. It issues a warning if the user or site |
85 | has configured the shell with inappropriate settings." | |
85f568ec | 86 | (interactive) |
d234707d GV |
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)) | |
85f568ec GV |
110 | |
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)) | |
116 | ||
d234707d GV |
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. | |
126 | (t | |
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))) | |
137 | ||
138 | (add-hook 'after-init-hook 'w32-check-shell-configuration) | |
139 | ||
85f568ec GV |
140 | |
141 | ;;; Basic support functions for managing Emacs' locale setting | |
142 | ||
143 | (defvar w32-valid-locales nil | |
144 | "List of locale ids known to be supported.") | |
145 | ||
146 | ;;; This is the brute-force version; an efficient version is now | |
147 | ;;; built-in though. | |
148 | (if (not (fboundp 'w32-get-valid-locale-ids)) | |
149 | (defun w32-get-valid-locale-ids () | |
150 | "Return list of all valid Windows locale ids." | |
151 | (let ((i 65535) | |
152 | locales) | |
153 | (while (> i 0) | |
154 | (if (w32-get-locale-info i) | |
155 | (setq locales (cons i locales))) | |
156 | (setq i (1- i))) | |
157 | locales))) | |
158 | ||
159 | (defun w32-list-locales () | |
160 | "List the name and id of all locales supported by Windows." | |
161 | (interactive) | |
162 | (if (null w32-valid-locales) | |
163 | (setq w32-valid-locales (w32-get-valid-locale-ids))) | |
164 | (switch-to-buffer-other-window (get-buffer-create "*Supported Locales*")) | |
165 | (erase-buffer) | |
166 | (insert "LCID\tAbbrev\tFull name\n\n") | |
167 | (insert (mapconcat | |
168 | '(lambda (x) | |
169 | (format "%d\t%s\t%s" | |
170 | x | |
171 | (w32-get-locale-info x) | |
172 | (w32-get-locale-info x t))) | |
173 | w32-valid-locales "\n")) | |
174 | (insert "\n") | |
175 | (goto-char (point-min))) | |
176 | ||
177 | ||
d234707d GV |
178 | ;;; Setup Info-default-directory-list to include the info directory |
179 | ;;; near where Emacs executable was installed. We used to set INFOPATH, | |
180 | ;;; but when this is set Info-default-directory-list is ignored. We | |
181 | ;;; also cannot rely upon what is set in paths.el because they assume | |
182 | ;;; that configuration during build time is correct for runtime. | |
183 | (defun w32-init-info () | |
184 | (let* ((instdir (file-name-directory invocation-directory)) | |
85f568ec | 185 | (dir1 (expand-file-name "../info/" instdir)) |
d234707d GV |
186 | (dir2 (expand-file-name "../../../info/" instdir))) |
187 | (if (file-exists-p dir1) | |
188 | (setq Info-default-directory-list | |
189 | (append Info-default-directory-list (list dir1))) | |
190 | (if (file-exists-p dir2) | |
191 | (setq Info-default-directory-list | |
192 | (append Info-default-directory-list (list dir2))))))) | |
193 | ||
194 | (add-hook 'before-init-hook 'w32-init-info) | |
3eab6a03 | 195 | |
8929f478 GV |
196 | ;;; The variable source-directory is used to initialize Info-directory-list. |
197 | ;;; However, the common case is that Emacs is being used from a binary | |
198 | ;;; distribution, and the value of source-directory is meaningless in that | |
199 | ;;; case. Even worse, source-directory can refer to a directory on a drive | |
200 | ;;; on the build machine that happens to be a removable drive on the user's | |
201 | ;;; machine. When this happens, Emacs tries to access the removable drive | |
202 | ;;; and produces the abort/retry/ignore dialog. Since we do not use | |
203 | ;;; source-directory, set it to something that is a reasonable approximation | |
204 | ;;; on the user's machine. | |
205 | ||
206 | (add-hook 'before-init-hook | |
207 | '(lambda () | |
208 | (setq source-directory (file-name-as-directory | |
209 | (expand-file-name ".." exec-directory))))) | |
210 | ||
926e2fdb | 211 | ;; Avoid creating auto-save file names containing invalid characters. |
4e0cd0df GV |
212 | (fset 'original-make-auto-save-file-name |
213 | (symbol-function 'make-auto-save-file-name)) | |
214 | ||
215 | (defun make-auto-save-file-name () | |
216 | "Return file name to use for auto-saves of current buffer. | |
217 | Does not consider `auto-save-visited-file-name' as that variable is checked | |
218 | before calling this function. You can redefine this for customization. | |
219 | See also `auto-save-file-name-p'." | |
d234707d GV |
220 | (convert-standard-filename (original-make-auto-save-file-name))) |
221 | ||
222 | (defun convert-standard-filename (filename) | |
223 | "Convert a standard file's name to something suitable for the current OS. | |
224 | This function's standard definition is trivial; it just returns the argument. | |
225 | However, on some systems, the function is redefined | |
226 | with a definition that really does change some file names." | |
227 | (let ((name (copy-sequence filename)) | |
4e0cd0df | 228 | (start 0)) |
d234707d GV |
229 | ;; leave ':' if part of drive specifier |
230 | (if (eq (aref name 1) ?:) | |
231 | (setq start 2)) | |
232 | ;; destructively replace invalid filename characters with ! | |
233 | (while (string-match "[?*:<>|\"\000-\037]" name start) | |
234 | (aset name (match-beginning 0) ?!) | |
235 | (setq start (match-end 0))) | |
dd89ee95 AI |
236 | ;; convert directory separators to Windows format |
237 | (while (string-match "/" name start) | |
238 | (aset name (match-beginning 0) ?\\) | |
239 | (setq start (match-end 0))) | |
4e0cd0df GV |
240 | name)) |
241 | ||
95ed0025 | 242 | ;;; Fix interface to (X-specific) mouse.el |
bffcf874 RS |
243 | (defun x-set-selection (type data) |
244 | (or type (setq type 'PRIMARY)) | |
245 | (put 'x-selections type data)) | |
246 | ||
247 | (defun x-get-selection (&optional type data-type) | |
248 | (or type (setq type 'PRIMARY)) | |
249 | (get 'x-selections type)) | |
250 | ||
81b38822 KH |
251 | ;;; Set to a system sound if you want a fancy bell. |
252 | (set-message-beep nil) | |
253 | ||
d234707d GV |
254 | ;;; The "Windows" keys on newer keyboards bring up the Start menu |
255 | ;;; whether you want it or not - make Emacs ignore these keystrokes | |
256 | ;;; rather than beep. | |
257 | (global-set-key [lwindow] 'ignore) | |
258 | (global-set-key [rwindow] 'ignore) | |
259 | ||
260 | ;; Map certain keypad keys into ASCII characters | |
261 | ;; that people usually expect. | |
262 | (define-key function-key-map [tab] [?\t]) | |
263 | (define-key function-key-map [linefeed] [?\n]) | |
264 | (define-key function-key-map [clear] [11]) | |
265 | (define-key function-key-map [return] [13]) | |
266 | (define-key function-key-map [escape] [?\e]) | |
267 | (define-key function-key-map [M-tab] [?\M-\t]) | |
268 | (define-key function-key-map [M-linefeed] [?\M-\n]) | |
269 | (define-key function-key-map [M-clear] [?\M-\013]) | |
270 | (define-key function-key-map [M-return] [?\M-\015]) | |
271 | (define-key function-key-map [M-escape] [?\M-\e]) | |
272 | ||
273 | ;; These don't do the right thing (voelker) | |
274 | ;(define-key function-key-map [backspace] [127]) | |
275 | ;(define-key function-key-map [delete] [127]) | |
276 | ;(define-key function-key-map [M-backspace] [?\M-\d]) | |
277 | ;(define-key function-key-map [M-delete] [?\M-\d]) | |
278 | ||
279 | ;; These tell read-char how to convert | |
280 | ;; these special chars to ASCII. | |
281 | (put 'tab 'ascii-character ?\t) | |
282 | (put 'linefeed 'ascii-character ?\n) | |
283 | (put 'clear 'ascii-character 12) | |
284 | (put 'return 'ascii-character 13) | |
285 | (put 'escape 'ascii-character ?\e) | |
286 | (put 'backspace 'ascii-character 127) | |
287 | (put 'delete 'ascii-character 127) | |
288 | ||
a0d14345 | 289 | ;;; w32-fns.el ends here |