gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Suggestion: minor mode for editing files in MS-DOS codepage


From: Guido Classen
Subject: Suggestion: minor mode for editing files in MS-DOS codepage
Date: Tue, 12 Nov 2002 23:21:13 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b) Gecko/20021016

Sometimes I must work with old files created under MS-DOS which have the
propritary IBM codepage 850 encoding (for most European languages).
These files have umlauts and accented characters at different places than
the iso-lat1 charset, used by NT-Emacs and GNU-Emacs on UNIX.

After a lot of tries I've figured how the coding systems and codepages
on Emacs work. It seems the will only work if the Emacs buffer is in
multibyte mode. My Emacs runs only in unibyte mode at default.

I thought it would be cool if emacs automatically selects the appropriate
coding-system on opening such as file. The coding: section of Local
Variable seems to work only in multibyte mode so it can't be done
with it.

Therefor I've create a simple minor-mode which switches the buffer to
multibyte and reverts the file. This mode can be selected in the Local
Variables section like this: -*- mode: text; mode: msdos-enc; -*-

If there is a simpler / smarter way to archive let me now. Maybe it could
derived to a more general concept, which supports other kind of files
(mac?).

Here my source file it can be include by autoload or require in .emacs
like this

(autoload 'msdos-enc-mode "path/dos-enc.el"
          "view file in current buffer as MS-DOS Extended ASCII")

(autoload 'find-msdos-file "path/dos-enc.el"
          "Find (visit) file as MS-DOS Extended ASCII")

Regards,
-- Guido

;;; dos-enc.el --- special minor mode for files with MS-DOS encoding

;;; Copyright (C) 2002  Guido Classen

;;; Author: Guido Classen <address@hidden>
;;; Keywords: encoding
;;; Version: 0.1
;;; Time-Stamp: <2002-11-08 16:52:55 gc>

;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2, or (at your option)
;;; any later version.

;;; This file is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.

;;; You should have received a copy of the GNU General Public License
;;; along with GNU Emacs; see the file COPYING.  If not, write to
;;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

;;; Version History:
;;;      2002-11-08 gc: corrected recusive issue if used in local variables
;;;      2001-11-23 gc: initial version


(provide 'dos-enc)

(defvar msdos-enc-codepage 850  "*Codepage used for MS-DOS files")

(defvar msdos-enc-active nil)


(defun msdos-enc-coding-system ()
  "deliver the coding-system for MS-DOS files (as symbol)"
  (intern (concat "cp"
                  (number-to-string
                   msdos-enc-codepage)
                  ))
  )

(defun find-msdos-file (filename-to-find)
  "Find (visit) file as MS-DOS Extended ASCII Codepage"
  (interactive)
  (codepage-setup msdos-enc-codepage)
  (find-file-literally filename-to-find)
  (toggle-enable-multibyte-characters 1)
  (setq buffer-file-coding-system (msdos-enc-coding-system))
  (revert-buffer nil t t)
)

(defun msdos-enc-mode ()
  "view file in current buffer as MS-DOS Extended ASCII Codepage"
  (interactive)

  ;;avoid recursive invoke of this function in revert-buffer if called
  ;;from Local Variable mode
  (cond ((not msdos-enc-active)
         (setq msdos-enc-active t)
         (codepage-setup msdos-enc-codepage)
         (cond ((buffer-modified-p)
                (cond ((y-or-n-p "current buffer is modified; it must be
saved to continue! save it? ")
                       (save-buffer)
                       )
                      (t (message "msdos-enc-mode aborted!"))
                      (return)
                      )
                ))

         (toggle-enable-multibyte-characters 1)
         (setq buffer-file-coding-system (msdos-enc-coding-system))
         (revert-buffer nil t t)
         (setq msdos-enc-active nil)
         ))
  )

;;;(setq coding-system-for-write (msdos-enc-coding-system))
;;;(setq default-enable-multibyte-characters t)


;;;
;;;Local Variables:
;;; mode: emacs-lisp
;;; time-stamp-pattern:"20/Time-Stamp:[\t ]+[\"<]%:y-%02m-%02d
%02H:%02M:%02S %u[\">]"
;;; End:







reply via email to

[Prev in Thread] Current Thread [Next in Thread]