mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-24 06:20:43 -08:00
(center-line): New arg NLINES.
Do nothing for lines that are too wide.
This commit is contained in:
parent
90b777c546
commit
aaf6c7ef84
1 changed files with 25 additions and 13 deletions
|
|
@ -141,20 +141,32 @@ See `center-line' for more info."
|
||||||
(center-line))
|
(center-line))
|
||||||
(forward-line 1)))))
|
(forward-line 1)))))
|
||||||
|
|
||||||
(defun center-line ()
|
(defun center-line (&optional nlines)
|
||||||
"Center the line point is on, within the width specified by `fill-column'.
|
"Center the line point is on, within the width specified by `fill-column'.
|
||||||
This means adjusting the indentation so that it equals
|
This means adjusting the indentation so that it equals
|
||||||
the distance between the end of the text and `fill-column'."
|
the distance between the end of the text and `fill-column'.
|
||||||
(interactive)
|
The argument NLINES says how many lines to center."
|
||||||
(save-excursion
|
(interactive "P")
|
||||||
(let ((lm (current-left-margin))
|
(if nlines (setq nlines (prefix-numeric-value nlines)))
|
||||||
line-length)
|
(while (not (eq nlines 0))
|
||||||
(beginning-of-line)
|
(save-excursion
|
||||||
(delete-horizontal-space)
|
(let ((lm (current-left-margin))
|
||||||
(end-of-line)
|
line-length)
|
||||||
(delete-horizontal-space)
|
(beginning-of-line)
|
||||||
(setq line-length (current-column))
|
(delete-horizontal-space)
|
||||||
(indent-line-to
|
(end-of-line)
|
||||||
(+ lm (/ (- fill-column lm line-length) 2))))))
|
(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
|
;;; text-mode.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue