diff options
| author | Stefan Monnier | 2006-10-10 00:33:16 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-10-10 00:33:16 +0000 |
| commit | e29d96b65f897a3cef09053c6491116de25cade5 (patch) | |
| tree | 7792eca7e85eb1d9798c3f6d52f1e395857d280f | |
| parent | 394ccd7d8bf47c9ecef244631cfda61e065e777d (diff) | |
| download | emacs-e29d96b65f897a3cef09053c6491116de25cade5.tar.gz emacs-e29d96b65f897a3cef09053c6491116de25cade5.zip | |
(comment-valid-prefix-p): Make the check more thorough.
From an idea by Martin Rudalics <rudalics@gmx.at>.
(comment-indent-new-line): Adjust call.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/newcomment.el | 49 |
2 files changed, 46 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a165ba11cbf..3d434dfed15 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2006-10-09 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * newcomment.el (comment-valid-prefix-p): Make the check | ||
| 4 | more thorough. From an idea by Martin Rudalics <rudalics@gmx.at>. | ||
| 5 | (comment-indent-new-line): Adjust call. | ||
| 6 | |||
| 1 | 2006-10-09 Ken Manheimer <ken.manheimer@gmail.com> | 7 | 2006-10-09 Ken Manheimer <ken.manheimer@gmail.com> |
| 2 | 8 | ||
| 3 | * allout.el (allout-back-to-current-heading): Base on lower-level | 9 | * allout.el (allout-back-to-current-heading): Base on lower-level |
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 0cf0160afb1..9d089a2e164 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -238,7 +238,7 @@ behavior for explicit filling, you might as well use \\[newline-and-indent]." | |||
| 238 | (defcustom comment-empty-lines nil | 238 | (defcustom comment-empty-lines nil |
| 239 | "If nil, `comment-region' does not comment out empty lines. | 239 | "If nil, `comment-region' does not comment out empty lines. |
| 240 | If t, it always comments out empty lines. | 240 | If t, it always comments out empty lines. |
| 241 | if `eol' it only comments out empty lines if comments are | 241 | If `eol' it only comments out empty lines if comments are |
| 242 | terminated by the end of line (i.e. `comment-end' is empty)." | 242 | terminated by the end of line (i.e. `comment-end' is empty)." |
| 243 | :type '(choice (const :tag "Never" nil) | 243 | :type '(choice (const :tag "Never" nil) |
| 244 | (const :tag "Always" t) | 244 | (const :tag "Always" t) |
| @@ -1124,12 +1124,44 @@ This has no effect in modes that do not define a comment syntax." | |||
| 1124 | :group 'comment) | 1124 | :group 'comment) |
| 1125 | 1125 | ||
| 1126 | (defun comment-valid-prefix-p (prefix compos) | 1126 | (defun comment-valid-prefix-p (prefix compos) |
| 1127 | (or | 1127 | "Check that the adaptive-fill-prefix is consistent with the context. |
| 1128 | ;; Accept any prefix if the current comment is not EOL-terminated. | 1128 | PREFIX is the prefix (presumably guessed by `adaptive-fill-mode'). |
| 1129 | (save-excursion (goto-char compos) (comment-forward) (not (bolp))) | 1129 | COMPOS is the position of the beginning of the comment we're in, or nil |
| 1130 | ;; Accept any prefix that starts with a comment-start marker. | 1130 | if we're not inside a comment." |
| 1131 | (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)") | 1131 | ;; This consistency checking is mostly needed to workaround the limitation |
| 1132 | prefix))) | 1132 | ;; of auto-fill-mode whose paragraph-determination doesn't pay attention |
| 1133 | ;; to comment boundaries. | ||
| 1134 | (if (null compos) | ||
| 1135 | ;; We're not inside a comment: the prefix shouldn't match | ||
| 1136 | ;; a comment-starter. | ||
| 1137 | (not (and comment-start comment-start-skip | ||
| 1138 | (string-match comment-start-skip prefix))) | ||
| 1139 | (or | ||
| 1140 | ;; Accept any prefix if the current comment is not EOL-terminated. | ||
| 1141 | (save-excursion (goto-char compos) (comment-forward) (not (bolp))) | ||
| 1142 | ;; Accept any prefix that starts with the same comment-start marker | ||
| 1143 | ;; as the current one. | ||
| 1144 | (when (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)") | ||
| 1145 | prefix) | ||
| 1146 | (let ((prefix-com (comment-string-strip (match-string 0 prefix) nil t))) | ||
| 1147 | (string-match "\\`[ \t]*" prefix-com) | ||
| 1148 | (let* ((prefix-space (match-string 0 prefix-com)) | ||
| 1149 | (prefix-indent (string-width prefix-space)) | ||
| 1150 | (prefix-comstart (substring prefix-com (match-end 0)))) | ||
| 1151 | (save-excursion | ||
| 1152 | (goto-char compos) | ||
| 1153 | ;; The comstart marker is the same. | ||
| 1154 | (and (looking-at (regexp-quote prefix-comstart)) | ||
| 1155 | ;; The indentation as well. | ||
| 1156 | (or (= prefix-indent | ||
| 1157 | (- (current-column) (current-left-margin))) | ||
| 1158 | ;; Check the indentation in two different ways, just | ||
| 1159 | ;; to try and avoid most of the potential funny cases. | ||
| 1160 | (equal prefix-space | ||
| 1161 | (buffer-substring (point) | ||
| 1162 | (progn (move-to-left-margin) | ||
| 1163 | (point))))))))))))) | ||
| 1164 | |||
| 1133 | 1165 | ||
| 1134 | ;;;###autoload | 1166 | ;;;###autoload |
| 1135 | (defun comment-indent-new-line (&optional soft) | 1167 | (defun comment-indent-new-line (&optional soft) |
| @@ -1182,8 +1214,7 @@ unless optional argument SOFT is non-nil." | |||
| 1182 | ;; If there's an adaptive prefix, use it unless we're inside | 1214 | ;; If there's an adaptive prefix, use it unless we're inside |
| 1183 | ;; a comment and the prefix is not a comment starter. | 1215 | ;; a comment and the prefix is not a comment starter. |
| 1184 | ((and fill-prefix | 1216 | ((and fill-prefix |
| 1185 | (or (not compos) | 1217 | (comment-valid-prefix-p fill-prefix compos)) |
| 1186 | (comment-valid-prefix-p fill-prefix compos))) | ||
| 1187 | (indent-to-left-margin) | 1218 | (indent-to-left-margin) |
| 1188 | (insert-and-inherit fill-prefix)) | 1219 | (insert-and-inherit fill-prefix)) |
| 1189 | ;; If we're not inside a comment, just try to indent. | 1220 | ;; If we're not inside a comment, just try to indent. |