aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2003-10-24 20:26:26 +0000
committerStefan Monnier2003-10-24 20:26:26 +0000
commit8cc313a338820edc56cecbde6e26dad17c8bc41b (patch)
tree0990adf5157972ce70400822ecc5fd36420d1ea5
parentcb3d3ec192d67e0799919123da6eb0cd46e09776 (diff)
downloademacs-8cc313a338820edc56cecbde6e26dad17c8bc41b.tar.gz
emacs-8cc313a338820edc56cecbde6e26dad17c8bc41b.zip
(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.
-rw-r--r--lisp/newcomment.el16
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."
501 (goto-char begpos) 501 (goto-char begpos)
502 ;; Compute desired indent. 502 ;; Compute desired indent.
503 (setq indent (save-excursion (funcall comment-indent-function))) 503 (setq indent (save-excursion (funcall comment-indent-function)))
504 ;; If `indent' is nil and there's code before the comment, we can't
505 ;; use `indent-according-to-mode', so we default to comment-column.
506 (unless (or indent (save-excursion (skip-chars-backward " \t") (bolp)))
507 (setq indent comment-column))
504 (if (not indent) 508 (if (not indent)
505 ;; comment-indent-function refuses: delegate to line-indent. 509 ;; comment-indent-function refuses: delegate to line-indent.
506 (indent-according-to-mode) 510 (indent-according-to-mode)
507 ;; Avoid moving comments past the fill-column. 511 ;; If the comment is at the left of code, adjust the indentation.
508 (unless (save-excursion (skip-chars-backward " \t") (bolp)) 512 (unless (save-excursion (skip-chars-backward " \t") (bolp))
513 ;; Avoid moving comments past the fill-column.
509 (let ((max (+ (current-column) 514 (let ((max (+ (current-column)
510 (- (or comment-fill-column fill-column) 515 (- (or comment-fill-column fill-column)
511 (save-excursion (end-of-line) (current-column)))))) 516 (save-excursion (end-of-line) (current-column))))))
@@ -513,13 +518,16 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
513 (setq indent max) ;Don't move past the fill column. 518 (setq indent max) ;Don't move past the fill column.
514 ;; We can choose anywhere between indent..max. 519 ;; We can choose anywhere between indent..max.
515 ;; Let's try to align to a comment on the previous line. 520 ;; Let's try to align to a comment on the previous line.
516 (let ((other nil)) 521 (let ((other nil)
522 (min (max indent
523 (save-excursion (skip-chars-backward " \t")
524 (1+ (current-column))))))
517 (save-excursion 525 (save-excursion
518 (when (and (zerop (forward-line -1)) 526 (when (and (zerop (forward-line -1))
519 (setq other (comment-search-forward 527 (setq other (comment-search-forward
520 (line-end-position) t))) 528 (line-end-position) t)))
521 (goto-char other) (setq other (current-column)))) 529 (goto-char other) (setq other (current-column))))
522 (if (and other (<= other max) (> other indent)) 530 (if (and other (<= other max) (>= other min))
523 ;; There is a comment and it's in the range: bingo. 531 ;; There is a comment and it's in the range: bingo.
524 (setq indent other) 532 (setq indent other)
525 ;; Let's try to align to a comment on the next line, then. 533 ;; 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."
529 (setq other (comment-search-forward 537 (setq other (comment-search-forward
530 (line-end-position) t))) 538 (line-end-position) t)))
531 (goto-char other) (setq other (current-column)))) 539 (goto-char other) (setq other (current-column))))
532 (if (and other (<= other max) (> other indent)) 540 (if (and other (<= other max) (> other min))
533 ;; There is a comment and it's in the range: bingo. 541 ;; There is a comment and it's in the range: bingo.
534 (setq indent other)))))))) 542 (setq indent other))))))))
535 (unless (= (current-column) indent) 543 (unless (= (current-column) indent)