aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-09-10 17:44:25 +0000
committerRichard M. Stallman1995-09-10 17:44:25 +0000
commitaaf6c7ef84d040792d9876b5e8f7a20d76a496c6 (patch)
tree76a55ba9c1366c1224b0cb8d39eac3af60d67d5e
parent90b777c5464d266060847fd58d7c481e3c9937f7 (diff)
downloademacs-aaf6c7ef84d040792d9876b5e8f7a20d76a496c6.tar.gz
emacs-aaf6c7ef84d040792d9876b5e8f7a20d76a496c6.zip
(center-line): New arg NLINES.
Do nothing for lines that are too wide.
-rw-r--r--lisp/textmodes/text-mode.el38
1 files changed, 25 insertions, 13 deletions
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index aa4e2fc9790..2dd825187ce 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -141,20 +141,32 @@ See `center-line' for more info."
141 (center-line)) 141 (center-line))
142 (forward-line 1))))) 142 (forward-line 1)))))
143 143
144(defun center-line () 144(defun center-line (&optional nlines)
145 "Center the line point is on, within the width specified by `fill-column'. 145 "Center the line point is on, within the width specified by `fill-column'.
146This means adjusting the indentation so that it equals 146This means adjusting the indentation so that it equals
147the distance between the end of the text and `fill-column'." 147the distance between the end of the text and `fill-column'.
148 (interactive) 148The argument NLINES says how many lines to center."
149 (save-excursion 149 (interactive "P")
150 (let ((lm (current-left-margin)) 150 (if nlines (setq nlines (prefix-numeric-value nlines)))
151 line-length) 151 (while (not (eq nlines 0))
152 (beginning-of-line) 152 (save-excursion
153 (delete-horizontal-space) 153 (let ((lm (current-left-margin))
154 (end-of-line) 154 line-length)
155 (delete-horizontal-space) 155 (beginning-of-line)
156 (setq line-length (current-column)) 156 (delete-horizontal-space)
157 (indent-line-to 157 (end-of-line)
158 (+ lm (/ (- fill-column lm line-length) 2)))))) 158 (delete-horizontal-space)
159 (setq line-length (current-column))
160 (if (> (- fill-column lm line-length) 0)
161 (indent-line-to
162 (+ lm (/ (- fill-column lm line-length) 2))))))
163 (cond ((null nlines)
164 (setq nlines 0))
165 ((> nlines 0)
166 (setq nlines (1- nlines))
167 (forward-line 1))
168 ((< nlines 0)
169 (setq nlines (1+ nlines))
170 (forward-line -1)))))
159 171
160;;; text-mode.el ends here 172;;; text-mode.el ends here