home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / next / software / 3393 < prev    next >
Encoding:
Text File  |  1993-01-11  |  6.3 KB  |  201 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!usc!news.service.uci.edu!hardy
  2. From: hardy@golem.ps.uci.edu (Meinhard E. Mayer (Hardy))
  3. Subject: Re: LaTeX problem (missing text)
  4. Nntp-Posting-Host: golem.ps.uci.edu
  5. Message-ID: <HARDY.93Jan11132243@golem.ps.uci.edu>
  6. In-reply-to: tlm@iastate.edu's message of Sun, 10 Jan 1993 19:21:26 GMT
  7. Newsgroups: comp.sys.next.software
  8. Organization: Department of Physics, UC Irvine, CA 92717-4575, USA
  9. Lines: 187
  10. References: <1in8f5INN9j4@tamsun.tamu.edu> <1993Jan9.211126.8260@newshost.lanl.gov>
  11.     <tlm.726651225@scl1.al.iastate.edu> <tlm.726693686@scl1.al.iastate.edu>
  12. Date: 11 Jan 93 21:22:48 GMT
  13.  
  14. For emacs-users here is an emacs-lisp file which will do the required
  15. things for you; sorry for its length ;):
  16.  
  17. ;; -*-Emacs-Lisp-*-
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;;
  20. ;; File:         dos-mode.el
  21. ;; RCS:          $Header: dos-mode.el,v 1.8 92/10/01 13:49:50 ange Exp $
  22. ;; Description:  MSDOS minor mode for GNU Emacs
  23. ;; Author:       Andy Norman, Hewlett-Packard Labs, Bristol, England.
  24. ;; Created:      Wed May  6 16:42:29 1992
  25. ;; Modified:     Thu Oct  1 13:49:32 1992 (Andy Norman) ange@hplb.hpl.hp.com
  26. ;; Language:     Emacs-Lisp
  27. ;;
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29.  
  30. ;;; Copyright (C) 1992  Andy Norman.
  31. ;;;
  32. ;;; Author: Andy Norman (ange@hplb.hpl.hp.com)
  33. ;;;
  34. ;;; This program is free software; you can redistribute it and/or modify
  35. ;;; it under the terms of the GNU General Public License as published by
  36. ;;; the Free Software Foundation; either version 1, or (at your option)
  37. ;;; any later version.
  38. ;;;
  39. ;;; This program is distributed in the hope that it will be useful,
  40. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  42. ;;; GNU General Public License for more details.
  43. ;;;
  44. ;;; A copy of the GNU General Public License can be obtained from this
  45. ;;; program's author (send electronic mail to ange@hplb.hpl.hp.com) or from
  46. ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  47. ;;; 02139, USA.
  48.  
  49. ;;; Description:
  50. ;;;
  51. ;;; This package does two things:
  52. ;;;
  53. ;;; If a file being read into a buffer has the ^M character at the end of each
  54. ;;; line then these extra characters are discarded from the file's buffer.
  55. ;;; The trailing ^Z, if present, is discarded too.  The buffer is now put into
  56. ;;; the dos-mode minor-mode.
  57. ;;;
  58. ;;; Secondly, when a buffer in dos-mode is being written out, the ^M and
  59. ;;; optional ^Z characters are replaced before the write happens.
  60. ;;;
  61. ;;; dos-mode can be toggled for a buffer with M-x dos-mode.
  62.  
  63. ;;; Installation:
  64. ;;;
  65. ;;; Byte-compile dos-mode.el to dos-mode.elc and put them both in a directory
  66. ;;; on your load-path.  Load the package from your .emacs file with:
  67. ;;;
  68. ;;;   (require 'dos-mode)
  69. ;;;
  70. ;;; dos-mode can't sensibly be auto-loaded; you are either using it, or you
  71. ;;; aren't.
  72.  
  73. ;;; LISPDIR ENTRY for the Elisp Archive
  74. ;;; 
  75. ;;;    LCD Archive Entry:
  76. ;;;    dos-mode|Andy Norman|ange@hplb.hpl.hp.com
  77. ;;;    |MSDOS minor mode for GNU Emacs
  78. ;;;    |$Date: 92/10/01 13:49:50 $|$Revision: 1.8 $|
  79.  
  80. (provide 'dos-mode)
  81.  
  82. (defvar dos-mode-distance 200
  83.   "Number of characters to search for RETURN when looking for a DOS file.")
  84.  
  85. (defvar dos-mode nil
  86.   "This buffer is to be converted to/from DOS format when read/written.")
  87.  
  88. (make-variable-buffer-local 'dos-mode)
  89. (setq-default dos-mode nil)
  90.  
  91. (or (assq 'dos-mode minor-mode-alist)
  92.     (setq minor-mode-alist (cons '(dos-mode " DOS") minor-mode-alist)))
  93.  
  94. (defun dos-mode (arg)
  95.   "Toggle DOS mode.
  96. With arg, turn DOS mode on iff arg is positive.
  97. In DOS mode, when the buffer is saved, it is converted to DOS format first,
  98. and when restored it is converted to UNIX format first."
  99.   (interactive "P")
  100.   (setq dos-mode
  101.     (if (null arg) (not dos-mode)
  102.       (> (prefix-numeric-value arg) 0)))
  103.   (set-buffer-modified-p t))
  104.  
  105. (defvar dos-seen-ctl-Z nil
  106.   "Remember whether C-Z was seen at the end of this buffer.")
  107.  
  108. (make-variable-buffer-local 'dos-seen-ctl-Z)
  109. (setq-default dos-seen-ctl-Z nil)
  110.  
  111. (defun dos-convert-buffer-to-unix ()
  112.   "Converts the current buffer from DOS format to UNIX format."
  113.   (let ((mod-p (buffer-modified-p))
  114.     (buffer-read-only nil))
  115.     (save-excursion
  116.       (goto-char (point-min))
  117.       (while (re-search-forward "\r" nil t)
  118.     (replace-match ""))
  119.       (goto-char (point-max))
  120.       (beginning-of-line)
  121.       (forward-line -1)            ;should be safe enough
  122.       (setq dos-seen-ctl-Z (search-forward "\C-z" nil t))
  123.       (if dos-seen-ctl-Z
  124.       (replace-match "")))
  125.     (set-buffer-modified-p mod-p)
  126.     (setq dos-mode t)))
  127.  
  128. (defun dos-convert-buffer-to-dos ()
  129.   "Converts the current buffer from UNIX format to DOS format."
  130.   (save-excursion
  131.     (goto-char (point-min))
  132.     (while (re-search-forward "\n" nil t)
  133.       (replace-match "\r\n"))
  134.     (if dos-seen-ctl-Z
  135.     (progn
  136.       (goto-char (point-max))
  137.       (insert "\C-z")))))
  138.  
  139. (defun dos-check-buffer ()
  140.   "Used as a find-file hook, if the buffer looks like a DOS format buffer
  141. then it will be converted to a UNIX format buffer."
  142.   (if (or dos-mode
  143.       (save-excursion
  144.         (goto-char (point-min))
  145.         (re-search-forward "\r\n"
  146.                    (min (point-max) dos-mode-distance)
  147.                    t)))
  148.       (dos-convert-buffer-to-unix)))
  149.  
  150. (defun dos-write-buffer ()
  151.   "If the current buffer was originally a DOS format buffer, write it as such."
  152.   (if dos-mode
  153.       (let* ((buffer-read-only nil)
  154.          (window (get-buffer-window (current-buffer)))
  155.          (p (point))
  156.          (m (mark))
  157.          (ws (and window (window-start window))))
  158.     (dos-convert-buffer-to-dos)
  159.     (unwind-protect
  160.         (write-region (point-min)
  161.               (point-max)
  162.               buffer-file-name
  163.               nil
  164.               t)
  165.       (dos-convert-buffer-to-unix)    ;convert back again!
  166.       (and window
  167.            (set-window-start window
  168.                  (save-excursion (goto-char ws)
  169.                          (beginning-of-line)
  170.                          (point))))
  171.       (goto-char p)
  172.       (set-mark m))
  173.     t)))
  174.  
  175. (or (memq 'dos-write-buffer write-file-hooks)
  176.     (setq write-file-hooks
  177.       (append write-file-hooks
  178.           (list 'dos-write-buffer)))) ;stick it on the end
  179.  
  180. (or (memq 'dos-check-buffer find-file-hooks)
  181.     (setq find-file-hooks
  182.       (append find-file-hooks
  183.           (list 'dos-check-buffer))))
  184. ;;;;;;; end of dos-mode.el ;;;;;;;
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. --
  196. Hardy 
  197. -----
  198. Meinhard E. Mayer,  Department of Physics, UC Irvine 
  199. e-mail: hardy@golem.ps.uci.edu (preferred) or MMAYER@UCI.BITNET
  200. !!!! NO NEXTMAIL TO THESE ADDRESSES, PLEASE !!!!!
  201.