* calendar/todo-mode.el (todo-set-top-priorities): Fix logic to
[bpt/emacs.git] / lisp / w32-fns.el
CommitLineData
06b60517 1;;; w32-fns.el --- Lisp routines for 32-bit Windows
b578f267 2
ba318903 3;; Copyright (C) 1994, 2001-2014 Free Software Foundation, Inc.
95ed0025 4
68429d86 5;; Author: Geoff Voelker <voelker@cs.washington.edu>
284b3043 6;; Keywords: internal
bd78fa1d 7;; Package: emacs
95ed0025
RS
8
9;; This file is part of GNU Emacs.
10
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
95ed0025 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
95ed0025
RS
15
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.
20
21;; You should have received a copy of the GNU General Public License
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
95ed0025
RS
23
24;;; Commentary:
25
95ed0025
RS
26
27;;; Code:
2f42c75f 28(require 'w32-vars)
0fda9b75 29(require 'w32-common-fns)
95ed0025 30
b5de9ae0
JB
31(defvar explicit-shell-file-name)
32
716eb574
JR
33;;;; Function keys
34
9a5f296f 35(declare-function set-message-beep "w32fns.c")
73e6adaa
DN
36(declare-function w32-get-locale-info "w32proc.c")
37(declare-function w32-get-valid-locale-ids "w32proc.c")
81b38822 38
bcaf1c36 39;; Map all versions of a filename (8.3, longname, mixed case) to the
d234707d
GV
40;; same buffer.
41(setq find-file-visit-truename t)
42
ee82af56 43(defun w32-shell-name ()
d234707d 44 "Return the name of the shell being used."
d43bb7d3 45 (or (bound-and-true-p shell-file-name)
ee82af56
GV
46 (getenv "ESHELL")
47 (getenv "SHELL")
48 (and (w32-using-nt) "cmd.exe")
49 "command.com"))
50
d234707d
GV
51(defun w32-system-shell-p (shell-name)
52 (and shell-name
bcaf1c36 53 (member (downcase (file-name-nondirectory shell-name))
d234707d 54 w32-system-shells)))
ee82af56 55
f3e62da2 56(defun w32-shell-dos-semantics ()
8fc29035 57 "Return non-nil if the interactive shell being used expects MS-DOS shell semantics."
f3e62da2
GV
58 (or (w32-system-shell-p (w32-shell-name))
59 (and (member (downcase (file-name-nondirectory (w32-shell-name)))
60 '("cmdproxy" "cmdproxy.exe"))
61 (w32-system-shell-p (getenv "COMSPEC")))))
62
200fe89b
DN
63(defvar w32-quote-process-args) ;; defined in w32proc.c
64
d234707d 65(defun w32-check-shell-configuration ()
72ab66eb 66 "Check the configuration of shell variables on Windows.
ee82af56 67This function is invoked after loading the init files and processing
d234707d
GV
68the command line arguments. It issues a warning if the user or site
69has configured the shell with inappropriate settings."
85f568ec 70 (interactive)
d234707d
GV
71 (let ((prev-buffer (current-buffer))
72 (buffer (get-buffer-create "*Shell Configuration*"))
73 (system-shell))
74 (set-buffer buffer)
75 (erase-buffer)
76 (if (w32-system-shell-p (getenv "ESHELL"))
77 (insert (format "Warning! The ESHELL environment variable uses %s.
bcaf1c36 78You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
d234707d
GV
79 (getenv "ESHELL"))))
80 (if (w32-system-shell-p (getenv "SHELL"))
81 (insert (format "Warning! The SHELL environment variable uses %s.
bcaf1c36 82You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
d234707d
GV
83 (getenv "SHELL"))))
84 (if (w32-system-shell-p shell-file-name)
85 (insert (format "Warning! shell-file-name uses %s.
bcaf1c36 86You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
d234707d
GV
87 shell-file-name)))
88 (if (and (boundp 'explicit-shell-file-name)
89 (w32-system-shell-p explicit-shell-file-name))
90 (insert (format "Warning! explicit-shell-file-name uses %s.
91You probably want to change it so that it uses cmdproxy.exe instead.\n\n"
92 explicit-shell-file-name)))
93 (setq system-shell (> (buffer-size) 0))
85f568ec
GV
94
95 ;; Allow user to specify that they really do want to use one of the
96 ;; "system" shells, despite the drawbacks, but still warn if
97 ;; shell-command-switch doesn't match.
98 (if w32-allow-system-shell
99 (erase-buffer))
100
d234707d
GV
101 (cond (system-shell
102 ;; System shells.
103 (if (string-equal "-c" shell-command-switch)
104 (insert "Warning! shell-command-switch is \"-c\".
105You should set this to \"/c\" when using a system shell.\n\n"))
106 (if w32-quote-process-args
107 (insert "Warning! w32-quote-process-args is t.
108You should set this to nil when using a system shell.\n\n")))
109 ;; Non-system shells.
110 (t
111 (if (string-equal "/c" shell-command-switch)
112 (insert "Warning! shell-command-switch is \"/c\".
113You should set this to \"-c\" when using a non-system shell.\n\n"))
114 (if (not w32-quote-process-args)
115 (insert "Warning! w32-quote-process-args is nil.
116You should set this to t when using a non-system shell.\n\n"))))
117 (if (> (buffer-size) 0)
118 (display-buffer buffer)
119 (kill-buffer buffer))
120 (set-buffer prev-buffer)))
121
122(add-hook 'after-init-hook 'w32-check-shell-configuration)
123
f2b256fa 124;; Override setting chosen at startup.
b1ed8648
AI
125(defun set-default-process-coding-system ()
126 ;; Most programs on Windows will accept Unix line endings on input
127 ;; (and some programs ported from Unix require it) but most will
128 ;; produce DOS line endings on output.
129 (setq default-process-coding-system
597e2240 130 (if (default-value 'enable-multibyte-characters)
b1ed8648
AI
131 '(undecided-dos . undecided-unix)
132 '(raw-text-dos . raw-text-unix)))
a272a739
JR
133 ;; Make cmdproxy default to using DOS line endings for input,
134 ;; because some Windows programs (including command.com) require it.
135 (add-to-list 'process-coding-system-alist
136 `("[cC][mM][dD][pP][rR][oO][xX][yY]"
597e2240 137 . ,(if (default-value 'enable-multibyte-characters)
a272a739
JR
138 '(undecided-dos . undecided-dos)
139 '(raw-text-dos . raw-text-dos))))
140 ;; plink needs DOS input when entering the password.
141 (add-to-list 'process-coding-system-alist
142 `("[pP][lL][iI][nN][kK]"
597e2240 143 . ,(if (default-value 'enable-multibyte-characters)
a272a739
JR
144 '(undecided-dos . undecided-dos)
145 '(raw-text-dos . raw-text-dos)))))
b1ed8648
AI
146
147(add-hook 'before-init-hook 'set-default-process-coding-system)
148
85f568ec 149
44e97401 150;;; Basic support functions for managing Emacs's locale setting
85f568ec
GV
151
152(defvar w32-valid-locales nil
153 "List of locale ids known to be supported.")
154
f2b256fa
SM
155;; This is the brute-force version; an efficient version is now
156;; built-in though.
85f568ec
GV
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."
160 (let ((i 65535)
161 locales)
162 (while (> i 0)
163 (if (w32-get-locale-info i)
164 (setq locales (cons i locales)))
165 (setq i (1- i)))
166 locales)))
167
168(defun w32-list-locales ()
169 "List the name and id of all locales supported by Windows."
170 (interactive)
ac62ec16
JB
171 (when (null w32-valid-locales)
172 (setq w32-valid-locales (sort (w32-get-valid-locale-ids) #'<)))
555e23cf
JB
173 (with-output-to-temp-buffer "*Supported Locales*"
174 (princ "LCID\tAbbrev\tFull name\n\n")
011a0143
JB
175 (dolist (locale w32-valid-locales)
176 (princ (format "%d\t%s\t%s\n"
177 locale
178 (w32-get-locale-info locale)
179 (w32-get-locale-info locale t))))))
85f568ec 180
f2b256fa
SM
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.
190
191;;(add-hook 'before-init-hook
192;; (lambda ()
193;; (setq source-directory (file-name-as-directory
194;; (expand-file-name ".." exec-directory)))))
8929f478 195
98d8b17e 196(defun w32-convert-standard-filename (filename)
b61dfbe2 197 "Convert a standard file's name to something suitable for MS-Windows.
915b0bf0
JB
198This means to guarantee valid names and perhaps to canonicalize
199certain patterns.
200
98d8b17e
EZ
201This function is called by `convert-standard-filename'.
202
203Replace invalid characters and turn Cygwin names into native
204names, and also turn slashes into backslashes if the shell
205requires it (see `w32-shell-dos-semantics')."
45b8a401
EZ
206 (save-match-data
207 (let ((name
208 (if (string-match "\\`/cygdrive/\\([a-zA-Z]\\)/" filename)
bcaf1c36 209 (replace-match "\\1:/" t nil filename)
45b8a401
EZ
210 (copy-sequence filename)))
211 (start 0))
212 ;; leave ':' if part of drive specifier
213 (if (and (> (length name) 1)
214 (eq (aref name 1) ?:))
215 (setq start 2))
216 ;; destructively replace invalid filename characters with !
217 (while (string-match "[?*:<>|\"\000-\037]" name start)
218 (aset name (match-beginning 0) ?!)
219 (setq start (match-end 0)))
220 ;; convert directory separators to Windows format
221 ;; (but only if the shell in use requires it)
222 (when (w32-shell-dos-semantics)
223 (setq start 0)
224 (while (string-match "/" name start)
225 (aset name (match-beginning 0) ?\\)
226 (setq start (match-end 0))))
227 name)))
4e0cd0df 228
1b42a753 229(defun set-w32-system-coding-system (coding-system)
49bd2bfe 230 "Set the coding system used by the Windows system to CODING-SYSTEM.
1b42a753 231This is used for things like passing font names with non-ASCII
551ea1bd 232characters in them to the system. For a list of possible values of
086ceb30
JR
233CODING-SYSTEM, use \\[list-coding-systems].
234
235This function is provided for backward compatibility, since
49bd2bfe 236`w32-system-coding-system' is now an alias for `locale-coding-system'."
1b42a753 237 (interactive
086ceb30 238 (list (let ((default locale-coding-system))
1b42a753 239 (read-coding-system
5b76833f 240 (format "Coding system for system calls (default %s): "
1b42a753
GV
241 default)
242 default))))
243 (check-coding-system coding-system)
086ceb30
JR
244 (setq locale-coding-system coding-system))
245
246;; locale-coding-system was introduced to do the same thing as
247;; w32-system-coding-system. Use that instead.
248(defvaralias 'w32-system-coding-system 'locale-coding-system)
1b42a753 249
f2b256fa 250;; Set to a system sound if you want a fancy bell.
81b38822
KH
251(set-message-beep nil)
252
7cc3af27
GM
253(defvar w32-charset-info-alist) ; w32font.c
254
15fa6efb
JR
255(defun w32-add-charset-info (xlfd-charset windows-charset codepage)
256 "Function to add character sets to display with Windows fonts.
257Creates entries in `w32-charset-info-alist'.
258XLFD-CHARSET is a string which will appear in the XLFD font name to
72ab66eb 259identify the character set. WINDOWS-CHARSET is a symbol identifying
551ea1bd
JB
260the Windows character set this maps to. For the list of possible
261values, see the documentation for `w32-charset-info-alist'. CODEPAGE
15fa6efb
JR
262can be a numeric codepage that Windows uses to display the character
263set, t for Unicode output with no codepage translation or nil for 8
264bit output with no translation."
265 (add-to-list 'w32-charset-info-alist
72ab66eb 266 (cons xlfd-charset (cons windows-charset codepage))))
15fa6efb 267
4c7ec703
JR
268;; The last charset we add becomes the "preferred" charset for the return
269;; value from w32-select-font etc, so list the most important charsets last.
15fa6efb
JR
270(w32-add-charset-info "iso8859-14" 'w32-charset-ansi 28604)
271(w32-add-charset-info "iso8859-15" 'w32-charset-ansi 28605)
2005121f
JR
272;; The following two are included for pattern matching.
273(w32-add-charset-info "jisx0201" 'w32-charset-shiftjis 932)
274(w32-add-charset-info "jisx0208" 'w32-charset-shiftjis 932)
15fa6efb
JR
275(w32-add-charset-info "jisx0201-latin" 'w32-charset-shiftjis 932)
276(w32-add-charset-info "jisx0201-katakana" 'w32-charset-shiftjis 932)
751be31e
JR
277(w32-add-charset-info "ksc5601.1989" 'w32-charset-hangeul 949)
278(w32-add-charset-info "big5" 'w32-charset-chinesebig5 950)
279(w32-add-charset-info "gb2312.1980" 'w32-charset-gb2312 936)
15fa6efb
JR
280(w32-add-charset-info "ms-symbol" 'w32-charset-symbol nil)
281(w32-add-charset-info "ms-oem" 'w32-charset-oem 437)
282(w32-add-charset-info "ms-oemlatin" 'w32-charset-oem 850)
57016d37
JR
283(w32-add-charset-info "iso8859-2" 'w32-charset-easteurope 28592)
284(w32-add-charset-info "iso8859-3" 'w32-charset-turkish 28593)
285(w32-add-charset-info "iso8859-4" 'w32-charset-baltic 28594)
286(w32-add-charset-info "iso8859-6" 'w32-charset-arabic 28596)
287(w32-add-charset-info "iso8859-7" 'w32-charset-greek 28597)
288(w32-add-charset-info "iso8859-8" 'w32-charset-hebrew 1255)
289(w32-add-charset-info "iso8859-9" 'w32-charset-turkish 1254)
290(w32-add-charset-info "iso8859-13" 'w32-charset-baltic 1257)
291(w32-add-charset-info "koi8-r" 'w32-charset-russian 20866)
292(w32-add-charset-info "iso8859-5" 'w32-charset-russian 28595)
18885c11 293(w32-add-charset-info "tis620-2533" 'w32-charset-thai 874)
57016d37
JR
294(w32-add-charset-info "windows-1258" 'w32-charset-vietnamese 1258)
295(w32-add-charset-info "ksc5601.1992" 'w32-charset-johab 1361)
7992f52c
JR
296(w32-add-charset-info "mac-roman" 'w32-charset-mac 10000)
297(w32-add-charset-info "iso10646-1" 'w32-charset-default t)
57016d37 298
fe7a3057 299;; ;; If Unicode Windows charset is not defined, use ansi fonts.
2005121f
JR
300;; (w32-add-charset-info "iso10646-1" 'w32-charset-ansi t))
301
e4920bc9 302;; Preferred names
2005121f
JR
303(w32-add-charset-info "big5-0" 'w32-charset-chinesebig5 950)
304(w32-add-charset-info "gb2312.1980-0" 'w32-charset-gb2312 936)
305(w32-add-charset-info "jisx0208-sjis" 'w32-charset-shiftjis 932)
306(w32-add-charset-info "ksc5601.1987-0" 'w32-charset-hangeul 949)
307(w32-add-charset-info "tis620-0" 'w32-charset-thai 874)
4c7ec703 308(w32-add-charset-info "iso8859-1" 'w32-charset-ansi 1252)
52f32671 309
3b4cf5db 310\f
3712a0b3 311;;;; Support for build process
06b60517
JB
312
313;; From autoload.el
314(defvar autoload-make-program)
315(defvar generated-autoload-file)
316
3712a0b3
EZ
317(defun w32-batch-update-autoloads ()
318 "Like `batch-update-autoloads', but takes the name of the autoloads file
319from the command line.
320
321This is required because some Windows build environments, such as MSYS,
322munge command-line arguments that include file names to a horrible mess
323that Emacs is unable to cope with."
324 (let ((generated-autoload-file
af9fb32f
GM
325 (expand-file-name (pop command-line-args-left)))
326 ;; I can only assume the same considerations may apply here...
327 (autoload-make-program (pop command-line-args-left)))
3712a0b3 328 (batch-update-autoloads)))
3b4cf5db 329
d1dcf3e7
EZ
330(defun w32-append-code-lines (orig extra)
331 "Append non-empty non-comment lines in the file EXTRA to the file ORIG.
332
333This function saves all buffers and kills the Emacs session, without asking
334for any permissions.
335
336This is required because the Windows build environment is not required
337to include Sed, which is used by leim/Makefile.in to do the job."
338 (find-file orig)
339 (goto-char (point-max))
340 (insert-file-contents extra)
341 (delete-matching-lines "^$\\|^;")
342 (save-buffers-kill-emacs t))
343
a0d14345 344;;; w32-fns.el ends here