aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/newcomment.el43
1 files changed, 32 insertions, 11 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index aa58c02b237..d7067184539 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1,6 +1,6 @@
1;;; newcomment.el --- (un)comment regions of buffers 1;;; newcomment.el --- (un)comment regions of buffers
2 2
3;; Copyright (C) 1999, 2000 Free Software Foundation Inc. 3;; Copyright (C) 1999,2000,2003 Free Software Foundation Inc.
4 4
5;; Author: code extracted from Emacs-20's simple.el 5;; Author: code extracted from Emacs-20's simple.el
6;; Maintainer: Stefan Monnier <monnier@cs.yale.edu> 6;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
@@ -493,15 +493,36 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
493 ;; Compute desired indent. 493 ;; Compute desired indent.
494 (setq indent (save-excursion (funcall comment-indent-function))) 494 (setq indent (save-excursion (funcall comment-indent-function)))
495 (if (not indent) 495 (if (not indent)
496 ;; comment-indent-function refuses: delegate to indent. 496 ;; comment-indent-function refuses: delegate to line-indent.
497 (indent-according-to-mode) 497 (indent-according-to-mode)
498 ;; Avoid moving comments past the fill-column. 498 ;; Avoid moving comments past the fill-column.
499 (unless (save-excursion (skip-chars-backward " \t") (bolp)) 499 (unless (save-excursion (skip-chars-backward " \t") (bolp))
500 (setq indent 500 (let ((max (+ (current-column)
501 (min indent
502 (+ (current-column)
503 (- (or comment-fill-column fill-column) 501 (- (or comment-fill-column fill-column)
504 (save-excursion (end-of-line) (current-column))))))) 502 (save-excursion (end-of-line) (current-column))))))
503 (if (<= max indent)
504 (setq indent max) ;Don't move past the fill column.
505 ;; We can choose anywhere between indent..max.
506 ;; Let's try to align to a comment on the previous line.
507 (let ((other nil))
508 (save-excursion
509 (when (and (zerop (forward-line -1))
510 (setq other (comment-search-forward
511 (line-end-position) t)))
512 (goto-char other) (setq other (current-column))))
513 (if (and other (<= other max) (> other indent))
514 ;; There is a comment and it's in the range: bingo.
515 (setq indent other)
516 ;; Let's try to align to a comment on the next line, then.
517 (let ((other nil))
518 (save-excursion
519 (when (and (zerop (forward-line 1))
520 (setq other (comment-search-forward
521 (line-end-position) t)))
522 (goto-char other) (setq other (current-column))))
523 (if (and other (<= other max) (> other indent))
524 ;; There is a comment and it's in the range: bingo.
525 (setq indent other))))))))
505 (unless (= (current-column) indent) 526 (unless (= (current-column) indent)
506 ;; If that's different from current, change it. 527 ;; If that's different from current, change it.
507 (delete-region (point) (progn (skip-chars-backward " \t") (point))) 528 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
@@ -764,9 +785,9 @@ Space is added (and then removed) at the beginning for the text's
764indentation to be kept as it was before narrowing." 785indentation to be kept as it was before narrowing."
765 (declare (debug t) (indent 2)) 786 (declare (debug t) (indent 2))
766 (let ((bindent (make-symbol "bindent"))) 787 (let ((bindent (make-symbol "bindent")))
767 `(let ((,bindent (save-excursion (goto-char beg) (current-column)))) 788 `(let ((,bindent (save-excursion (goto-char ,beg) (current-column))))
768 (save-restriction 789 (save-restriction
769 (narrow-to-region beg end) 790 (narrow-to-region ,beg ,end)
770 (goto-char (point-min)) 791 (goto-char (point-min))
771 (insert (make-string ,bindent ? )) 792 (insert (make-string ,bindent ? ))
772 (prog1 793 (prog1
@@ -988,13 +1009,13 @@ Else, call `comment-indent'."
988This has no effect in modes that do not define a comment syntax." 1009This has no effect in modes that do not define a comment syntax."
989 :type 'boolean) 1010 :type 'boolean)
990 1011
991(defun comment-valid-prefix (prefix compos) 1012(defun comment-valid-prefix-p (prefix compos)
992 (or 1013 (or
993 ;; Accept any prefix if the current comment is not EOL-terminated. 1014 ;; Accept any prefix if the current comment is not EOL-terminated.
994 (save-excursion (goto-char compos) (comment-forward) (not (bolp))) 1015 (save-excursion (goto-char compos) (comment-forward) (not (bolp)))
995 ;; Accept any prefix that starts with a comment-start marker. 1016 ;; Accept any prefix that starts with a comment-start marker.
996 (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)") 1017 (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
997 fill-prefix))) 1018 prefix)))
998 1019
999;;;###autoload 1020;;;###autoload
1000(defun comment-indent-new-line (&optional soft) 1021(defun comment-indent-new-line (&optional soft)
@@ -1048,7 +1069,7 @@ unless optional argument SOFT is non-nil."
1048 ;; a comment and the prefix is not a comment starter. 1069 ;; a comment and the prefix is not a comment starter.
1049 ((and fill-prefix 1070 ((and fill-prefix
1050 (or (not compos) 1071 (or (not compos)
1051 (comment-valid-prefix fill-prefix compos))) 1072 (comment-valid-prefix-p fill-prefix compos)))
1052 (indent-to-left-margin) 1073 (indent-to-left-margin)
1053 (insert-and-inherit fill-prefix)) 1074 (insert-and-inherit fill-prefix))
1054 ;; If we're not inside a comment, just try to indent. 1075 ;; If we're not inside a comment, just try to indent.