123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- (setq path-separator ";")
- (setq minibuffer-history-case-insensitive-variables
- (cons 'file-name-history minibuffer-history-case-insensitive-variables))
- (setq null-device "NUL")
- (defvar file-name-buffer-file-type-alist
- '(
- ("[:/].*config.sys$" . nil)
- ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|bin\\|ico\\|pif\\|class\\)$" . t)
-
- ("\\.\\(dll\\|drv\\|386\\|vxd\\|fon\\|fnt\\|fot\\|ttf\\|grp\\)$" . t)
-
- ("\\.\\(bmp\\|wav\\|avi\\|mpg\\|jpg\\|tif\\|mov\\|au\\)$" . t)
-
- ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t)
-
- ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\|jar\\)$" . t)
-
- ("\\.sx[dmicw]$" . t)
- ("\\.tp[ulpw]$" . t)
- ("[:/]tags$" . nil)
- )
- "*Alist for distinguishing text files from binary files.
- Each element has the form (REGEXP . TYPE), where REGEXP is matched
- against the file name, and TYPE is nil for text, t for binary.")
- (defun find-buffer-file-type-match (filename)
- (let ((alist file-name-buffer-file-type-alist)
- (found nil))
- (let ((case-fold-search t))
- (setq filename (file-name-sans-versions filename))
- (while (and (not found) alist)
- (if (string-match (car (car alist)) filename)
- (setq found (car alist)))
- (setq alist (cdr alist)))
- found)))
- (defun find-buffer-file-type (filename)
- (let ((match (find-buffer-file-type-match filename))
- (code))
- (if (not match)
- (default-value 'buffer-file-type)
- (setq code (cdr match))
- (cond ((memq code '(nil t)) code)
- ((and (symbolp code) (fboundp code))
- (funcall code filename))))))
- (setq-default buffer-file-coding-system 'undecided-dos)
- (defun find-buffer-file-type-coding-system (command)
- "Choose a coding system for a file operation in COMMAND.
- COMMAND is a list that specifies the operation, an I/O primitive, as its
- CAR, and the arguments that might be given to that operation as its CDR.
- If operation is `insert-file-contents', the coding system is chosen based
- upon the filename (the CAR of the arguments beyond the operation), the contents
- of `untranslated-filesystem-list' and `file-name-buffer-file-type-alist',
- and whether the file exists:
- If it matches in `untranslated-filesystem-list':
- If the file exists: `undecided'
- If the file does not exist: `undecided-unix'
- If it matches in `file-name-buffer-file-type-alist':
- If the match is t (for binary): `no-conversion'
- If the match is nil (for dos-text): `undecided-dos'
- Otherwise:
- If the file exists: `undecided'
- If the file does not exist default value of `buffer-file-coding-system'
- Note that the CAR of arguments to `insert-file-contents' operation could
- be a cons cell of the form \(FILENAME . BUFFER\), where BUFFER is a buffer
- into which the file's contents were already read, but not yet decoded.
- If operation is `write-region', the coding system is chosen based upon
- the value of `buffer-file-coding-system' and `buffer-file-type'. If
- `buffer-file-coding-system' is non-nil, its value is used. If it is
- nil and `buffer-file-type' is t, the coding system is `no-conversion'.
- Otherwise, it is `undecided-dos'.
- The two most common situations are when DOS and Unix files are read
- and written, and their names do not match in
- `untranslated-filesystem-list' and `file-name-buffer-file-type-alist'.
- In these cases, the coding system initially will be `undecided'. As
- the file is read in the DOS case, the coding system will be changed to
- `undecided-dos' as CR/LFs are detected. As the file is read in the
- Unix case, the coding system will be changed to `undecided-unix' as
- LFs are detected. In both cases, `buffer-file-coding-system' will be
- set to the appropriate coding system, and the value of
- `buffer-file-coding-system' will be used when writing the file."
- (let ((op (nth 0 command))
- (binary nil) (text nil)
- (undecided nil) (undecided-unix nil)
- target target-buf)
- (cond ((eq op 'insert-file-contents)
- (setq target (nth 1 command))
-
-
-
-
-
-
- (when (consp target)
- (setq target-buf
- (and (bufferp (cdr target))
- (buffer-name (cdr target))))
- (setq target (car target)))
-
-
- (setq binary (find-buffer-file-type target))
- (cond (binary)
-
- ((find-buffer-file-type-match target)
- (setq text t))
-
- ((or
- (file-exists-p target)
-
-
-
-
-
- (and (stringp target-buf)
- (file-exists-p
- (expand-file-name target-buf
- (file-name-directory target)))))
- (setq undecided t))
-
- ((untranslated-file-p target)
- (setq undecided-unix t)))
- (cond (binary '(no-conversion . no-conversion))
- (text '(undecided-dos . undecided-dos))
- (undecided-unix '(undecided-unix . undecided-unix))
- (undecided '(undecided . undecided))
- (t (cons (default-value 'buffer-file-coding-system)
- (default-value 'buffer-file-coding-system)))))
- ((eq op 'write-region)
- (if buffer-file-coding-system
- (cons buffer-file-coding-system
- buffer-file-coding-system)
-
-
-
- (if buffer-file-type
- '(no-conversion . no-conversion)
- '(undecided-dos . undecided-dos)))))))
- (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)
- (defun find-file-binary (filename)
- "Visit file FILENAME and treat it as binary."
- (interactive "FFind file binary: ")
- (let ((file-name-buffer-file-type-alist '(("" . t))))
- (find-file filename)))
- (defun find-file-text (filename)
- "Visit file FILENAME and treat it as a text file."
- (interactive "FFind file text: ")
- (let ((file-name-buffer-file-type-alist '(("" . nil))))
- (find-file filename)))
- (defun find-file-not-found-set-buffer-file-coding-system ()
- (with-current-buffer (current-buffer)
- (let ((coding buffer-file-coding-system))
-
-
-
-
- (when (and (null coding-system-for-read)
- (or inhibit-eol-conversion
- (untranslated-file-p (buffer-file-name))))
- (setq coding (coding-system-change-eol-conversion coding 0))
- (setq buffer-file-coding-system coding))
- (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion)))))
- (add-hook 'find-file-not-found-functions
- 'find-file-not-found-set-buffer-file-coding-system)
- (defvar untranslated-filesystem-list nil
- "List of filesystems that require no CR/LF translation when reading
- and writing files. Each filesystem in the list is a string naming
- the directory prefix corresponding to the filesystem.")
- (defun untranslated-canonical-name (filename)
- "Return FILENAME in a canonicalized form for use with the functions
- dealing with untranslated filesystems."
- (if (memq system-type '(ms-dos windows-nt cygwin))
-
-
- (let ((name nil))
- (setq name (mapconcat
- (lambda (char)
- (if (and (<= ?A char) (<= char ?Z))
- (char-to-string (+ (- char ?A) ?a))
- (char-to-string char)))
- filename nil))
-
-
-
-
- (if (or (string-match "^.:$" name)
- (string-match "^/[^/:]+:" name))
- name
- (expand-file-name name)))
- filename))
- (defun untranslated-file-p (filename)
- "Return t if FILENAME is on a filesystem that does not require
- CR/LF translation, and nil otherwise."
- (let ((fs (untranslated-canonical-name filename))
- (ufs-list untranslated-filesystem-list)
- (found nil))
- (while (and (not found) ufs-list)
- (if (string-match (concat "^" (car ufs-list)) fs)
- (setq found t)
- (setq ufs-list (cdr ufs-list))))
- found))
- (defun add-untranslated-filesystem (filesystem)
- "Add FILESYSTEM to the list of filesystems that do not require
- CR/LF translation. FILESYSTEM is a string containing the directory
- prefix corresponding to the filesystem. For example, for a Unix
- filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
-
-
-
- (interactive "DUntranslated file system: ")
- (let ((fs (untranslated-canonical-name filesystem)))
- (if (member fs untranslated-filesystem-list)
- untranslated-filesystem-list
- (setq untranslated-filesystem-list
- (cons fs untranslated-filesystem-list)))))
- (defun remove-untranslated-filesystem (filesystem)
- "Remove FILESYSTEM from the list of filesystems that do not require
- CR/LF translation. FILESYSTEM is a string containing the directory
- prefix corresponding to the filesystem. For example, for a Unix
- filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
- (interactive "fUntranslated file system: ")
- (setq untranslated-filesystem-list
- (delete (untranslated-canonical-name filesystem)
- untranslated-filesystem-list)))
- (defvar direct-print-region-use-command-dot-com t
- "*Control whether command.com is used to print on Windows 9x.")
- (defun direct-print-region-helper (printer
- start end
- lpr-prog
- _delete-text _buf _display
- rest)
- (let* (
- (case-fold-search t)
-
- (printer
- (if (stringp printer)
- (subst-char-in-string ?/ ?\\ printer)
- printer))
-
- (safe-dir
- (let ((safe-dirs (list "c:/" (getenv "windir") (getenv "TMPDIR"))))
- (while (not (file-attributes (car safe-dirs)))
- (setq safe-dirs (cdr safe-dirs)))
- (car safe-dirs)))
- (tempfile
- (subst-char-in-string
- ?/ ?\\
- (make-temp-name
- (expand-file-name "EP" temporary-file-directory))))
-
- (errbuf (list (get-buffer-create " *print-region-helper*") t)))
-
-
-
-
-
-
-
- (if (and (stringp printer) (not (string-match "^\\\\" printer)))
- (setq printer
- (subst-char-in-string ?/ ?\\ (expand-file-name printer safe-dir))))
-
- (unwind-protect
- (cond
-
- ((string-match "^nprint\\(\\.exe\\)?$" (file-name-nondirectory lpr-prog))
- (write-region start end tempfile nil 0)
- (call-process lpr-prog nil errbuf nil
- tempfile (concat "P=" printer)))
-
- ((string-match "^print\\(\\.exe\\)?$" (file-name-nondirectory lpr-prog))
-
-
- (or (and (eq system-type 'windows-nt)
- (null (getenv "winbootdir")))
- (error "Printing via print.exe is not supported on MS-DOS or Windows 9x"))
-
-
- (if (and (> end start)
- (char-equal (char-before end) ?\C-l))
- (setq end (1- end)))
-
- (let ((write-region-annotate-functions nil))
- (write-region start end tempfile nil 0))
- (call-process lpr-prog nil errbuf nil
- (concat "/D:" printer) tempfile))
-
-
-
- ((> (length lpr-prog) 0)
- (write-region start end tempfile nil 0)
- (setq rest (append rest (list tempfile)))
- (apply 'call-process lpr-prog nil errbuf nil rest))
-
-
-
-
- ((and (eq system-type 'windows-nt)
- (getenv "winbootdir")
-
- direct-print-region-use-command-dot-com
-
-
- (eq (or (nth 7 (file-attributes printer)) 0) 0))
- (write-region start end tempfile nil 0)
- (let ((w32-quote-process-args nil))
- (call-process "command.com" nil errbuf nil "/c"
- (format "copy /b %s %s" tempfile printer))))
-
- (t
- (write-region start end printer t 0)))
-
- (if (file-exists-p tempfile)
- (delete-file tempfile)))))
- (defvar printer-name)
- (declare-function default-printer-name "w32fns.c")
- (defun direct-print-region-function (start end
- &optional lpr-prog
- delete-text buf display
- &rest rest)
- "DOS/Windows-specific function to print the region on a printer.
- Writes the region to the device or file which is a value of
- `printer-name' \(which see\), unless the value of `lpr-command'
- indicates a specific program should be invoked."
-
-
- (let* ((coding coding-system-for-write)
- (coding-base
- (if (null coding) 'undecided (coding-system-base coding)))
- (eol-type (coding-system-eol-type coding-base))
-
-
- (write-region-annotate-functions
- (cons
- (lambda (_start end)
- (if (not (char-equal (char-before end) ?\C-l))
- `((,end . "\f"))))
- write-region-annotate-functions))
- (printer (or (and (boundp 'dos-printer)
- (stringp (symbol-value 'dos-printer))
- (symbol-value 'dos-printer))
- printer-name
- (default-printer-name))))
- (or (eq coding-system-for-write 'no-conversion)
- (setq coding-system-for-write
- (aref eol-type 1)))
- (direct-print-region-helper printer start end lpr-prog
- delete-text buf display rest)))
- (defvar print-region-function)
- (defvar lpr-headers-switches)
- (setq print-region-function 'direct-print-region-function)
- (setq lpr-headers-switches "(page headers are not supported)")
- (defvar ps-printer-name)
- (defun direct-ps-print-region-function (start end
- &optional lpr-prog
- delete-text buf display
- &rest rest)
- "DOS/Windows-specific function to print the region on a PostScript printer.
- Writes the region to the device or file which is a value of
- `ps-printer-name' \(which see\), unless the value of `ps-lpr-command'
- indicates a specific program should be invoked."
- (let ((printer (or (and (boundp 'dos-ps-printer)
- (stringp (symbol-value 'dos-ps-printer))
- (symbol-value 'dos-ps-printer))
- ps-printer-name
- (default-printer-name))))
- (direct-print-region-helper printer start end lpr-prog
- delete-text buf display rest)))
- (defvar ps-print-region-function)
- (setq ps-print-region-function 'direct-ps-print-region-function)
- (provide 'dos-w32)
|