annotate lisp/textmodes/text-mode.el @ 42843:49c29a684355

Describe global-hl-line-mode.
author Richard M. Stallman <rms@gnu.org>
date Sun, 20 Jan 2002 09:27:57 +0000
parents 2e6c799155b3
children 2630388260f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38412
253f761ad37b Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents: 28108
diff changeset
1 ;;; text-mode.el --- text mode, and its idiosyncratic commands
657
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
38697
a19197c6442f Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents: 38412
diff changeset
6 ;; Keywords: wp
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; 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
12 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; 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
21 ;; 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
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13023
diff changeset
23 ;; Boston, MA 02111-1307, USA.
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
24
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
25 ;;; Commentary:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
26
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
27 ;; 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
28 ;; Emacs user's manual.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1576
diff changeset
29
775
1ca26ccad38e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 727
diff changeset
30 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31
26598
7c28a5765af4 (text-mode-hook): Customize.
Dave Love <fx@gnu.org>
parents: 26544
diff changeset
32 (defcustom text-mode-hook nil
7c28a5765af4 (text-mode-hook): Customize.
Dave Love <fx@gnu.org>
parents: 26544
diff changeset
33 "Normal hook run when entering Text mode and many related modes."
7c28a5765af4 (text-mode-hook): Customize.
Dave Love <fx@gnu.org>
parents: 26544
diff changeset
34 :type 'hook
28108
0d9cac36402a (text-mode-hook): Add flyspell-mode to
Dave Love <fx@gnu.org>
parents: 27202
diff changeset
35 :options '(turn-on-auto-fill flyspell-mode)
26598
7c28a5765af4 (text-mode-hook): Customize.
Dave Love <fx@gnu.org>
parents: 26544
diff changeset
36 :group 'data)
19589
8c19d570a391 (text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18256
diff changeset
37
19590
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
38 (defvar text-mode-variant nil
40484
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
39 "Non-nil if this buffer's major mode is a variant of Text mode.
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
40 Use (derived-mode-p 'text-mode) instead.")
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41
40484
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
42 (defvar text-mode-syntax-table
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
43 (let ((st (make-syntax-table)))
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
44 (modify-syntax-entry ?\" ". " st)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
45 (modify-syntax-entry ?\\ ". " st)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
46 (modify-syntax-entry ?' "w " st)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
47 st)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
48 "Syntax table used while in `text-mode'.")
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49
40484
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
50 (defvar text-mode-map
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
51 (let ((map (make-sparse-keymap)))
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
52 (define-key map "\e\t" 'ispell-complete-word)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
53 (define-key map "\es" 'center-line)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
54 (define-key map "\eS" 'center-paragraph)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
55 map)
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
56 "Keymap for `text-mode'.
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
57 Many other modes, such as `mail-mode', `outline-mode' and `indented-text-mode',
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 inherit all the commands defined in this map.")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60
40360
04be247dd745 (text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38697
diff changeset
61 (define-derived-mode text-mode nil "Text"
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
62 "Major mode for editing text written for humans to read.
18256
27f2dfb2c1de (text-mode): Let all-white lines separate paragraphs.
Richard M. Stallman <rms@gnu.org>
parents: 18222
diff changeset
63 In this mode, paragraphs are delimited only by blank or white lines.
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
64 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
65 (see the variable `adaptive-fill-mode').
6323
30bb1685217f (text-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6258
diff changeset
66 \\{text-mode-map}
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
67 Turning on Text mode runs the normal hook `text-mode-hook'."
40484
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
68 (set (make-local-variable 'indent-line-function) 'indent-relative))
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
69
40481
7b44c3509111 (paragraph-indent-minor-mode): Don't set paragraph-separate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40360
diff changeset
70 (define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
71 "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
72 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
73 when the first line of the following paragraph starts with whitespace.
27202
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
74 `paragraph-indent-minor-mode' provides a similar facility as a minor mode.
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
75 Special commands:
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
76 \\{text-mode-map}
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
77 Turning on Paragraph-Indent Text mode runs the normal hooks
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
78 `text-mode-hook' and `paragraph-indent-text-mode-hook'."
40484
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
79 (paragraph-indent-minor-mode))
27202
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
80
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
81 (defun paragraph-indent-minor-mode ()
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
82 "Minor mode for editing text, with leading spaces starting a paragraph.
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
83 In this mode, you do not need blank lines between paragraphs when the
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
84 first line of the following paragraph starts with whitespace, as with
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
85 `paragraph-indent-mode'.
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
86 Turning on Paragraph-Indent minor mode runs the normal hook
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
87 `paragraph-indent-text-mode-hook'."
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
88 (interactive)
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
89 (set (make-local-variable 'paragraph-start)
40481
7b44c3509111 (paragraph-indent-minor-mode): Don't set paragraph-separate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40360
diff changeset
90 (concat "[ \t\n\f]\\|" paragraph-start))
7b44c3509111 (paragraph-indent-minor-mode): Don't set paragraph-separate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40360
diff changeset
91 (set (make-local-variable 'indent-line-function) 'indent-to-left-margin)
27202
6047ac0aaa7c (text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents: 26598
diff changeset
92 (run-hooks 'paragraph-indent-text-mode-hook))
18132
95f6ac42b352 (spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
93
18222
b7ad635feeb8 (paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents: 18132
diff changeset
94 (defalias 'indented-text-mode 'text-mode)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95
19620
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
96 (defun text-mode-hook-identify ()
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
97 "Mark that this mode has run `text-mode-hook'.
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
98 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on."
40484
2e6c799155b3 (text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40481
diff changeset
99 (set (make-local-variable 'text-mode-variant) t))
19620
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
100
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
101 (add-hook 'text-mode-hook 'text-mode-hook-identify)
7fccc0f34e57 (text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents: 19590
diff changeset
102
19590
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
103 (defun toggle-text-mode-auto-fill ()
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
104 "Toggle whether to use Auto Fill in Text mode and related modes.
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
105 This command affects all buffers that use modes related to Text mode,
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
106 both existing buffers and buffers that you subsequently create."
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
107 (interactive)
40360
04be247dd745 (text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38697
diff changeset
108 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook))))
19590
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
109 (if enable-mode
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
110 (add-hook 'text-mode-hook 'turn-on-auto-fill)
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
111 (remove-hook 'text-mode-hook 'turn-on-auto-fill))
40360
04be247dd745 (text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38697
diff changeset
112 (dolist (buffer (buffer-list))
04be247dd745 (text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38697
diff changeset
113 (with-current-buffer buffer
04be247dd745 (text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38697
diff changeset
114 (if (or (derived-mode-p 'text-mode) text-mode-variant)
04be247dd745 (text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38697
diff changeset
115 (auto-fill-mode (if enable-mode 1 0)))))
19590
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
116 (message "Auto Fill %s in Text modes"
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
117 (if enable-mode "enabled" "disabled"))))
167f4700890a (text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 19589
diff changeset
118
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 (defun center-paragraph ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120 "Center each nonblank line in the paragraph at or after point.
1576
ddfd236e2c0c Dox fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
121 See `center-line' for more info."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
123 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 (forward-paragraph)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 (or (bolp) (newline 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 (let ((end (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127 (backward-paragraph)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 (center-region (point) end))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (defun center-region (from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131 "Center each nonblank line starting in the region.
1576
ddfd236e2c0c Dox fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
132 See `center-line' for more info."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 (interactive "r")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
134 (if (> from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (let ((tem to))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (setq to from from tem)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 (save-restriction
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (narrow-to-region from to)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (goto-char from)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 (while (not (eobp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142 (or (save-excursion (skip-chars-forward " \t") (eolp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 (center-line))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
144 (forward-line 1)))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
145
13023
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
146 (defun center-line (&optional nlines)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147 "Center the line point is on, within the width specified by `fill-column'.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 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
149 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
150 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
151 (interactive "P")
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
152 (if nlines (setq nlines (prefix-numeric-value nlines)))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
153 (while (not (eq nlines 0))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
154 (save-excursion
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
155 (let ((lm (current-left-margin))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
156 line-length)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
157 (beginning-of-line)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
158 (delete-horizontal-space)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
159 (end-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 (setq line-length (current-column))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
162 (if (> (- fill-column lm line-length) 0)
28108
0d9cac36402a (text-mode-hook): Add flyspell-mode to
Dave Love <fx@gnu.org>
parents: 27202
diff changeset
163 (indent-line-to
13023
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
164 (+ lm (/ (- fill-column lm line-length) 2))))))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
165 (cond ((null nlines)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
166 (setq nlines 0))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
167 ((> nlines 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
168 (setq nlines (1- nlines))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
169 (forward-line 1))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
170 ((< nlines 0)
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
171 (setq nlines (1+ nlines))
78f30dd2c8fd (center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents: 10899
diff changeset
172 (forward-line -1)))))
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
173
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 283
diff changeset
174 ;;; text-mode.el ends here