Doc fixes.
[bpt/emacs.git] / lisp / newcomment.el
CommitLineData
83b96b22
SM
1;;; newcomment.el --- (un)comment regions of buffers
2
39cb51e7 3;; Copyright (C) 1999, 2000 Free Software Foundation Inc.
83b96b22 4
59a1ce8d 5;; Author: code extracted from Emacs-20's simple.el
771c9b97 6;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
83b96b22 7;; Keywords: comment uncomment
9d5240d2 8;; Revision: $Id: newcomment.el,v 1.36 2001/10/11 01:44:48 monnier Exp $
83b96b22 9
59a1ce8d
SM
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
83b96b22 13;; it under the terms of the GNU General Public License as published by
59a1ce8d
SM
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
83b96b22
SM
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
59a1ce8d 21
83b96b22 22;; You should have received a copy of the GNU General Public License
59a1ce8d
SM
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
83b96b22
SM
26
27;;; Commentary:
28
771c9b97 29;; A replacement for simple.el's comment-related functions.
83b96b22
SM
30
31;;; Bugs:
32
2ab98065
SM
33;; - single-char nestable comment-start can only do the "\\s<+" stuff
34;; if the corresponding closing marker happens to be right.
771c9b97 35;; - comment-box in TeXinfo generate bogus comments @ccccc@
3e569d22
SM
36;; - uncomment-region with a numeric argument can render multichar
37;; comment markers invalid.
3fc5b4e2
SM
38;; - comment-indent or comment-region when called inside a comment
39;; will happily break the surrounding comment.
40;; - comment-quote-nested will not (un)quote properly all nested comment
41;; markers if there are more than just comment-start and comment-end.
42;; For example, in Pascal where {...*) and (*...} are possible.
83b96b22
SM
43
44;;; Todo:
45
dde6824c 46;; - quantized steps in comment-alignment
771c9b97
SM
47;; - try to align tail comments
48;; - check what c-comment-line-break-function has to say
3e569d22 49;; - spill auto-fill of comments onto the end of the next line
7a0a180a
SM
50;; - uncomment-region with a consp (for blocks) or somehow make the
51;; deletion of continuation markers less dangerous
2ab98065 52;; - drop block-comment-<foo> unless it's really used
f5215400 53;; - uncomment-region on a subpart of a comment
771c9b97 54;; - support gnu-style "multi-line with space in continue"
771c9b97
SM
55;; - somehow allow comment-dwim to use the region even if transient-mark-mode
56;; is not turned on.
83b96b22 57
bdbe3a89
SM
58;; - when auto-filling a comment, try to move the comment to the left
59;; rather than break it (if possible).
60;; - sometimes default the comment-column to the same
61;; one used on the preceding line(s).
62
83b96b22
SM
63;;; Code:
64
be83ecb2 65;;;###autoload
59a1ce8d 66(defalias 'indent-for-comment 'comment-indent)
be83ecb2 67;;;###autoload
59a1ce8d 68(defalias 'set-comment-column 'comment-set-column)
be83ecb2 69;;;###autoload
59a1ce8d 70(defalias 'kill-comment 'comment-kill)
be83ecb2 71;;;###autoload
59a1ce8d 72(defalias 'indent-new-comment-line 'comment-indent-new-line)
83b96b22 73
be83ecb2 74;;;###autoload
3e569d22
SM
75(defgroup comment nil
76 "Indenting and filling of comments."
77 :prefix "comment-"
ac87b3a9 78 :version "21.1"
3e569d22
SM
79 :group 'fill)
80
771c9b97
SM
81(defvar comment-use-syntax 'undecided
82 "Non-nil if syntax-tables can be used instead of regexps.
83Can also be `undecided' which means that a somewhat expensive test will
84be used to try to determine whether syntax-tables should be trusted
f5215400
SM
85to understand comments or not in the given buffer.
86Major modes should set this variable.")
2ab98065 87
be83ecb2 88;;;###autoload
83b96b22
SM
89(defcustom comment-column 32
90 "*Column to indent right-margin comments to.
91Setting this variable automatically makes it local to the current buffer.
92Each mode establishes a different default value for this variable; you
93can set the value for a particular mode using that mode's hook."
94 :type 'integer
3e569d22 95 :group 'comment)
83b96b22
SM
96(make-variable-buffer-local 'comment-column)
97
be83ecb2 98;;;###autoload
f5215400
SM
99(defvar comment-start nil
100 "*String to insert to start a new comment, or nil if no comment syntax.")
83b96b22 101
be83ecb2 102;;;###autoload
f5215400 103(defvar comment-start-skip nil
83b96b22
SM
104 "*Regexp to match the start of a comment plus everything up to its body.
105If there are any \\(...\\) pairs, the comment delimiter text is held to begin
f5215400 106at the place matched by the close of the first pair.")
771c9b97 107
be83ecb2 108;;;###autoload
3e569d22
SM
109(defvar comment-end-skip nil
110 "Regexp to match the end of a comment plus everything up to its body.")
83b96b22 111
be83ecb2 112;;;###autoload
f5215400 113(defvar comment-end ""
83b96b22 114 "*String to insert to end a new comment.
f5215400 115Should be an empty string if comments are terminated by end-of-line.")
83b96b22 116
be83ecb2 117;;;###autoload
87cf8421 118(defvar comment-indent-function 'comment-indent-default
83b96b22
SM
119 "Function to compute desired indentation for a comment.
120This function is called with no args with point at the beginning of
87cf8421
SM
121the comment's starting delimiter and should return either the desired
122column indentation or nil.
123If nil is returned, indentation is delegated to `indent-according-to-mode'.")
83b96b22 124
3e569d22
SM
125(defvar block-comment-start nil)
126(defvar block-comment-end nil)
83b96b22 127
771c9b97
SM
128(defvar comment-quote-nested t
129 "Non-nil if nested comments should be quoted.
130This should be locally set by each major mode if needed.")
131
132(defvar comment-continue nil
f5215400
SM
133 "Continuation string to insert for multiline comments.
134This string will be added at the beginning of each line except the very
135first one when commenting a region with a commenting style that allows
136comments to span several lines.
137It should generally have the same length as `comment-start' in order to
138preserve indentation.
139If it is nil a value will be automatically derived from `comment-start'
140by replacing its first character with a space.")
141
771c9b97 142(defvar comment-add 0
f5215400
SM
143 "How many more comment chars should be inserted by `comment-region'.
144This determines the default value of the numeric argument of `comment-region'.
145This should generally stay 0, except for a few modes like Lisp where
146it can be convenient to set it to 1 so that regions are commented with
147two semi-colons.")
2ab98065 148
2ab98065 149(defconst comment-styles
771c9b97
SM
150 '((plain . (nil nil nil nil))
151 (indent . (nil nil nil t))
152 (aligned . (nil t nil t))
153 (multi-line . (t nil nil t))
154 (extra-line . (t nil t t))
9b0d1d6e
SM
155 (box . (nil t t t))
156 (box-multi . (t t t t)))
f5215400
SM
157 "Possible comment styles of the form (STYLE . (MULTI ALIGN EXTRA INDENT)).
158STYLE should be a mnemonic symbol.
159MULTI specifies that comments are allowed to span multiple lines.
160ALIGN specifies that the `comment-end' markers should be aligned.
161EXTRA specifies that an extra line should be used before and after the
162 region to comment (to put the `comment-end' and `comment-start').
163INDENT specifies that the `comment-start' markers should not be put at the
164 left margin but at the current indentation of the region to comment.")
165
be83ecb2 166;;;###autoload
f5215400
SM
167(defcustom comment-style 'plain
168 "*Style to be used for `comment-region'.
169See `comment-styles' for a list of available styles."
170 :group 'comment
be83ecb2
SM
171 :type (if (boundp 'comment-styles)
172 `(choice ,@(mapcar (lambda (s) `(const ,(car s))) comment-styles))
173 'symbol))
2ab98065 174
be83ecb2
SM
175;;;###autoload
176(defcustom comment-padding " "
f5215400
SM
177 "Padding string that `comment-region' puts between comment chars and text.
178Can also be an integer which will be automatically turned into a string
179of the corresponding number of spaces.
2ab98065
SM
180
181Extra spacing between the comment characters and the comment text
771c9b97 182makes the comment easier to read. Default is 1. nil means 0.")
2ab98065 183
be83ecb2 184;;;###autoload
3e569d22 185(defcustom comment-multi-line nil
ac87b3a9 186 "*Non-nil means \\[comment-indent-new-line] continues comments, with no new terminator or starter.
3e569d22
SM
187This is obsolete because you might as well use \\[newline-and-indent]."
188 :type 'boolean
189 :group 'comment)
190
2ab98065
SM
191;;;;
192;;;; Helpers
193;;;;
194
f5215400
SM
195(defun comment-string-strip (str beforep afterp)
196 "Strip STR of any leading (if BEFOREP) and/or trailing (if AFTERP) space."
197 (string-match (concat "\\`" (if beforep "\\s-*")
ad679e45 198 "\\(.*?\\)" (if afterp "\\s-*\n?")
2ab98065
SM
199 "\\'") str)
200 (match-string 1 str))
201
202(defun comment-string-reverse (s)
f5215400 203 "Return the mirror image of string S, without any trailing space."
771c9b97 204 (comment-string-strip (concat (nreverse (string-to-list s))) nil t))
2ab98065 205
7164ef13 206;;;###autoload
2ab98065
SM
207(defun comment-normalize-vars (&optional noerror)
208 (if (not comment-start) (or noerror (error "No comment syntax is defined"))
209 ;; comment-use-syntax
771c9b97 210 (when (eq comment-use-syntax 'undecided)
2ab98065
SM
211 (set (make-local-variable 'comment-use-syntax)
212 (let ((st (syntax-table))
213 (cs comment-start)
214 (ce (if (string= "" comment-end) "\n" comment-end)))
771c9b97
SM
215 ;; Try to skip over a comment using forward-comment
216 ;; to see if the syntax tables properly recognize it.
2ab98065
SM
217 (with-temp-buffer
218 (set-syntax-table st)
219 (insert cs " hello " ce)
220 (goto-char (point-min))
221 (and (forward-comment 1) (eobp))))))
2ab98065
SM
222 ;; comment-padding
223 (when (integerp comment-padding)
224 (setq comment-padding (make-string comment-padding ? )))
225 ;; comment markers
226 ;;(setq comment-start (comment-string-strip comment-start t nil))
227 ;;(setq comment-end (comment-string-strip comment-end nil t))
228 ;; comment-continue
f5215400 229 (unless (or comment-continue (string= comment-end ""))
2ab98065 230 (set (make-local-variable 'comment-continue)
9b0d1d6e 231 (concat (if (string-match "\\S-\\S-" comment-start) " " "|")
7164ef13
SM
232 (substring comment-start 1)))
233 ;; Hasn't been necessary yet.
234 ;; (unless (string-match comment-start-skip comment-continue)
235 ;; (kill-local-variable 'comment-continue))
236 )
2ab98065
SM
237 ;; comment-skip regexps
238 (unless comment-start-skip
239 (set (make-local-variable 'comment-start-skip)
240 (concat "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(\\s<+\\|"
241 (regexp-quote (comment-string-strip comment-start t t))
75ed43a6
SM
242 ;; Let's not allow any \s- but only [ \t] since \n
243 ;; might be both a comment-end marker and \s-.
244 "+\\)[ \t]*")))
2ab98065
SM
245 (unless comment-end-skip
246 (let ((ce (if (string= "" comment-end) "\n"
247 (comment-string-strip comment-end t t))))
248 (set (make-local-variable 'comment-end-skip)
37dbd369
SM
249 ;; We use [ \t] rather than \s- because we don't want to
250 ;; remove ^L in C mode when uncommenting.
251 (concat "[ \t]*\\(\\s>" (if comment-quote-nested "" "+")
2ab98065 252 "\\|" (regexp-quote (substring ce 0 1))
771c9b97 253 (if (and comment-quote-nested (<= (length ce) 1)) "" "+")
2ab98065
SM
254 (regexp-quote (substring ce 1))
255 "\\)"))))))
256
f5215400
SM
257(defun comment-quote-re (str unp)
258 (concat (regexp-quote (substring str 0 1))
259 "\\\\" (if unp "+" "*")
260 (regexp-quote (substring str 1))))
261
262(defun comment-quote-nested (cs ce unp)
263 "Quote or unquote nested comments.
264If UNP is non-nil, unquote nested comment markers."
265 (setq cs (comment-string-strip cs t t))
266 (setq ce (comment-string-strip ce t t))
267 (when (and comment-quote-nested (> (length ce) 0))
268 (let ((re (concat (comment-quote-re ce unp)
269 "\\|" (comment-quote-re cs unp))))
270 (goto-char (point-min))
271 (while (re-search-forward re nil t)
272 (goto-char (match-beginning 0))
273 (forward-char 1)
274 (if unp (delete-char 1) (insert "\\"))
275 (when (= (length ce) 1)
276 ;; If the comment-end is a single char, adding a \ after that
277 ;; "first" char won't deactivate it, so we turn such a CE
278 ;; into !CS. I.e. for pascal, we turn } into !{
279 (if (not unp)
280 (when (string= (match-string 0) ce)
281 (replace-match (concat "!" cs) t t))
282 (when (and (< (point-min) (match-beginning 0))
283 (string= (buffer-substring (1- (match-beginning 0))
284 (1- (match-end 0)))
285 (concat "!" cs)))
286 (backward-char 2)
287 (delete-char (- (match-end 0) (match-beginning 0)))
288 (insert ce))))))))
2ab98065
SM
289
290;;;;
291;;;; Navigation
292;;;;
293
ad679e45 294(defun comment-search-forward (limit &optional noerror)
771c9b97
SM
295 "Find a comment start between point and LIMIT.
296Moves point to inside the comment and returns the position of the
297comment-starter. If no comment is found, moves point to LIMIT
e8fe7d39 298and raises an error or returns nil of NOERROR is non-nil."
2ab98065 299 (if (not comment-use-syntax)
9b0d1d6e
SM
300 (if (re-search-forward comment-start-skip limit noerror)
301 (or (match-end 1) (match-beginning 0))
302 (goto-char limit)
303 (unless noerror (error "No comment")))
ad679e45
SM
304 (let* ((pt (point))
305 ;; Assume (at first) that pt is outside of any string.
306 (s (parse-partial-sexp pt (or limit (point-max)) nil nil nil t)))
307 (when (and (nth 8 s) (nth 3 s))
308 ;; The search ended inside a string. Try to see if it
309 ;; works better when we assume that pt is inside a string.
310 (setq s (parse-partial-sexp
311 pt (or limit (point-max)) nil nil
312 (list nil nil nil (nth 3 s) nil nil nil nil)
313 t)))
314 (if (not (and (nth 8 s) (not (nth 3 s))))
315 (unless noerror (error "No comment"))
316 ;; We found the comment.
9b0d1d6e 317 (let ((pos (point))
ad679e45 318 (start (nth 8 s))
9b0d1d6e 319 (bol (line-beginning-position))
ad679e45
SM
320 (end nil))
321 (while (and (null end) (>= (point) bol))
322 (if (looking-at comment-start-skip)
323 (setq end (min (or limit (point-max)) (match-end 0)))
324 (backward-char)))
9b0d1d6e 325 (goto-char (or end pos))
ad679e45 326 start)))))
2ab98065
SM
327
328(defun comment-search-backward (&optional limit noerror)
329 "Find a comment start between LIMIT and point.
771c9b97
SM
330Moves point to inside the comment and returns the position of the
331comment-starter. If no comment is found, moves point to LIMIT
2ab98065 332and raises an error or returns nil of NOERROR is non-nil."
ad679e45
SM
333 ;; FIXME: If a comment-start appears inside a comment, we may erroneously
334 ;; stop there. This can be rather bad in general, but since
335 ;; comment-search-backward is only used to find the comment-column (in
336 ;; comment-set-column) and to find the comment-start string (via
337 ;; comment-beginning) in indent-new-comment-line, it should be harmless.
2ab98065
SM
338 (if (not (re-search-backward comment-start-skip limit t))
339 (unless noerror (error "No comment"))
340 (beginning-of-line)
341 (let* ((end (match-end 0))
342 (cs (comment-search-forward end t))
343 (pt (point)))
344 (if (not cs)
345 (progn (beginning-of-line)
346 (comment-search-backward limit noerror))
347 (while (progn (goto-char cs)
348 (comment-forward)
349 (and (< (point) end)
350 (setq cs (comment-search-forward end t))))
351 (setq pt (point)))
352 (goto-char pt)
353 cs))))
354
355(defun comment-beginning ()
771c9b97
SM
356 "Find the beginning of the enclosing comment.
357Returns nil if not inside a comment, else moves point and returns
2ab98065 358the same as `comment-search-forward'."
75ed43a6
SM
359 ;; HACK ATTACK!
360 ;; We should really test `in-string-p' but that can be expensive.
361 (unless (eq (get-text-property (point) 'face) 'font-lock-string-face)
362 (let ((pt (point))
363 (cs (comment-search-backward nil t)))
364 (when cs
365 (if (save-excursion
366 (goto-char cs)
dde6824c
SM
367 (and
368 ;; For modes where comment-start and comment-end are the same,
369 ;; the search above may have found a `ce' rather than a `cs'.
370 (or (not (looking-at comment-end-skip))
371 ;; Maybe font-lock knows that it's a `cs'?
372 (eq (get-text-property (match-end 0) 'face)
373 'font-lock-comment-face)
374 (unless (eq (get-text-property (point) 'face)
375 'font-lock-comment-face)
376 ;; Let's assume it's a `cs' if we're on the same line.
377 (>= (line-end-position) pt)))
378 ;; Make sure that PT is not past the end of the comment.
379 (if (comment-forward 1) (> (point) pt) (eobp))))
75ed43a6
SM
380 cs
381 (goto-char pt)
382 nil)))))
2ab98065
SM
383
384(defun comment-forward (&optional n)
385 "Skip forward over N comments.
386Just like `forward-comment' but only for positive N
387and can use regexps instead of syntax."
388 (setq n (or n 1))
389 (if (< n 0) (error "No comment-backward")
390 (if comment-use-syntax (forward-comment n)
391 (while (> n 0)
392 (skip-syntax-forward " ")
59a1ce8d
SM
393 (setq n
394 (if (and (looking-at comment-start-skip)
76a4de07 395 (goto-char (match-end 0))
59a1ce8d
SM
396 (re-search-forward comment-end-skip nil 'move))
397 (1- n) -1)))
2ab98065
SM
398 (= n 0))))
399
400(defun comment-enter-backward ()
401 "Move from the end of a comment to the end of its content.
771c9b97 402Point is assumed to be just at the end of a comment."
2ab98065
SM
403 (if (bolp)
404 ;; comment-end = ""
405 (progn (backward-char) (skip-syntax-backward " "))
406 (let ((end (point)))
407 (beginning-of-line)
408 (save-restriction
409 (narrow-to-region (point) end)
ad679e45
SM
410 (if (re-search-forward (concat comment-end-skip "\\'") nil t)
411 (goto-char (match-beginning 0))
412 ;; comment-end-skip not found probably because it was not set right.
413 ;; Since \\s> should catch the single-char case, we'll blindly
414 ;; assume we're at the end of a two-char comment-end.
415 (goto-char (point-max))
416 (backward-char 2)
417 (skip-chars-backward (string (char-after)))
418 (skip-syntax-backward " "))))))
2ab98065
SM
419
420;;;;
421;;;; Commands
422;;;;
423
fae99944 424;;;###autoload
87cf8421
SM
425(defun comment-indent-default ()
426 "Default for `comment-indent-function'."
d3fcda22
SM
427 (if (and (looking-at "\\s<\\s<\\(\\s<\\)?")
428 (or (match-end 1) (/= (current-column) (current-indentation))))
429 0
87cf8421
SM
430 (when (or (/= (current-column) (current-indentation))
431 (and (> comment-add 0) (looking-at "\\s<\\S<")))
432 comment-column)))
433
be83ecb2 434;;;###autoload
3e569d22 435(defun comment-indent (&optional continue)
2ab98065 436 "Indent this line's comment to comment column, or insert an empty comment.
dde6824c 437If CONTINUE is non-nil, use the `comment-continue' markers if any."
83b96b22 438 (interactive "*")
ad679e45 439 (comment-normalize-vars)
83b96b22
SM
440 (let* ((empty (save-excursion (beginning-of-line)
441 (looking-at "[ \t]*$")))
f5215400 442 (starter (or (and continue comment-continue)
2ab98065 443 (and empty block-comment-start) comment-start))
f5215400 444 (ender (or (and continue comment-continue "")
2ab98065 445 (and empty block-comment-end) comment-end)))
2e1fbba4
SM
446 (unless starter (error "No comment syntax defined"))
447 (beginning-of-line)
448 (let* ((eolpos (line-end-position))
449 (begpos (comment-search-forward eolpos t))
450 cpos indent)
451 ;; An existing comment?
452 (if begpos (setq cpos (point-marker))
453 ;; If none, insert one.
454 (save-excursion
455 ;; Some comment-indent-function insist on not moving comments that
567e961e
SM
456 ;; are in column 0, so we first go to the likely target column.
457 (indent-to comment-column)
2e1fbba4 458 (setq begpos (point))
bb304a7a 459 (insert starter)
2e1fbba4
SM
460 (setq cpos (point-marker))
461 (insert ender)))
462 (goto-char begpos)
463 ;; Compute desired indent.
053b8d35 464 (setq indent (save-excursion (funcall comment-indent-function)))
2e1fbba4
SM
465 (if (not indent)
466 ;; comment-indent-function refuses delegates to indent.
467 (indent-according-to-mode)
468 ;; Avoid moving comments past the fill-column.
469 (setq indent
470 (min indent
471 (+ (current-column)
472 (- fill-column
473 (save-excursion (end-of-line) (current-column))))))
7164ef13 474 (unless (= (current-column) indent)
2e1fbba4 475 ;; If that's different from current, change it.
7164ef13 476 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
2e1fbba4
SM
477 (indent-to (if (bolp) indent
478 (max indent (1+ (current-column)))))))
479 (goto-char cpos)
480 (set-marker cpos nil))))
83b96b22 481
be83ecb2 482;;;###autoload
3e569d22 483(defun comment-set-column (arg)
83b96b22 484 "Set the comment column based on point.
2ab98065 485With no ARG, set the comment column to the current column.
83b96b22
SM
486With just minus as arg, kill any comment on this line.
487With any other arg, set comment column to indentation of the previous comment
488 and then align or create a comment on this line at that column."
489 (interactive "P")
e8fe7d39 490 (cond
ad679e45 491 ((eq arg '-) (comment-kill nil))
e8fe7d39
SM
492 (arg
493 (save-excursion
494 (beginning-of-line)
2ab98065 495 (comment-search-backward)
e8fe7d39 496 (beginning-of-line)
ad679e45 497 (goto-char (comment-search-forward (line-end-position)))
83b96b22 498 (setq comment-column (current-column))
e8fe7d39 499 (message "Comment column set to %d" comment-column))
ad679e45 500 (comment-indent))
e8fe7d39 501 (t (setq comment-column (current-column))
83b96b22
SM
502 (message "Comment column set to %d" comment-column))))
503
be83ecb2 504;;;###autoload
3e569d22 505(defun comment-kill (arg)
7a0a180a
SM
506 "Kill the comment on this line, if any.
507With prefix ARG, kill comments on that many lines starting with this one."
508 (interactive "P")
ad679e45
SM
509 (dotimes (_ (prefix-numeric-value arg))
510 (save-excursion
511 (beginning-of-line)
512 (let ((cs (comment-search-forward (line-end-position) t)))
513 (when cs
514 (goto-char cs)
515 (skip-syntax-backward " ")
516 (setq cs (point))
517 (comment-forward)
518 (kill-region cs (if (bolp) (1- (point)) (point)))
519 (indent-according-to-mode))))
520 (if arg (forward-line 1))))
7a0a180a 521
2ab98065
SM
522(defun comment-padright (str &optional n)
523 "Construct a string composed of STR plus `comment-padding'.
f5215400 524It also adds N copies of the last non-whitespace chars of STR.
2ab98065 525If STR already contains padding, the corresponding amount is
f5215400
SM
526ignored from `comment-padding'.
527N defaults to 0.
771c9b97 528If N is `re', a regexp is returned instead, that would match
f5215400 529the string for any N."
2ab98065
SM
530 (setq n (or n 0))
531 (when (and (stringp str) (not (string= "" str)))
f5215400 532 ;; Separate the actual string from any leading/trailing padding
3e569d22 533 (string-match "\\`\\s-*\\(.*?\\)\\s-*\\'" str)
f5215400
SM
534 (let ((s (match-string 1 str)) ;actual string
535 (lpad (substring str 0 (match-beginning 1))) ;left padding
536 (rpad (concat (substring str (match-end 1)) ;original right padding
537 (substring comment-padding ;additional right padding
3e569d22 538 (min (- (match-end 0) (match-end 1))
9b0d1d6e
SM
539 (length comment-padding)))))
540 ;; We can only duplicate C if the comment-end has multiple chars
541 ;; or if comments can be nested, else the comment-end `}' would
542 ;; be turned into `}}}' where only the first ends the comment
543 ;; and the rest becomes bogus junk.
544 (multi (not (and comment-quote-nested
545 ;; comment-end is a single char
546 (string-match "\\`\\s-*\\S-\\s-*\\'" comment-end)))))
f5215400 547 (if (not (symbolp n))
9b0d1d6e 548 (concat lpad s (when multi (make-string n (aref str (1- (match-end 1))))) rpad)
f5215400
SM
549 ;; construct a regexp that would match anything from just S
550 ;; to any possible output of this function for any N.
551 (concat (mapconcat (lambda (c) (concat (regexp-quote (string c)) "?"))
552 lpad "") ;padding is not required
9b0d1d6e
SM
553 (regexp-quote s)
554 (when multi "+") ;the last char of S might be repeated
f5215400
SM
555 (mapconcat (lambda (c) (concat (regexp-quote (string c)) "?"))
556 rpad "")))))) ;padding is not required
2ab98065
SM
557
558(defun comment-padleft (str &optional n)
559 "Construct a string composed of `comment-padding' plus STR.
f5215400 560It also adds N copies of the first non-whitespace chars of STR.
2ab98065 561If STR already contains padding, the corresponding amount is
f5215400
SM
562ignored from `comment-padding'.
563N defaults to 0.
771c9b97 564If N is `re', a regexp is returned instead, that would match
2ab98065
SM
565 the string for any N."
566 (setq n (or n 0))
567 (when (and (stringp str) (not (string= "" str)))
f5215400 568 ;; Only separate the left pad because we assume there is no right pad.
2ab98065
SM
569 (string-match "\\`\\s-*" str)
570 (let ((s (substring str (match-end 0)))
571 (pad (concat (substring comment-padding
572 (min (- (match-end 0) (match-beginning 0))
573 (length comment-padding)))
574 (match-string 0 str)))
f5215400
SM
575 (c (aref str (match-end 0))) ;the first non-space char of STR
576 ;; We can only duplicate C if the comment-end has multiple chars
577 ;; or if comments can be nested, else the comment-end `}' would
578 ;; be turned into `}}}' where only the first ends the comment
579 ;; and the rest becomes bogus junk.
580 (multi (not (and comment-quote-nested
581 ;; comment-end is a single char
582 (string-match "\\`\\s-*\\S-\\s-*\\'" comment-end)))))
583 (if (not (symbolp n))
584 (concat pad (when multi (make-string n c)) s)
585 ;; Construct a regexp that would match anything from just S
586 ;; to any possible output of this function for any N.
587 ;; We match any number of leading spaces because this regexp will
588 ;; be used for uncommenting where we might want to remove
589 ;; uncomment markers with arbitrary leading space (because
590 ;; they were aligned).
591 (concat "\\s-*"
592 (if multi (concat (regexp-quote (string c)) "*"))
593 (regexp-quote s))))))
83b96b22 594
be83ecb2 595;;;###autoload
7a0a180a
SM
596(defun uncomment-region (beg end &optional arg)
597 "Uncomment each line in the BEG..END region.
f5215400
SM
598The numeric prefix ARG can specify a number of chars to remove from the
599comment markers."
83b96b22
SM
600 (interactive "*r\nP")
601 (comment-normalize-vars)
602 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
603 (save-excursion
7a0a180a 604 (goto-char beg)
f5215400 605 (setq end (copy-marker end))
7a0a180a 606 (let ((numarg (prefix-numeric-value arg))
2ab98065 607 spt)
7a0a180a 608 (while (and (< (point) end)
2ab98065
SM
609 (setq spt (comment-search-forward end t)))
610 (let* ((ipt (point))
f5215400 611 ;; Find the end of the comment.
e8fe7d39 612 (ept (progn
2ab98065
SM
613 (goto-char spt)
614 (unless (comment-forward)
e8fe7d39 615 (error "Can't find the comment end"))
f5215400
SM
616 (point)))
617 (box nil)
618 (ccs comment-continue)
2ab98065 619 (srei (comment-padright ccs 're))
3e569d22 620 (sre (and srei (concat "^\\s-*?\\(" srei "\\)"))))
e8fe7d39
SM
621 (save-restriction
622 (narrow-to-region spt ept)
f5215400 623 ;; Remove the comment-start.
2ab98065
SM
624 (goto-char ipt)
625 (skip-syntax-backward " ")
9b0d1d6e
SM
626 ;; Check for special `=' used sometimes in comment-box.
627 (when (and (= (- (point) (point-min)) 1) (looking-at "=\\{7\\}"))
628 (skip-chars-forward "="))
f5215400 629 ;; A box-comment starts with a looong comment-start marker.
2ab98065 630 (when (> (- (point) (point-min) (length comment-start)) 7)
f5215400 631 (setq box t))
2ab98065
SM
632 (when (looking-at (regexp-quote comment-padding))
633 (goto-char (match-end 0)))
634 (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei)))
635 (goto-char (match-end 0)))
3e569d22
SM
636 (if (null arg) (delete-region (point-min) (point))
637 (skip-syntax-backward " ")
638 (delete-char (- numarg)))
2ab98065 639
f5215400 640 ;; Remove the end-comment (and leading padding and such).
2ab98065 641 (goto-char (point-max)) (comment-enter-backward)
9b0d1d6e 642 ;; Check for special `=' used sometimes in comment-box.
6dcd3806
SM
643 (when (= (- (point-max) (point)) 1)
644 (let ((pos (point)))
645 ;; skip `=' but only if there are at least 7.
646 (when (> (skip-chars-backward "=") -7) (goto-char pos))))
9b0d1d6e 647 (unless (looking-at "\\(\n\\|\\s-\\)*\\'")
2ab98065 648 (when (and (bolp) (not (bobp))) (backward-char))
f5215400 649 (if (null arg) (delete-region (point) (point-max))
3e569d22
SM
650 (skip-syntax-forward " ")
651 (delete-char numarg)))
e8fe7d39 652
f5215400
SM
653 ;; Unquote any nested end-comment.
654 (comment-quote-nested comment-start comment-end t)
655
656 ;; Eliminate continuation markers as well.
657 (when sre
658 (let* ((cce (comment-string-reverse (or comment-continue
659 comment-start)))
660 (erei (and box (comment-padleft cce 're)))
661 (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
7a0a180a 662 (goto-char (point-min))
f5215400
SM
663 (while (progn
664 (if (and ere (re-search-forward
665 ere (line-end-position) t))
666 (replace-match "" t t nil (if (match-end 2) 2 1))
667 (setq ere nil))
668 (forward-line 1)
669 (re-search-forward sre (line-end-position) t))
2ab98065 670 (replace-match "" t t nil (if (match-end 2) 2 1)))))
f5215400
SM
671 ;; Go the the end for the next comment.
672 (goto-char (point-max)))))
673 (set-marker end nil))))
83b96b22 674
aac88001 675(defun comment-make-extra-lines (cs ce ccs cce min-indent max-indent &optional block)
ad679e45
SM
676 "Make the leading and trailing extra lines.
677This is used for `extra-line' style (or `box' style if BLOCK is specified)."
9b0d1d6e
SM
678 (let ((eindent 0))
679 (if (not block)
680 ;; Try to match CS and CE's content so they align aesthetically.
681 (progn
682 (setq ce (comment-string-strip ce t t))
683 (when (string-match "\\(.+\\).*\n\\(.*?\\)\\1" (concat ce "\n" cs))
684 (setq eindent
685 (max (- (match-end 2) (match-beginning 2) (match-beginning 0))
686 0))))
687 ;; box comment
688 (let* ((width (- max-indent min-indent))
689 (s (concat cs "a=m" cce))
690 (e (concat ccs "a=m" ce))
691 (c (if (string-match ".*\\S-\\S-" cs)
692 (aref cs (1- (match-end 0))) ?=))
3fc5b4e2 693 (_ (string-match "\\s-*a=m\\s-*" s))
9b0d1d6e
SM
694 (fill
695 (make-string (+ width (- (match-end 0)
696 (match-beginning 0) (length cs) 3)) c)))
aac88001 697 (setq cs (replace-match fill t t s))
3fc5b4e2 698 (string-match "\\s-*a=m\\s-*" e)
9b0d1d6e
SM
699 (setq ce (replace-match fill t t e))))
700 (cons (concat cs "\n" (make-string min-indent ? ) ccs)
701 (concat cce "\n" (make-string (+ min-indent eindent) ? ) ce))))
aac88001
SM
702
703(def-edebug-spec comment-with-narrowing t)
704(put 'comment-with-narrowing 'lisp-indent-function 2)
705(defmacro comment-with-narrowing (beg end &rest body)
706 "Execute BODY with BEG..END narrowing.
707Space is added (and then removed) at the beginning for the text's
708indentation to be kept as it was before narrowing."
59a1ce8d
SM
709 (let ((bindent (make-symbol "bindent")))
710 `(let ((,bindent (save-excursion (goto-char beg) (current-column))))
711 (save-restriction
712 (narrow-to-region beg end)
713 (goto-char (point-min))
714 (insert (make-string ,bindent ? ))
715 (prog1
716 (progn ,@body)
717 ;; remove the bindent
718 (save-excursion
719 (goto-char (point-min))
720 (when (looking-at " *")
721 (let ((n (min (- (match-end 0) (match-beginning 0)) ,bindent)))
aac88001 722 (delete-char n)
59a1ce8d
SM
723 (setq ,bindent (- ,bindent n))))
724 (end-of-line)
725 (let ((e (point)))
726 (beginning-of-line)
727 (while (and (> ,bindent 0) (re-search-forward " *" e t))
728 (let ((n (min ,bindent (- (match-end 0) (match-beginning 0) 1))))
729 (goto-char (match-beginning 0))
730 (delete-char n)
731 (setq ,bindent (- ,bindent n)))))))))))
aac88001 732
771c9b97
SM
733(defun comment-region-internal (beg end cs ce
734 &optional ccs cce block lines indent)
f5215400 735 "Comment region BEG..END.
4125ec7e
SM
736CS and CE are the comment start resp end string.
737CCS and CCE are the comment continuation strings for the start resp end
f5215400
SM
738of lines (default to CS and CE).
739BLOCK indicates that end of lines should be marked with either CCE, CE or CS
740\(if CE is empty) and that those markers should be aligned.
741LINES indicates that an extra lines will be used at the beginning and end
742of the region for CE and CS.
743INDENT indicates to put CS and CCS at the current indentation of the region
744rather than at left margin."
59a1ce8d 745 ;;(assert (< beg end))
83b96b22 746 (let ((no-empty t))
f5215400 747 ;; Sanitize CE and CCE.
83b96b22
SM
748 (if (and (stringp ce) (string= "" ce)) (setq ce nil))
749 (if (and (stringp cce) (string= "" cce)) (setq cce nil))
f5215400
SM
750 ;; If CE is empty, multiline cannot be used.
751 (unless ce (setq ccs nil cce nil))
752 ;; Should we mark empty lines as well ?
83b96b22 753 (if (or ccs block lines) (setq no-empty nil))
f5215400 754 ;; Make sure we have end-markers for BLOCK mode.
2ab98065 755 (when block (unless ce (setq ce (comment-string-reverse cs))))
f5215400
SM
756 ;; If BLOCK is not requested, we don't need CCE.
757 (unless block (setq cce nil))
758 ;; Continuation defaults to the same as CS and CE.
759 (unless ccs (setq ccs cs cce ce))
7a0a180a 760
83b96b22 761 (save-excursion
aac88001 762 (goto-char end)
f5215400
SM
763 ;; If the end is not at the end of a line and the comment-end
764 ;; is implicit (i.e. a newline), explicitly insert a newline.
aac88001
SM
765 (unless (or ce (eolp)) (insert "\n") (indent-according-to-mode))
766 (comment-with-narrowing beg end
f5215400 767 (let ((min-indent (point-max))
9d5240d2 768 (max-indent 0))
83b96b22 769 (goto-char (point-min))
f5215400
SM
770 ;; Quote any nested comment marker
771 (comment-quote-nested comment-start comment-end nil)
772
773 ;; Loop over all lines to find the needed indentations.
4125ec7e 774 (goto-char (point-min))
f5215400
SM
775 (while
776 (progn
777 (unless (looking-at "[ \t]*$")
778 (setq min-indent (min min-indent (current-indentation))))
779 (end-of-line)
780 (setq max-indent (max max-indent (current-column)))
781 (not (or (eobp) (progn (forward-line) nil)))))
782
783 ;; Inserting ccs can change max-indent by (1- tab-width).
59a1ce8d
SM
784 (setq max-indent
785 (+ max-indent (max (length cs) (length ccs)) tab-width -1))
771c9b97 786 (unless indent (setq min-indent 0))
83b96b22 787
aac88001 788 ;; make the leading and trailing lines if requested
83b96b22 789 (when lines
771c9b97
SM
790 (let ((csce
791 (comment-make-extra-lines
792 cs ce ccs cce min-indent max-indent block)))
793 (setq cs (car csce))
794 (setq ce (cdr csce))))
83b96b22
SM
795
796 (goto-char (point-min))
797 ;; Loop over all lines from BEG to END.
f5215400
SM
798 (while
799 (progn
800 (unless (and no-empty (looking-at "[ \t]*$"))
801 (move-to-column min-indent t)
802 (insert cs) (setq cs ccs) ;switch to CCS after the first line
803 (end-of-line)
804 (if (eobp) (setq cce ce))
805 (when cce
806 (when block (move-to-column max-indent t))
807 (insert cce)))
808 (end-of-line)
809 (not (or (eobp) (progn (forward-line) nil))))))))))
83b96b22 810
be83ecb2 811;;;###autoload
83b96b22
SM
812(defun comment-region (beg end &optional arg)
813 "Comment or uncomment each line in the region.
39cb51e7 814With just \\[universal-argument] prefix arg, uncomment each line in region BEG..END.
83b96b22
SM
815Numeric prefix arg ARG means use ARG comment characters.
816If ARG is negative, delete that many comment characters instead.
be83ecb2
SM
817By default, comments start at the left margin, are terminated on each line,
818even for syntax in which newline does not end the comment and blank lines
819do not get comments. This can be changed with `comment-style'.
83b96b22
SM
820
821The strings used as comment starts are built from
822`comment-start' without trailing spaces and `comment-padding'."
823 (interactive "*r\nP")
824 (comment-normalize-vars)
825 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
2ab98065 826 (let* ((numarg (prefix-numeric-value arg))
771c9b97 827 (add comment-add)
2ab98065
SM
828 (style (cdr (assoc comment-style comment-styles)))
829 (lines (nth 2 style))
830 (block (nth 1 style))
831 (multi (nth 0 style)))
83b96b22
SM
832 (save-excursion
833 ;; we use `chars' instead of `syntax' because `\n' might be
834 ;; of end-comment syntax rather than of whitespace syntax.
835 ;; sanitize BEG and END
836 (goto-char beg) (skip-chars-forward " \t\n\r") (beginning-of-line)
837 (setq beg (max beg (point)))
838 (goto-char end) (skip-chars-backward " \t\n\r") (end-of-line)
839 (setq end (min end (point)))
840 (if (>= beg end) (error "Nothing to comment"))
841
83b96b22
SM
842 ;; sanitize LINES
843 (setq lines
844 (and
9b0d1d6e 845 lines ;; multi
83b96b22
SM
846 (progn (goto-char beg) (beginning-of-line)
847 (skip-syntax-forward " ")
848 (>= (point) beg))
849 (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
850 (<= (point) end))
771c9b97 851 (or (not (string= "" comment-end)) block)
2ab98065 852 (progn (goto-char beg) (search-forward "\n" end t)))))
83b96b22 853
2ab98065
SM
854 ;; don't add end-markers just because the user asked for `block'
855 (unless (or lines (string= "" comment-end)) (setq block nil))
856
83b96b22
SM
857 (cond
858 ((consp arg) (uncomment-region beg end))
859 ((< numarg 0) (uncomment-region beg end (- numarg)))
860 (t
59a1ce8d
SM
861 (setq numarg (if (and (null arg) (= (length comment-start) 1))
862 add (1- numarg)))
83b96b22
SM
863 (comment-region-internal
864 beg end
3e569d22
SM
865 (let ((s (comment-padright comment-start numarg)))
866 (if (string-match comment-start-skip s) s
867 (comment-padright comment-start)))
868 (let ((s (comment-padleft comment-end numarg)))
869 (and s (if (string-match comment-end-skip s) s
870 (comment-padright comment-end))))
f5215400
SM
871 (if multi (comment-padright comment-continue numarg))
872 (if multi (comment-padleft (comment-string-reverse comment-continue) numarg))
83b96b22 873 block
771c9b97
SM
874 lines
875 (nth 3 style))))))
876
877(defun comment-box (beg end &optional arg)
878 "Comment out the BEG..END region, putting it inside a box.
879The numeric prefix ARG specifies how many characters to add to begin- and
880end- comment markers additionally to what `comment-add' already specifies."
881 (interactive "*r\np")
9b0d1d6e
SM
882 (let ((comment-style (if (cadr (assoc comment-style comment-styles))
883 'box-multi 'box)))
771c9b97 884 (comment-region beg end (+ comment-add arg))))
83b96b22 885
be83ecb2 886;;;###autoload
2ab98065 887(defun comment-dwim (arg)
ad679e45
SM
888 "Call the comment command you want (Do What I Mean).
889If the region is active and `transient-mark-mode' is on, call
39cb51e7 890 `comment-region' (unless it only consists of comments, in which
ad679e45 891 case it calls `uncomment-region').
2ab98065 892Else, if the current line is empty, insert a comment and indent it.
ad679e45
SM
893Else if a prefix ARG is specified, call `comment-kill'.
894Else, call `comment-indent'."
2ab98065
SM
895 (interactive "*P")
896 (comment-normalize-vars)
771c9b97 897 (if (and mark-active transient-mark-mode)
2ab98065
SM
898 (let ((beg (min (point) (mark)))
899 (end (max (point) (mark))))
900 (if (save-excursion ;; check for already commented region
901 (goto-char beg)
902 (comment-forward (point-max))
903 (<= end (point)))
904 (uncomment-region beg end arg)
905 (comment-region beg end arg)))
906 (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
ad679e45
SM
907 ;; FIXME: If there's no comment to kill on this line and ARG is
908 ;; specified, calling comment-kill is not very clever.
909 (if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
2ab98065 910 (let ((add (if arg (prefix-numeric-value arg)
771c9b97 911 (if (= (length comment-start) 1) comment-add 0))))
2e1fbba4
SM
912 ;; Some modes insist on keeping column 0 comment in column 0
913 ;; so we need to move away from it before inserting the comment.
914 (indent-according-to-mode)
2ab98065
SM
915 (insert (comment-padright comment-start add))
916 (save-excursion
917 (unless (string= "" comment-end)
918 (insert (comment-padleft comment-end add)))
919 (indent-according-to-mode))))))
920
392f1ef5
SM
921(defcustom comment-auto-fill-only-comments nil
922 "Non-nil means to only auto-fill inside comments.
923This has no effect in modes that do not define a comment syntax."
924 :type 'boolean
925 :group 'comment)
926
7164ef13
SM
927(defun comment-valid-prefix (prefix compos)
928 (or
929 ;; Accept any prefix if the current comment is not EOL-terminated.
930 (save-excursion (goto-char compos) (comment-forward) (not (bolp)))
931 ;; Accept any prefix that starts with a comment-start marker.
932 (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
933 fill-prefix)))
934
be83ecb2 935;;;###autoload
ad679e45 936(defun comment-indent-new-line (&optional soft)
2ab98065
SM
937 "Break line at point and indent, continuing comment if within one.
938This indents the body of the continued comment
939under the previous comment line.
940
941This command is intended for styles where you write a comment per line,
942starting a new comment (and terminating it if necessary) on each line.
943If you want to continue one comment across several lines, use \\[newline-and-indent].
944
945If a fill column is specified, it overrides the use of the comment column
946or comment indentation.
947
948The inserted newline is marked hard if variable `use-hard-newlines' is true,
949unless optional argument SOFT is non-nil."
950 (interactive)
951 (comment-normalize-vars t)
59a1ce8d
SM
952 (let (compos comin)
953 ;; If we are not inside a comment and we only auto-fill comments,
954 ;; don't do anything (unless no comment syntax is defined).
392f1ef5
SM
955 (unless (and comment-start
956 comment-auto-fill-only-comments
957 (not (save-excursion
59a1ce8d 958 (prog1 (setq compos (comment-beginning))
392f1ef5 959 (setq comin (point))))))
59a1ce8d
SM
960
961 ;; Now we know we should auto-fill.
adf9c994 962 (delete-horizontal-space)
392f1ef5 963 (if soft (insert-and-inherit ?\n) (newline 1))
7164ef13
SM
964 (if (and fill-prefix (not adaptive-fill-mode))
965 ;; Blindly trust a non-adaptive fill-prefix.
392f1ef5
SM
966 (progn
967 (indent-to-left-margin)
968 (insert-and-inherit fill-prefix))
59a1ce8d
SM
969
970 ;; If necessary check whether we're inside a comment.
971 (unless (or comment-multi-line compos (null comment-start))
392f1ef5
SM
972 (save-excursion
973 (backward-char)
59a1ce8d
SM
974 (setq compos (comment-beginning))
975 (setq comin (point))))
976
7164ef13
SM
977 (cond
978 ;; If there's an adaptive prefix, use it unless we're inside
979 ;; a comment and the prefix is not a comment starter.
980 ((and fill-prefix
981 (or (not compos)
982 (comment-valid-prefix fill-prefix compos)))
983 (indent-to-left-margin)
984 (insert-and-inherit fill-prefix))
985 ;; If we're not inside a comment, just try to indent.
986 ((not compos) (indent-according-to-mode))
987 (t
59a1ce8d
SM
988 (let* ((comment-column
989 ;; The continuation indentation should be somewhere between
990 ;; the current line's indentation (plus 2 for good measure)
991 ;; and the current comment's indentation, with a preference
992 ;; for comment-column.
993 (save-excursion
994 (goto-char compos)
995 (min (current-column) (max comment-column
996 (+ 2 (current-indentation))))))
997 (comstart (buffer-substring compos comin))
998 (normalp
999 (string-match (regexp-quote (comment-string-strip
1000 comment-start t t))
1001 comstart))
1002 (comment-end
1003 (if normalp comment-end
1004 ;; The comment starter is not the normal comment-start
1005 ;; so we can't just use comment-end.
1006 (save-excursion
1007 (goto-char compos)
1008 (if (not (comment-forward)) comment-end
1009 (comment-string-strip
1010 (buffer-substring
1011 (save-excursion (comment-enter-backward) (point))
1012 (point))
1013 nil t)))))
1014 (comment-start comstart)
1015 ;; Force comment-continue to be recreated from comment-start.
dde6824c 1016 ;; FIXME: wrong if comment-continue was set explicitly!
59a1ce8d
SM
1017 (comment-continue nil))
1018 (insert-and-inherit ?\n)
1019 (forward-char -1)
1020 (comment-indent (cadr (assoc comment-style comment-styles)))
1021 (save-excursion
1022 (let ((pt (point)))
1023 (end-of-line)
1024 (let ((comend (buffer-substring pt (point))))
1025 ;; The 1+ is to make sure we delete the \n inserted above.
1026 (delete-region pt (1+ (point)))
1027 (beginning-of-line)
1028 (backward-char)
1029 (insert comend)
7164ef13 1030 (forward-char)))))))))))
2ab98065 1031
83b96b22
SM
1032(provide 'newcomment)
1033
83b96b22 1034;;; newcomment.el ends here