annotate lisp/newcomment.el @ 29404:5b490e305c65

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