Mercurial > emacs
comparison lisp/dos-fns.el @ 108520:a4cdc6d33cc6
* dos-fns.el: Add "dos-" prefix for namespace control.
(convert-standard-filename): Define as alias for
dos-convert-standard-filename but only if applicable.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 12 May 2010 20:35:07 -0400 |
parents | 1d1d5d9bd884 |
children | a5969c855306 |
comparison
equal
deleted
inserted
replaced
108519:24e2a1f40d57 | 108520:a4cdc6d33cc6 |
---|---|
29 | 29 |
30 (declare-function int86 "dosfns.c") | 30 (declare-function int86 "dosfns.c") |
31 (declare-function msdos-long-file-names "msdos.c") | 31 (declare-function msdos-long-file-names "msdos.c") |
32 | 32 |
33 ;; This overrides a trivial definition in files.el. | 33 ;; This overrides a trivial definition in files.el. |
34 (defun convert-standard-filename (filename) | 34 (defun dos-convert-standard-filename (filename) |
35 "Convert a standard file's name to something suitable for the current OS. | 35 "Convert a standard file's name to something suitable for the current OS. |
36 This means to guarantee valid names and perhaps to canonicalize | 36 This means to guarantee valid names and perhaps to canonicalize |
37 certain patterns. | 37 certain patterns. |
38 | 38 |
39 On Windows and DOS, replace invalid characters. On DOS, make | 39 On Windows and DOS, replace invalid characters. On DOS, make |
46 (string-match "\\`\\([a-zA-Z]:\\)?[/\\]?\\'" filename)) | 46 (string-match "\\`\\([a-zA-Z]:\\)?[/\\]?\\'" filename)) |
47 filename | 47 filename |
48 (let ((flen (length filename))) | 48 (let ((flen (length filename))) |
49 ;; If FILENAME has a trailing slash, remove it and recurse. | 49 ;; If FILENAME has a trailing slash, remove it and recurse. |
50 (if (memq (aref filename (1- flen)) '(?/ ?\\)) | 50 (if (memq (aref filename (1- flen)) '(?/ ?\\)) |
51 (concat (convert-standard-filename | 51 (concat (dos-convert-standard-filename |
52 (substring filename 0 (1- flen))) | 52 (substring filename 0 (1- flen))) |
53 "/") | 53 "/") |
54 (let* (;; ange-ftp gets in the way for names like "/foo:bar". | 54 (let* (;; ange-ftp gets in the way for names like "/foo:bar". |
55 ;; We need to inhibit all magic file names, because | 55 ;; We need to inhibit all magic file names, because |
56 ;; remote file names should never be passed through | 56 ;; remote file names should never be passed through |
120 ;; backup and auto-save files retain their telltale form. | 120 ;; backup and auto-save files retain their telltale form. |
121 (if (memq lastchar '(?~ ?#)) | 121 (if (memq lastchar '(?~ ?#)) |
122 (aset string (1- (length string)) lastchar)))) | 122 (aset string (1- (length string)) lastchar)))) |
123 (concat (if (and (stringp dir) | 123 (concat (if (and (stringp dir) |
124 (memq (aref dir dlen-m-1) '(?/ ?\\))) | 124 (memq (aref dir dlen-m-1) '(?/ ?\\))) |
125 (concat (convert-standard-filename | 125 (concat (dos-convert-standard-filename |
126 (substring dir 0 dlen-m-1)) | 126 (substring dir 0 dlen-m-1)) |
127 "/") | 127 "/") |
128 (convert-standard-filename dir)) | 128 (dos-convert-standard-filename dir)) |
129 string)))))) | 129 string)))))) |
130 | |
131 ;; Only redirect convert-standard-filename if it has a chance of working, | |
132 ;; otherwise loading dos-fns.el might make your non-DOS Emacs misbehave. | |
133 (when (fboundp 'msdos-long-file-names) | |
134 (defalias 'convert-standard-filename 'dos-convert-standard-filename)) | |
130 | 135 |
131 (defun dos-8+3-filename (filename) | 136 (defun dos-8+3-filename (filename) |
132 "Truncate FILENAME to DOS 8+3 limits." | 137 "Truncate FILENAME to DOS 8+3 limits." |
133 (if (or (not (stringp filename)) | 138 (if (or (not (stringp filename)) |
134 (< (length filename) 5)) ; too short to give any trouble | 139 (< (length filename) 5)) ; too short to give any trouble |
186 (dos-8+3-filename dir)) | 191 (dos-8+3-filename dir)) |
187 string)))))) | 192 string)))))) |
188 | 193 |
189 ;; This is for the sake of standard file names elsewhere in Emacs that | 194 ;; This is for the sake of standard file names elsewhere in Emacs that |
190 ;; are defined as constant strings or via defconst, and whose | 195 ;; are defined as constant strings or via defconst, and whose |
191 ;; conversion via `convert-standard-filename' does not give good | 196 ;; conversion via `dos-convert-standard-filename' does not give good |
192 ;; enough results. | 197 ;; enough results. |
193 (defun dosified-file-name (file-name) | 198 (defun dosified-file-name (file-name) |
194 "Return a variant of FILE-NAME that is valid on MS-DOS filesystems. | 199 "Return a variant of FILE-NAME that is valid on MS-DOS filesystems. |
195 | 200 |
196 This function is for those rare cases where `convert-standard-filename' | 201 This function is for those rare cases where `dos-convert-standard-filename' |
197 does not do a job that is good enough, e.g. if you need to preserve the | 202 does not do a job that is good enough, e.g. if you need to preserve the |
198 file-name extension. It recognizes only certain specific file names | 203 file-name extension. It recognizes only certain specific file names |
199 that are used in Emacs Lisp sources; any other file name will be | 204 that are used in Emacs Lisp sources; any other file name will be |
200 returned unaltered." | 205 returned unaltered." |
201 (cond | 206 (cond |
207 | 212 |
208 ;; See dos-vars.el for defcustom. | 213 ;; See dos-vars.el for defcustom. |
209 (defvar msdos-shells) | 214 (defvar msdos-shells) |
210 | 215 |
211 ;; Override settings chosen at startup. | 216 ;; Override settings chosen at startup. |
212 (defun set-default-process-coding-system () | 217 (defun dos-set-default-process-coding-system () |
213 (setq default-process-coding-system | 218 (setq default-process-coding-system |
214 (if (default-value 'enable-multibyte-characters) | 219 (if (default-value 'enable-multibyte-characters) |
215 '(undecided-dos . undecided-dos) | 220 '(undecided-dos . undecided-dos) |
216 '(raw-text-dos . raw-text-dos)))) | 221 '(raw-text-dos . raw-text-dos)))) |
217 | 222 |
218 (add-hook 'before-init-hook 'set-default-process-coding-system) | 223 (add-hook 'before-init-hook 'dos-set-default-process-coding-system) |
219 | 224 |
220 ;; File names defined in preloaded packages can be incorrect or | 225 ;; File names defined in preloaded packages can be incorrect or |
221 ;; invalid if long file names were available during dumping, but not | 226 ;; invalid if long file names were available during dumping, but not |
222 ;; at runtime, or vice versa, and if the default file name begins with | 227 ;; at runtime, or vice versa, and if the default file name begins with |
223 ;; a period. Their defcustom's need to be reevaluated at startup. To | 228 ;; a period. Their defcustom's need to be reevaluated at startup. To |
230 ;(custom-reevaluate-setting 'trash-directory) | 235 ;(custom-reevaluate-setting 'trash-directory) |
231 ) | 236 ) |
232 | 237 |
233 (add-hook 'before-init-hook 'dos-reevaluate-defcustoms) | 238 (add-hook 'before-init-hook 'dos-reevaluate-defcustoms) |
234 | 239 |
235 (defvar register-name-alist | 240 (defvar dos-register-name-alist |
236 '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5) | 241 '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5) |
237 (cflag . 6) (flags . 7) | 242 (cflag . 6) (flags . 7) |
238 (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0)) | 243 (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0)) |
239 (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1)))) | 244 (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1)))) |
240 | 245 |
241 (defun make-register () | 246 (defun dos-make-register () |
242 (make-vector 8 0)) | 247 (make-vector 8 0)) |
243 | 248 |
244 (defun register-value (regs name) | 249 (defun dos-register-value (regs name) |
245 (let ((where (cdr (assoc name register-name-alist)))) | 250 (let ((where (cdr (assoc name dos-register-name-alist)))) |
246 (cond ((consp where) | 251 (cond ((consp where) |
247 (let ((tem (aref regs (car where)))) | 252 (let ((tem (aref regs (car where)))) |
248 (if (zerop (cdr where)) | 253 (if (zerop (cdr where)) |
249 (% tem 256) | 254 (% tem 256) |
250 (/ tem 256)))) | 255 (/ tem 256)))) |
251 ((numberp where) | 256 ((numberp where) |
252 (aref regs where)) | 257 (aref regs where)) |
253 (t nil)))) | 258 (t nil)))) |
254 | 259 |
255 (defun set-register-value (regs name value) | 260 (defun dos-set-register-value (regs name value) |
256 (and (numberp value) | 261 (and (numberp value) |
257 (>= value 0) | 262 (>= value 0) |
258 (let ((where (cdr (assoc name register-name-alist)))) | 263 (let ((where (cdr (assoc name dos-register-name-alist)))) |
259 (cond ((consp where) | 264 (cond ((consp where) |
260 (let ((tem (aref regs (car where))) | 265 (let ((tem (aref regs (car where))) |
261 (value (logand value 255))) | 266 (value (logand value 255))) |
262 (aset regs | 267 (aset regs |
263 (car where) | 268 (car where) |
266 (logior (logand tem 255) (lsh value 8)))))) | 271 (logior (logand tem 255) (lsh value 8)))))) |
267 ((numberp where) | 272 ((numberp where) |
268 (aset regs where (logand value 65535)))))) | 273 (aset regs where (logand value 65535)))))) |
269 regs) | 274 regs) |
270 | 275 |
271 (defsubst intdos (regs) | 276 (defsubst dos-intdos (regs) |
272 (int86 33 regs)) | 277 (int86 33 regs)) |
273 | 278 |
274 ;; Backward compatibility for obsolescent functions which | 279 ;; Backward compatibility for obsolescent functions which |
275 ;; set screen size. | 280 ;; set screen size. |
276 | 281 |
277 (defun mode25 () | 282 (defun dos-mode25 () |
278 "Changes the number of screen rows to 25." | 283 "Changes the number of screen rows to 25." |
279 (interactive) | 284 (interactive) |
280 (set-frame-size (selected-frame) 80 25)) | 285 (set-frame-size (selected-frame) 80 25)) |
281 | 286 |
282 (defun mode4350 () | 287 (defun dos-mode4350 () |
283 "Changes the number of rows to 43 or 50. | 288 "Changes the number of rows to 43 or 50. |
284 Emacs always tries to set the screen height to 50 rows first. | 289 Emacs always tries to set the screen height to 50 rows first. |
285 If this fails, it will try to set it to 43 rows, on the assumption | 290 If this fails, it will try to set it to 43 rows, on the assumption |
286 that your video hardware might not support 50-line mode." | 291 that your video hardware might not support 50-line mode." |
287 (interactive) | 292 (interactive) |