(texinfo-mode): Undo changes mistakenly added with
[bpt/emacs.git] / lisp / textmodes / text-mode.el
CommitLineData
d501f516
ER
1;;; text-mode.el --- text mode, and its idiosyncratic commands.
2
daa37602 3;; Copyright (C) 1985, 1992 Free Software Foundation, Inc.
a2535589 4
58142744
ER
5;; Maintainer: FSF
6
a2535589
JA
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software; you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
daa37602 11;; the Free Software Foundation; either version 2, or (at your option)
a2535589
JA
12;; any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs; see the file COPYING. If not, write to
21;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
d9ecc911
ER
23
24;;; Commentary:
25
26;; This package provides the fundamental text mode documented in the
27;; Emacs user's manual.
28
22a89ee8 29;;; Code:
a2535589
JA
30
31(defvar text-mode-syntax-table nil
32 "Syntax table used while in text mode.")
33
34(defvar text-mode-abbrev-table nil
35 "Abbrev table used while in text mode.")
36(define-abbrev-table 'text-mode-abbrev-table ())
37
38(if text-mode-syntax-table
39 ()
40 (setq text-mode-syntax-table (make-syntax-table))
41 (modify-syntax-entry ?\" ". " text-mode-syntax-table)
42 (modify-syntax-entry ?\\ ". " text-mode-syntax-table)
43 (modify-syntax-entry ?' "w " text-mode-syntax-table))
44
45(defvar text-mode-map nil
46 "Keymap for Text mode.
47Many other modes, such as Mail mode, Outline mode and Indented Text mode,
48inherit all the commands defined in this map.")
49
50(if text-mode-map
51 ()
52 (setq text-mode-map (make-sparse-keymap))
53 (define-key text-mode-map "\t" 'tab-to-tab-stop)
54 (define-key text-mode-map "\es" 'center-line)
55 (define-key text-mode-map "\eS" 'center-paragraph))
56
57\f
58;(defun non-saved-text-mode ()
59; "Like text-mode, but delete auto save file when file is saved for real."
60; (text-mode)
61; (make-local-variable 'delete-auto-save-files)
62; (setq delete-auto-save-files t))
63
64(defun text-mode ()
65 "Major mode for editing text intended for humans to read. Special commands:\\{text-mode-map}
d367fa71 66Turning on Text mode calls the value of the variable `text-mode-hook',
a2535589
JA
67if that value is non-nil."
68 (interactive)
69 (kill-all-local-variables)
70 (use-local-map text-mode-map)
71 (setq mode-name "Text")
72 (setq major-mode 'text-mode)
73 (setq local-abbrev-table text-mode-abbrev-table)
74 (set-syntax-table text-mode-syntax-table)
75 (run-hooks 'text-mode-hook))
76
77(defvar indented-text-mode-map ()
78 "Keymap for Indented Text mode.
79All the commands defined in Text mode are inherited unless overridden.")
80
81(if indented-text-mode-map
82 ()
eb8c3be9 83 ;; Make different definition for TAB before the one in text-mode-map, but
8c73a61a
JB
84 ;; share the rest.
85 (let ((newmap (make-sparse-keymap)))
86 (define-key newmap "\t" 'indent-relative)
87 (setq indented-text-mode-map (nconc newmap text-mode-map))))
a2535589
JA
88
89(defun indented-text-mode ()
90 "Major mode for editing indented text intended for humans to read.\\{indented-text-mode-map}
d367fa71
CZ
91Turning on `indented-text-mode' calls the value of the variable
92`text-mode-hook', if that value is non-nil."
a2535589
JA
93 (interactive)
94 (kill-all-local-variables)
95 (use-local-map text-mode-map)
96 (define-abbrev-table 'text-mode-abbrev-table ())
97 (setq local-abbrev-table text-mode-abbrev-table)
98 (set-syntax-table text-mode-syntax-table)
99 (make-local-variable 'indent-line-function)
100 (setq indent-line-function 'indent-relative-maybe)
101 (use-local-map indented-text-mode-map)
102 (setq mode-name "Indented Text")
103 (setq major-mode 'indented-text-mode)
104 (run-hooks 'text-mode-hook))
105
a2535589
JA
106(defun center-paragraph ()
107 "Center each nonblank line in the paragraph at or after point.
d367fa71 108See `center-line' for more info."
a2535589
JA
109 (interactive)
110 (save-excursion
111 (forward-paragraph)
112 (or (bolp) (newline 1))
113 (let ((end (point)))
114 (backward-paragraph)
115 (center-region (point) end))))
116
117(defun center-region (from to)
118 "Center each nonblank line starting in the region.
d367fa71 119See `center-line' for more info."
a2535589
JA
120 (interactive "r")
121 (if (> from to)
122 (let ((tem to))
123 (setq to from from tem)))
124 (save-excursion
125 (save-restriction
126 (narrow-to-region from to)
127 (goto-char from)
128 (while (not (eobp))
129 (or (save-excursion (skip-chars-forward " \t") (eolp))
130 (center-line))
131 (forward-line 1)))))
132
133(defun center-line ()
134 "Center the line point is on, within the width specified by `fill-column'.
135This means adjusting the indentation so that it equals
136the distance between the end of the text and `fill-column'."
137 (interactive)
138 (save-excursion
139 (let (line-length)
140 (beginning-of-line)
141 (delete-horizontal-space)
142 (end-of-line)
143 (delete-horizontal-space)
144 (setq line-length (current-column))
145 (beginning-of-line)
146 (indent-to
147 (+ left-margin
148 (/ (- fill-column left-margin line-length) 2))))))
d501f516
ER
149
150;;; text-mode.el ends here