(vc-update-change-log): Doc fix.
[emacs.git] / lisp / w32-fns.el
blobc681dc7b6e4e03e7500865d48429831c718283fa
1 ;;; winnt.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 ;; Show file type (text or binary) on modeline
43 (setq-default mode-line-format
44 (list (purecopy "")
45 'mode-line-modified
46 'mode-line-buffer-identification
47 (purecopy " ")
48 'global-mode-string
49 (purecopy " %[(")
50 (purecopy "%t:")
51 'mode-name 'mode-line-process 'minor-mode-alist
52 (purecopy "%n")
53 (purecopy ")%]--")
54 (purecopy '(line-number-mode "L%l--"))
55 (purecopy '(column-number-mode "C%c--"))
56 (purecopy '(-3 . "%p"))
57 (purecopy "-%-")))
59 ;; Ignore case on file-name completion
60 (setq completion-ignore-case t)
62 ;; The cmd.exe shell uses the "/c" switch instead of the "-c" switch
63 ;; for executing its command line argument (from simple.el).
64 (setq shell-command-switch "/c")
66 ;; For appending suffixes to directories and files in shell completions.
67 (add-hook 'shell-mode-hook
68 '(lambda () (setq comint-completion-addsuffix '("\\" . " "))))
70 ;; Use ";" instead of ":" as a path separator (from files.el).
71 (setq path-separator ";")
73 ;; Set the null device (for compile.el).
74 (setq grep-null-device "NUL")
76 ;; Set the grep regexp to match entries with drive letters.
77 (setq grep-regexp-alist
78 '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3)))
80 ;; Taken from dos-fn.el ... don't want all that's in the file, maybe
81 ;; separate it out someday.
83 (defvar file-name-buffer-file-type-alist
85 ("[:/].*config.sys$" . nil) ; config.sys text
86 ("\\.elc$" . t) ; emacs stuff
87 ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\)$" . t)
88 ; MS-Dos stuff
89 ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t)
90 ; Packers
91 ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\)$" . t)
92 ; Unix stuff
93 ("\\.tp[ulpw]$" . t)
94 ; Borland Pascal stuff
96 "*Alist for distinguishing text files from binary files.
97 Each element has the form (REGEXP . TYPE), where REGEXP is matched
98 against the file name, and TYPE is nil for text, t for binary.")
100 (defun find-buffer-file-type (filename)
101 (let ((alist file-name-buffer-file-type-alist)
102 (found nil)
103 (code nil))
104 (let ((case-fold-search t))
105 (setq filename (file-name-sans-versions filename))
106 (while (and (not found) alist)
107 (if (string-match (car (car alist)) filename)
108 (setq code (cdr (car alist))
109 found t))
110 (setq alist (cdr alist))))
111 (if found
112 (cond((memq code '(nil t)) code)
113 ((and (symbolp code) (fboundp code))
114 (funcall code filename)))
115 default-buffer-file-type)))
117 (defun find-file-binary (filename)
118 "Visit file FILENAME and treat it as binary."
119 (interactive "FFind file binary: ")
120 (let ((file-name-buffer-file-type-alist '(("" . t))))
121 (find-file filename)))
123 (defun find-file-text (filename)
124 "Visit file FILENAME and treat it as a text file."
125 (interactive "FFind file text: ")
126 (let ((file-name-buffer-file-type-alist '(("" . nil))))
127 (find-file filename)))
129 (defun find-file-not-found-set-buffer-file-type ()
130 (save-excursion
131 (set-buffer (current-buffer))
132 (setq buffer-file-type (find-buffer-file-type (buffer-file-name))))
133 nil)
135 ;;; To set the default file type on new files.
136 (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type)
138 ;;; For using attached Unix filesystems.
139 (defun save-to-unix-hook ()
140 (save-excursion
141 (setq buffer-file-type t))
142 nil)
144 (defun revert-from-unix-hook ()
145 (save-excursion
146 (setq buffer-file-type (find-buffer-file-type (buffer-file-name))))
147 nil)
149 ;; Really should provide this capability at the drive letter granularity.
150 (defun using-unix-filesystems (flag)
151 "Read and write files without CR/LF translation, if FLAG is non-nil.
152 This is in effect assuming the files are on a remote Unix file system.
153 If FLAG is nil, resume using CR/LF translation as usual."
154 (if flag
155 (progn
156 (add-hook 'write-file-hooks 'save-to-unix-hook)
157 (add-hook 'after-save-hook 'revert-from-unix-hook))
158 (progn
159 (remove-hook 'write-file-hooks 'save-to-unix-hook)
160 (remove-hook 'after-save-hook 'revert-from-unix-hook))))
162 ;;; Avoid creating auto-save file names containing invalid characters
163 ;;; (primarily "*", eg. for the *mail* buffer).
164 (fset 'original-make-auto-save-file-name
165 (symbol-function 'make-auto-save-file-name))
167 (defun make-auto-save-file-name ()
168 "Return file name to use for auto-saves of current buffer.
169 Does not consider `auto-save-visited-file-name' as that variable is checked
170 before calling this function. You can redefine this for customization.
171 See also `auto-save-file-name-p'."
172 (let ((name (original-make-auto-save-file-name))
173 (start 0))
174 ;; destructively replace occurences of * or ? with $
175 (while (string-match "[?*]" name start)
176 (aset name (match-beginning 0) ?$)
177 (setq start (1+ (match-end 0))))
178 name))
180 ;;; Fix interface to (X-specific) mouse.el
181 (defun x-set-selection (type data)
182 (or type (setq type 'PRIMARY))
183 (put 'x-selections type data))
185 (defun x-get-selection (&optional type data-type)
186 (or type (setq type 'PRIMARY))
187 (get 'x-selections type))
189 (fmakunbound 'font-menu-add-default)
190 (global-unset-key [C-down-mouse-1])
191 (global-unset-key [C-down-mouse-2])
192 (global-unset-key [C-down-mouse-3])
194 ;;; Set to a system sound if you want a fancy bell.
195 (set-message-beep nil)
197 ;;; winnt.el ends here