aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-05-13 19:41:08 +0000
committerStefan Monnier2000-05-13 19:41:08 +0000
commit771c9b9735e1437fd073aab706e7ac08ea496a7d (patch)
tree93144b78884801e5b833cb4f47fce8ea928a6bb1
parent4240c779d5d84b1e4b1e81abd86b3cfd998246fc (diff)
downloademacs-771c9b9735e1437fd073aab706e7ac08ea496a7d.tar.gz
emacs-771c9b9735e1437fd073aab706e7ac08ea496a7d.zip
(comment-use-syntax): Change `maybe' to `undecided'.
(comment-quote-nested): New. Replaces comment-nested. (comment-add): Turn into a mere defvar or a integer. (comment-style): Change default to `plain'. (comment-styles): Rename `plain' to `indent' and create a new plainer `plain'. (comment-string-reverse): Use nreverse. (comment-normalize-vars): Change `maybe' to `undecided', add comments. Don't infer the setting of comment-nested anymore (the default for comment-quote-nested is safe). Use comment-quote-nested. (comment-end-quote-re): Use comment-quote-nested. (comment-search-forward): Obey LIMIT. (comment-indent): Don't skip forward further past comment-search-forward. (comment-padleft): Use comment-quote-nested. (comment-make-extra-lines): Use `cons' rather than `values'. (comment-region-internal): New arg INDENT. Use line-end-position. Avoid multiple-value-setq. (comment-region): Follow the new comment-add semantics. Don't do box comments any more. (comment-box): New function. (comment-dwim): Only do the region stuff is transient-mark-active.
-rw-r--r--lisp/newcomment.el164
1 files changed, 96 insertions, 68 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index ed8658fc33b..0507048ab4f 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1,11 +1,12 @@
1;;; newcomment.el --- (un)comment regions of buffers 1;;; newcomment.el --- (un)comment regions of buffers
2 2
3;; Copyright (C) 1999 Stefan Monnier <monnier@cs.yale.edu> 3;; Copyright (C) 1999-2000 Free Software Foundation Inc.
4 4
5;; Author: Stefan Monnier <monnier@cs.yale.edu> 5;; Author: FSF??
6;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
6;; Keywords: comment uncomment 7;; Keywords: comment uncomment
7;; Version: $Name: $ 8;; Version: $Name: $
8;; Revision: $Id: newcomment.el,v 1.5 1999/11/30 16:20:55 monnier Exp $ 9;; Revision: $Id: newcomment.el,v 1.6 1999/12/08 00:19:51 monnier Exp $
9 10
10;; This program is free software; you can redistribute it and/or modify 11;; This program is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by 12;; it under the terms of the GNU General Public License as published by
@@ -23,27 +24,41 @@
23 24
24;;; Commentary: 25;;; Commentary:
25 26
26;;; History: 27;; A replacement for simple.el's comment-related functions.
27 28
28;;; Bugs: 29;;; Bugs:
29 30
30;; - single-char nestable comment-start can only do the "\\s<+" stuff 31;; - single-char nestable comment-start can only do the "\\s<+" stuff
31;; if the corresponding closing marker happens to be right. 32;; if the corresponding closing marker happens to be right.
32;; - C-u C-u comment-region in TeXinfo generates bogus comments @ccccc@ 33;; - comment-box in TeXinfo generate bogus comments @ccccc@
33;; - the code assumes that bol is outside of any comment/string. 34;; - the code assumes that bol is outside of any comment/string.
34;; - uncomment-region with a numeric argument can render multichar 35;; - uncomment-region with a numeric argument can render multichar
35;; comment markers invalid. 36;; comment markers invalid.
37;; - comment-box in C with a numeric argument generates wrong end-of-line
38;; continuation markers.
36 39
37;;; Todo: 40;;; Todo:
38 41
39;; - extract comment data from the syntax-table 42;; - try to align tail comments
40;; - maybe do the opposite as well (set the syntax-table from other data) 43;; - check what c-comment-line-break-function has to say
41;; - spill auto-fill of comments onto the end of the next line 44;; - spill auto-fill of comments onto the end of the next line
42;; - uncomment-region with a consp (for blocks) or somehow make the 45;; - uncomment-region with a consp (for blocks) or somehow make the
43;; deletion of continuation markers less dangerous 46;; deletion of continuation markers less dangerous
44;; - drop block-comment-<foo> unless it's really used 47;; - drop block-comment-<foo> unless it's really used
45;; - uncomment-region on a part of a comment 48;; - uncomment-region on a part of a comment
46;; - obey the numarg of uncomment-region for continuation markers 49;; - obey the numarg of uncomment-region for continuation markers
50;; - support gnu-style "multi-line with space in continue"
51;; - document string-strip
52;; - better document comment-continue (and probably turn it into a
53;; simple string).
54;; - don't overwrite comment-padding.
55;; - better document comment-end-quote. Probably make it better
56;; self-sufficient so that other quoting can be used.
57;; - comment the padright/padleft.
58;; - somehow allow comment-dwim to use the region even if transient-mark-mode
59;; is not turned on.
60;; - document comment-region-internal
61;; - comment-quote-nested should quote both the start and end of comment.
47 62
48;;; Code: 63;;; Code:
49 64
@@ -54,8 +69,11 @@
54 :prefix "comment-" 69 :prefix "comment-"
55 :group 'fill) 70 :group 'fill)
56 71
57(defvar comment-use-syntax 'maybe 72(defvar comment-use-syntax 'undecided
58 "Non-nil if syntax-tables can be used instead of regexps.") 73 "Non-nil if syntax-tables can be used instead of regexps.
74Can also be `undecided' which means that a somewhat expensive test will
75be used to try to determine whether syntax-tables should be trusted
76to understand comments or not.")
59 77
60(defcustom comment-column 32 78(defcustom comment-column 32
61 "*Column to indent right-margin comments to. 79 "*Column to indent right-margin comments to.
@@ -79,6 +97,7 @@ at the place matched by the close of the first pair."
79 :type '(choice (const :tag "None" nil) 97 :type '(choice (const :tag "None" nil)
80 regexp) 98 regexp)
81 :group 'comment) 99 :group 'comment)
100
82(defvar comment-end-skip nil 101(defvar comment-end-skip nil
83 "Regexp to match the end of a comment plus everything up to its body.") 102 "Regexp to match the end of a comment plus everything up to its body.")
84 103
@@ -94,7 +113,7 @@ This function is called with no args with point at the beginning of
94the comment's starting delimiter.") 113the comment's starting delimiter.")
95 114
96(defvar comment-indent-function 115(defvar comment-indent-function
97 '(lambda () comment-column) 116 (lambda () comment-column)
98 "Function to compute desired indentation for a comment. 117 "Function to compute desired indentation for a comment.
99This function is called with no args with point at the beginning of 118This function is called with no args with point at the beginning of
100the comment's starting delimiter.") 119the comment's starting delimiter.")
@@ -102,33 +121,40 @@ the comment's starting delimiter.")
102(defvar block-comment-start nil) 121(defvar block-comment-start nil)
103(defvar block-comment-end nil) 122(defvar block-comment-end nil)
104 123
105(defcustom comment-nested 'maybe 124(defvar comment-quote-nested t
106 "Whether the comments can be nested.") 125 "Non-nil if nested comments should be quoted.
107(defcustom comment-continue nil 126This should be locally set by each major mode if needed.")
127
128(defvar comment-continue nil
108 "Pair of strings to insert for multiline comments.") 129 "Pair of strings to insert for multiline comments.")
109(defcustom comment-add '(0 . 2) 130(defvar comment-add 0
110 "How many more chars should be inserted by default.") 131 "How many more chars should be inserted by default.")
111 132
112(defcustom comment-style 'multi-line 133(defcustom comment-style 'plain
113 "*Style to be used for inserting comments." 134 "*Style to be used for inserting comments."
114 :group 'comment 135 :group 'comment
115 :type '(choice (const plain) 136 :type '(choice (const plain)
137 (const indent)
116 (const aligned) 138 (const aligned)
117 (const multi-line) 139 (const multi-line)
118 (const extra-line))) 140 (const extra-line)
141 (const box)))
119(defconst comment-styles 142(defconst comment-styles
120 '((plain . (nil nil nil)) 143 '((plain . (nil nil nil nil))
121 (aligned . (nil t nil)) 144 (indent . (nil nil nil t))
122 (multi-line . (t nil nil)) 145 (aligned . (nil t nil t))
123 (extra-line . (t nil t))) 146 (multi-line . (t nil nil t))
124 "Possible styles.") 147 (extra-line . (t nil t t))
148 (box . (t t t t)))
149 "Possible styles.
150(STYLE . (MULTI ALIGN EXTRA INDENT).")
125 151
126(defcustom comment-padding 1 152(defcustom comment-padding 1
127 "Number of spaces `comment-region' puts between comment chars and text. 153 "Number of spaces `comment-region' puts between comment chars and text.
128Can also be a string instead. 154Can also be a string instead.
129 155
130Extra spacing between the comment characters and the comment text 156Extra spacing between the comment characters and the comment text
131makes the comment easier to read. Default is 1. Nil means 0.") 157makes the comment easier to read. Default is 1. nil means 0.")
132 158
133(defcustom comment-multi-line nil 159(defcustom comment-multi-line nil
134 "*Non-nil means \\[indent-new-comment-line] should continue same comment 160 "*Non-nil means \\[indent-new-comment-line] should continue same comment
@@ -148,31 +174,23 @@ This is obsolete because you might as well use \\[newline-and-indent]."
148 (match-string 1 str)) 174 (match-string 1 str))
149 175
150(defun comment-string-reverse (s) 176(defun comment-string-reverse (s)
151 (comment-string-strip (concat (reverse (string-to-list s))) nil t)) 177 (comment-string-strip (concat (nreverse (string-to-list s))) nil t))
152 178
153(defun comment-normalize-vars (&optional noerror) 179(defun comment-normalize-vars (&optional noerror)
154 (if (not comment-start) (or noerror (error "No comment syntax is defined")) 180 (if (not comment-start) (or noerror (error "No comment syntax is defined"))
155 ;; comment-use-syntax 181 ;; comment-use-syntax
156 (when (eq comment-use-syntax 'maybe) 182 (when (eq comment-use-syntax 'undecided)
157 (set (make-local-variable 'comment-use-syntax) 183 (set (make-local-variable 'comment-use-syntax)
158 (let ((st (syntax-table)) 184 (let ((st (syntax-table))
159 (cs comment-start) 185 (cs comment-start)
160 (ce (if (string= "" comment-end) "\n" comment-end))) 186 (ce (if (string= "" comment-end) "\n" comment-end)))
187 ;; Try to skip over a comment using forward-comment
188 ;; to see if the syntax tables properly recognize it.
161 (with-temp-buffer 189 (with-temp-buffer
162 (set-syntax-table st) 190 (set-syntax-table st)
163 (insert cs " hello " ce) 191 (insert cs " hello " ce)
164 (goto-char (point-min)) 192 (goto-char (point-min))
165 (and (forward-comment 1) (eobp)))))) 193 (and (forward-comment 1) (eobp))))))
166 (when (eq comment-nested 'maybe)
167 (set (make-local-variable 'comment-nested)
168 (let ((st (syntax-table))
169 (cs comment-start)
170 (ce (if (string= "" comment-end) "\n" comment-end)))
171 (with-temp-buffer
172 (set-syntax-table st)
173 (insert cs " he " cs " hello " ce " ho " ce)
174 (goto-char (point-min))
175 (and (forward-comment 1) (eobp))))))
176 ;; comment-padding 194 ;; comment-padding
177 (when (integerp comment-padding) 195 (when (integerp comment-padding)
178 (setq comment-padding (make-string comment-padding ? ))) 196 (setq comment-padding (make-string comment-padding ? )))
@@ -196,9 +214,9 @@ This is obsolete because you might as well use \\[newline-and-indent]."
196 (let ((ce (if (string= "" comment-end) "\n" 214 (let ((ce (if (string= "" comment-end) "\n"
197 (comment-string-strip comment-end t t)))) 215 (comment-string-strip comment-end t t))))
198 (set (make-local-variable 'comment-end-skip) 216 (set (make-local-variable 'comment-end-skip)
199 (concat "\\s-*\\(\\s>" (if comment-nested "+" "") 217 (concat "\\s-*\\(\\s>" (if comment-quote-nested "" "+")
200 "\\|" (regexp-quote (substring ce 0 1)) 218 "\\|" (regexp-quote (substring ce 0 1))
201 (if (or comment-nested (> (length ce) 1)) "+" "") 219 (if (and comment-quote-nested (<= (length ce) 1)) "" "+")
202 (regexp-quote (substring ce 1)) 220 (regexp-quote (substring ce 1))
203 "\\)")))))) 221 "\\)"))))))
204 222
@@ -214,7 +232,7 @@ This is obsolete because you might as well use \\[newline-and-indent]."
214The regexp has one group in it which matches RE right after the 232The regexp has one group in it which matches RE right after the
215potential quoting." 233potential quoting."
216 (setq str (comment-string-strip str t t)) 234 (setq str (comment-string-strip str t t))
217 (when (and (not comment-nested) (> (length str) 1)) 235 (when (and comment-quote-nested (> (length str) 1))
218 (concat (regexp-quote (substring str 0 1)) 236 (concat (regexp-quote (substring str 0 1))
219 "\\\\*\\(" re "\\)" 237 "\\\\*\\(" re "\\)"
220 (regexp-quote (substring str 1))))) 238 (regexp-quote (substring str 1)))))
@@ -224,9 +242,9 @@ potential quoting."
224;;;; 242;;;;
225 243
226(defun comment-search-forward (&optional limit noerror) 244(defun comment-search-forward (&optional limit noerror)
227 "Find a comment start between the point and LIMIT. 245 "Find a comment start between point and LIMIT.
228Moves the point to inside the comment and returns the position of the 246Moves point to inside the comment and returns the position of the
229comment-starter. If no comment is found, moves the point to LIMIT 247comment-starter. If no comment is found, moves point to LIMIT
230and raises an error or returns nil of NOERROR is non-nil." 248and raises an error or returns nil of NOERROR is non-nil."
231 (if (not comment-use-syntax) 249 (if (not comment-use-syntax)
232 (when (re-search-forward comment-start-skip limit noerror) 250 (when (re-search-forward comment-start-skip limit noerror)
@@ -239,7 +257,7 @@ and raises an error or returns nil of NOERROR is non-nil."
239 (end nil)) 257 (end nil))
240 (while (and (null end) (>= (point) bol)) 258 (while (and (null end) (>= (point) bol))
241 (if (looking-at comment-start-skip) 259 (if (looking-at comment-start-skip)
242 (setq end (match-end 0)) 260 (setq end (min (or limit (point-max)) (match-end 0)))
243 (backward-char))) 261 (backward-char)))
244 (goto-char end) 262 (goto-char end)
245 start) 263 start)
@@ -247,8 +265,8 @@ and raises an error or returns nil of NOERROR is non-nil."
247 265
248(defun comment-search-backward (&optional limit noerror) 266(defun comment-search-backward (&optional limit noerror)
249 "Find a comment start between LIMIT and point. 267 "Find a comment start between LIMIT and point.
250Moves the point to inside the comment and returns the position of the 268Moves point to inside the comment and returns the position of the
251comment-starter. If no comment is found, moves the point to LIMIT 269comment-starter. If no comment is found, moves point to LIMIT
252and raises an error or returns nil of NOERROR is non-nil." 270and raises an error or returns nil of NOERROR is non-nil."
253 (if (not (re-search-backward comment-start-skip limit t)) 271 (if (not (re-search-backward comment-start-skip limit t))
254 (unless noerror (error "No comment")) 272 (unless noerror (error "No comment"))
@@ -268,8 +286,8 @@ and raises an error or returns nil of NOERROR is non-nil."
268 cs)))) 286 cs))))
269 287
270(defun comment-beginning () 288(defun comment-beginning ()
271 "Find the beginning of the inclosing comment. 289 "Find the beginning of the enclosing comment.
272Returns nil if not inside a comment, else moves the point and returns 290Returns nil if not inside a comment, else moves point and returns
273the same as `comment-search-forward'." 291the same as `comment-search-forward'."
274 (let ((pt (point)) 292 (let ((pt (point))
275 (cs (comment-search-backward nil t))) 293 (cs (comment-search-backward nil t)))
@@ -295,7 +313,7 @@ and can use regexps instead of syntax."
295 313
296(defun comment-enter-backward () 314(defun comment-enter-backward ()
297 "Move from the end of a comment to the end of its content. 315 "Move from the end of a comment to the end of its content.
298The point is assumed to be right at the end of a comment." 316Point is assumed to be just at the end of a comment."
299 (if (bolp) 317 (if (bolp)
300 ;; comment-end = "" 318 ;; comment-end = ""
301 (progn (backward-char) (skip-syntax-backward " ")) 319 (progn (backward-char) (skip-syntax-backward " "))
@@ -328,8 +346,6 @@ If CONTINUE is non-nil, use the `comment-continuation' markers if any."
328 cpos indent begpos) 346 cpos indent begpos)
329 (beginning-of-line) 347 (beginning-of-line)
330 (when (setq begpos (comment-search-forward eolpos t)) 348 (when (setq begpos (comment-search-forward eolpos t))
331 (skip-chars-forward
332 (concat (buffer-substring (1- (point)) (point)) " \t"))
333 (setq cpos (point-marker)) 349 (setq cpos (point-marker))
334 (goto-char begpos)) 350 (goto-char begpos))
335 (setq begpos (point)) 351 (setq begpos (point))
@@ -401,7 +417,7 @@ It contains N copies of the last non-whitespace chars of STR.
401If STR already contains padding, the corresponding amount is 417If STR already contains padding, the corresponding amount is
402 ignored from `comment-padding'. 418 ignored from `comment-padding'.
403N defaults to 1. 419N defaults to 1.
404It N is 're, a regexp is returned instead, that would match 420If N is `re', a regexp is returned instead, that would match
405 the string for any N." 421 the string for any N."
406 (setq n (or n 0)) 422 (setq n (or n 0))
407 (when (and (stringp str) (not (string= "" str))) 423 (when (and (stringp str) (not (string= "" str)))
@@ -426,7 +442,7 @@ It contains N copies of the last non-whitespace chars of STR.
426If STR already contains padding, the corresponding amount is 442If STR already contains padding, the corresponding amount is
427 ignored from `comment-padding'. 443 ignored from `comment-padding'.
428N defaults to 1. 444N defaults to 1.
429It N is 're, a regexp is returned instead, that would match 445If N is `re', a regexp is returned instead, that would match
430 the string for any N." 446 the string for any N."
431 (setq n (or n 0)) 447 (setq n (or n 0))
432 (when (and (stringp str) (not (string= "" str))) 448 (when (and (stringp str) (not (string= "" str)))
@@ -437,7 +453,7 @@ It N is 're, a regexp is returned instead, that would match
437 (length comment-padding))) 453 (length comment-padding)))
438 (match-string 0 str))) 454 (match-string 0 str)))
439 (c (aref str (match-end 0))) 455 (c (aref str (match-end 0)))
440 (multi (or comment-nested (string= comment-end "") 456 (multi (or (not comment-quote-nested) (string= comment-end "")
441 (> (length str) (1+ (match-end 0)))))) 457 (> (length str) (1+ (match-end 0))))))
442 (if (symbolp n) 458 (if (symbolp n)
443 (concat "\\s-*" 459 (concat "\\s-*"
@@ -542,7 +558,7 @@ ARG is currently ignored."
542 min-indent))) 558 min-indent)))
543 (setq ce (concat cce "\n" (make-string indent ? ) (or ce cs))) 559 (setq ce (concat cce "\n" (make-string indent ? ) (or ce cs)))
544 (setq cs (concat cs "\n" (make-string min-indent ? ) ccs)))) 560 (setq cs (concat cs "\n" (make-string min-indent ? ) ccs))))
545 (values cs ce)) 561 (cons cs ce))
546 562
547(def-edebug-spec comment-with-narrowing t) 563(def-edebug-spec comment-with-narrowing t)
548(put 'comment-with-narrowing 'lisp-indent-function 2) 564(put 'comment-with-narrowing 'lisp-indent-function 2)
@@ -573,7 +589,8 @@ indentation to be kept as it was before narrowing."
573 (delete-char n) 589 (delete-char n)
574 (decf -bindent n))))))))) 590 (decf -bindent n)))))))))
575 591
576(defun comment-region-internal (beg end cs ce &optional ccs cce block lines) 592(defun comment-region-internal (beg end cs ce
593 &optional ccs cce block lines indent)
577 (assert (< beg end)) 594 (assert (< beg end))
578 (let ((no-empty t)) 595 (let ((no-empty t))
579 ;; sanitize ce and cce 596 ;; sanitize ce and cce
@@ -600,7 +617,7 @@ indentation to be kept as it was before narrowing."
600 (unless (looking-at "[ \t]*$") 617 (unless (looking-at "[ \t]*$")
601 (setq min-indent (min min-indent (current-indentation)))) 618 (setq min-indent (min min-indent (current-indentation))))
602 (when ce-quote-re 619 (when ce-quote-re
603 (let ((eol (save-excursion (end-of-line) (point)))) 620 (let ((eol (line-end-position)))
604 (while (re-search-forward ce-quote-re eol 'move) 621 (while (re-search-forward ce-quote-re eol 'move)
605 (incf eol) 622 (incf eol)
606 (replace-match "\\" t t nil 1)))) 623 (replace-match "\\" t t nil 1))))
@@ -610,12 +627,15 @@ indentation to be kept as it was before narrowing."
610 627
611 ;; inserting ccs can change max-indent by (1- tab-width) 628 ;; inserting ccs can change max-indent by (1- tab-width)
612 (incf max-indent (+ (max (length cs) (length ccs)) -1 tab-width)) 629 (incf max-indent (+ (max (length cs) (length ccs)) -1 tab-width))
630 (unless indent (setq min-indent 0))
613 631
614 ;; make the leading and trailing lines if requested 632 ;; make the leading and trailing lines if requested
615 (when lines 633 (when lines
616 (multiple-value-setq (cs ce) 634 (let ((csce
617 (comment-make-extra-lines 635 (comment-make-extra-lines
618 cs ce ccs cce min-indent max-indent block))) 636 cs ce ccs cce min-indent max-indent block)))
637 (setq cs (car csce))
638 (setq ce (cdr csce))))
619 639
620 (goto-char (point-min)) 640 (goto-char (point-min))
621 ;; Loop over all lines from BEG to END. 641 ;; Loop over all lines from BEG to END.
@@ -645,7 +665,7 @@ The strings used as comment starts are built from
645 (comment-normalize-vars) 665 (comment-normalize-vars)
646 (if (> beg end) (let (mid) (setq mid beg beg end end mid))) 666 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
647 (let* ((numarg (prefix-numeric-value arg)) 667 (let* ((numarg (prefix-numeric-value arg))
648 (add (car comment-add)) 668 (add comment-add)
649 (style (cdr (assoc comment-style comment-styles))) 669 (style (cdr (assoc comment-style comment-styles)))
650 (lines (nth 2 style)) 670 (lines (nth 2 style))
651 (block (nth 1 style)) 671 (block (nth 1 style))
@@ -669,14 +689,9 @@ The strings used as comment starts are built from
669 (>= (point) beg)) 689 (>= (point) beg))
670 (progn (goto-char end) (end-of-line) (skip-syntax-backward " ") 690 (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
671 (<= (point) end)) 691 (<= (point) end))
672 (not (string= "" comment-end)) 692 (or (not (string= "" comment-end)) block)
673 (progn (goto-char beg) (search-forward "\n" end t))))) 693 (progn (goto-char beg) (search-forward "\n" end t)))))
674 694
675 ;; C-u C-u makes a full block
676 (when (and (consp arg) (>= numarg 16))
677 (setq lines t block t add (or (cdr comment-add) 2))
678 (setq arg nil numarg 1))
679
680 ;; don't add end-markers just because the user asked for `block' 695 ;; don't add end-markers just because the user asked for `block'
681 (unless (or lines (string= "" comment-end)) (setq block nil)) 696 (unless (or lines (string= "" comment-end)) (setq block nil))
682 697
@@ -697,17 +712,27 @@ The strings used as comment starts are built from
697 (if multi (comment-padright (car comment-continue) numarg)) 712 (if multi (comment-padright (car comment-continue) numarg))
698 (if multi (comment-padleft (cdr comment-continue) numarg)) 713 (if multi (comment-padleft (cdr comment-continue) numarg))
699 block 714 block
700 lines))))) 715 lines
716 (nth 3 style))))))
717
718(defun comment-box (beg end &optional arg)
719 "Comment out the BEG..END region, putting it inside a box.
720The numeric prefix ARG specifies how many characters to add to begin- and
721end- comment markers additionally to what `comment-add' already specifies."
722 (interactive "*r\np")
723 (let ((comment-style 'box))
724 (comment-region beg end (+ comment-add arg))))
701 725
702(defun comment-dwim (arg) 726(defun comment-dwim (arg)
703 "Call the comment command you want. 727 "Call the comment command you want.
704If the region is active, calls `comment-region' (unless it only consists 728If the region is active and `transient-mark-mode' is on,
729calls `comment-region' (unless it only consists
705in comments, in which case it calls `uncomment-region'). 730in comments, in which case it calls `uncomment-region').
706Else, if the current line is empty, insert a comment and indent it. 731Else, if the current line is empty, insert a comment and indent it.
707Else call `indent-for-comment' or `kill-comment' if a prefix ARG is specified." 732Else call `indent-for-comment' or `kill-comment' if a prefix ARG is specified."
708 (interactive "*P") 733 (interactive "*P")
709 (comment-normalize-vars) 734 (comment-normalize-vars)
710 (if mark-active 735 (if (and mark-active transient-mark-mode)
711 (let ((beg (min (point) (mark))) 736 (let ((beg (min (point) (mark)))
712 (end (max (point) (mark)))) 737 (end (max (point) (mark))))
713 (if (save-excursion ;; check for already commented region 738 (if (save-excursion ;; check for already commented region
@@ -719,7 +744,7 @@ Else call `indent-for-comment' or `kill-comment' if a prefix ARG is specified."
719 (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$"))) 744 (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
720 (if arg (kill-comment (and (integerp arg) arg)) (indent-for-comment)) 745 (if arg (kill-comment (and (integerp arg) arg)) (indent-for-comment))
721 (let ((add (if arg (prefix-numeric-value arg) 746 (let ((add (if arg (prefix-numeric-value arg)
722 (if (= (length comment-start) 1) (car comment-add) 0)))) 747 (if (= (length comment-start) 1) comment-add 0))))
723 (insert (comment-padright comment-start add)) 748 (insert (comment-padright comment-start add))
724 (save-excursion 749 (save-excursion
725 (unless (string= "" comment-end) 750 (unless (string= "" comment-end)
@@ -804,6 +829,9 @@ unless optional argument SOFT is non-nil."
804 829
805;;; Change Log: 830;;; Change Log:
806;; $Log: newcomment.el,v $ 831;; $Log: newcomment.el,v $
832;; Revision 1.6 1999/12/08 00:19:51 monnier
833;; various fixes and gratuitous movements.
834;;
807;; Revision 1.5 1999/11/30 16:20:55 monnier 835;; Revision 1.5 1999/11/30 16:20:55 monnier
808;; (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line). 836;; (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
809;; (comment-use-syntax): Whether to use the syntax-table or just the regexps. 837;; (comment-use-syntax): Whether to use the syntax-table or just the regexps.