diff options
| author | Richard M. Stallman | 2007-10-26 09:52:12 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2007-10-26 09:52:12 +0000 |
| commit | c391a81ff31e3e3532e6fabb3b02dbba7616cf09 (patch) | |
| tree | 09bb122f1ee6f1193aa96bbead057e03a63e58db | |
| parent | f2b480f4baf25c2b6272bd0ac4cf6f1e9d562ee2 (diff) | |
| download | emacs-c391a81ff31e3e3532e6fabb3b02dbba7616cf09.tar.gz emacs-c391a81ff31e3e3532e6fabb3b02dbba7616cf09.zip | |
(comment-styles): New style indent-or-triple.
(comment-style): Make that the default.
(comment-add defvar): Doc fix.
(comment-add): Delete arg EXTRA.
(comment-region-default): Open code call to comment-add.
Handle indent-or-triple style which uses `multi-char' for INDENT.
| -rw-r--r-- | lisp/newcomment.el | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 6b0589da43d..06dc7efbc99 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -182,13 +182,16 @@ by replacing its first character with a space.") | |||
| 182 | (defvar comment-add 0 | 182 | (defvar comment-add 0 |
| 183 | "How many more comment chars should be inserted by `comment-region'. | 183 | "How many more comment chars should be inserted by `comment-region'. |
| 184 | This determines the default value of the numeric argument of `comment-region'. | 184 | This determines the default value of the numeric argument of `comment-region'. |
| 185 | The `plain' comment style doubles this value. | ||
| 186 | |||
| 185 | This should generally stay 0, except for a few modes like Lisp where | 187 | This should generally stay 0, except for a few modes like Lisp where |
| 186 | it can be convenient to set it to 1 so that regions are commented with | 188 | it is 1 so that regions are commented with two or three semi-colons.") |
| 187 | two semi-colons.") | ||
| 188 | 189 | ||
| 189 | (defconst comment-styles | 190 | (defconst comment-styles |
| 190 | '((plain . (nil nil nil nil)) | 191 | '((plain . (nil nil nil nil)) |
| 191 | (indent . (nil nil nil t)) | 192 | (indent . (nil nil nil t)) |
| 193 | (indent-or-triple | ||
| 194 | . (nil nil nil multi-char)) | ||
| 192 | (aligned . (nil t nil t)) | 195 | (aligned . (nil t nil t)) |
| 193 | (multi-line . (t nil nil t)) | 196 | (multi-line . (t nil nil t)) |
| 194 | (extra-line . (t nil t t)) | 197 | (extra-line . (t nil t t)) |
| @@ -201,10 +204,12 @@ ALIGN specifies that the `comment-end' markers should be aligned. | |||
| 201 | EXTRA specifies that an extra line should be used before and after the | 204 | EXTRA specifies that an extra line should be used before and after the |
| 202 | region to comment (to put the `comment-end' and `comment-start'). | 205 | region to comment (to put the `comment-end' and `comment-start'). |
| 203 | INDENT specifies that the `comment-start' markers should not be put at the | 206 | INDENT specifies that the `comment-start' markers should not be put at the |
| 204 | left margin but at the current indentation of the region to comment.") | 207 | left margin but at the current indentation of the region to comment. |
| 208 | If INDENT is `multi-char', that means indent multi-character | ||
| 209 | comment starters, but not one-character comment starters.") | ||
| 205 | 210 | ||
| 206 | ;;;###autoload | 211 | ;;;###autoload |
| 207 | (defcustom comment-style 'plain | 212 | (defcustom comment-style 'indent-or-triple |
| 208 | "Style to be used for `comment-region'. | 213 | "Style to be used for `comment-region'. |
| 209 | See `comment-styles' for a list of available styles." | 214 | See `comment-styles' for a list of available styles." |
| 210 | :type (if (boundp 'comment-styles) | 215 | :type (if (boundp 'comment-styles) |
| @@ -939,14 +944,14 @@ indentation to be kept as it was before narrowing." | |||
| 939 | (delete-char n) | 944 | (delete-char n) |
| 940 | (setq ,bindent (- ,bindent n))))))))))) | 945 | (setq ,bindent (- ,bindent n))))))))))) |
| 941 | 946 | ||
| 942 | ;; Compute the number of extra semicolons to add to the comment starter | 947 | ;; Compute the number of extra comment starter characters |
| 943 | ;; in Lisp mode, extra stars in C mode, etc. | 948 | ;; (extra semicolons in Lisp mode, extra stars in C mode, etc.) |
| 944 | ;; If ARG is non-nil, just follow ARG. | 949 | ;; If ARG is non-nil, just follow ARG. |
| 945 | ;; If the comment-starter is multi-char, just follow ARG. | 950 | ;; If the comment-starter is multi-char, just follow ARG. |
| 946 | ;; Otherwise obey comment-add, and double it if EXTRA is non-nil. | 951 | ;; Otherwise obey comment-add, and double it if EXTRA is non-nil. |
| 947 | (defun comment-add (arg &optional extra) | 952 | (defun comment-add (arg) |
| 948 | (if (and (null arg) (= (string-match "[ \t]*\\'" comment-start) 1)) | 953 | (if (and (null arg) (= (string-match "[ \t]*\\'" comment-start) 1)) |
| 949 | (* comment-add (if extra 2 1)) | 954 | (* comment-add 1) |
| 950 | (1- (prefix-numeric-value arg)))) | 955 | (1- (prefix-numeric-value arg)))) |
| 951 | 956 | ||
| 952 | (defun comment-region-internal (beg end cs ce | 957 | (defun comment-region-internal (beg end cs ce |
| @@ -1086,24 +1091,33 @@ The strings used as comment starts are built from | |||
| 1086 | ((consp arg) (uncomment-region beg end)) | 1091 | ((consp arg) (uncomment-region beg end)) |
| 1087 | ((< numarg 0) (uncomment-region beg end (- numarg))) | 1092 | ((< numarg 0) (uncomment-region beg end (- numarg))) |
| 1088 | (t | 1093 | (t |
| 1089 | ;; Add an extra semicolon in Lisp and similar modes. | 1094 | (let ((multi-char (/= (string-match "[ \t]*\\'" comment-start) 1)) |
| 1090 | ;; If STYLE doesn't specify indenting the comments, | 1095 | indent) |
| 1091 | ;; then double the value of `comment-add'. | 1096 | (if (eq (nth 3 style) 'multi-char) |
| 1092 | (setq numarg (comment-add arg (null (nth 3 style)))) | 1097 | (setq indent multi-char) |
| 1093 | (comment-region-internal | 1098 | (setq indent (nth 3 style))) |
| 1094 | beg end | 1099 | |
| 1095 | (let ((s (comment-padright comment-start numarg))) | 1100 | ;; In Lisp and similar modes with one-character comment starters, |
| 1096 | (if (string-match comment-start-skip s) s | 1101 | ;; double it by default if `comment-add' says so. |
| 1097 | (comment-padright comment-start))) | 1102 | ;; If it isn't indented, triple it. |
| 1098 | (let ((s (comment-padleft comment-end numarg))) | 1103 | (if (and (null arg) (not multi-char)) |
| 1099 | (and s (if (string-match comment-end-skip s) s | 1104 | (setq numarg (* comment-add (if indent 1 2))) |
| 1100 | (comment-padright comment-end)))) | 1105 | (setq numarg (1- (prefix-numeric-value arg)))) |
| 1101 | (if multi (comment-padright comment-continue numarg)) | 1106 | |
| 1102 | (if multi | 1107 | (comment-region-internal |
| 1103 | (comment-padleft (comment-string-reverse comment-continue) numarg)) | 1108 | beg end |
| 1104 | block | 1109 | (let ((s (comment-padright comment-start numarg))) |
| 1105 | lines | 1110 | (if (string-match comment-start-skip s) s |
| 1106 | (nth 3 style)))))) | 1111 | (comment-padright comment-start))) |
| 1112 | (let ((s (comment-padleft comment-end numarg))) | ||
| 1113 | (and s (if (string-match comment-end-skip s) s | ||
| 1114 | (comment-padright comment-end)))) | ||
| 1115 | (if multi (comment-padright comment-continue numarg)) | ||
| 1116 | (if multi | ||
| 1117 | (comment-padleft (comment-string-reverse comment-continue) numarg)) | ||
| 1118 | block | ||
| 1119 | lines | ||
| 1120 | indent)))))) | ||
| 1107 | 1121 | ||
| 1108 | ;;;###autoload | 1122 | ;;;###autoload |
| 1109 | (defun comment-box (beg end &optional arg) | 1123 | (defun comment-box (beg end &optional arg) |