changeset 13023:78f30dd2c8fd

(center-line): New arg NLINES. Do nothing for lines that are too wide.
author Richard M. Stallman <rms@gnu.org>
date Sun, 10 Sep 1995 17:44:25 +0000
parents 3c1e69b96db6
children 53205d572b1b
files lisp/textmodes/text-mode.el
diffstat 1 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/text-mode.el	Sun Sep 10 15:16:16 1995 +0000
+++ b/lisp/textmodes/text-mode.el	Sun Sep 10 17:44:25 1995 +0000
@@ -141,20 +141,32 @@
 	    (center-line))
 	(forward-line 1)))))
 
-(defun center-line ()
+(defun center-line (&optional nlines)
   "Center the line point is on, within the width specified by `fill-column'.
 This means adjusting the indentation so that it equals
-the distance between the end of the text and `fill-column'."
-  (interactive)
-  (save-excursion
-    (let ((lm (current-left-margin))
-	  line-length)
-      (beginning-of-line)
-      (delete-horizontal-space)
-      (end-of-line)
-      (delete-horizontal-space)
-      (setq line-length (current-column))
-      (indent-line-to 
-	(+ lm (/ (- fill-column lm line-length) 2))))))
+the distance between the end of the text and `fill-column'.
+The argument NLINES says how many lines to center."
+  (interactive "P")
+  (if nlines (setq nlines (prefix-numeric-value nlines)))
+  (while (not (eq nlines 0))
+    (save-excursion
+      (let ((lm (current-left-margin))
+	    line-length)
+	(beginning-of-line)
+	(delete-horizontal-space)
+	(end-of-line)
+	(delete-horizontal-space)
+	(setq line-length (current-column))
+	(if (> (- fill-column lm line-length) 0)
+	    (indent-line-to 
+	     (+ lm (/ (- fill-column lm line-length) 2))))))
+    (cond ((null nlines)
+	   (setq nlines 0))
+	  ((> nlines 0)
+	   (setq nlines (1- nlines))
+	   (forward-line 1))
+	  ((< nlines 0)
+	   (setq nlines (1+ nlines))
+	   (forward-line -1)))))
 
 ;;; text-mode.el ends here