From 3a0c47555c3aa253cceca709812fccf48a6ed77c Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Fri, 21 Jul 1995 01:43:21 +0000 Subject: [PATCH] (indent-new-comment-line): fill-prefix overrides comment indentation. --- lisp/simple.el | 108 +++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 0b69cf6ed68..eae4cb1b482 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2419,6 +2419,9 @@ This command is intended for styles where you write a comment per line, starting a new comment (and terminating it if necessary) on each line. If you want to continue one comment across several lines, use \\[newline-and-indent]. +If a fill column is specified, it overrides the use of the comment column +or comment indentation. + The inserted newline is marked hard if `use-hard-newlines' is true, unless optional argument SOFT is non-nil." (interactive) @@ -2428,59 +2431,60 @@ unless optional argument SOFT is non-nil." (progn (skip-chars-forward " \t") (point))) (if soft (insert-and-inherit ?\n) (newline 1)) - (if (not comment-multi-line) - (save-excursion - (if (and comment-start-skip - (let ((opoint (point))) - (forward-line -1) - (re-search-forward comment-start-skip opoint t))) - ;; The old line is a comment. - ;; Set WIN to the pos of the comment-start. - ;; But if the comment is empty, look at preceding lines - ;; to find one that has a nonempty comment. - - ;; If comment-start-skip contains a \(...\) pair, - ;; the real comment delimiter starts at the end of that pair. - (let ((win (or (match-end 1) (match-beginning 0)))) - (while (and (eolp) (not (bobp)) - (let (opoint) - (beginning-of-line) - (setq opoint (point)) - (forward-line -1) - (re-search-forward comment-start-skip opoint t))) - (setq win (or (match-end 1) (match-beginning 0)))) - ;; Indent this line like what we found. - (goto-char win) - (setq comcol (current-column)) - (setq comstart - (buffer-substring (point) (match-end 0))))))) - (if comcol - (let ((comment-column comcol) - (comment-start comstart) - (comment-end comment-end)) - (and comment-end (not (equal comment-end "")) -; (if (not comment-multi-line) - (progn - (forward-char -1) - (insert comment-end) - (forward-char 1)) -; (setq comment-column (+ comment-column (length comment-start)) -; comment-start "") -; ) - ) - (if (not (eolp)) - (setq comment-end "")) - (insert-and-inherit ?\n) - (forward-char -1) - (indent-for-comment) + (if fill-prefix + (progn + (indent-to-left-margin) + (insert-and-inherit fill-prefix)) + (if (not comment-multi-line) (save-excursion - ;; Make sure we delete the newline inserted above. - (end-of-line) - (delete-char 1))) - (if (null fill-prefix) - (indent-according-to-mode) - (indent-to-left-margin) - (insert-and-inherit fill-prefix))))) + (if (and comment-start-skip + (let ((opoint (point))) + (forward-line -1) + (re-search-forward comment-start-skip opoint t))) + ;; The old line is a comment. + ;; Set WIN to the pos of the comment-start. + ;; But if the comment is empty, look at preceding lines + ;; to find one that has a nonempty comment. + + ;; If comment-start-skip contains a \(...\) pair, + ;; the real comment delimiter starts at the end of that pair. + (let ((win (or (match-end 1) (match-beginning 0)))) + (while (and (eolp) (not (bobp)) + (let (opoint) + (beginning-of-line) + (setq opoint (point)) + (forward-line -1) + (re-search-forward comment-start-skip opoint t))) + (setq win (or (match-end 1) (match-beginning 0)))) + ;; Indent this line like what we found. + (goto-char win) + (setq comcol (current-column)) + (setq comstart + (buffer-substring (point) (match-end 0))))))) + (if comcol + (let ((comment-column comcol) + (comment-start comstart) + (comment-end comment-end)) + (and comment-end (not (equal comment-end "")) + ; (if (not comment-multi-line) + (progn + (forward-char -1) + (insert comment-end) + (forward-char 1)) + ; (setq comment-column (+ comment-column (length comment-start)) + ; comment-start "") + ; ) + ) + (if (not (eolp)) + (setq comment-end "")) + (insert-and-inherit ?\n) + (forward-char -1) + (indent-for-comment) + (save-excursion + ;; Make sure we delete the newline inserted above. + (end-of-line) + (delete-char 1))) + (indent-according-to-mode))))) (defun set-selective-display (arg) "Set `selective-display' to ARG; clear it if no arg. -- 2.39.2