|
|
1.1 root 1: ;; Text mode, and its ideosyncratic commands.
2: ;; Copyright (C) 1985 Richard M. Stallman.
3:
4: ;; This file is part of GNU Emacs.
5:
6: ;; GNU Emacs is distributed in the hope that it will be useful,
7: ;; but WITHOUT ANY WARRANTY. No author or distributor
8: ;; accepts responsibility to anyone for the consequences of using it
9: ;; or for whether it serves any particular purpose or works at all,
10: ;; unless he says so in writing. Refer to the GNU Emacs General Public
11: ;; License for full details.
12:
13: ;; Everyone is granted permission to copy, modify and redistribute
14: ;; GNU Emacs, but only under the conditions described in the
15: ;; GNU Emacs General Public License. A copy of this license is
16: ;; supposed to have been given to you along with GNU Emacs so you
17: ;; can know your rights and responsibilities. It should be in a
18: ;; file named COPYING. Among other things, the copyright notice
19: ;; and this notice must be preserved on all copies.
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:
28: (if (null text-mode-syntax-table)
29: (let ((st (syntax-table)))
30: (unwind-protect
31: (progn
32: (setq text-mode-syntax-table (make-syntax-table))
33: (set-syntax-table text-mode-syntax-table)
34: (modify-syntax-entry ?\" ". ")
35: (modify-syntax-entry ?\\ ". ")
36: (modify-syntax-entry ?' "w "))
37: (set-syntax-table st))))
38:
39: (defvar text-mode-map (make-sparse-keymap))
40: (define-key text-mode-map "\t" 'tab-to-tab-stop)
41: (define-key text-mode-map "\es" 'center-line)
42: (define-key text-mode-map "\eS" 'center-paragraph)
43:
44: (defun non-saved-text-mode ()
45: "Like text-mode, but delete auto save file when file is saved for real."
46: (text-mode)
47: (make-local-variable 'delete-auto-save-files)
48: (setq delete-auto-save-files t))
49:
50: (defun text-mode ()
51: "Major mode for editing text intended for humans to read. Special commands:\\{text-mode-map}
52: Turning on text-mode calls the value of the variable text-mode-hook,
53: if that value is non-nil."
54: (interactive)
55: (kill-all-local-variables)
56: (use-local-map text-mode-map)
57: (setq mode-name "Text")
58: (setq major-mode 'text-mode)
59: (define-abbrev-table 'text-mode-abbrev-table ())
60: (setq local-abbrev-table text-mode-abbrev-table)
61: (set-syntax-table text-mode-syntax-table)
62: (run-hooks 'text-mode-hook))
63:
64: (defvar indented-text-mode-map (make-sparse-keymap))
65: (define-key indented-text-mode-map "\t" 'indent-relative)
66: (define-key indented-text-mode-map "\es" 'center-line)
67: (define-key indented-text-mode-map "\eS" 'center-paragraph)
68:
69: (defun indented-text-mode ()
70: "Major mode for editing indented text intended for humans to read.\\{indented-text-mode-map}
71: Turning on indented-text-mode calls the value of the variable text-mode-hook,
72: if that value is non-nil."
73: (interactive)
74: (kill-all-local-variables)
75: (use-local-map text-mode-map)
76: (define-abbrev-table 'text-mode-abbrev-table ())
77: (setq local-abbrev-table text-mode-abbrev-table)
78: (set-syntax-table text-mode-syntax-table)
79: (make-local-variable 'indent-line-function)
80: (setq indent-line-function 'indent-relative-maybe)
81: (use-local-map indented-text-mode-map)
82: (setq mode-name "Indented Text")
83: (setq major-mode 'indented-text-mode)
84: (run-hooks 'text-mode-hook))
85:
86: (defun center-paragraph ()
87: "Center each line in the paragraph at or after point.
88: See center-line for more info."
89: (interactive)
90: (save-excursion
91: (forward-paragraph)
92: (or (bolp) (newline 1))
93: (let ((end (point)))
94: (backward-paragraph)
95: (center-region (point) end))))
96:
97: (defun center-region (from to)
98: "Center each line starting in the region.
99: See center-line for more info."
100: (interactive "r")
101: (if (> from to)
102: (let ((tem to))
103: (setq to from from tem)))
104: (save-excursion
105: (goto-char from)
106: (while (< (point) to)
107: (center-line)
108: (forward-line 1))))
109:
110: (defun center-line ()
111: "Center the line point is on.
112: This means adjusting its indentation to match
113: the distance between the end of the text and fill-column."
114: (interactive)
115: (save-excursion
116: (let (line-length)
117: (beginning-of-line)
118: (delete-horizontal-space)
119: (end-of-line)
120: (delete-horizontal-space)
121: (setq line-length (current-column))
122: (beginning-of-line)
123: (indent-to
124: (+ left-margin
125: (/ (- fill-column left-margin line-length) 2))))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.