annotate lisp/newcomment.el @ 28904:8d91ded5215c

(comment-start, comment-start-skip, comment-end): Made `defvar'. (comment-style): Extract the choice out of comment-styles. (comment-continue): Just a simple string now. (comment-normalize-vars): Update for the new comment-continue. (until, comment-end-quote-re): Removed. (comment-quote-re, comment-quote-nested): New functions for quoting. These quote both the end and the start and also work for single-chars. (comment-padright): Added lots of comments. (comment-padleft): Added more comments. Check comment-end rather than STR to determine whether N can be applied or not. (uncomment-region): Rename BLOCK to BOX. Use the new comment-quote-nested. Use only one marker and properly set it back to nil. Be more picky when eliminating continuation markers.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 14 May 2000 00:56:10 +0000
parents 0e7bbb764f47
children 856f1364a955
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: $
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
9 ;; Revision: $Id: newcomment.el,v 1.7 2000/05/13 19:41:08 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 ;; - the code assumes that bol is outside of any comment/string.
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
35 ;; - 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
36 ;; comment markers invalid.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;;; Todo:
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
40 ;; - try to align tail comments
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
41 ;; - 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
42 ;; - 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
43 ;; - 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
44 ;; 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
45 ;; - 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
46 ;; - 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
47 ;; - 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
48 ;; - 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
49 ;; is not turned on.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 ;;; Code:
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 (eval-when-compile (require 'cl))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
55 (defgroup comment nil
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
56 "Indenting and filling of comments."
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
57 :prefix "comment-"
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
58 :group 'fill)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
59
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
60 (defvar comment-use-syntax 'undecided
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
61 "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
62 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
63 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
64 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
65 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
66
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 (defcustom comment-column 32
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 "*Column to indent right-margin comments to.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 Setting this variable automatically makes it local to the current buffer.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 Each mode establishes a different default value for this variable; you
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 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
72 :type 'integer
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
73 :group 'comment)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 (make-variable-buffer-local 'comment-column)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
76 (defvar comment-start nil
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
77 "*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
78
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
79 (defvar comment-start-skip nil
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 "*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
81 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
82 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
83
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
84 (defvar comment-end-skip nil
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
85 "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
86
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
87 (defvar comment-end ""
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 "*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
89 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
90
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 (defvar comment-indent-hook nil
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 "Obsolete variable for function to compute desired indentation for a comment.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 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
94 the comment's starting delimiter.")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 (defvar comment-indent-function
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
97 (lambda () comment-column)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 "Function to compute desired indentation for a comment.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 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
100 the comment's starting delimiter.")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
102 (defvar block-comment-start nil)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
103 (defvar block-comment-end nil)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
105 (defvar comment-quote-nested t
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
106 "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
107 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
108
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
109 (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
110 "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
111 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
112 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
113 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
114 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
115 preserve indentation.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
116 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
117 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
118
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
119 (defvar comment-add 0
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
120 "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
121 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
122 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
123 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
124 two semi-colons.")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
125
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
126 (defconst comment-styles
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
127 '((plain . (nil nil nil nil))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
128 (indent . (nil nil nil t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
129 (aligned . (nil t nil t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
130 (multi-line . (t nil nil t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
131 (extra-line . (t nil t t))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
132 (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
133 "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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
142 (defcustom comment-style 'plain
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
143 "*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
144 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
145 :group 'comment
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
146 :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
147
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
148 (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
149 "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
150 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
151 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
152
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
153 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
154 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
155
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
156 (defcustom comment-multi-line nil
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
157 "*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
158 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
159 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
160 :type 'boolean
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
161 :group 'comment)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
162
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
163 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
164 ;;;; Helpers
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
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
167 (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
168 "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
169 (string-match (concat "\\`" (if beforep "\\s-*")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
170 "\\(.*?\\)" (if afterp "\\s-*")
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
171 "\\'") str)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
172 (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
173
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
174 (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
175 "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
176 (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
177
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
178 (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
179 (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
180 ;; comment-use-syntax
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
181 (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
182 (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
183 (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
184 (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
185 (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
186 ;; 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
187 ;; 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
188 (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
189 (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
190 (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
191 (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
192 (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
193 ;; comment-padding
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
194 (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
195 (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
196 ;; comment markers
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-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
198 ;;(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
199 ;; comment-continue
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
200 (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
201 (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
202 (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
203 ;; 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
204 (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
205 (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
206 (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
207 (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
208 "+\\)\\s-*")))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
209 (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
210 (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
211 (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
212 (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
213 (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
214 "\\|" (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
215 (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
216 (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
217 "\\)"))))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
218
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
219 (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
220 (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
221 "\\\\" (if unp "+" "*")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
222 (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
223
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
224 (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
225 "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
226 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
227 (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
228 (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
229 (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
230 (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
231 "\\|" (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
232 (goto-char (point-min))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
233 (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
234 (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
235 (forward-char 1)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
236 (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
237 (when (= (length ce) 1)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
238 ;; 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
239 ;; "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
240 ;; 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
241 (if (not unp)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
242 (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
243 (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
244 (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
245 (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
246 (1- (match-end 0)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
247 (concat "!" cs)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
248 (backward-char 2)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
249 (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
250 (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
251
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
252 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
253 ;;;; Navigation
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
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
256 (defun comment-search-forward (&optional limit noerror)
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
257 "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
258 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
259 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
260 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
261 (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
262 (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
263 (or (match-end 1) (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
264 (let ((s (parse-partial-sexp (point) (or limit (point-max)) nil nil nil t)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
265 (if (and (nth 8 s) (not (nth 3 s)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
266 (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
267 (start (nth 8 s))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
268 (bol (save-excursion (beginning-of-line) (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
269 (end nil))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
270 (while (and (null end) (>= (point) bol))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
271 (if (looking-at comment-start-skip)
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
272 (setq end (min (or limit (point-max)) (match-end 0)))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
273 (backward-char)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
274 (goto-char end)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
275 start)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
276 (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
277
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
278 (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
279 "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
280 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
281 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
282 and raises an error or returns nil of NOERROR 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
283 (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
284 (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
285 (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
286 (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
287 (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
288 (pt (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
289 (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
290 (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
291 (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
292 (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
293 (comment-forward)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
294 (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
295 (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
296 (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
297 (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
298 cs))))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
299
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
300 (defun comment-beginning ()
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
301 "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
302 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
303 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
304 (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
305 (cs (comment-search-backward nil t)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
306 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
307 (and cs
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
308 (progn (goto-char cs) (forward-comment 1) (> (point) pt))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
309 cs))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
310
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
311 (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
312 "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
313 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
314 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
315 (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
316 (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
317 (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
318 (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
319 (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
320 (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
321 (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
322 (decf n)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
323 (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
324 (= n 0))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
325
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
326 (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
327 "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
328 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
329 (if (bolp)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
330 ;; comment-end = ""
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
331 (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
332 (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
333 (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
334 (save-restriction
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
335 (narrow-to-region (point) end)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
336 (re-search-forward (concat 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
337 (goto-char (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
338
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
339 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
340 ;;;; Commands
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
341 ;;;;
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
342
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
343 (defalias 'indent-for-comment 'comment-indent)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
344 (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
345 "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
346 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
347 (interactive "*")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
348 (let* ((empty (save-excursion (beginning-of-line)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 (looking-at "[ \t]*$")))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
350 (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
351 (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
352 (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
353 (and empty block-comment-end) comment-end)))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354 (cond
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
355 ((null starter)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
356 (error "No comment syntax defined"))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
357 (t (let* ((eolpos (save-excursion (end-of-line) (point)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358 cpos indent begpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 (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
360 (when (setq begpos (comment-search-forward eolpos t))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
361 (setq cpos (point-marker))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
362 (goto-char begpos))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
363 (setq begpos (point))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 ;; Compute desired indent.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
365 (if (= (current-column)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
366 (setq indent (if comment-indent-hook
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 (funcall comment-indent-hook)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
368 (funcall comment-indent-function))))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
369 (goto-char begpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
370 ;; If that's different from current, change it.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371 (skip-chars-backward " \t")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 (delete-region (point) begpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
373 (indent-to indent))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374 ;; An existing comment?
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
375 (if cpos
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376 (progn (goto-char cpos)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
377 (set-marker cpos nil))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
378 ;; No, insert one.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
379 (insert starter)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
380 (save-excursion
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
381 (insert ender))))))))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
383 (defalias 'set-comment-column 'comment-set-column)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
384 (defun comment-set-column (arg)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 "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
386 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
387 With just minus as arg, kill any comment on this line.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 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
389 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
390 (interactive "P")
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
391 (cond
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
392 ((eq arg '-) (kill-comment nil))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
393 (arg
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
394 (save-excursion
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
395 (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
396 (comment-search-backward)
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
397 (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
398 (goto-char (comment-search-forward))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 (setq comment-column (current-column))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
400 (message "Comment column set to %d" comment-column))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
401 (indent-for-comment))
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
402 (t (setq comment-column (current-column))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403 (message "Comment column set to %d" comment-column))))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
405 (defalias 'kill-comment 'comment-kill)
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
406 (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
407 "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
408 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
409 (interactive "P")
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
410 (let (endc)
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
411 (dotimes (_ (prefix-numeric-value arg))
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
412 (save-excursion
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
413 (end-of-line)
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
414 (setq endc (point))
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
415 (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
416 (let ((cs (comment-search-forward endc 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
417 (when cs
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
418 (goto-char cs)
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
419 (skip-syntax-backward " ")
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
420 (setq cs (point))
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
421 (comment-forward)
26646
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
422 (kill-region cs (if (bolp) (1- (point)) (point)))
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
423 (indent-according-to-mode))))
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
424 (if arg (forward-line 1)))))
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
425
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
426 (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
427 "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
428 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
429 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
430 ignored from `comment-padding'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
431 N defaults to 0.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
432 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
433 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
434 (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
435 (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
436 ;; 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
437 (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
438 (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
439 (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
440 (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
441 (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
442 (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
443 (length comment-padding))))))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
444 (if (not (symbolp n))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
445 (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
446 ;; 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
447 ;; 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
448 (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
449 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
450 (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
451 (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
452 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
453
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
454 (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
455 "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
456 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
457 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
458 ignored from `comment-padding'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
459 N defaults to 0.
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
460 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
461 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
462 (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
463 (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
464 ;; 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
465 (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
466 (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
467 (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
468 (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
469 (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
470 (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
471 (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
472 ;; 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
473 ;; 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
474 ;; 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
475 ;; 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
476 (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
477 ;; 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
478 (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
479 (if (not (symbolp n))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
480 (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
481 ;; 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
482 ;; 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
483 ;; 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
484 ;; 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
485 ;; 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
486 ;; they were aligned).
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
487 (concat "\\s-*"
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
488 (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
489 (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
490
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 (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
492 "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
493 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
494 comment markers."
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 (interactive "*r\nP")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 (comment-normalize-vars)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 (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
498 (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
499 (goto-char beg)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
500 (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
501 (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
502 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
503 (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
504 (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
505 (let* ((ipt (point))
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
506 ;; Find the end of the comment.
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
507 (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
508 (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
509 (unless (comment-forward)
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
510 (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
511 (point)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
512 (box nil)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
513 (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
514 (srei (comment-padright ccs 're))
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
515 (sre (and srei (concat "^\\s-*?\\(" srei "\\)"))))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
516 (save-restriction
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
517 (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
518 ;; 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
519 (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
520 (skip-syntax-backward " ")
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
521 ;; 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
522 (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
523 (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
524 (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
525 (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
526 (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
527 (goto-char (match-end 0)))
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
528 (if (null arg) (delete-region (point-min) (point))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
529 (skip-syntax-backward " ")
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
530 (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
531
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
532 ;; 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
533 (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
534 (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
535 (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
536 (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
537 (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
538 (skip-syntax-forward " ")
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
539 (delete-char numarg)))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
540
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
541 ;; 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
542 (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
543
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
544 ;; 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
545 (when sre
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
546 (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
547 comment-start)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
548 (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
549 (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
550 (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
551 (while (progn
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
552 (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
553 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
554 (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
555 (setq ere nil))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
556 (forward-line 1)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
557 (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
558 (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
559 ;; 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
560 (goto-char (point-max)))))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
561 (set-marker end nil))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
562
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
563 (defun comment-make-extra-lines (cs ce ccs cce min-indent max-indent &optional block)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
564 (if block
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
565 (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
566 (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
567 (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
568 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
569 (_ (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
570 (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
571 min-indent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
572 (match-beginning 0))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
573 (- (match-end 0)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
574 (match-end 1)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
575 (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
576 (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
577 (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
578 (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
579 (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
580 (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
581 (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
582 (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
583 (max (+ min-indent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
584 (- (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
585 (- (match-beginning 0)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
586 0)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
587 min-indent)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
588 (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
589 (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
590 (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
591
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
592 (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
593 (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
594 (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
595 "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
596 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
597 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
598 `(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
599 (save-restriction
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
600 (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
601 (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
602 (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
603 (prog1
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
604 (progn ,@body)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
605 ;; remove the -bindent
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
606 (save-excursion
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
607 (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
608 (when (looking-at " *")
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
609 (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
610 (delete-char n)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
611 (decf -bindent n)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
612 (end-of-line)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
613 (let ((e (point)))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
614 (beginning-of-line)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
615 (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
616 (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
617 (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
618 (delete-char n)
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
619 (decf -bindent n)))))))))
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
620
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
621 (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
622 &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
623 "Comment region BEG..END.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
624 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
625 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
626 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
627 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
628 \(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
629 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
630 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
631 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
632 rather than at left margin."
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
633 (assert (< beg end))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
634 (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
635 ;; Sanitize CE and CCE.
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
636 (if (and (stringp ce) (string= "" ce)) (setq ce nil))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
637 (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
638 ;; 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
639 (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
640 ;; Should we mark empty lines as well ?
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
641 (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
642 ;; 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
643 (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
644 ;; 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
645 (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
646 ;; 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
647 (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
648
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
649 (save-excursion
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
650 (goto-char end)
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
651 ;; 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
652 ;; 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
653 (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
654 (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
655 (let ((min-indent (point-max))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
656 (max-indent 0))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
657 (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
658 ;; 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
659 (comment-quote-nested comment-start comment-end nil)
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
660
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
661 ;; 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
662 (while
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
663 (progn
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
664 (unless (looking-at "[ \t]*$")
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
665 (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
666 (end-of-line)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
667 (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
668 (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
669
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
670 ;; Inserting ccs can change max-indent by (1- tab-width).
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
671 (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
672 (unless indent (setq min-indent 0))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
674 ;; make the leading and trailing lines if requested
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
675 (when lines
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
676 (let ((csce
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
677 (comment-make-extra-lines
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
678 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
679 (setq cs (car csce))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
680 (setq ce (cdr csce))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
681
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682 (goto-char (point-min))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
683 ;; 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
684 (while
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
685 (progn
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
686 (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
687 (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
688 (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
689 (end-of-line)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
690 (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
691 (when cce
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
692 (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
693 (insert cce)))
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
694 (end-of-line)
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
695 (not (or (eobp) (progn (forward-line) nil))))))))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
697 (defun comment-region (beg end &optional arg)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 "Comment or uncomment each line in the region.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
699 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
700 Numeric prefix arg ARG means use ARG comment characters.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
701 If ARG is negative, delete that many comment characters instead.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702 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
703 not end the comment. Blank lines do not get comments.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
704
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
705 The strings used as comment starts are built from
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
706 `comment-start' without trailing spaces and `comment-padding'."
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 (interactive "*r\nP")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 (comment-normalize-vars)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
709 (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
710 (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
711 (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
712 (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
713 (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
714 (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
715 (multi (nth 0 style)))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
716 (save-excursion
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717 ;; we use `chars' instead of `syntax' because `\n' might be
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718 ;; of end-comment syntax rather than of whitespace syntax.
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
719 ;; sanitize BEG and END
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
720 (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
721 (setq beg (max beg (point)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (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
723 (setq end (min end (point)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 (if (>= beg end) (error "Nothing to comment"))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726 ;; sanitize LINES
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727 (setq lines
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 (and
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
729 lines multi
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 (progn (goto-char beg) (beginning-of-line)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
731 (skip-syntax-forward " ")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (>= (point) beg))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733 (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (<= (point) end))
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
735 (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
736 (progn (goto-char beg) (search-forward "\n" end t)))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
737
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
738 ;; 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
739 (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
740
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
741 (cond
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742 ((consp arg) (uncomment-region beg end))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
743 ((< numarg 0) (uncomment-region beg end (- numarg)))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 (t
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745 (if (and (null arg) (= (length comment-start) 1))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
746 (setq numarg add) (decf numarg))
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
747 (comment-region-internal
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
748 beg end
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
749 (let ((s (comment-padright comment-start numarg)))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
750 (if (string-match comment-start-skip s) s
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
751 (comment-padright comment-start)))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
752 (let ((s (comment-padleft comment-end numarg)))
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
753 (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
754 (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
755 (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
756 (if multi (comment-padleft (comment-string-reverse comment-continue) numarg))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 block
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
758 lines
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
759 (nth 3 style))))))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
760
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
761 (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
762 "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
763 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
764 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
765 (interactive "*r\np")
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
766 (let ((comment-style 'box))
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
767 (comment-region beg end (+ comment-add arg))))
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
769 (defun comment-dwim (arg)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
770 "Call the comment command you want.
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
771 If the region is active and `transient-mark-mode' is on,
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
772 calls `comment-region' (unless it only consists
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
773 in comments, in which case it calls `uncomment-region').
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
774 Else, if the current line is empty, insert a comment and indent it.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
775 Else call `indent-for-comment' or `kill-comment' if a prefix ARG is specified."
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
776 (interactive "*P")
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
777 (comment-normalize-vars)
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
778 (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
779 (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
780 (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
781 (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
782 (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
783 (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
784 (<= end (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
785 (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
786 (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
787 (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
788 (if arg (kill-comment (and (integerp arg) arg)) (indent-for-comment))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
789 (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
790 (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
791 (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
792 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
793 (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
794 (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
795 (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
796
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
797 (defcustom comment-spill t
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
798 "")
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
799
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
800 (defun indent-new-comment-line (&optional soft)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
801 "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
802 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
803 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
804
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
805 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
806 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
807 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
808
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
809 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
810 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
811
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
812 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
813 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
814 (interactive)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
815 (comment-normalize-vars t)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
816 (let (comcol comstart)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
817 (skip-chars-backward " \t")
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
818 (delete-region (point)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
819 (progn (skip-chars-forward " \t")
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
820 (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
821 (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
822 (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
823 (progn
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
824 (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
825 (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
826 (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
827 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
828 (backward-char)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
829 (if (and comment-start
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
830 (setq comcol (comment-beginning)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
831 ;; The old line has a comment and point was inside the comment.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
832 ;; Set WIN to the pos of the comment-start.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
833
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
834 ;; If comment-start-skip contains a \(...\) pair,
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
835 ;; the real comment delimiter starts at the end of that pair.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
836 (let ((win comcol))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
837 ;; But if the comment is empty, look at preceding lines
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
838 ;; to find one that has a nonempty comment.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
839 ;; (while (and (eolp) (not (bobp))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
840 ;; (let (opoint)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
841 ;; (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
842 ;; (setq opoint (point))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
843 ;; (forward-line -1)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
844 ;; (setq win (comment-search-forward opoint t)))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
845 ;; Why do we do that ? -sm
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
846
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
847 ;; Indent this line like what we found.
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
848 (setq comstart (buffer-substring win (point)))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
849 (goto-char win)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
850 (setq comcol (current-column))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
851 ))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
852 (if comcol
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
853 (let ((comment-column comcol)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
854 (comment-start comstart))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
855 ;;(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
856 (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
857 (forward-char -1)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
858 (indent-for-comment (cadr (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
859 (save-excursion
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
860 (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
861 (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
862 (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
863 ;; 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
864 (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
865 (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
866 (backward-char)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
867 (insert comend)
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
868 (forward-char)))))
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
869 (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
870
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
871 (provide 'newcomment)
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
872
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
873 ;;; Change Log:
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
874 ;; $Log: newcomment.el,v $
28904
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
875 ;; 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
876 ;; (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
877 ;; (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
878 ;; (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
879 ;; (comment-style): Change default to `plain'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
880 ;; (comment-styles): Rename `plain' to `indent' and create a new plainer `plain'.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
881 ;; (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
882 ;; (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
883 ;; 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
884 ;; 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
885 ;; (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
886 ;; (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
887 ;; (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
888 ;; (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
889 ;; (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
890 ;; (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
891 ;; Avoid multiple-value-setq.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
892 ;; (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
893 ;; 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
894 ;; (comment-box): New function.
8d91ded5215c (comment-start, comment-start-skip, comment-end): Made `defvar'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28901
diff changeset
895 ;; (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
896 ;;
28901
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
897 ;; 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
898 ;; various fixes and gratuitous movements.
0e7bbb764f47 (comment-use-syntax): Change `maybe' to `undecided'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26763
diff changeset
899 ;;
26763
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
900 ;; 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
901 ;; (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
902 ;; (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
903 ;; (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
904 ;; ...
5a4671b4895c various fixes and gratuitous movements.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26663
diff changeset
905 ;;
26663
9979145a424e (comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26647
diff changeset
906 ;; 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
907 ;; (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
908 ;; (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
909 ;;
26647
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
910 ;; 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
911 ;; (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
912 ;; (comment-normalize-vars): Set default (cdr comment-continue)
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
913 ;; (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
914 ;; (uncomment-region): Rewritten using syntax-tables. Also unquotes
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
915 ;; nested comment-ends and eliminates continuation markers.
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
916 ;; (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
917 ;; Use `comment-end-quote-re'.
b00a81cd0f6e (comment-find): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26646
diff changeset
918 ;;
26646
0d447856a2f7 (kill-comment): Fixed by rewriting it with syntax-tables rather than regexps
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26645
diff changeset
919 ;; 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
920 ;; (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
921 ;; (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
922 ;; 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
923 ;; (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
924 ;; 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
925 ;;
26645
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
926 ;; 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
927 ;; First "working" version:
39f87d842e57 (comment-make-extra-lines): Moved out of comment-region-internal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26640
diff changeset
928 ;; - 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
929 ;; - 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
930 ;; - 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
931 ;; - 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
932 ;; - 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
933 ;; - 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
934 ;; - 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
935 ;; - 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
936 ;; - 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
937 ;;
26640
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
938
f95236e53857 First "working" version:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
939 ;;; newcomment.el ends here