home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / modes / text-mode.el.z / text-mode.el
Encoding:
Text File  |  1998-05-21  |  5.8 KB  |  179 lines

  1. ;;; text-mode.el --- text mode, and its idiosyncratic commands.
  2.  
  3. ;; Copyright (C) 1985, 1992, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; 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.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  22. ;; 02111-1307, USA.
  23.  
  24. ;;; Synched up with: FSF 19.34.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; This package provides the fundamental text mode documented in the
  29. ;; Emacs user's manual.
  30.  
  31. ;;; Code:
  32.  
  33. (defvar text-mode-syntax-table nil
  34.   "Syntax table used while in text mode.")
  35.  
  36. (defvar text-mode-abbrev-table nil
  37.   "Abbrev table used while in text mode.")
  38. (define-abbrev-table 'text-mode-abbrev-table ())
  39.  
  40. (if text-mode-syntax-table
  41.     ()
  42.   (setq text-mode-syntax-table (make-syntax-table))
  43.   (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  44.   (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  45.   (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  46.  
  47. (defvar text-mode-map nil
  48.   "Keymap for Text mode.
  49. Many other modes, such as Mail mode, Outline mode and Indented Text mode,
  50. inherit all the commands defined in this map.")
  51.  
  52. (if text-mode-map
  53.     ()
  54.   (setq text-mode-map (make-sparse-keymap))
  55.   ;; XEmacs change
  56.   (set-keymap-name text-mode-map 'text-mode-map)
  57.   (define-key text-mode-map "\e\t" 'ispell-complete-word)
  58.   (define-key text-mode-map "\t" 'tab-to-tab-stop)
  59.   (define-key text-mode-map "\es" 'center-line)
  60.   (define-key text-mode-map "\eS" 'center-paragraph))
  61.  
  62.  
  63. ;(defun non-saved-text-mode ()
  64. ;  "Like text-mode, but delete auto save file when file is saved for real."
  65. ;  (text-mode)
  66. ;  (make-local-variable 'delete-auto-save-files)
  67. ;  (setq delete-auto-save-files t))
  68.  
  69. (defun text-mode ()
  70.   "Major mode for editing text intended for humans to read.
  71. Special commands:
  72. \\{text-mode-map}
  73. Turning on Text mode calls the value of the variable `text-mode-hook',
  74. if that value is non-nil."
  75.   (interactive)
  76.   (kill-all-local-variables)
  77.   (use-local-map text-mode-map)
  78.   (setq mode-name "Text")
  79.   (setq major-mode 'text-mode)
  80.   (setq local-abbrev-table text-mode-abbrev-table)
  81.   (set-syntax-table text-mode-syntax-table)
  82.   (run-hooks 'text-mode-hook))
  83.  
  84. (defvar indented-text-mode-map ()
  85.   "Keymap for Indented Text mode.
  86. All the commands defined in Text mode are inherited unless overridden.")
  87.  
  88. (if indented-text-mode-map
  89.     ()
  90.   ;; Make different definition for TAB before the one in text-mode-map, but
  91.   ;; share the rest.
  92.   ;; XEmacs change
  93.   (setq indented-text-mode-map (make-sparse-keymap))
  94.   (set-keymap-name indented-text-mode-map 'indented-text-mode-map)
  95.   (set-keymap-parents indented-text-mode-map (list text-mode-map))
  96.   (define-key indented-text-mode-map "\t" 'indent-relative))
  97.  
  98. (defun indented-text-mode ()
  99.   "Major mode for editing text with indented paragraphs.
  100. In this mode, paragraphs are delimited only by blank lines.
  101. You can thus get the benefit of adaptive filling
  102.  (see the variable `adaptive-fill-mode').
  103. \\{indented-text-mode-map}
  104. Turning on `indented-text-mode' calls the value of the variable
  105. `text-mode-hook', if that value is non-nil."
  106.   (interactive)
  107.   (kill-all-local-variables)
  108.   (use-local-map text-mode-map)
  109.   (define-abbrev-table 'text-mode-abbrev-table ())
  110.   (setq local-abbrev-table text-mode-abbrev-table)
  111.   (set-syntax-table text-mode-syntax-table)
  112.   (make-local-variable 'indent-line-function)
  113.   (setq indent-line-function 'indent-relative-maybe)
  114.   (make-local-variable 'paragraph-start)
  115.   (setq paragraph-start (concat "$\\|" page-delimiter))
  116.   (make-local-variable 'paragraph-separate)
  117.   (setq paragraph-separate paragraph-start)
  118.   (use-local-map indented-text-mode-map)
  119.   (setq mode-name "Indented Text")
  120.   (setq major-mode 'indented-text-mode)
  121.   (run-hooks 'text-mode-hook 'indented-text-mode-hook))
  122.  
  123. (defun center-paragraph ()
  124.   "Center each nonblank line in the paragraph at or after point.
  125. See `center-line' for more info."
  126.   (interactive)
  127.   (save-excursion
  128.     (forward-paragraph)
  129.     (or (bolp) (newline 1))
  130.     (let ((end (point)))
  131.       (backward-paragraph)
  132.       (center-region (point) end))))
  133.  
  134. (defun center-region (from to)
  135.   "Center each nonblank line starting in the region.
  136. See `center-line' for more info."
  137.   (interactive "r")
  138.   (if (> from to)
  139.       (let ((tem to))
  140.     (setq to from from tem)))
  141.   (save-excursion
  142.     (save-restriction
  143.       (narrow-to-region from to)
  144.       (goto-char from)
  145.       (while (not (eobp))
  146.     (or (save-excursion (skip-chars-forward " \t") (eolp))
  147.         (center-line))
  148.     (forward-line 1)))))
  149.  
  150. (defun center-line (&optional nlines)
  151.   "Center the line point is on, within the width specified by `fill-column'.
  152. This means adjusting the indentation so that it equals
  153. the distance between the end of the text and `fill-column'.
  154. The argument NLINES says how many lines to center."
  155.   (interactive "P")
  156.   (if nlines (setq nlines (prefix-numeric-value nlines)))
  157.   (while (not (eq nlines 0))
  158.     (save-excursion
  159.       (let ((lm (current-left-margin))
  160.         line-length)
  161.     (beginning-of-line)
  162.     (delete-horizontal-space)
  163.     (end-of-line)
  164.     (delete-horizontal-space)
  165.     (setq line-length (current-column))
  166.     (if (> (- fill-column lm line-length) 0)
  167.         (indent-line-to 
  168.          (+ lm (/ (- fill-column lm line-length) 2))))))
  169.     (cond ((null nlines)
  170.        (setq nlines 0))
  171.       ((> nlines 0)
  172.        (setq nlines (1- nlines))
  173.        (forward-line 1))
  174.       ((< nlines 0)
  175.        (setq nlines (1+ nlines))
  176.        (forward-line -1)))))
  177.  
  178. ;;; text-mode.el ends here
  179.