Mercurial > emacs
comparison lisp/newcomment.el @ 85905:7100260421ed
(comment-dwim): Call comment-insert-comment-function, if defined, for
blank lines. Doc fix.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 03 Nov 2007 03:00:32 +0000 |
parents | 597274bf7123 |
children | e947df5d708b 880960b70474 |
comparison
equal
deleted
inserted
replaced
85904:09ca3d882222 | 85905:7100260421ed |
---|---|
1150 (defun comment-dwim (arg) | 1150 (defun comment-dwim (arg) |
1151 "Call the comment command you want (Do What I Mean). | 1151 "Call the comment command you want (Do What I Mean). |
1152 If the region is active and `transient-mark-mode' is on, call | 1152 If the region is active and `transient-mark-mode' is on, call |
1153 `comment-region' (unless it only consists of comments, in which | 1153 `comment-region' (unless it only consists of comments, in which |
1154 case it calls `uncomment-region'). | 1154 case it calls `uncomment-region'). |
1155 Else, if the current line is empty, insert a comment and indent it. | 1155 Else, if the current line is empty, call `comment-insert-comment-function' |
1156 if it is defined, otherwise insert a comment and indent it. | |
1156 Else if a prefix ARG is specified, call `comment-kill'. | 1157 Else if a prefix ARG is specified, call `comment-kill'. |
1157 Else, call `comment-indent'. | 1158 Else, call `comment-indent'. |
1158 You can configure `comment-style' to change the way regions are commented." | 1159 You can configure `comment-style' to change the way regions are commented." |
1159 (interactive "*P") | 1160 (interactive "*P") |
1160 (comment-normalize-vars) | 1161 (comment-normalize-vars) |
1162 (comment-or-uncomment-region (region-beginning) (region-end) arg) | 1163 (comment-or-uncomment-region (region-beginning) (region-end) arg) |
1163 (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$"))) | 1164 (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$"))) |
1164 ;; FIXME: If there's no comment to kill on this line and ARG is | 1165 ;; FIXME: If there's no comment to kill on this line and ARG is |
1165 ;; specified, calling comment-kill is not very clever. | 1166 ;; specified, calling comment-kill is not very clever. |
1166 (if arg (comment-kill (and (integerp arg) arg)) (comment-indent)) | 1167 (if arg (comment-kill (and (integerp arg) arg)) (comment-indent)) |
1167 (let ((add (comment-add arg))) | 1168 ;; Inserting a comment on a blank line. comment-indent calls |
1168 ;; Some modes insist on keeping column 0 comment in column 0 | 1169 ;; c-i-c-f if needed in the non-blank case. |
1169 ;; so we need to move away from it before inserting the comment. | 1170 (if comment-insert-comment-function |
1170 (indent-according-to-mode) | 1171 (funcall comment-insert-comment-function) |
1171 (insert (comment-padright comment-start add)) | 1172 (let ((add (comment-add arg))) |
1172 (save-excursion | 1173 ;; Some modes insist on keeping column 0 comment in column 0 |
1173 (unless (string= "" comment-end) | 1174 ;; so we need to move away from it before inserting the comment. |
1174 (insert (comment-padleft comment-end add))) | 1175 (indent-according-to-mode) |
1175 (indent-according-to-mode)))))) | 1176 (insert (comment-padright comment-start add)) |
1177 (save-excursion | |
1178 (unless (string= "" comment-end) | |
1179 (insert (comment-padleft comment-end add))) | |
1180 (indent-according-to-mode))))))) | |
1176 | 1181 |
1177 ;;;###autoload | 1182 ;;;###autoload |
1178 (defcustom comment-auto-fill-only-comments nil | 1183 (defcustom comment-auto-fill-only-comments nil |
1179 "Non-nil means to only auto-fill inside comments. | 1184 "Non-nil means to only auto-fill inside comments. |
1180 This has no effect in modes that do not define a comment syntax." | 1185 This has no effect in modes that do not define a comment syntax." |