Mercurial > emacs
annotate lisp/newcomment.el @ 52685:d35d6c2f780f
Comment change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 30 Sep 2003 12:44:53 +0000 |
parents | 695cf19ef79e |
children | 3f44b2120fba 375f2633d815 |
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 |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
3 ;; Copyright (C) 1999,2000,2003 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 |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
10 |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
11 ;; 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
|
12 ;; 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
|
13 ;; 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
|
14 ;; any later version. |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
15 |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
16 ;; 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
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
20 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;; 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
|
22 ;; 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
|
23 ;; 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
|
24 ;; Boston, MA 02111-1307, USA. |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 ;;; Commentary: |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
28 ;; A replacement for simple.el's comment-related functions. |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;;; Bugs: |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
32 ;; - boxed comments in Perl are not properly uncommented because they are |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
33 ;; uncommented one-line at a time. |
41689 | 34 ;; - nested comments in sgml-mode are not properly quoted. |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
35 ;; - 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
|
36 ;; if the corresponding closing marker happens to be right. |
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 |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
47 ;; - rebox.el-style refill. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
48 ;; - quantized steps in comment-alignment. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
49 ;; - try to align tail comments. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
50 ;; - check what c-comment-line-break-function has to say. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
51 ;; - 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
|
52 ;; - uncomment-region with a consp (for blocks) or somehow make the |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
53 ;; deletion of continuation markers less dangerous. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
54 ;; - drop block-comment-<foo> unless it's really used. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
55 ;; - uncomment-region on a subpart of a comment. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
56 ;; - support gnu-style "multi-line with space in continue". |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
57 ;; - 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
|
58 ;; is not turned on. |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 |
32014
13bd1ce1c353
(comment-indent-function): Use 0 for ;;; and %%%.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30091
diff
changeset
|
60 ;; - when auto-filling a comment, try to move the comment to the left |
13bd1ce1c353
(comment-indent-function): Use 0 for ;;; and %%%.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30091
diff
changeset
|
61 ;; rather than break it (if possible). |
13bd1ce1c353
(comment-indent-function): Use 0 for ;;; and %%%.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30091
diff
changeset
|
62 ;; - sometimes default the comment-column to the same |
13bd1ce1c353
(comment-indent-function): Use 0 for ;;; and %%%.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30091
diff
changeset
|
63 ;; one used on the preceding line(s). |
13bd1ce1c353
(comment-indent-function): Use 0 for ;;; and %%%.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30091
diff
changeset
|
64 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 ;;; Code: |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
67 ;;;###autoload |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
68 (defalias 'indent-for-comment 'comment-indent) |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
69 ;;;###autoload |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
70 (defalias 'set-comment-column 'comment-set-column) |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
71 ;;;###autoload |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
72 (defalias 'kill-comment 'comment-kill) |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
73 ;;;###autoload |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
74 (defalias 'indent-new-comment-line 'comment-indent-new-line) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
76 (defgroup comment nil |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
77 "Indenting and filling of comments." |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
78 :prefix "comment-" |
29760
c2940b6e267e
(comment) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
29409
diff
changeset
|
79 :version "21.1" |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
80 :group 'fill) |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
81 |
50640
8ec8f6706902
(comment-use-syntax): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
49768
diff
changeset
|
82 ;; Autoload this to avoid warnings, since some major modes define it. |
8ec8f6706902
(comment-use-syntax): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
49768
diff
changeset
|
83 ;;;###autoload |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
84 (defvar comment-use-syntax 'undecided |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
85 "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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
91 (defcustom comment-fill-column nil |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
92 "Column to use for `comment-indent'. If nil, use `fill-column' instead." |
45023
e4546fd8cb33
(comment-fill-column): Fix :type spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44999
diff
changeset
|
93 :type '(choice (const nil) integer)) |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
94 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
95 ;;;###autoload |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 (defcustom comment-column 32 |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 "*Column to indent right-margin comments to. |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 Each mode establishes a different default value for this variable; you |
44455
8a30d8f66e1a
(comment-column): Docstring improvement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43689
diff
changeset
|
99 can set the value for a particular mode using that mode's hook. |
8a30d8f66e1a
(comment-column): Docstring improvement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43689
diff
changeset
|
100 Comments might be indented to a value smaller than this in order |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
101 not to go beyond `comment-fill-column'." |
41286
6b56e476153d
(comment-column, comment-style, comment-multi-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41253
diff
changeset
|
102 :type 'integer) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (make-variable-buffer-local 'comment-column) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
105 ;;;###autoload |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
106 (defvar comment-start nil |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
107 "*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
|
108 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
109 ;;;###autoload |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
110 (defvar comment-start-skip nil |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 "*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
|
112 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
|
113 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
|
114 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
115 ;;;###autoload |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
116 (defvar comment-end-skip nil |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
117 "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
|
118 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
119 ;;;###autoload |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
120 (defvar comment-end "" |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 "*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
|
122 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
|
123 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
124 ;;;###autoload |
32186
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
125 (defvar comment-indent-function 'comment-indent-default |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 "Function to compute desired indentation for a comment. |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 This function is called with no args with point at the beginning of |
32186
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
128 the comment's starting delimiter and should return either the desired |
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
129 column indentation or nil. |
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
130 If nil is returned, indentation is delegated to `indent-according-to-mode'.") |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
132 (defvar block-comment-start nil) |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
133 (defvar block-comment-end nil) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
135 (defvar comment-quote-nested t |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
136 "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
|
137 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
|
138 |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
139 (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
|
140 "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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 preserve indentation. |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
146 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
|
147 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
|
148 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
149 (defvar comment-add 0 |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
150 "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
|
151 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
|
152 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
|
153 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
|
154 two semi-colons.") |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
155 |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
156 (defconst comment-styles |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
157 '((plain . (nil nil nil nil)) |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
158 (indent . (nil nil nil t)) |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
159 (aligned . (nil t nil t)) |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
160 (multi-line . (t nil nil t)) |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
161 (extra-line . (t nil t t)) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
162 (box . (nil t t t)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
163 (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
|
164 "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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
173 ;;;###autoload |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
174 (defcustom comment-style 'plain |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
175 "*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
|
176 See `comment-styles' for a list of available styles." |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
177 :type (if (boundp 'comment-styles) |
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
178 `(choice ,@(mapcar (lambda (s) `(const ,(car s))) comment-styles)) |
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
179 'symbol)) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
180 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
181 ;;;###autoload |
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
182 (defcustom comment-padding " " |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
183 "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
|
184 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
|
185 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
|
186 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
187 Extra spacing between the comment characters and the comment text |
41286
6b56e476153d
(comment-column, comment-style, comment-multi-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41253
diff
changeset
|
188 makes the comment easier to read. Default is 1. nil means 0." |
6b56e476153d
(comment-column, comment-style, comment-multi-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41253
diff
changeset
|
189 :type '(choice string integer (const nil))) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
190 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
191 ;;;###autoload |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
192 (defcustom comment-multi-line nil |
29760
c2940b6e267e
(comment) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
29409
diff
changeset
|
193 "*Non-nil means \\[comment-indent-new-line] continues comments, with no new terminator or starter. |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
194 This is obsolete because you might as well use \\[newline-and-indent]." |
41286
6b56e476153d
(comment-column, comment-style, comment-multi-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41253
diff
changeset
|
195 :type 'boolean) |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
196 |
51337
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
197 (defcustom comment-empty-lines nil |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
198 "If nil, `comment-region' does not comment out empty lines. |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
199 If t, it always comments out empty lines. |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
200 if `eol' it only comments out empty lines if comments are |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
201 terminated by the end of line (i.e. `comment-end' is empty)." |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
202 :type '(choice (const :tag "Never" nil) |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
203 (const :tag "Always" t) |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
204 (const :tag "EOl-terminated" 'eol))) |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
205 |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
206 ;;;; |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
207 ;;;; Helpers |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
208 ;;;; |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
209 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
210 (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
|
211 "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
|
212 (string-match (concat "\\`" (if beforep "\\s-*") |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
213 "\\(.*?\\)" (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
|
214 "\\'") str) |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
215 (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
|
216 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
217 (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
|
218 "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
|
219 (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
|
220 |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
221 ;;;###autoload |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
222 (defun comment-normalize-vars (&optional noerror) |
50845
ac2120f868b9
(comment-normalize-vars): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50843
diff
changeset
|
223 "Check and setup the variables needed by other commenting functions. |
ac2120f868b9
(comment-normalize-vars): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50843
diff
changeset
|
224 Functions autoloaded from newcomment.el, being entry points, should call |
ac2120f868b9
(comment-normalize-vars): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50843
diff
changeset
|
225 this function before any other, so the rest of the code can assume that |
ac2120f868b9
(comment-normalize-vars): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50843
diff
changeset
|
226 the variables are properly set." |
50673
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
227 (if (not comment-start) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
228 (unless noerror |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
229 (set (make-local-variable 'comment-start) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
230 (read-string "No comment syntax is defined. Use: "))) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
231 ;; comment-use-syntax |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
232 (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
|
233 (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
|
234 (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
|
235 (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
|
236 (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
|
237 ;; 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
|
238 ;; 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
|
239 (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
|
240 (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
|
241 (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
|
242 (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
|
243 (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
|
244 ;; comment-padding |
41021
c07719cfdfcd
(comment-normalize-vars): Handle a nil comment-padding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39864
diff
changeset
|
245 (unless comment-padding (setq comment-padding 0)) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
246 (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
|
247 (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
|
248 ;; comment markers |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
249 ;;(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
|
250 ;;(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
|
251 ;; comment-continue |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
252 (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
|
253 (set (make-local-variable 'comment-continue) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
254 (concat (if (string-match "\\S-\\S-" comment-start) " " "|") |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
255 (substring comment-start 1))) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
256 ;; Hasn't been necessary yet. |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
257 ;; (unless (string-match comment-start-skip comment-continue) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
258 ;; (kill-local-variable 'comment-continue)) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
259 ) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
260 ;; comment-skip regexps |
45902
24d34388fd69
(comment-normalize-vars): Refresh the comment-foo-skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45023
diff
changeset
|
261 (unless (and comment-start-skip |
24d34388fd69
(comment-normalize-vars): Refresh the comment-foo-skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45023
diff
changeset
|
262 ;; In case comment-start has changed since last time. |
24d34388fd69
(comment-normalize-vars): Refresh the comment-foo-skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45023
diff
changeset
|
263 (string-match comment-start-skip 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
|
264 (set (make-local-variable 'comment-start-skip) |
50673
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
265 (concat "\\(\\(^\\|[^\\\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
|
266 (regexp-quote (comment-string-strip comment-start t t)) |
36490
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
267 ;; Let's not allow any \s- but only [ \t] since \n |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
268 ;; might be both a comment-end marker and \s-. |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
269 "+\\)[ \t]*"))) |
45902
24d34388fd69
(comment-normalize-vars): Refresh the comment-foo-skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45023
diff
changeset
|
270 (unless (and comment-end-skip |
24d34388fd69
(comment-normalize-vars): Refresh the comment-foo-skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45023
diff
changeset
|
271 ;; In case comment-end has changed since last time. |
24d34388fd69
(comment-normalize-vars): Refresh the comment-foo-skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45023
diff
changeset
|
272 (string-match comment-end-skip 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
|
273 (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
|
274 (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
|
275 (set (make-local-variable 'comment-end-skip) |
39486
54fe59ee8057
(comment-normalize-vars): Use " \t" rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39079
diff
changeset
|
276 ;; We use [ \t] rather than \s- because we don't want to |
54fe59ee8057
(comment-normalize-vars): Use " \t" rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39079
diff
changeset
|
277 ;; remove ^L in C mode when uncommenting. |
54fe59ee8057
(comment-normalize-vars): Use " \t" rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39079
diff
changeset
|
278 (concat "[ \t]*\\(\\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
|
279 "\\|" (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
|
280 (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
|
281 (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
|
282 "\\)")))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48257
diff
changeset
|
283 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
284 (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
|
285 (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
|
286 "\\\\" (if unp "+" "*") |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
287 (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
|
288 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
289 (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
|
290 "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
|
291 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
|
292 (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
|
293 (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
|
294 (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
|
295 (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
|
296 "\\|" (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
|
297 (goto-char (point-min)) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
298 (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
|
299 (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
|
300 (forward-char 1) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
301 (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
|
302 (when (= (length ce) 1) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
303 ;; 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
|
304 ;; "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
|
305 ;; 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
|
306 (if (not unp) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
307 (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
|
308 (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
|
309 (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
|
310 (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
|
311 (1- (match-end 0))) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
312 (concat "!" cs))) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
313 (backward-char 2) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
314 (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
|
315 (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
|
316 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
317 ;;;; |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
318 ;;;; Navigation |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
319 ;;;; |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
320 |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
321 (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
|
322 "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
|
323 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
|
324 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
|
325 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
|
326 (if (not comment-use-syntax) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
327 (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
|
328 (or (match-end 1) (match-beginning 0)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
329 (goto-char limit) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
330 (unless noerror (error "No comment"))) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
331 (let* ((pt (point)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
332 ;; 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
|
333 (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
|
334 (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
|
335 ;; 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
|
336 ;; 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
|
337 (setq s (parse-partial-sexp |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
338 pt (or limit (point-max)) nil nil |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
339 (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
|
340 t))) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
341 (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
|
342 (unless noerror (error "No comment")) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
343 ;; We found the comment. |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
344 (let ((pos (point)) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
345 (start (nth 8 s)) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
346 (bol (line-beginning-position)) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
347 (end nil)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
348 (while (and (null end) (>= (point) bol)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
349 (if (looking-at comment-start-skip) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
350 (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
|
351 (backward-char))) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
352 (goto-char (or end pos)) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
353 start))))) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
354 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
355 (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
|
356 "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
|
357 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
|
358 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
|
359 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
|
360 ;; 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
|
361 ;; 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
|
362 ;; 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
|
363 ;; 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
|
364 ;; 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
|
365 (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
|
366 (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
|
367 (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
|
368 (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
|
369 (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
|
370 (pt (point))) |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
371 (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
|
372 (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
|
373 (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
|
374 (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
|
375 (comment-forward) |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
376 (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
|
377 (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
|
378 (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
|
379 (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
|
380 cs)))) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
381 |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
382 (defun comment-beginning () |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
383 "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
|
384 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
|
385 the same as `comment-search-forward'." |
36490
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
386 ;; HACK ATTACK! |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
387 ;; We should really test `in-string-p' but that can be expensive. |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
388 (unless (eq (get-text-property (point) 'face) 'font-lock-string-face) |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
389 (let ((pt (point)) |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
390 (cs (comment-search-backward nil t))) |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
391 (when cs |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
392 (if (save-excursion |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
393 (goto-char cs) |
38898
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
394 (and |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
395 ;; For modes where comment-start and comment-end are the same, |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
396 ;; the search above may have found a `ce' rather than a `cs'. |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
397 (or (not (looking-at comment-end-skip)) |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
398 ;; Maybe font-lock knows that it's a `cs'? |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
399 (eq (get-text-property (match-end 0) 'face) |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
400 'font-lock-comment-face) |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
401 (unless (eq (get-text-property (point) 'face) |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
402 'font-lock-comment-face) |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
403 ;; Let's assume it's a `cs' if we're on the same line. |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
404 (>= (line-end-position) pt))) |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
405 ;; Make sure that PT is not past the end of the comment. |
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
406 (if (comment-forward 1) (> (point) pt) (eobp)))) |
36490
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
407 cs |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
408 (goto-char pt) |
e40c1ae4f04b
(comment-normalize-vars): Use [ \t] for the trailing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36271
diff
changeset
|
409 nil))))) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
410 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
411 (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
|
412 "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
|
413 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
|
414 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
|
415 (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
|
416 (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
|
417 (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
|
418 (while (> n 0) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
419 (setq n |
43689
5e6a5df9973a
(comment-forward): Use forward-comment to skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
420 (if (or (forward-comment 1) |
5e6a5df9973a
(comment-forward): Use forward-comment to skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
421 (and (looking-at comment-start-skip) |
5e6a5df9973a
(comment-forward): Use forward-comment to skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
422 (goto-char (match-end 0)) |
5e6a5df9973a
(comment-forward): Use forward-comment to skip
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
423 (re-search-forward comment-end-skip nil 'move))) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
424 (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
|
425 (= n 0)))) |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
426 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
427 (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
|
428 "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
|
429 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
|
430 (if (bolp) |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
431 ;; comment-end = "" |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
432 (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
|
433 (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
|
434 (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
|
435 (save-restriction |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
436 (narrow-to-region (point) end) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
437 (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
|
438 (goto-char (match-beginning 0)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
439 ;; 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
|
440 ;; 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
|
441 ;; 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
|
442 (goto-char (point-max)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
443 (backward-char 2) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
444 (skip-chars-backward (string (char-after))) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
445 (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
|
446 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
447 ;;;; |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
448 ;;;; Commands |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
449 ;;;; |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
450 |
32307
c3058f7483c4
(comment-indent-default): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32186
diff
changeset
|
451 ;;;###autoload |
32186
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
452 (defun comment-indent-default () |
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
453 "Default for `comment-indent-function'." |
33468
4d15850856e4
(comment-indent-default): Stick \s<\s< to the left
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32307
diff
changeset
|
454 (if (and (looking-at "\\s<\\s<\\(\\s<\\)?") |
4d15850856e4
(comment-indent-default): Stick \s<\s< to the left
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32307
diff
changeset
|
455 (or (match-end 1) (/= (current-column) (current-indentation)))) |
4d15850856e4
(comment-indent-default): Stick \s<\s< to the left
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32307
diff
changeset
|
456 0 |
32186
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
457 (when (or (/= (current-column) (current-indentation)) |
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
458 (and (> comment-add 0) (looking-at "\\s<\\S<"))) |
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
459 comment-column))) |
964f10494360
(comment-indent):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32014
diff
changeset
|
460 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
461 ;;;###autoload |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
462 (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
|
463 "Indent this line's comment to comment column, or insert an empty comment. |
38898
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
464 If CONTINUE is non-nil, use the `comment-continue' markers if any." |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
465 (interactive "*") |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
466 (comment-normalize-vars) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
467 (let* ((empty (save-excursion (beginning-of-line) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
468 (looking-at "[ \t]*$"))) |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
469 (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
|
470 (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
|
471 (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
|
472 (and empty block-comment-end) comment-end))) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
473 (unless starter (error "No comment syntax defined")) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
474 (beginning-of-line) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
475 (let* ((eolpos (line-end-position)) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
476 (begpos (comment-search-forward eolpos t)) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
477 cpos indent) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
478 ;; An existing comment? |
42030
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
479 (if begpos |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
480 (progn |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
481 (if (and (not (looking-at "[\t\n ]")) |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
482 (looking-at comment-end-skip)) |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
483 ;; The comment is empty and we have skipped all its space |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
484 ;; and landed right before the comment-ender: |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
485 ;; Go back to the middle of the space. |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
486 (forward-char (/ (skip-chars-backward " \t") -2))) |
74a3864ffe9a
(comment-indent): Jump to the middle of empty comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41760
diff
changeset
|
487 (setq cpos (point-marker))) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
488 ;; If none, insert one. |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
489 (save-excursion |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
490 ;; Some comment-indent-function insist on not moving comments that |
39079
fc69197cb76d
(comment-indent): Don't insert a fixed number of spaces.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39078
diff
changeset
|
491 ;; are in column 0, so we first go to the likely target column. |
fc69197cb76d
(comment-indent): Don't insert a fixed number of spaces.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39078
diff
changeset
|
492 (indent-to comment-column) |
49768
ffe55e61c3fc
(comment-indent): Ensure space before added comment.
Dave Love <fx@gnu.org>
parents:
49597
diff
changeset
|
493 ;; Ensure there's a space before the comment for things |
ffe55e61c3fc
(comment-indent): Ensure space before added comment.
Dave Love <fx@gnu.org>
parents:
49597
diff
changeset
|
494 ;; like sh where it matters (as well as being neater). |
50929
068965f379b3
(comment-indent): Be more careful when inserting
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50845
diff
changeset
|
495 (unless (memq (char-before) '(nil ?\n ?\t ?\ )) |
49768
ffe55e61c3fc
(comment-indent): Ensure space before added comment.
Dave Love <fx@gnu.org>
parents:
49597
diff
changeset
|
496 (insert ?\ )) |
50929
068965f379b3
(comment-indent): Be more careful when inserting
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50845
diff
changeset
|
497 (setq begpos (point)) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
498 (insert starter) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
499 (setq cpos (point-marker)) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
500 (insert ender))) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
501 (goto-char begpos) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
502 ;; Compute desired indent. |
33980
3aa61201a0ab
(comment-indent): Save excursion around call to comment-indent-function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33705
diff
changeset
|
503 (setq indent (save-excursion (funcall comment-indent-function))) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
504 (if (not indent) |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
505 ;; comment-indent-function refuses: delegate to line-indent. |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
506 (indent-according-to-mode) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
507 ;; Avoid moving comments past the fill-column. |
41253
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
508 (unless (save-excursion (skip-chars-backward " \t") (bolp)) |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
509 (let ((max (+ (current-column) |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
510 (- (or comment-fill-column fill-column) |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
511 (save-excursion (end-of-line) (current-column)))))) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
512 (if (<= max indent) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
513 (setq indent max) ;Don't move past the fill column. |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
514 ;; We can choose anywhere between indent..max. |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
515 ;; Let's try to align to a comment on the previous line. |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
516 (let ((other nil)) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
517 (save-excursion |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
518 (when (and (zerop (forward-line -1)) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
519 (setq other (comment-search-forward |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
520 (line-end-position) t))) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
521 (goto-char other) (setq other (current-column)))) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
522 (if (and other (<= other max) (> other indent)) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
523 ;; There is a comment and it's in the range: bingo. |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
524 (setq indent other) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
525 ;; Let's try to align to a comment on the next line, then. |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
526 (let ((other nil)) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
527 (save-excursion |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
528 (when (and (zerop (forward-line 1)) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
529 (setq other (comment-search-forward |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
530 (line-end-position) t))) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
531 (goto-char other) (setq other (current-column)))) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
532 (if (and other (<= other max) (> other indent)) |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
533 ;; There is a comment and it's in the range: bingo. |
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
534 (setq indent other)))))))) |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
535 (unless (= (current-column) indent) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
536 ;; If that's different from current, change it. |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
537 (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
538 (indent-to (if (bolp) indent |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
539 (max indent (1+ (current-column))))))) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
540 (goto-char cpos) |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
541 (set-marker cpos nil)))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
542 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
543 ;;;###autoload |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
544 (defun comment-set-column (arg) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
545 "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
|
546 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
|
547 With just minus as arg, kill any comment on this line. |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
548 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
|
549 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
|
550 (interactive "P") |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
551 (cond |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
552 ((eq arg '-) (comment-kill nil)) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
553 (arg |
50843
bc3a5a6b96ab
(comment-set-column, comment-kill, comment-or-uncomment-region):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50839
diff
changeset
|
554 (comment-normalize-vars) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
555 (save-excursion |
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
556 (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
|
557 (comment-search-backward) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
558 (beginning-of-line) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
559 (goto-char (comment-search-forward (line-end-position))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
560 (setq comment-column (current-column)) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
561 (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
|
562 (comment-indent)) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
563 (t (setq comment-column (current-column)) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
564 (message "Comment column set to %d" comment-column)))) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
565 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
566 ;;;###autoload |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
567 (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
|
568 "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
|
569 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
|
570 (interactive "P") |
50843
bc3a5a6b96ab
(comment-set-column, comment-kill, comment-or-uncomment-region):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50839
diff
changeset
|
571 (comment-normalize-vars) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
572 (dotimes (_ (prefix-numeric-value arg)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
573 (save-excursion |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
574 (beginning-of-line) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
575 (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
|
576 (when cs |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
577 (goto-char cs) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
578 (skip-syntax-backward " ") |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
579 (setq cs (point)) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
580 (comment-forward) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
581 (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
|
582 (indent-according-to-mode)))) |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
583 (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
|
584 |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
585 (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
|
586 "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
|
587 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
|
588 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
|
589 ignored from `comment-padding'. |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
590 N defaults to 0. |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
591 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
|
592 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
|
593 (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
|
594 (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
|
595 ;; 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
|
596 (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
|
597 (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
|
598 (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
|
599 (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
|
600 (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
|
601 (min (- (match-end 0) (match-end 1)) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
602 (length comment-padding))))) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
603 ;; 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
|
604 ;; 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
|
605 ;; 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
|
606 ;; and the rest becomes bogus junk. |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
607 (multi (not (and comment-quote-nested |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
608 ;; comment-end is a single char |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
609 (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
|
610 (if (not (symbolp n)) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
611 (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
|
612 ;; 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
|
613 ;; 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
|
614 (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
|
615 lpad "") ;padding is not required |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
616 (regexp-quote s) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
617 (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
|
618 (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
|
619 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
|
620 |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
621 (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
|
622 "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
|
623 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
|
624 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
|
625 ignored from `comment-padding'. |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
626 N defaults to 0. |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
627 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
|
628 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
|
629 (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
|
630 (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
|
631 ;; 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
|
632 (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
|
633 (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
|
634 (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
|
635 (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
|
636 (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
|
637 (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
|
638 (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
|
639 ;; 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
|
640 ;; 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
|
641 ;; 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
|
642 ;; 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
|
643 (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
|
644 ;; 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
|
645 (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
|
646 (if (not (symbolp n)) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
647 (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
|
648 ;; 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
|
649 ;; 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
|
650 ;; 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
|
651 ;; 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
|
652 ;; 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
|
653 ;; they were aligned). |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
654 (concat "\\s-*" |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
655 (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
|
656 (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
|
657 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
658 ;;;###autoload |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
659 (defun uncomment-region (beg end &optional arg) |
47370
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
660 "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
|
661 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
|
662 comment markers." |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
663 (interactive "*r\nP") |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
664 (comment-normalize-vars) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
665 (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
|
666 (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
|
667 (goto-char beg) |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
668 (setq end (copy-marker end)) |
47400
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
669 (let* ((numarg (prefix-numeric-value arg)) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
670 (ccs comment-continue) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
671 (srei (comment-padright ccs 're)) |
51734
400a9c7868fd
(uncomment-region): Remove padding coming from
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51337
diff
changeset
|
672 (csre (comment-padright comment-start 're)) |
47400
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
673 (sre (and srei (concat "^\\s-*?\\(" srei "\\)"))) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
674 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
|
675 (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
|
676 (setq spt (comment-search-forward end t))) |
47400
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
677 (let ((ipt (point)) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
678 ;; Find the end of the comment. |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
679 (ept (progn |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
680 (goto-char spt) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
681 (unless (comment-forward) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
682 (error "Can't find the comment end")) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
683 (point))) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
684 (box nil) |
2885b5553da7
(uncomment-region): Fix let/let* use.
Juanma Barranquero <lekktu@gmail.com>
parents:
47370
diff
changeset
|
685 (box-equal nil)) ;Whether we might be using `=' for boxes. |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
686 (save-restriction |
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
687 (narrow-to-region spt ept) |
47370
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
688 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
689 ;; 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
|
690 (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
|
691 (skip-syntax-backward " ") |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
692 ;; A box-comment starts with a looong comment-start marker. |
47370
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
693 (when (and (or (and (= (- (point) (point-min)) 1) |
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
694 (setq box-equal t) |
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
695 (looking-at "=\\{7\\}") |
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
696 (not (eq (char-before (point-max)) ?\n)) |
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
697 (skip-chars-forward "=")) |
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
698 (> (- (point) (point-min) (length comment-start)) 7)) |
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
699 (> (count-lines (point-min) (point-max)) 2)) |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
700 (setq box t)) |
51734
400a9c7868fd
(uncomment-region): Remove padding coming from
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51337
diff
changeset
|
701 ;; Skip the padding. Padding can come from comment-padding and/or |
400a9c7868fd
(uncomment-region): Remove padding coming from
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51337
diff
changeset
|
702 ;; from comment-start, so we first check comment-start. |
400a9c7868fd
(uncomment-region): Remove padding coming from
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51337
diff
changeset
|
703 (if (or (save-excursion (goto-char (point-min)) (looking-at csre)) |
400a9c7868fd
(uncomment-region): Remove padding coming from
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51337
diff
changeset
|
704 (looking-at (regexp-quote comment-padding))) |
400a9c7868fd
(uncomment-region): Remove padding coming from
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51337
diff
changeset
|
705 (goto-char (match-end 0))) |
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 (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
|
707 (goto-char (match-end 0))) |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
708 (if (null arg) (delete-region (point-min) (point)) |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
709 (skip-syntax-backward " ") |
50673
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
710 (delete-char (- numarg)) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
711 (unless (or (bobp) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
712 (save-excursion (goto-char (point-min)) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
713 (looking-at comment-start-skip))) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
714 ;; If there's something left but it doesn't look like |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
715 ;; a comment-start any more, just remove it. |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
716 (delete-region (point-min) (point)))) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
717 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
718 ;; 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
|
719 (goto-char (point-max)) (comment-enter-backward) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
720 ;; Check for special `=' used sometimes in comment-box. |
47370
408ecff0939b
(uncomment-region): Be more careful with `='.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47212
diff
changeset
|
721 (when (and box-equal (not (eq (char-before (point-max)) ?\n))) |
30090
6ea3040d5833
(uncomment-region): Be more careful when skipping
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29760
diff
changeset
|
722 (let ((pos (point))) |
6ea3040d5833
(uncomment-region): Be more careful when skipping
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29760
diff
changeset
|
723 ;; skip `=' but only if there are at least 7. |
6ea3040d5833
(uncomment-region): Be more careful when skipping
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29760
diff
changeset
|
724 (when (> (skip-chars-backward "=") -7) (goto-char pos)))) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
725 (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
|
726 (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
|
727 (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
|
728 (skip-syntax-forward " ") |
50673
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
729 (delete-char numarg) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
730 (unless (or (eobp) (looking-at comment-end-skip)) |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
731 ;; If there's something left but it doesn't look like |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
732 ;; a comment-end any more, just remove it. |
4b5928c8d588
(comment-normalize-vars): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50640
diff
changeset
|
733 (delete-region (point) (point-max))))) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
734 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
735 ;; 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
|
736 (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
|
737 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
738 ;; 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
|
739 (when sre |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
740 (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
|
741 comment-start))) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
742 (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
|
743 (ere (and erei (concat "\\(" erei "\\)\\s-*$")))) |
26647
b00a81cd0f6e
(comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26646
diff
changeset
|
744 (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
|
745 (while (progn |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
746 (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
|
747 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
|
748 (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
|
749 (setq ere nil)) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
750 (forward-line 1) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
751 (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
|
752 (replace-match "" t t nil (if (match-end 2) 2 1))))) |
42706 | 753 ;; Go to the end for the next comment. |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
754 (goto-char (point-max))))) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
755 (set-marker end nil)))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
756 |
26645
39f87d842e57
(comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26640
diff
changeset
|
757 (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
|
758 "Make the leading and trailing extra lines. |
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
759 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
|
760 (let ((eindent 0)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
761 (if (not block) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
762 ;; 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
|
763 (progn |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
764 (setq ce (comment-string-strip ce t t)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
765 (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
|
766 (setq eindent |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
767 (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
|
768 0)))) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
769 ;; box comment |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
770 (let* ((width (- max-indent min-indent)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
771 (s (concat cs "a=m" cce)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
772 (e (concat ccs "a=m" ce)) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
773 (c (if (string-match ".*\\S-\\S-" cs) |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
774 (aref cs (1- (match-end 0))) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
775 (if (and (equal comment-end "") (string-match ".*\\S-" cs)) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
776 (aref cs (1- (match-end 0))) ?=))) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
777 (re "\\s-*a=m\\s-*") |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
778 (_ (string-match re s)) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
779 (lcs (length cs)) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
780 (fill |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
781 (make-string (+ width (- (match-end 0) |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
782 (match-beginning 0) lcs 3)) c))) |
26645
39f87d842e57
(comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26640
diff
changeset
|
783 (setq cs (replace-match fill t t s)) |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
784 (when (and (not (string-match comment-start-skip cs)) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
785 (string-match "a=m" s)) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
786 ;; The whitespace around CS cannot be ignored: put it back. |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
787 (setq re "a=m") |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
788 (setq fill (make-string (- width lcs) c)) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
789 (setq cs (replace-match fill t t s))) |
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
790 (string-match re e) |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
791 (setq ce (replace-match fill t t e)))) |
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
792 (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
|
793 (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
|
794 |
39f87d842e57
(comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26640
diff
changeset
|
795 (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
|
796 "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
|
797 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
|
798 indentation to be kept as it was before narrowing." |
47467
c5035e184eba
(comment-with-narrowing): Use the `declare' thingy.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47400
diff
changeset
|
799 (declare (debug t) (indent 2)) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
800 (let ((bindent (make-symbol "bindent"))) |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
801 `(let ((,bindent (save-excursion (goto-char ,beg) (current-column)))) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
802 (save-restriction |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
803 (narrow-to-region ,beg ,end) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
804 (goto-char (point-min)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
805 (insert (make-string ,bindent ? )) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
806 (prog1 |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
807 (progn ,@body) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
808 ;; remove the bindent |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
809 (save-excursion |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
810 (goto-char (point-min)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
811 (when (looking-at " *") |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
812 (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
|
813 (delete-char n) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
814 (setq ,bindent (- ,bindent n)))) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
815 (end-of-line) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
816 (let ((e (point))) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
817 (beginning-of-line) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
818 (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
|
819 (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
|
820 (goto-char (match-beginning 0)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
821 (delete-char n) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
822 (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
|
823 |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
824 (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
|
825 &optional ccs cce block lines indent) |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
826 "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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 \(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
|
832 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
|
833 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
|
834 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
|
835 rather than at left margin." |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
836 ;;(assert (< beg end)) |
51337
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
837 (let ((no-empty (not (or (eq comment-empty-lines t) |
0237e2420453
(comment-empty-lines): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50947
diff
changeset
|
838 (and comment-empty-lines (zerop (length ce))))))) |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
839 ;; Sanitize CE and CCE. |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
840 (if (and (stringp ce) (string= "" ce)) (setq ce nil)) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
841 (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
|
842 ;; 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
|
843 (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
|
844 ;; Should we mark empty lines as well ? |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
845 (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
|
846 ;; 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
|
847 (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
|
848 ;; 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
|
849 (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
|
850 ;; 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
|
851 (unless ccs (setq ccs cs cce ce)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48257
diff
changeset
|
852 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
853 (save-excursion |
26645
39f87d842e57
(comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26640
diff
changeset
|
854 (goto-char end) |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
855 ;; 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
|
856 ;; 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
|
857 (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
|
858 (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
|
859 (let ((min-indent (point-max)) |
39864
71f93e410115
(comment-region-internal): Don't rebind
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39761
diff
changeset
|
860 (max-indent 0)) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
861 (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
|
862 ;; 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
|
863 (comment-quote-nested comment-start comment-end nil) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
864 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
865 ;; 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
|
866 (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
|
867 (while |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
868 (progn |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
869 (unless (looking-at "[ \t]*$") |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
870 (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
|
871 (end-of-line) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
872 (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
|
873 (not (or (eobp) (progn (forward-line) nil))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48257
diff
changeset
|
874 |
28904
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
875 ;; 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
|
876 (setq max-indent |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
877 (+ 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
|
878 (unless indent (setq min-indent 0)) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
879 |
26645
39f87d842e57
(comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26640
diff
changeset
|
880 ;; make the leading and trailing lines if requested |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
881 (when lines |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
882 (let ((csce |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
883 (comment-make-extra-lines |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
884 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
|
885 (setq cs (car csce)) |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
886 (setq ce (cdr csce)))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48257
diff
changeset
|
887 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
888 (goto-char (point-min)) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
889 ;; 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
|
890 (while |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
891 (progn |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
892 (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
|
893 (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
|
894 (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
|
895 (end-of-line) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
896 (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
|
897 (when cce |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
898 (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
|
899 (insert cce))) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
900 (end-of-line) |
8d91ded5215c
(comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28901
diff
changeset
|
901 (not (or (eobp) (progn (forward-line) nil)))))))))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
902 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
903 ;;;###autoload |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
904 (defun comment-region (beg end &optional arg) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
905 "Comment or uncomment each line in the region. |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
906 With just \\[universal-argument] prefix arg, uncomment each line in region BEG .. END. |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
907 Numeric prefix arg ARG means use ARG comment characters. |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
908 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
|
909 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
|
910 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
|
911 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
|
912 |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
913 The strings used as comment starts are built from |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
914 `comment-start' without trailing spaces and `comment-padding'." |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
915 (interactive "*r\nP") |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
916 (comment-normalize-vars) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
917 (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
|
918 (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
|
919 (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
|
920 (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
|
921 (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
|
922 (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
|
923 (multi (nth 0 style))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
924 (save-excursion |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
925 ;; we use `chars' instead of `syntax' because `\n' might be |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
926 ;; of end-comment syntax rather than of whitespace syntax. |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
927 ;; sanitize BEG and END |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
928 (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
|
929 (setq beg (max beg (point))) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
930 (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
|
931 (setq end (min end (point))) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
932 (if (>= beg end) (error "Nothing to comment")) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
933 |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
934 ;; sanitize LINES |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
935 (setq lines |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
936 (and |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
937 lines ;; multi |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
938 (progn (goto-char beg) (beginning-of-line) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
939 (skip-syntax-forward " ") |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
940 (>= (point) beg)) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
941 (progn (goto-char end) (end-of-line) (skip-syntax-backward " ") |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
942 (<= (point) end)) |
46870
a5e3d40d6003
(comment-region): Force `lines' when `block' is set.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45902
diff
changeset
|
943 (or block (not (string= "" comment-end))) |
a5e3d40d6003
(comment-region): Force `lines' when `block' is set.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45902
diff
changeset
|
944 (or block (progn (goto-char beg) (search-forward "\n" end t)))))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
945 |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
946 ;; 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
|
947 (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
|
948 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
949 (cond |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
950 ((consp arg) (uncomment-region beg end)) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
951 ((< numarg 0) (uncomment-region beg end (- numarg))) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
952 (t |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
953 (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
|
954 add (1- numarg))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
955 (comment-region-internal |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
956 beg end |
26763
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
957 (let ((s (comment-padright comment-start numarg))) |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
958 (if (string-match comment-start-skip s) s |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
959 (comment-padright comment-start))) |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
960 (let ((s (comment-padleft comment-end numarg))) |
5a4671b4895c
various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26663
diff
changeset
|
961 (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
|
962 (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
|
963 (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
|
964 (if multi (comment-padleft (comment-string-reverse comment-continue) numarg)) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
965 block |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
966 lines |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
967 (nth 3 style)))))) |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
968 |
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
969 (defun comment-box (beg end &optional arg) |
47212
5ddbbad82052
(comment-make-extra-lines): Only use the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46870
diff
changeset
|
970 "Comment out the BEG .. END region, putting it inside a box. |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
971 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
|
972 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
|
973 (interactive "*r\np") |
29037
238233843fc1
(comment-styles): New `box-multi'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28990
diff
changeset
|
974 (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
|
975 'box-multi 'box))) |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
976 (comment-region beg end (+ comment-add arg)))) |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
977 |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
978 |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
979 ;;;###autoload |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
980 (defun comment-or-uncomment-region (beg end &optional arg) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
981 "Call `comment-region', unless the region only consists of comments, |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
982 in which case call `uncomment-region'. If a prefix arg is given, it |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
983 is passed on to the respective function." |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
984 (interactive "*r\nP") |
50843
bc3a5a6b96ab
(comment-set-column, comment-kill, comment-or-uncomment-region):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50839
diff
changeset
|
985 (comment-normalize-vars) |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
986 (funcall (if (save-excursion ;; check for already commented region |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
987 (goto-char beg) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
988 (comment-forward (point-max)) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
989 (<= end (point))) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
990 'uncomment-region 'comment-region) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
991 beg end arg)) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
992 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
993 ;;;###autoload |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
994 (defun comment-dwim (arg) |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
995 "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
|
996 If the region is active and `transient-mark-mode' is on, call |
34301 | 997 `comment-region' (unless it only consists of comments, in which |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
998 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
|
999 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
|
1000 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
|
1001 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
|
1002 (interactive "*P") |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1003 (comment-normalize-vars) |
28901
0e7bbb764f47
(comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26763
diff
changeset
|
1004 (if (and mark-active transient-mark-mode) |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1005 (comment-or-uncomment-region (region-beginning) (region-end) arg) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1006 (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
|
1007 ;; 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
|
1008 ;; 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
|
1009 (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
|
1010 (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
|
1011 (if (= (length comment-start) 1) comment-add 0)))) |
33705
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
1012 ;; Some modes insist on keeping column 0 comment in column 0 |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
1013 ;; so we need to move away from it before inserting the comment. |
273d5b4aba82
(comment-indent): Insert comment before calling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33485
diff
changeset
|
1014 (indent-according-to-mode) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1015 (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
|
1016 (save-excursion |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1017 (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
|
1018 (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
|
1019 (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
|
1020 |
28961
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1021 (defcustom comment-auto-fill-only-comments nil |
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1022 "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
|
1023 This has no effect in modes that do not define a comment syntax." |
41286
6b56e476153d
(comment-column, comment-style, comment-multi-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41253
diff
changeset
|
1024 :type 'boolean) |
28961
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1025 |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
1026 (defun comment-valid-prefix-p (prefix compos) |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1027 (or |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1028 ;; Accept any prefix if the current comment is not EOL-terminated. |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1029 (save-excursion (goto-char compos) (comment-forward) (not (bolp))) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1030 ;; Accept any prefix that starts with a comment-start marker. |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1031 (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)") |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
1032 prefix))) |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1033 |
29215
21c457830b9d
Add abundant autoload cookies.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29119
diff
changeset
|
1034 ;;;###autoload |
28949
856f1364a955
(comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28904
diff
changeset
|
1035 (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
|
1036 "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
|
1037 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
|
1038 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
|
1039 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1040 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
|
1041 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
|
1042 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
|
1043 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1044 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
|
1045 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
|
1046 |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1047 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
|
1048 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
|
1049 (interactive) |
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1050 (comment-normalize-vars t) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1051 (let (compos comin) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1052 ;; 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
|
1053 ;; 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
|
1054 (unless (and comment-start |
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1055 comment-auto-fill-only-comments |
41286
6b56e476153d
(comment-column, comment-style, comment-multi-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41253
diff
changeset
|
1056 (not (interactive-p)) |
28961
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1057 (not (save-excursion |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1058 (prog1 (setq compos (comment-beginning)) |
28961
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1059 (setq comin (point)))))) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1060 |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1061 ;; Now we know we should auto-fill. |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1062 ;; Insert the newline before removing empty space so that markers |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1063 ;; get preserved better. |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1064 (if soft (insert-and-inherit ?\n) (newline 1)) |
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1065 (save-excursion (forward-char -1) (delete-horizontal-space)) |
34459
1007fb1b5df9
(comment-indent-new-line): Use delete-horizontal-space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34301
diff
changeset
|
1066 (delete-horizontal-space) |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1067 |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1068 (if (and fill-prefix (not adaptive-fill-mode)) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1069 ;; Blindly trust a non-adaptive fill-prefix. |
28961
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1070 (progn |
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1071 (indent-to-left-margin) |
44999
a8d9e35048ff
(comment-fill-column): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44455
diff
changeset
|
1072 (insert-before-markers-and-inherit fill-prefix)) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1073 |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1074 ;; If necessary check whether we're inside a comment. |
41253
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1075 (unless (or compos (null comment-start)) |
28961
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1076 (save-excursion |
8092e0d9d8b9
(comment-beginning): Handle unclosed comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28949
diff
changeset
|
1077 (backward-char) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1078 (setq compos (comment-beginning)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1079 (setq comin (point)))) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1080 |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1081 (cond |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1082 ;; If there's an adaptive prefix, use it unless we're inside |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1083 ;; a comment and the prefix is not a comment starter. |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1084 ((and fill-prefix |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1085 (or (not compos) |
50947
15c3c47aca50
(comment-indent): Try to align to adjacent comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50929
diff
changeset
|
1086 (comment-valid-prefix-p fill-prefix compos))) |
39761
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1087 (indent-to-left-margin) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1088 (insert-and-inherit fill-prefix)) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1089 ;; If we're not inside a comment, just try to indent. |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1090 ((not compos) (indent-according-to-mode)) |
1cf8ddfb831f
(comment-indent): Be a little more robust in case
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39486
diff
changeset
|
1091 (t |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1092 (let* ((comment-column |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1093 ;; The continuation indentation should be somewhere between |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1094 ;; 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
|
1095 ;; 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
|
1096 ;; for comment-column. |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1097 (save-excursion |
41253
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1098 ;; FIXME: use prev line's info rather than first line's. |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1099 (goto-char compos) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1100 (min (current-column) (max comment-column |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1101 (+ 2 (current-indentation)))))) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1102 (comstart (buffer-substring compos comin)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1103 (normalp |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1104 (string-match (regexp-quote (comment-string-strip |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1105 comment-start t t)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1106 comstart)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1107 (comment-end |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1108 (if normalp comment-end |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1109 ;; 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
|
1110 ;; so we can't just use comment-end. |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1111 (save-excursion |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1112 (goto-char compos) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1113 (if (not (comment-forward)) comment-end |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1114 (comment-string-strip |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1115 (buffer-substring |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1116 (save-excursion (comment-enter-backward) (point)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1117 (point)) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1118 nil t))))) |
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1119 (comment-start comstart) |
41253
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1120 (continuep (or comment-multi-line |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1121 (cadr (assoc comment-style comment-styles)))) |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1122 ;; Force comment-continue to be recreated from comment-start. |
38898
29a1feb5e1fe
(comment-beginning): Make sure the comment-start
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36490
diff
changeset
|
1123 ;; FIXME: wrong if comment-continue was set explicitly! |
41253
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1124 ;; FIXME: use prev line's continuation if available. |
28990
80e6f0d6eac1
Fix license text and author.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28961
diff
changeset
|
1125 (comment-continue nil)) |
41253
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1126 (if (and comment-multi-line (> (length comment-end) 0)) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1127 (indent-according-to-mode) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1128 (insert-and-inherit ?\n) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1129 (forward-char -1) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1130 (comment-indent continuep) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1131 (save-excursion |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1132 (let ((pt (point))) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1133 (end-of-line) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1134 (let ((comend (buffer-substring pt (point)))) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1135 ;; The 1+ is to make sure we delete the \n inserted above. |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1136 (delete-region pt (1+ (point))) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1137 (end-of-line 0) |
87ae7a37e076
(comment-indent): Fix misindentation for comment-only lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41021
diff
changeset
|
1138 (insert comend)))))))))))) |
26663
9979145a424e
(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26647
diff
changeset
|
1139 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1140 (provide 'newcomment) |
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1141 |
52401 | 1142 ;;; arch-tag: 01e3320a-00c8-44ea-a696-8f8e7354c858 |
26640
f95236e53857
First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1143 ;;; newcomment.el ends here |