annotate lisp/newcomment.el @ 28949:856f1364a955

(comment-string-strip): Strip terminating newlines. (comment-search-forward): Make LIMIT compulsory. If an unterminated string (rather than a comment) is found, try again, assuming that the region starts inside a string. (comment-beginning): Make sure we don't move if we find a comment but it's not the one we're in. (comment-enter-backward): Handle the case where comment-end-skip fails. (comment-indent): Normalize variables and use line-end-position. (comment-kill): Use line-end-position. (comment-spill): Remove. (comment-indent-new-line): Renamed from indent-new-comment-line. Cleaned up old commented-out code. Reset comment-continue and comment-end before calling comment-indent.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 16 May 2000 22:02:37 +0000
parents 8d91ded5215c
children 8092e0d9d8b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; newcomment.el --- (un)comment regions of buffers
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
3 ;; Copyright (C) 1999-2000 Free Software Foundation Inc.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
4
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
5 ;; Author: FSF??
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
6 ;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7 ;; Keywords: comment uncomment
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8 ;; Version: $Name: $
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
9 ;; Revision: $Id: newcomment.el,v 1.8 2000/05/14 00:56:10 monnier Exp $
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or modify
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
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2 of the License, or
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 ;; (at your option) any later version.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15 ;;
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful,
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.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20 ;;
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
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; along with this program; if not, write to the Free Software
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
23 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
24
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25 ;;; Commentary:
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
27 ;; A replacement for simple.el's comment-related functions.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 ;;; Bugs:
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
31 ;; - 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
32 ;; if the corresponding closing marker happens to be right.
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
33 ;; - comment-box in TeXinfo generate bogus comments @ccccc@
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
34 ;; - 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
35 ;; comment markers invalid.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 ;;; Todo:
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
39 ;; - try to align tail comments
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
40 ;; - check what c-comment-line-break-function has to say
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
41 ;; - 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
42 ;; - uncomment-region with a consp (for blocks) or somehow make the
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
43 ;; deletion of continuation markers less dangerous
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
44 ;; - drop block-comment-<foo> unless it's really used
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
45 ;; - uncomment-region on a subpart of a comment
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
46 ;; - support gnu-style "multi-line with space in continue"
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
47 ;; - 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
48 ;; is not turned on.
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
49 ;; - (from c-comment-line-break-function): c-ignore-auto-fill so that you can
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
50 ;; auto-fill comments but not code. This should probably be moved directly
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
51 ;; inside do-auto-fill.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 ;;; Code:
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 (eval-when-compile (require 'cl))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
57 (defgroup comment nil
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
58 "Indenting and filling of comments."
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
59 :prefix "comment-"
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
60 :group 'fill)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
61
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
62 (defvar comment-use-syntax 'undecided
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
63 "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
64 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
65 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
66 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
67 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
68
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 (defcustom comment-column 32
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 "*Column to indent right-margin comments to.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 Setting this variable automatically makes it local to the current buffer.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 Each mode establishes a different default value for this variable; you
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 can set the value for a particular mode using that mode's hook."
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 :type 'integer
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
75 :group 'comment)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 (make-variable-buffer-local 'comment-column)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
78 (defvar comment-start nil
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
79 "*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
80
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
81 (defvar comment-start-skip nil
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 "*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
83 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
84 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
85
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
86 (defvar comment-end-skip nil
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
87 "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
88
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
89 (defvar comment-end ""
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 "*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
91 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
92
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 (defvar comment-indent-hook nil
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 "Obsolete variable for function to compute desired indentation for a comment.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 This function is called with no args with point at the beginning of
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 the comment's starting delimiter.")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 (defvar comment-indent-function
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
99 (lambda () comment-column)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 "Function to compute desired indentation for a comment.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 This function is called with no args with point at the beginning of
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 the comment's starting delimiter.")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
104 (defvar block-comment-start nil)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
105 (defvar block-comment-end nil)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
107 (defvar comment-quote-nested t
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
108 "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
109 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
110
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
111 (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
112 "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
113 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
114 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
115 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
116 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
117 preserve indentation.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
118 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
119 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
120
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
121 (defvar comment-add 0
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
122 "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
123 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
124 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
125 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
126 two semi-colons.")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
127
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
128 (defconst comment-styles
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
129 '((plain . (nil nil nil nil))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
130 (indent . (nil nil nil t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
131 (aligned . (nil t nil t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
132 (multi-line . (t nil nil t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
133 (extra-line . (t nil t t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
134 (box . (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
135 "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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
144 (defcustom comment-style 'plain
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
145 "*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
146 See `comment-styles' for a list of available styles."
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
147 :group 'comment
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
148 :type `(choice ,@(mapcar (lambda (s) `(const ,(car s))) comment-styles)))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
149
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
150 (defcustom comment-padding 1
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
151 "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
152 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
153 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
154
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
155 Extra spacing between the comment characters and the comment text
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
156 makes the comment easier to read. Default is 1. nil means 0.")
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
157
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
158 (defcustom comment-multi-line nil
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
159 "*Non-nil means \\[indent-new-comment-line] should continue same comment
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
160 on new line, with no new terminator or starter.
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
161 This is obsolete because you might as well use \\[newline-and-indent]."
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
162 :type 'boolean
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
163 :group 'comment)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
164
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
165 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
166 ;;;; Helpers
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
167 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
168
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
169 (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
170 "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
171 (string-match (concat "\\`" (if beforep "\\s-*")
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
172 "\\(.*?\\)" (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
173 "\\'") str)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
174 (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
175
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
176 (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
177 "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
178 (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
179
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
180 (defun comment-normalize-vars (&optional noerror)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
181 (if (not comment-start) (or noerror (error "No comment syntax is defined"))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
182 ;; comment-use-syntax
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
183 (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
184 (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
185 (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
186 (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
187 (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
188 ;; 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
189 ;; 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
190 (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
191 (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
192 (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
193 (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
194 (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
195 ;; comment-padding
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
196 (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
197 (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
198 ;; comment markers
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
199 ;;(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
200 ;;(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
201 ;; comment-continue
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
202 (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
203 (set (make-local-variable 'comment-continue)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
204 (concat " " (substring comment-start 1))))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
205 ;; comment-skip regexps
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
206 (unless comment-start-skip
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
207 (set (make-local-variable 'comment-start-skip)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
208 (concat "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(\\s<+\\|"
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
209 (regexp-quote (comment-string-strip comment-start t t))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
210 "+\\)\\s-*")))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
211 (unless comment-end-skip
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
212 (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
213 (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
214 (set (make-local-variable 'comment-end-skip)
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
215 (concat "\\s-*\\(\\s>" (if comment-quote-nested "" "+")
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
216 "\\|" (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
217 (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
218 (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
219 "\\)"))))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
220
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
221 (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
222 (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
223 "\\\\" (if unp "+" "*")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
224 (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
225
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
226 (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
227 "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
228 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
229 (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
230 (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
231 (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
232 (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
233 "\\|" (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
234 (goto-char (point-min))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
235 (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
236 (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
237 (forward-char 1)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
238 (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
239 (when (= (length ce) 1)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
240 ;; 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
241 ;; "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
242 ;; 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
243 (if (not unp)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
244 (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
245 (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
246 (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
247 (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
248 (1- (match-end 0)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
249 (concat "!" cs)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
250 (backward-char 2)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
251 (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
252 (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
253
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
254 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
255 ;;;; Navigation
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
256 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
257
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
258 (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
259 "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
260 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
261 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
262 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
263 (if (not 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
264 (when (re-search-forward comment-start-skip limit noerror)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
265 (or (match-end 1) (match-beginning 0)))
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
266 (let* ((pt (point))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
267 ;; 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
268 (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
269 (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
270 ;; 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
271 ;; 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
272 (setq s (parse-partial-sexp
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
273 pt (or limit (point-max)) nil nil
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
274 (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
275 t)))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
276 (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
277 (unless noerror (error "No comment"))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
278 ;; We found the comment.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
279 (let ((pt (point))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
280 (start (nth 8 s))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
281 (bol (save-excursion (beginning-of-line) (point)))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
282 (end nil))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
283 (while (and (null end) (>= (point) bol))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
284 (if (looking-at comment-start-skip)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
285 (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
286 (backward-char)))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
287 (goto-char end)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
288 start)))))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
289
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
290 (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
291 "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
292 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
293 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
294 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
295 ;; 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
296 ;; 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
297 ;; 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
298 ;; 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
299 ;; 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
300 (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
301 (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
302 (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
303 (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
304 (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
305 (pt (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
306 (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
307 (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
308 (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
309 (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
310 (comment-forward)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
311 (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
312 (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
313 (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
314 (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
315 cs))))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
316
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
317 (defun comment-beginning ()
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
318 "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
319 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
320 the same as `comment-search-forward'."
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
321 (let ((pt (point))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
322 (cs (comment-search-backward nil t)))
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
323 (when cs
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
324 (if (save-excursion (goto-char cs) (comment-forward 1) (> (point) pt))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
325 cs
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
326 (goto-char pt)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
327 nil))))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
328
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
329 (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
330 "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
331 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
332 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
333 (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
334 (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
335 (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
336 (while (> n 0)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
337 (skip-syntax-forward " ")
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
338 (if (and (looking-at comment-start-skip)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
339 (re-search-forward comment-end-skip nil 'move))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
340 (decf n)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
341 (setq n -1)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
342 (= n 0))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
343
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
344 (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
345 "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
346 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
347 (if (bolp)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
348 ;; comment-end = ""
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
349 (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
350 (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
351 (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
352 (save-restriction
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
353 (narrow-to-region (point) end)
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
354 (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
355 (goto-char (match-beginning 0))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
356 ;; 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
357 ;; 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
358 ;; 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
359 (goto-char (point-max))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
360 (backward-char 2)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
361 (skip-chars-backward (string (char-after)))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
362 (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
363
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
364 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
365 ;;;; Commands
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
366 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
367
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
368 (defalias 'indent-for-comment 'comment-indent)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
369 (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
370 "Indent this line's comment to comment column, or insert an empty comment.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
371 If CONTINUE is non-nil, use the `comment-continuation' markers if any."
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 (interactive "*")
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
373 (comment-normalize-vars)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374 (let* ((empty (save-excursion (beginning-of-line)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
375 (looking-at "[ \t]*$")))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
376 (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
377 (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
378 (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
379 (and empty block-comment-end) comment-end)))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
380 (cond
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
381 ((null starter)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 (error "No comment syntax defined"))
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
383 (t (let* ((eolpos (line-end-position))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
384 cpos indent begpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 (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
386 (when (setq begpos (comment-search-forward eolpos t))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
387 (setq cpos (point-marker))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
388 (goto-char begpos))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
389 (setq begpos (point))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390 ;; Compute desired indent.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
391 (if (= (current-column)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392 (setq indent (if comment-indent-hook
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 (funcall comment-indent-hook)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 (funcall comment-indent-function))))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 (goto-char begpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396 ;; If that's different from current, change it.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
397 (skip-chars-backward " \t")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
398 (delete-region (point) begpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 (indent-to indent))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
400 ;; An existing comment?
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
401 (if cpos
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
402 (progn (goto-char cpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403 (set-marker cpos nil))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 ;; No, insert one.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 (insert starter)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 (save-excursion
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407 (insert ender))))))))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
409 (defalias 'set-comment-column 'comment-set-column)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
410 (defun comment-set-column (arg)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
411 "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
412 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
413 With just minus as arg, kill any comment on this line.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
414 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
415 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
416 (interactive "P")
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
417 (cond
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
418 ((eq arg '-) (comment-kill nil))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
419 (arg
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
420 (save-excursion
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
421 (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
422 (comment-search-backward)
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
423 (beginning-of-line)
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
424 (goto-char (comment-search-forward (line-end-position)))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425 (setq comment-column (current-column))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
426 (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
427 (comment-indent))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
428 (t (setq comment-column (current-column))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429 (message "Comment column set to %d" comment-column))))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
430
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
431 (defalias 'kill-comment 'comment-kill)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
432 (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
433 "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
434 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
435 (interactive "P")
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
436 (dotimes (_ (prefix-numeric-value arg))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
437 (save-excursion
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
438 (beginning-of-line)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
439 (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
440 (when cs
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
441 (goto-char cs)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
442 (skip-syntax-backward " ")
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
443 (setq cs (point))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
444 (comment-forward)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
445 (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
446 (indent-according-to-mode))))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
447 (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
448
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
449 (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
450 "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
451 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
452 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
453 ignored from `comment-padding'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
454 N defaults to 0.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
455 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
456 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
457 (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
458 (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
459 ;; 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
460 (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
461 (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
462 (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
463 (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
464 (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
465 (min (- (match-end 0) (match-end 1))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
466 (length comment-padding))))))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
467 (if (not (symbolp n))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
468 (concat lpad s (make-string n (aref str (1- (match-end 1)))) rpad)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
469 ;; 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
470 ;; 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
471 (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
472 lpad "") ;padding is not required
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
473 (regexp-quote s) "+" ;the last char of S might be repeated
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
474 (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
475 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
476
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
477 (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
478 "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
479 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
480 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
481 ignored from `comment-padding'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
482 N defaults to 0.
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
483 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
484 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
485 (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
486 (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
487 ;; 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
488 (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
489 (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
490 (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
491 (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
492 (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
493 (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
494 (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
495 ;; 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
496 ;; 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
497 ;; 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
498 ;; 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
499 (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
500 ;; 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
501 (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
502 (if (not (symbolp n))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
503 (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
504 ;; 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
505 ;; 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
506 ;; 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
507 ;; 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
508 ;; 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
509 ;; they were aligned).
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
510 (concat "\\s-*"
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
511 (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
512 (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
513
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 (defun uncomment-region (beg end &optional arg)
26646
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
515 "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
516 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
517 comment markers."
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 (interactive "*r\nP")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 (comment-normalize-vars)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 (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
521 (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
522 (goto-char beg)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
523 (setq end (copy-marker end))
26646
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
524 (let ((numarg (prefix-numeric-value arg))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
525 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
526 (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
527 (setq spt (comment-search-forward end t)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
528 (let* ((ipt (point))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
529 ;; Find the end of the comment.
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
530 (ept (progn
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
531 (goto-char spt)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
532 (unless (comment-forward)
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
533 (error "Can't find the comment end"))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
534 (point)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
535 (box nil)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
536 (ccs comment-continue)
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
537 (srei (comment-padright ccs 're))
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
538 (sre (and srei (concat "^\\s-*?\\(" srei "\\)"))))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
539 (save-restriction
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
540 (narrow-to-region spt ept)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
541 ;; 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
542 (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
543 (skip-syntax-backward " ")
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
544 ;; A box-comment starts with a looong comment-start marker.
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
545 (when (> (- (point) (point-min) (length comment-start)) 7)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
546 (setq box t))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
547 (when (looking-at (regexp-quote comment-padding))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
548 (goto-char (match-end 0)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
549 (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
550 (goto-char (match-end 0)))
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
551 (if (null arg) (delete-region (point-min) (point))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
552 (skip-syntax-backward " ")
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
553 (delete-char (- numarg)))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
554
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
555 ;; 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
556 (goto-char (point-max)) (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
557 (unless (string-match "\\`\\(\n\\|\\s-\\)*\\'"
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
558 (buffer-substring (point) (point-max)))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
559 (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
560 (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
561 (skip-syntax-forward " ")
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
562 (delete-char numarg)))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
563
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
564 ;; 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
565 (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
566
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
567 ;; 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
568 (when sre
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
569 (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
570 comment-start)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
571 (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
572 (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
573 (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
574 (while (progn
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
575 (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
576 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
577 (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
578 (setq ere nil))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
579 (forward-line 1)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
580 (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
581 (replace-match "" t t nil (if (match-end 2) 2 1)))))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
582 ;; Go the the end for the next comment.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
583 (goto-char (point-max)))))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
584 (set-marker end nil))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
585
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
586 (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
587 "Make the leading and trailing extra lines.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
588 This is used for `extra-line' style (or `box' style if BLOCK is specified)."
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
589 (if block
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
590 (let* ((s (concat cs "a=m" cce "\n"
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
591 (make-string min-indent ? ) ccs))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
592 (e (concat cce "\n" (make-string min-indent ? )
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
593 ccs "a=m" ce))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
594 (_ (assert (string-match "\\s-*\\(a=m\\)\\s-*" s)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
595 (fill (make-string (+ (- max-indent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
596 min-indent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
597 (match-beginning 0))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
598 (- (match-end 0)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
599 (match-end 1)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
600 (aref s (match-end 0)))))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
601 (setq cs (replace-match fill t t s))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
602 (assert (string-match "\\s-*\\(a=m\\)\\s-*" e))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
603 (setq ce (replace-match fill t t e)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
604 (when (and ce (string-match "\\`\\s-*\\(.*\\S-\\)\\s-*\\'" ce))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
605 (setq ce (match-string 1 ce)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
606 (let* ((c (concat ce "a=m" cs))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
607 (indent (if (string-match "\\(.+\\).*a=m\\(.*\\)\\1" c)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
608 (max (+ min-indent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
609 (- (match-end 2) (match-beginning 2))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
610 (- (match-beginning 0)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
611 0)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
612 min-indent)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
613 (setq ce (concat cce "\n" (make-string indent ? ) (or ce cs)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
614 (setq cs (concat cs "\n" (make-string min-indent ? ) ccs))))
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
615 (cons cs ce))
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
616
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
617 (def-edebug-spec comment-with-narrowing t)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
618 (put 'comment-with-narrowing 'lisp-indent-function 2)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
619 (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
620 "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
621 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
622 indentation to be kept as it was before narrowing."
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
623 `(let ((-bindent (save-excursion (goto-char beg) (current-column))))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
624 (save-restriction
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
625 (narrow-to-region beg end)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
626 (goto-char (point-min))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
627 (insert (make-string -bindent ? ))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
628 (prog1
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
629 (progn ,@body)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
630 ;; remove the -bindent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
631 (save-excursion
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
632 (goto-char (point-min))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
633 (when (looking-at " *")
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
634 (let ((n (min (- (match-end 0) (match-beginning 0)) -bindent)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
635 (delete-char n)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
636 (decf -bindent n)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
637 (end-of-line)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
638 (let ((e (point)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
639 (beginning-of-line)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
640 (while (and (> -bindent 0) (re-search-forward " +" e t))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
641 (let ((n (min -bindent (- (match-end 0) (match-beginning 0) 1))))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
642 (goto-char (match-beginning 0))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
643 (delete-char n)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
644 (decf -bindent n)))))))))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
645
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
646 (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
647 &optional ccs cce block lines indent)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
648 "Comment region BEG..END.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
649 CS and CE are the comment start resp. end string.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
650 CCS and CCE are the comment continuation strings for the start resp. end
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
651 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
652 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
653 \(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
654 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
655 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
656 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
657 rather than at left margin."
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
658 (assert (< beg end))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
659 (let ((no-empty t))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
660 ;; Sanitize CE and CCE.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
661 (if (and (stringp ce) (string= "" ce)) (setq ce nil))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
662 (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
663 ;; 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
664 (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
665 ;; Should we mark empty lines as well ?
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
666 (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
667 ;; 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
668 (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
669 ;; 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
670 (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
671 ;; 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
672 (unless ccs (setq ccs cs cce ce))
26646
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
673
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
674 (save-excursion
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
675 (goto-char end)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
676 ;; 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
677 ;; 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
678 (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
679 (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
680 (let ((min-indent (point-max))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
681 (max-indent 0))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682 (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
683 ;; 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
684 (comment-quote-nested comment-start comment-end nil)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
685
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
686 ;; Loop over all lines to find the needed indentations.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
687 (while
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
688 (progn
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
689 (unless (looking-at "[ \t]*$")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
690 (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
691 (end-of-line)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
692 (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
693 (not (or (eobp) (progn (forward-line) nil)))))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
694
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
695 ;; Inserting ccs can change max-indent by (1- tab-width).
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696 (incf max-indent (+ (max (length cs) (length ccs)) -1 tab-width))
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
697 (unless indent (setq min-indent 0))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
699 ;; make the leading and trailing lines if requested
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 (when lines
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
701 (let ((csce
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
702 (comment-make-extra-lines
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
703 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
704 (setq cs (car csce))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
705 (setq ce (cdr csce))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
706
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 (goto-char (point-min))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 ;; 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
709 (while
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
710 (progn
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
711 (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
712 (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
713 (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
714 (end-of-line)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
715 (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
716 (when cce
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
717 (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
718 (insert cce)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
719 (end-of-line)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
720 (not (or (eobp) (progn (forward-line) nil))))))))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
721
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (defun comment-region (beg end &optional arg)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 "Comment or uncomment each line in the region.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 With just \\[universal-prefix] prefix arg, uncomment each line in region BEG..END.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 Numeric prefix arg ARG means use ARG comment characters.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726 If ARG is negative, delete that many comment characters instead.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727 Comments are terminated on each line, even for syntax in which newline does
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 not end the comment. Blank lines do not get comments.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
729
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 The strings used as comment starts are built from
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
731 `comment-start' without trailing spaces and `comment-padding'."
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (interactive "*r\nP")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733 (comment-normalize-vars)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (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
735 (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
736 (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
737 (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
738 (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
739 (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
740 (multi (nth 0 style)))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
741 (save-excursion
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742 ;; we use `chars' instead of `syntax' because `\n' might be
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
743 ;; of end-comment syntax rather than of whitespace syntax.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 ;; sanitize BEG and END
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745 (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
746 (setq beg (max beg (point)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
747 (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
748 (setq end (min end (point)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
749 (if (>= beg end) (error "Nothing to comment"))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
751 ;; sanitize LINES
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
752 (setq lines
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
753 (and
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
754 lines multi
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
755 (progn (goto-char beg) (beginning-of-line)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
756 (skip-syntax-forward " ")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (>= (point) beg))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
758 (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
759 (<= (point) end))
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
760 (or (not (string= "" comment-end)) block)
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
761 (progn (goto-char beg) (search-forward "\n" end t)))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
763 ;; 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
764 (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
765
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (cond
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767 ((consp arg) (uncomment-region beg end))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768 ((< numarg 0) (uncomment-region beg end (- numarg)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
769 (t
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
770 (if (and (null arg) (= (length comment-start) 1))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
771 (setq numarg add) (decf numarg))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
772 (comment-region-internal
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
773 beg end
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
774 (let ((s (comment-padright comment-start numarg)))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
775 (if (string-match comment-start-skip s) s
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
776 (comment-padright comment-start)))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
777 (let ((s (comment-padleft comment-end numarg)))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
778 (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
779 (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
780 (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
781 (if multi (comment-padleft (comment-string-reverse comment-continue) numarg))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
782 block
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
783 lines
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
784 (nth 3 style))))))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
785
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
786 (defun comment-box (beg end &optional arg)
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
787 "Comment out the BEG..END region, putting it inside a box.
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
788 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
789 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
790 (interactive "*r\np")
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
791 (let ((comment-style 'box))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
792 (comment-region beg end (+ comment-add arg))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
794 (defun comment-dwim (arg)
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
795 "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
796 If the region is active and `transient-mark-mode' is on, call
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
797 `comment-region' (unless it only consists in comments, in which
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
798 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
799 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
800 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
801 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
802 (interactive "*P")
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
803 (comment-normalize-vars)
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
804 (if (and mark-active transient-mark-mode)
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
805 (let ((beg (min (point) (mark)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
806 (end (max (point) (mark))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
807 (if (save-excursion ;; check for already commented region
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
808 (goto-char beg)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
809 (comment-forward (point-max))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
810 (<= end (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
811 (uncomment-region beg end arg)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
812 (comment-region beg end arg)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
813 (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
814 ;; 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
815 ;; 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
816 (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
817 (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
818 (if (= (length comment-start) 1) comment-add 0))))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
819 (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
820 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
821 (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
822 (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
823 (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
824
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
825 (defalias 'indent-new-comment-line 'comment-indent-new-line)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
826 (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
827 "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
828 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
829 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
830
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
831 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
832 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
833 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
834
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
835 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
836 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
837
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
838 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
839 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
840 (interactive)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
841 (comment-normalize-vars t)
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
842 (let (comcol comstart compt)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
843 (delete-region (progn (skip-chars-backward " \t") (point))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
844 (progn (skip-chars-forward " \t") (point)))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
845 (if soft (insert-and-inherit ?\n) (newline 1))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
846 (if fill-prefix
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
847 (progn
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
848 (indent-to-left-margin)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
849 (insert-and-inherit fill-prefix))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
850 (unless comment-multi-line
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
851 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
852 (backward-char)
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
853 (when (and comment-start
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
854 (setq compt (comment-beginning)))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
855 ;; The old line has a comment and point was inside the comment.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
856 ;; Indent this line like what we found.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
857 (setq comstart (buffer-substring compt (point)))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
858 (goto-char compt)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
859 (setq comcol (current-column)))))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
860 (if compt
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
861 (let* ((comment-column comcol)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
862 (normal-comment
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
863 (string-match (regexp-quote (comment-string-strip
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
864 comment-start t t))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
865 comstart))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
866 ;; Force comment-continue to be recreated from comment-start.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
867 (comment-continue nil) ;(if normal-comment comment-continue)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
868 (comment-end
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
869 (if normal-comment comment-end
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
870 ;; The comment starter is not the normal comment-start
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
871 ;; so we can't just use comment-end.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
872 (save-excursion
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
873 (goto-char compt)
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
874 (if (not (comment-forward)) comment-end
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
875 (comment-string-strip
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
876 (buffer-substring
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
877 (save-excursion (comment-enter-backward) (point))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
878 (point))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
879 nil t)))))
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
880 (comment-start comstart))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
881 ;;(if (not (eolp)) (setq comment-end ""))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
882 (insert-and-inherit ?\n)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
883 (forward-char -1)
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
884 (comment-indent (cadr (assoc comment-style comment-styles)))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
885 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
886 (let ((pt (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
887 (end-of-line)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
888 (let ((comend (buffer-substring pt (point))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
889 ;; The 1+ is to make sure we delete the \n inserted above.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
890 (delete-region pt (1+ (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
891 (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
892 (backward-char)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
893 (insert comend)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
894 (forward-char)))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
895 (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
896
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
897 (provide 'newcomment)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
898
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
899 ;;; Change Log:
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
900 ;; $Log: newcomment.el,v $
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
901 ;; Revision 1.8 2000/05/14 00:56:10 monnier
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
902 ;; (comment-start, comment-start-skip, comment-end): Made `defvar'.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
903 ;; (comment-style): Extract the choice out of comment-styles.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
904 ;; (comment-continue): Just a simple string now.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
905 ;; (comment-normalize-vars): Update for the new comment-continue.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
906 ;; (until, comment-end-quote-re): Removed.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
907 ;; (comment-quote-re, comment-quote-nested): New functions for quoting.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
908 ;; These quote both the end and the start and also work for single-chars.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
909 ;; (comment-padright): Added lots of comments.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
910 ;; (comment-padleft): Added more comments. Check comment-end rather than
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
911 ;; STR to determine whether N can be applied or not.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
912 ;; (uncomment-region): Rename BLOCK to BOX.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
913 ;; Use the new comment-quote-nested.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
914 ;; Use only one marker and properly set it back to nil.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
915 ;; Be more picky when eliminating continuation markers.
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
916 ;;
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
917 ;; Revision 1.7 2000/05/13 19:41:08 monnier
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
918 ;; (comment-use-syntax): Change `maybe' to `undecided'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
919 ;; (comment-quote-nested): New. Replaces comment-nested.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
920 ;; (comment-add): Turn into a mere defvar or a integer.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
921 ;; (comment-style): Change default to `plain'.
28949
856f1364a955 (comment-string-strip): Strip terminating newlines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28904
diff changeset
922 ;; (comment-styles): Rename `plain' to `indent' and create a new plainer `plain'
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
923 ;; (comment-string-reverse): Use nreverse.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
924 ;; (comment-normalize-vars): Change `maybe' to `undecided', add comments.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
925 ;; Don't infer the setting of comment-nested anymore (the default for
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
926 ;; comment-quote-nested is safe). Use comment-quote-nested.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
927 ;; (comment-end-quote-re): Use comment-quote-nested.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
928 ;; (comment-search-forward): Obey LIMIT.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
929 ;; (comment-indent): Don't skip forward further past comment-search-forward.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
930 ;; (comment-padleft): Use comment-quote-nested.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
931 ;; (comment-make-extra-lines): Use `cons' rather than `values'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
932 ;; (comment-region-internal): New arg INDENT. Use line-end-position.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
933 ;; Avoid multiple-value-setq.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
934 ;; (comment-region): Follow the new comment-add semantics.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
935 ;; Don't do box comments any more.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
936 ;; (comment-box): New function.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
937 ;; (comment-dwim): Only do the region stuff is transient-mark-active.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
938 ;;
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
939 ;; Revision 1.6 1999/12/08 00:19:51 monnier
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
940 ;; various fixes and gratuitous movements.
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
941 ;;
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
942 ;; Revision 1.5 1999/11/30 16:20:55 monnier
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
943 ;; (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
944 ;; (comment-use-syntax): Whether to use the syntax-table or just the regexps.
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
945 ;; (comment-end-skip): To find the end of the text.
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
946 ;; ...
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
947 ;;
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
948 ;; Revision 1.4 1999/11/29 01:31:47 monnier
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
949 ;; (comment-find): New function.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
950 ;; (indent-for-comment, set-comment-column, kill-comment): use it.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
951 ;;
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
952 ;; Revision 1.3 1999/11/29 00:49:18 monnier
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
953 ;; (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
954 ;; (comment-normalize-vars): Set default (cdr comment-continue)
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
955 ;; (comment-end-quote-re): new function taken out of `comment-region-internal'
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
956 ;; (uncomment-region): Rewritten using syntax-tables. Also unquotes
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
957 ;; nested comment-ends and eliminates continuation markers.
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
958 ;; (comment-region-internal): Don't create a default for cce.
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
959 ;; Use `comment-end-quote-re'.
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
960 ;;
26646
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
961 ;; Revision 1.2 1999/11/28 21:33:55 monnier
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
962 ;; (comment-make-extra-lines): Moved out of comment-region-internal.
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
963 ;; (comment-with-narrowing): New macro. Provides a way to preserve
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
964 ;; indentation inside narrowing.
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
965 ;; (comment-region-internal): Add "\n" to close the comment if necessary.
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
966 ;; Correctly handle commenting-out when BEG is not bolp.
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
967 ;;
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
968 ;; Revision 1.1 1999/11/28 18:51:06 monnier
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
969 ;; First "working" version:
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
970 ;; - uncomment-region doesn't work for some unknown reason
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
971 ;; - comment-multi-line allows the use of multi line comments
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
972 ;; - comment-extra-lines allows yet another style choice
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
973 ;; - comment-add allows to default to `;;'
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
974 ;; - comment-region on a comment calls uncomment-region
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
975 ;; - C-u C-u comment-region aligns comment end markers
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
976 ;; - C-u C-u C-u comment-region puts the comment inside a rectangle
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
977 ;; - comment-region will try to quote comment-end markers inside the region
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
978 ;; - comment-start markers are placed at the indentation level
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
979 ;;
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
980
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
981 ;;; newcomment.el ends here