Commit | Line | Data |
---|---|---|
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 | ||
22a89ee8 | 23 | ;;; Code: |
a2535589 JA |
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 | "Keymap for Text mode. | |
41 | Many other modes, such as Mail mode, Outline mode and Indented Text mode, | |
42 | inherit all the commands defined in this map.") | |
43 | ||
44 | (if text-mode-map | |
45 | () | |
46 | (setq text-mode-map (make-sparse-keymap)) | |
47 | (define-key text-mode-map "\t" 'tab-to-tab-stop) | |
48 | (define-key text-mode-map "\es" 'center-line) | |
49 | (define-key text-mode-map "\eS" 'center-paragraph)) | |
50 | ||
51 | \f | |
52 | ;(defun non-saved-text-mode () | |
53 | ; "Like text-mode, but delete auto save file when file is saved for real." | |
54 | ; (text-mode) | |
55 | ; (make-local-variable 'delete-auto-save-files) | |
56 | ; (setq delete-auto-save-files t)) | |
57 | ||
58 | (defun text-mode () | |
59 | "Major mode for editing text intended for humans to read. Special commands:\\{text-mode-map} | |
d367fa71 | 60 | Turning on Text mode calls the value of the variable `text-mode-hook', |
a2535589 JA |
61 | if that value is non-nil." |
62 | (interactive) | |
63 | (kill-all-local-variables) | |
64 | (use-local-map text-mode-map) | |
65 | (setq mode-name "Text") | |
66 | (setq major-mode 'text-mode) | |
67 | (setq local-abbrev-table text-mode-abbrev-table) | |
68 | (set-syntax-table text-mode-syntax-table) | |
69 | (run-hooks 'text-mode-hook)) | |
70 | ||
71 | (defvar indented-text-mode-map () | |
72 | "Keymap for Indented Text mode. | |
73 | All the commands defined in Text mode are inherited unless overridden.") | |
74 | ||
75 | (if indented-text-mode-map | |
76 | () | |
8c73a61a JB |
77 | ;; Make different definintion for TAB before the one in text-mode-map, but |
78 | ;; share the rest. | |
79 | (let ((newmap (make-sparse-keymap))) | |
80 | (define-key newmap "\t" 'indent-relative) | |
81 | (setq indented-text-mode-map (nconc newmap text-mode-map)))) | |
a2535589 JA |
82 | |
83 | (defun indented-text-mode () | |
84 | "Major mode for editing indented text intended for humans to read.\\{indented-text-mode-map} | |
d367fa71 CZ |
85 | Turning on `indented-text-mode' calls the value of the variable |
86 | `text-mode-hook', if that value is non-nil." | |
a2535589 JA |
87 | (interactive) |
88 | (kill-all-local-variables) | |
89 | (use-local-map text-mode-map) | |
90 | (define-abbrev-table 'text-mode-abbrev-table ()) | |
91 | (setq local-abbrev-table text-mode-abbrev-table) | |
92 | (set-syntax-table text-mode-syntax-table) | |
93 | (make-local-variable 'indent-line-function) | |
94 | (setq indent-line-function 'indent-relative-maybe) | |
95 | (use-local-map indented-text-mode-map) | |
96 | (setq mode-name "Indented Text") | |
97 | (setq major-mode 'indented-text-mode) | |
98 | (run-hooks 'text-mode-hook)) | |
99 | ||
a2535589 JA |
100 | (defun center-paragraph () |
101 | "Center each nonblank line in the paragraph at or after point. | |
d367fa71 | 102 | See `center-line' for more info." |
a2535589 JA |
103 | (interactive) |
104 | (save-excursion | |
105 | (forward-paragraph) | |
106 | (or (bolp) (newline 1)) | |
107 | (let ((end (point))) | |
108 | (backward-paragraph) | |
109 | (center-region (point) end)))) | |
110 | ||
111 | (defun center-region (from to) | |
112 | "Center each nonblank line starting in the region. | |
d367fa71 | 113 | See `center-line' for more info." |
a2535589 JA |
114 | (interactive "r") |
115 | (if (> from to) | |
116 | (let ((tem to)) | |
117 | (setq to from from tem))) | |
118 | (save-excursion | |
119 | (save-restriction | |
120 | (narrow-to-region from to) | |
121 | (goto-char from) | |
122 | (while (not (eobp)) | |
123 | (or (save-excursion (skip-chars-forward " \t") (eolp)) | |
124 | (center-line)) | |
125 | (forward-line 1))))) | |
126 | ||
127 | (defun center-line () | |
128 | "Center the line point is on, within the width specified by `fill-column'. | |
129 | This means adjusting the indentation so that it equals | |
130 | the distance between the end of the text and `fill-column'." | |
131 | (interactive) | |
132 | (save-excursion | |
133 | (let (line-length) | |
134 | (beginning-of-line) | |
135 | (delete-horizontal-space) | |
136 | (end-of-line) | |
137 | (delete-horizontal-space) | |
138 | (setq line-length (current-column)) | |
139 | (beginning-of-line) | |
140 | (indent-to | |
141 | (+ left-margin | |
142 | (/ (- fill-column left-margin line-length) 2)))))) | |
d501f516 ER |
143 | |
144 | ;;; text-mode.el ends here |