# HG changeset patch # User Richard M. Stallman # Date 790489316 0 # Node ID 2546bad342002ac04870ad3d1a2a17e243378328 # Parent d0854b6f32162916b7137b982aef9674e77137b2 (do-auto-fill): Fill, don't fill, or fill-and-justify depending on setting of justification text-property. Respect left-margin and right-margin text properties. (open-line, indent-new-comment-line): Inherit when inserting. (newline-and-indent, reindent-then-newline-and-indent): Doc fix. diff -r d0854b6f3216 -r 2546bad34200 lisp/simple.el --- a/lisp/simple.el Thu Jan 19 04:20:52 1995 +0000 +++ b/lisp/simple.el Thu Jan 19 04:21:56 1995 +0000 @@ -34,7 +34,7 @@ (let* ((do-fill-prefix (and fill-prefix (bolp))) (loc (point))) (while (> arg 0) - (if do-fill-prefix (insert fill-prefix)) + (if do-fill-prefix (insert-and-inherit fill-prefix)) (newline 1) (setq arg (1- arg))) (goto-char loc)) @@ -170,7 +170,7 @@ Indentation is done using the value of `indent-line-function'. In programming language modes, this is the same as TAB. In some text modes, where TAB inserts a tab, this command indents to the -column specified by the variable `left-margin'." +column specified by the function `current-left-margin'." (interactive "*") (delete-region (point) (progn (skip-chars-backward " \t") (point))) (newline) @@ -182,7 +182,7 @@ which means calling the current value of `indent-line-function'. In programming language modes, this is the same as TAB. In some text modes, where TAB inserts a tab, this indents to the -column specified by the variable `left-margin'." +column specified by the function `current-left-margin'." (interactive "*") (save-excursion (delete-region (point) (progn (skip-chars-backward " \t") (point))) @@ -2162,18 +2162,31 @@ "*Regexp to match lines which should not be auto-filled.") (defun do-auto-fill () - (let (give-up) - (or (and auto-fill-inhibit-regexp - (save-excursion (beginning-of-line) - (looking-at auto-fill-inhibit-regexp))) - (while (and (not give-up) (> (current-column) fill-column)) + (let (fc justify bol give-up) + (if (or (not (setq justify (justification))) + (and (setq fc (current-fill-column)) ; make sure this gets set + (eq justify 'left) + (<= (current-column) (setq fc (current-fill-column)))) + (save-excursion (beginning-of-line) + (setq bol (point)) + (and auto-fill-inhibit-regexp + (looking-at auto-fill-inhibit-regexp)))) + nil ;; Auto-filling not required + ;; Remove justification-introduced whitespace before filling + (cond ((eq 'left justify) nil) + ((eq 'full justify) ; full justify: remove extra spaces + (canonically-space-region + (point) (save-excursion (end-of-line) (point)))) + ;; right or center justify: remove extra indentation. + (t (save-excursion (indent-according-to-mode)))) + (while (and (not give-up) (> (current-column) fc)) ;; Determine where to split the line. (let ((fill-point (let ((opoint (point)) bounce (first t)) (save-excursion - (move-to-column (1+ fill-column)) + (move-to-column (1+ fc)) ;; Move back to a word boundary. (while (or first ;; If this is after period and a single space, @@ -2214,18 +2227,25 @@ (save-excursion (goto-char fill-point) (indent-new-comment-line t))) + ;; Now do justification, if required + (if (not (eq justify 'left)) + (save-excursion + (end-of-line 0) + (justify-current-line justify nil t))) ;; If making the new line didn't reduce the hpos of ;; the end of the line, then give up now; ;; trying again will not help. (if (>= (current-column) prev-column) (setq give-up t))) ;; No place to break => stop trying. - (setq give-up t))))))) + (setq give-up t)))) + ;; justify last line + (justify-current-line justify t t)))) (defun auto-fill-mode (&optional arg) "Toggle auto-fill mode. With arg, turn Auto-Fill mode on if and only if arg is positive. -In Auto-Fill mode, inserting a space at a column beyond `fill-column' +In Auto-Fill mode, inserting a space at a column beyond `current-fill-column' automatically breaks the line at a previous space." (interactive "P") (prog1 (setq auto-fill-function @@ -2275,7 +2295,7 @@ (delete-region (point) (progn (skip-chars-forward " \t") (point))) - (if soft (insert ?\n) (newline 1)) + (if soft (insert-and-inherit ?\n) (newline 1)) (if (not comment-multi-line) (save-excursion (if (and comment-start-skip @@ -2314,7 +2334,7 @@ ) (if (not (eolp)) (setq comment-end "")) - (insert ?\n) + (insert-and-inherit ?\n) (forward-char -1) (indent-for-comment) (save-excursion @@ -2322,7 +2342,7 @@ (end-of-line) (delete-char 1))) (if fill-prefix - (insert fill-prefix) + (insert-and-inherit fill-prefix) (indent-according-to-mode))))) (defun set-selective-display (arg)