home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / modes / text-mode.el < prev    next >
Encoding:
Text File  |  1992-06-29  |  4.9 KB  |  148 lines

  1. ;; Text mode, and its ideosyncratic commands.
  2. ;; Copyright (C) 1985 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. (defvar text-mode-syntax-table nil
  22.   "Syntax table used while in text mode.")
  23.  
  24. (defvar text-mode-abbrev-table nil
  25.   "Abbrev table used while in text mode.")
  26. (define-abbrev-table 'text-mode-abbrev-table ())
  27.  
  28. (if text-mode-syntax-table
  29.     ()
  30.   (setq text-mode-syntax-table (make-syntax-table))
  31.   (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  32.   (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  33.   (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  34.  
  35. (defvar text-mode-map nil
  36.   "Keymap for Text mode.
  37. Many other modes, such as Mail mode, Outline mode and Indented Text mode,
  38. inherit all the commands defined in this map.")
  39.  
  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.   "Keymap for Indented Text mode.
  69. All the commands defined in Text mode are inherited unless overridden.")
  70.  
  71. (if indented-text-mode-map
  72.     ()
  73.   (setq indented-text-mode-map (copy-keymap text-mode-map))
  74.   (define-key indented-text-mode-map "\t" 'indent-relative))
  75.  
  76. (defun indented-text-mode ()
  77.   "Major mode for editing indented text intended for humans to read.\\{indented-text-mode-map}
  78. Turning on indented-text-mode calls the value of the variable `text-mode-hook',
  79. if that value is non-nil."
  80.   (interactive)
  81.   (kill-all-local-variables)
  82.   (use-local-map text-mode-map)
  83.   (define-abbrev-table 'text-mode-abbrev-table ())
  84.   (setq local-abbrev-table text-mode-abbrev-table)
  85.   (set-syntax-table text-mode-syntax-table)
  86.   (make-local-variable 'indent-line-function)
  87.   (setq indent-line-function 'indent-relative-maybe)
  88.   (use-local-map indented-text-mode-map)
  89.   (setq mode-name "Indented Text")
  90.   (setq major-mode 'indented-text-mode)
  91.   (run-hooks 'text-mode-hook))
  92.  
  93. (defun change-log-mode ()
  94.   "Major mode for editing ChangeLog files.  See M-x add-change-log-entry.
  95. Almost the same as Indented Text mode, but prevents numeric backups
  96. and sets `left-margin' to 8 and `fill-column' to 74."
  97.   (interactive)
  98.   (indented-text-mode)
  99.   (setq left-margin 8)
  100.   (setq fill-column 74)
  101.   (make-local-variable 'version-control)
  102.   (setq version-control 'never)
  103.   (run-hooks 'change-log-mode-hook))
  104.  
  105. (defun center-paragraph ()
  106.   "Center each nonblank line in the paragraph at or after point.
  107. See center-line for more info."
  108.   (interactive)
  109.   (save-excursion
  110.     (forward-paragraph)
  111.     (or (bolp) (newline 1))
  112.     (let ((end (point)))
  113.       (backward-paragraph)
  114.       (center-region (point) end))))
  115.  
  116. (defun center-region (from to)
  117.   "Center each nonblank line starting in the region.
  118. See center-line for more info."
  119.   (interactive "r")
  120.   (if (> from to)
  121.       (let ((tem to))
  122.     (setq to from from tem)))
  123.   (save-excursion
  124.     (save-restriction
  125.       (narrow-to-region from to)
  126.       (goto-char from)
  127.       (while (not (eobp))
  128.     (or (save-excursion (skip-chars-forward " \t") (eolp))
  129.         (center-line))
  130.     (forward-line 1)))))
  131.  
  132. (defun center-line ()
  133.   "Center the line point is on, within the width specified by `fill-column'.
  134. This means adjusting the indentation so that it equals
  135. the distance between the end of the text and `fill-column'."
  136.   (interactive)
  137.   (save-excursion
  138.     (let (line-length)
  139.       (beginning-of-line)
  140.       (delete-horizontal-space)
  141.       (end-of-line)
  142.       (delete-horizontal-space)
  143.       (setq line-length (current-column))
  144.       (beginning-of-line)
  145.       (indent-to 
  146.     (+ left-margin 
  147.        (/ (- fill-column left-margin line-length) 2))))))
  148.