Mercurial > emacs
comparison lisp/newcomment.el @ 50947:15c3c47aca50
(comment-indent): Try to align to adjacent comments.
(comment-with-narrowing): Actually use the arguments.
(comment-valid-prefix-p): Rename from comment-valid-prefix
and fix to actually use its argument.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 10 May 2003 22:54:35 +0000 |
parents | 068965f379b3 |
children | 0237e2420453 |
comparison
equal
deleted
inserted
replaced
50946:89a47df61860 | 50947:15c3c47aca50 |
---|---|
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> |
7 ;; Keywords: comment uncomment | 7 ;; Keywords: comment uncomment |
8 | 8 |
491 (insert ender))) | 491 (insert ender))) |
492 (goto-char begpos) | 492 (goto-char begpos) |
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))) |
508 (indent-to (if (bolp) indent | 529 (indent-to (if (bolp) indent |
509 (max indent (1+ (current-column))))))) | 530 (max indent (1+ (current-column))))))) |
762 "Execute BODY with BEG..END narrowing. | 783 "Execute BODY with BEG..END narrowing. |
763 Space is added (and then removed) at the beginning for the text's | 784 Space is added (and then removed) at the beginning for the text's |
764 indentation to be kept as it was before narrowing." | 785 indentation 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 |
773 (progn ,@body) | 794 (progn ,@body) |
774 ;; remove the bindent | 795 ;; remove the bindent |
986 (defcustom comment-auto-fill-only-comments nil | 1007 (defcustom comment-auto-fill-only-comments nil |
987 "Non-nil means to only auto-fill inside comments. | 1008 "Non-nil means to only auto-fill inside comments. |
988 This has no effect in modes that do not define a comment syntax." | 1009 This 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) |
1001 "Break line at point and indent, continuing comment if within one. | 1022 "Break line at point and indent, continuing comment if within one. |
1002 This indents the body of the continued comment | 1023 This indents the body of the continued comment |
1046 (cond | 1067 (cond |
1047 ;; If there's an adaptive prefix, use it unless we're inside | 1068 ;; If there's an adaptive prefix, use it unless we're inside |
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. |
1055 ((not compos) (indent-according-to-mode)) | 1076 ((not compos) (indent-according-to-mode)) |
1056 (t | 1077 (t |