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