Mercurial > emacs
changeset 82303:76cd87e9edd6
(default-indent-new-line): New function.
It calls comment-line-break-function if there are comments.
(do-auto-fill): Use that.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 07 Aug 2007 03:04:23 +0000 |
parents | c0e2cbf10e3a |
children | eb3132265290 |
files | lisp/simple.el |
diffstat | 1 files changed, 39 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/simple.el Tue Aug 07 03:02:04 2007 +0000 +++ b/lisp/simple.el Tue Aug 07 03:04:23 2007 +0000 @@ -4329,13 +4329,6 @@ regexp) :group 'fill) -(defvar comment-line-break-function 'comment-indent-new-line - "*Mode-specific function which line breaks and continues a comment. - -This function is only called during auto-filling of a comment section. -The function should take a single optional argument, which is a flag -indicating whether it should use soft newlines.") - ;; This function is used as the auto-fill-function of a buffer ;; when Auto-Fill mode is enabled. ;; It returns t if it really did any work. @@ -4409,10 +4402,10 @@ (if (save-excursion (skip-chars-backward " \t") (= (point) fill-point)) - (funcall comment-line-break-function t) + (default-indent-new-line t) (save-excursion (goto-char fill-point) - (funcall comment-line-break-function t))) + (default-indent-new-line t))) ;; Now do justification, if required (if (not (eq justify 'left)) (save-excursion @@ -4427,6 +4420,43 @@ (justify-current-line justify t t) t))) +(defvar comment-line-break-function 'comment-indent-new-line + "*Mode-specific function which line breaks and continues a comment. +This function is called during auto-filling when a comment syntax +is defined. +The function should take a single optional argument, which is a flag +indicating whether it should use soft newlines.") + +(defun default-indent-new-line (&optional soft) + "Break line at point and indent. +If a comment syntax is defined, call `comment-indent-new-line'. + +The inserted newline is marked hard if variable `use-hard-newlines' is true, +unless optional argument SOFT is non-nil." + (interactive) + (if comment-start + (funcall comment-line-break-function soft) + ;; Insert the newline before removing empty space so that markers + ;; get preserved better. + (if soft (insert-and-inherit ?\n) (newline 1)) + (save-excursion (forward-char -1) (delete-horizontal-space)) + (delete-horizontal-space) + + (if (and fill-prefix (not adaptive-fill-mode)) + ;; Blindly trust a non-adaptive fill-prefix. + (progn + (indent-to-left-margin) + (insert-before-markers-and-inherit fill-prefix)) + + (cond + ;; If there's an adaptive prefix, use it unless we're inside + ;; a comment and the prefix is not a comment starter. + (fill-prefix + (indent-to-left-margin) + (insert-and-inherit fill-prefix)) + ;; If we're not inside a comment, just try to indent. + (t (indent-according-to-mode)))))) + (defvar normal-auto-fill-function 'do-auto-fill "The function to use for `auto-fill-function' if Auto Fill mode is turned on. Some major modes set this.")