annotate lisp/textmodes/text-mode.el @ 18159:21e4deb76701

(setup-8-bit-environment): Load the file with load, not require, so that we reload it if nec.
author Richard M. Stallman <rms@gnu.org>
date Sat, 07 Jun 1997 07:02:02 +0000
parents 95f6ac42b352
children b7ad635feeb8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
1 ;;; text-mode.el --- text mode, and its idiosyncratic commands.
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
2
7300
cc7cd83ccf3f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6323
diff changeset
3 ;; Copyright (C) 1985, 1992, 1994 Free Software Foundation, Inc.
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 775
diff changeset
4
775
1ca26ccad38e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 727
diff changeset
5 ;; Maintainer: FSF
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
22 ;; Boston, MA 02111-1307, USA.
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
23
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
24 ;;; Commentary:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
25
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
26 ;; This package provides the fundamental text mode documented in the
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
27 ;; Emacs user's manual.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
28
775
1ca26ccad38e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 727
diff changeset
29 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 (defvar text-mode-syntax-table nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 "Syntax table used while in text mode.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 (defvar text-mode-abbrev-table nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 "Abbrev table used while in text mode.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 (define-abbrev-table 'text-mode-abbrev-table ())
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 (if text-mode-syntax-table
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39 ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 (setq text-mode-syntax-table (make-syntax-table))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 (modify-syntax-entry ?\" ". " text-mode-syntax-table)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 (modify-syntax-entry ?\\ ". " text-mode-syntax-table)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 (modify-syntax-entry ?' "w " text-mode-syntax-table))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 (defvar text-mode-map nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 "Keymap for Text mode.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 Many other modes, such as Mail mode, Outline mode and Indented Text mode,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 inherit all the commands defined in this map.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 (if text-mode-map
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 (setq text-mode-map (make-sparse-keymap))
4896
bc777b8e4b45 (text-mode-map): Bind ispell-complete-word to M-TAB.
Richard M. Stallman <rms@gnu.org>
parents: 4744
diff changeset
53 (define-key text-mode-map "\e\t" 'ispell-complete-word)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (define-key text-mode-map "\t" 'tab-to-tab-stop)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 (define-key text-mode-map "\es" 'center-line)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 (define-key text-mode-map "\eS" 'center-paragraph))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 (defun text-mode ()
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
60 "Major mode for editing text written for humans to read.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
61 In this mode, paragraphs are delimited only by blank lines.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
62 You can thus get the full benefit of adaptive filling
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
63 (see the variable `adaptive-fill-mode').
6323
30bb1685217f (text-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6258
diff changeset
64 \\{text-mode-map}
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
65 Turning on Text mode runs the normal hook `text-mode-hook'."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (kill-all-local-variables)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 (use-local-map text-mode-map)
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
69 (setq local-abbrev-table text-mode-abbrev-table)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
70 (set-syntax-table text-mode-syntax-table)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
71 (make-local-variable 'paragraph-start)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
72 (setq paragraph-start (concat "$\\|" page-delimiter))
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
73 (make-local-variable 'paragraph-separate)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
74 (setq paragraph-separate paragraph-start)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 (setq mode-name "Text")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 (setq major-mode 'text-mode)
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
77 (run-hooks 'text-mode-hook))
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
78
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
79 (defun spaced-text-mode ()
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
80 "Major mode for editing text, with leading spaces starting a paragraph.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
81 In this mode, you do not need blank lines between paragraphs
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
82 when the first line of the following paragraph starts with whitespace.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
83 Special commands:
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
84 \\{text-mode-map}
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
85 Turning on Spaced Text mode runs the normal hook `spaced-text-mode-hook'."
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
86 (interactive)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
87 (kill-all-local-variables)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
88 (use-local-map text-mode-map)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
89 (setq mode-name "Spaced Text")
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
90 (setq major-mode 'spaced-text-mode)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (setq local-abbrev-table text-mode-abbrev-table)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (set-syntax-table text-mode-syntax-table)
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
93 (run-hooks 'text-mode-hook 'spaced-text-mode-hook))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 (defvar indented-text-mode-map ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 "Keymap for Indented Text mode.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 All the commands defined in Text mode are inherited unless overridden.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (if indented-text-mode-map
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 ()
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2315
diff changeset
101 ;; Make different definition for TAB before the one in text-mode-map, but
283
78fbe3043a5d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 36
diff changeset
102 ;; share the rest.
78fbe3043a5d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 36
diff changeset
103 (let ((newmap (make-sparse-keymap)))
78fbe3043a5d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 36
diff changeset
104 (define-key newmap "\t" 'indent-relative)
78fbe3043a5d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 36
diff changeset
105 (setq indented-text-mode-map (nconc newmap text-mode-map))))
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
106
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (defun indented-text-mode ()
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
108 "Major mode for editing text which is often indented.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
109 This is like Text mode except that TAB runs `indent-relative'.
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
110 \\{text-mode-map}
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
111 Turning on Indented Text mode runs the normal hook `indented-text-mode-hook'."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 (interactive)
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
113 (text-mode)
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
114 (use-local-map indented-text-mode-map)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 (make-local-variable 'indent-line-function)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 (setq indent-line-function 'indent-relative-maybe)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 (setq mode-name "Indented Text")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (setq major-mode 'indented-text-mode)
6258
5360e784af1d (indented-text-mode): Run indented-text-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents: 4896
diff changeset
119 (run-hooks 'text-mode-hook 'indented-text-mode-hook))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 (defun center-paragraph ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 "Center each nonblank line in the paragraph at or after point.
1576
ddfd236e2c0c Dox fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
123 See `center-line' for more info."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 (forward-paragraph)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127 (or (bolp) (newline 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 (let ((end (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 (backward-paragraph)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (center-region (point) end))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 (defun center-region (from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 "Center each nonblank line starting in the region.
1576
ddfd236e2c0c Dox fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
134 See `center-line' for more info."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (interactive "r")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (if (> from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 (let ((tem to))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 (setq to from from tem)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (save-restriction
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 (narrow-to-region from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142 (goto-char from)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 (while (not (eobp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
144 (or (save-excursion (skip-chars-forward " \t") (eolp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
145 (center-line))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
146 (forward-line 1)))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147
13023
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
148 (defun center-line (&optional nlines)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 "Center the line point is on, within the width specified by `fill-column'.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 This means adjusting the indentation so that it equals
13023
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
151 the distance between the end of the text and `fill-column'.
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
152 The argument NLINES says how many lines to center."
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
153 (interactive "P")
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
154 (if nlines (setq nlines (prefix-numeric-value nlines)))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
155 (while (not (eq nlines 0))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
156 (save-excursion
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
157 (let ((lm (current-left-margin))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
158 line-length)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
159 (beginning-of-line)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
160 (delete-horizontal-space)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
161 (end-of-line)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
162 (delete-horizontal-space)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
163 (setq line-length (current-column))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
164 (if (> (- fill-column lm line-length) 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
165 (indent-line-to
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
166 (+ lm (/ (- fill-column lm line-length) 2))))))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
167 (cond ((null nlines)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
168 (setq nlines 0))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
169 ((> nlines 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
170 (setq nlines (1- nlines))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
171 (forward-line 1))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
172 ((< nlines 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
173 (setq nlines (1+ nlines))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
174 (forward-line -1)))))
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
175
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
176 ;;; text-mode.el ends here