diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2003-10-24 20:26:26 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2003-10-24 20:26:26 +0000 |
commit | 8cc313a338820edc56cecbde6e26dad17c8bc41b (patch) | |
tree | 0990adf5157972ce70400822ecc5fd36420d1ea5 /lisp/newcomment.el | |
parent | cb3d3ec192d67e0799919123da6eb0cd46e09776 (diff) | |
download | emacs-8cc313a338820edc56cecbde6e26dad17c8bc41b.tar.gz |
(comment-indent): Don't call indent-according-to-mode if the line has code.
Don't try to line up with something that's too far left.
Diffstat (limited to 'lisp/newcomment.el')
-rw-r--r-- | lisp/newcomment.el | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 5e85fbc39fe..fb2cf480c0d 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -501,11 +501,16 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any." (goto-char begpos) ;; Compute desired indent. (setq indent (save-excursion (funcall comment-indent-function))) + ;; If `indent' is nil and there's code before the comment, we can't + ;; use `indent-according-to-mode', so we default to comment-column. + (unless (or indent (save-excursion (skip-chars-backward " \t") (bolp))) + (setq indent comment-column)) (if (not indent) ;; comment-indent-function refuses: delegate to line-indent. (indent-according-to-mode) - ;; Avoid moving comments past the fill-column. + ;; If the comment is at the left of code, adjust the indentation. (unless (save-excursion (skip-chars-backward " \t") (bolp)) + ;; Avoid moving comments past the fill-column. (let ((max (+ (current-column) (- (or comment-fill-column fill-column) (save-excursion (end-of-line) (current-column)))))) @@ -513,13 +518,16 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any." (setq indent max) ;Don't move past the fill column. ;; We can choose anywhere between indent..max. ;; Let's try to align to a comment on the previous line. - (let ((other nil)) + (let ((other nil) + (min (max indent + (save-excursion (skip-chars-backward " \t") + (1+ (current-column)))))) (save-excursion (when (and (zerop (forward-line -1)) (setq other (comment-search-forward (line-end-position) t))) (goto-char other) (setq other (current-column)))) - (if (and other (<= other max) (> other indent)) + (if (and other (<= other max) (>= other min)) ;; There is a comment and it's in the range: bingo. (setq indent other) ;; Let's try to align to a comment on the next line, then. @@ -529,7 +537,7 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any." (setq other (comment-search-forward (line-end-position) t))) (goto-char other) (setq other (current-column)))) - (if (and other (<= other max) (> other indent)) + (if (and other (<= other max) (> other min)) ;; There is a comment and it's in the range: bingo. (setq indent other)))))))) (unless (= (current-column) indent) |