home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / emcs1857 / 1857bi~1.zoo / lisp / text-mode.el < prev    next >
Encoding:
Text File  |  1992-02-03  |  4.4 KB  |  136 lines

  1. ;; Text mode, and its ideosyncratic commands.
  2. ;; Copyright (C) 1985, 1990 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. ;; Modified 1990 for 8-bit character support by Howard Gayle.
  22. ;; See case-table.el for details.
  23.  
  24.  
  25. (defvar text-mode-syntax-table nil
  26.   "Syntax table used while in text mode.")
  27.  
  28. (defvar text-mode-abbrev-table nil
  29.   "Abbrev table used while in text mode.")
  30. (define-abbrev-table 'text-mode-abbrev-table ())
  31.  
  32. (if text-mode-syntax-table
  33.     ()
  34.   (setq text-mode-syntax-table (make-syntax-table))
  35.   (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  36.   (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  37.   (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  38.  
  39. (defvar text-mode-map nil "")
  40. (if text-mode-map
  41.     ()
  42.   (setq text-mode-map (make-sparse-keymap))
  43.   (define-key text-mode-map "\t" 'tab-to-tab-stop)
  44.   (define-key text-mode-map "\es" 'center-line)
  45.   (define-key text-mode-map "\eS" 'center-paragraph))
  46.  
  47.  
  48. ;(defun non-saved-text-mode ()
  49. ;  "Like text-mode, but delete auto save file when file is saved for real."
  50. ;  (text-mode)
  51. ;  (make-local-variable 'delete-auto-save-files)
  52. ;  (setq delete-auto-save-files t))
  53.  
  54. (defun text-mode ()
  55.   "Major mode for editing text intended for humans to read.  Special commands:\\{text-mode-map}
  56. Turning on text-mode calls the value of the variable text-mode-hook,
  57. if that value is non-nil."
  58.   (interactive)
  59.   (kill-all-local-variables)
  60.   (use-local-map text-mode-map)
  61.   (setq mode-name "Text")
  62.   (setq major-mode 'text-mode)
  63.   (setq local-abbrev-table text-mode-abbrev-table)
  64.   (set-syntax-table text-mode-syntax-table)
  65.   (run-hooks 'text-mode-hook))
  66.  
  67. (defvar indented-text-mode-map ())
  68. (if indented-text-mode-map
  69.     ()
  70.   (setq indented-text-mode-map (make-sparse-keymap))
  71.   (define-key indented-text-mode-map "\t" 'indent-relative)
  72.   (define-key indented-text-mode-map "\es" 'center-line)
  73.   (define-key indented-text-mode-map "\eS" 'center-paragraph))
  74.  
  75. (defun indented-text-mode ()
  76.   "Major mode for editing indented text intended for humans to read.\\{indented-text-mode-map}
  77. Turning on indented-text-mode calls the value of the variable text-mode-hook,
  78. if that value is non-nil."
  79.   (interactive)
  80.   (kill-all-local-variables)
  81.   (use-local-map text-mode-map)
  82.   (define-abbrev-table 'text-mode-abbrev-table ())
  83.   (setq local-abbrev-table text-mode-abbrev-table)
  84.   (set-syntax-table text-mode-syntax-table)
  85.   (make-local-variable 'indent-line-function)
  86.   (setq indent-line-function 'indent-relative-maybe)
  87.   (use-local-map indented-text-mode-map)
  88.   (setq mode-name "Indented Text")
  89.   (setq major-mode 'indented-text-mode)
  90.   (run-hooks 'text-mode-hook))
  91.  
  92. (defun center-paragraph ()
  93.   "Center each line in the paragraph at or after point.
  94. See center-line for more info."
  95.   (interactive)
  96.   (save-excursion
  97.     (forward-paragraph)
  98.     (or (bolp) (newline 1))
  99.     (let ((end (point)))
  100.       (backward-paragraph)
  101.       (center-region (point) end))))
  102.  
  103. (defun center-region (from to)
  104.   "Center each line starting in the region.
  105. See center-line for more info."
  106.   (interactive "r")
  107.   (if (> from to)
  108.       (let ((tem to))
  109.     (setq to from from tem)))
  110.   (save-excursion
  111.     (save-restriction
  112.       (narrow-to-region from to)
  113.       (goto-char from)
  114.       (while (not (eobp))
  115.     (center-line)
  116.     (forward-line 1)))))
  117.  
  118. (defun center-line ()
  119.   "Center the line point is on, within the width specified by `fill-column'.
  120. This means adjusting the indentation to match
  121. the distance between the end of the text and `fill-column'."
  122.   (interactive)
  123.   (save-excursion
  124.     (let (line-length)
  125.       (beginning-of-line)
  126.       (delete-horizontal-space)
  127.       (end-of-line)
  128.       (delete-horizontal-space)
  129.       (setq line-length (current-column))
  130.       (beginning-of-line)
  131.       (indent-to 
  132.     (+ left-margin 
  133.        (/ (- fill-column left-margin line-length) 2))))))
  134.  
  135. (provide 'text-mode)
  136.