diff options
| author | Stefan Monnier | 2002-04-29 23:43:11 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-04-29 23:43:11 +0000 |
| commit | 88fe06af569e5c87225f4048e618c8a15106ac79 (patch) | |
| tree | 0fcde22c8c0326c6d100038deac603d811492ff0 | |
| parent | 6965846537b7fbc0b812e1ab20992b071ff4b76b (diff) | |
| download | emacs-88fe06af569e5c87225f4048e618c8a15106ac79.tar.gz emacs-88fe06af569e5c87225f4048e618c8a15106ac79.zip | |
(comment-fill-column): New var.
(comment-indent): Use it.
(comment-or-uncomment-region): New fun.
(comment-dwim): Use it.
| -rw-r--r-- | lisp/newcomment.el | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 96d29618c00..68681f51681 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: code extracted from Emacs-20's simple.el | 5 | ;; Author: code extracted from Emacs-20's simple.el |
| 6 | ;; Maintainer: Stefan Monnier <monnier@cs.yale.edu> | 6 | ;; Maintainer: Stefan Monnier <monnier@cs.yale.edu> |
| 7 | ;; Keywords: comment uncomment | 7 | ;; Keywords: comment uncomment |
| 8 | ;; Revision: $Id: newcomment.el,v 1.45 2002/03/04 01:10:55 monnier Exp $ | 8 | ;; Revision: $Id: newcomment.el,v 1.46 2002/04/08 22:58:27 monnier Exp $ |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -86,13 +86,17 @@ be used to try to determine whether syntax-tables should be trusted | |||
| 86 | to understand comments or not in the given buffer. | 86 | to understand comments or not in the given buffer. |
| 87 | Major modes should set this variable.") | 87 | Major modes should set this variable.") |
| 88 | 88 | ||
| 89 | (defcustom comment-fill-column nil | ||
| 90 | "Column to use for `comment-indent'. If nil, use `fill-column' instead." | ||
| 91 | :type '(choice nil integer)) | ||
| 92 | |||
| 89 | ;;;###autoload | 93 | ;;;###autoload |
| 90 | (defcustom comment-column 32 | 94 | (defcustom comment-column 32 |
| 91 | "*Column to indent right-margin comments to. | 95 | "*Column to indent right-margin comments to. |
| 92 | Each mode establishes a different default value for this variable; you | 96 | Each mode establishes a different default value for this variable; you |
| 93 | can set the value for a particular mode using that mode's hook. | 97 | can set the value for a particular mode using that mode's hook. |
| 94 | Comments might be indented to a value smaller than this in order | 98 | Comments might be indented to a value smaller than this in order |
| 95 | not to go beyond `fill-column'." | 99 | not to go beyond `comment-fill-column'." |
| 96 | :type 'integer) | 100 | :type 'integer) |
| 97 | (make-variable-buffer-local 'comment-column) | 101 | (make-variable-buffer-local 'comment-column) |
| 98 | 102 | ||
| @@ -479,7 +483,7 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any." | |||
| 479 | (setq indent | 483 | (setq indent |
| 480 | (min indent | 484 | (min indent |
| 481 | (+ (current-column) | 485 | (+ (current-column) |
| 482 | (- fill-column | 486 | (- (or comment-fill-column fill-column) |
| 483 | (save-excursion (end-of-line) (current-column))))))) | 487 | (save-excursion (end-of-line) (current-column))))))) |
| 484 | (unless (= (current-column) indent) | 488 | (unless (= (current-column) indent) |
| 485 | ;; If that's different from current, change it. | 489 | ;; If that's different from current, change it. |
| @@ -893,6 +897,20 @@ end- comment markers additionally to what `comment-add' already specifies." | |||
| 893 | 'box-multi 'box))) | 897 | 'box-multi 'box))) |
| 894 | (comment-region beg end (+ comment-add arg)))) | 898 | (comment-region beg end (+ comment-add arg)))) |
| 895 | 899 | ||
| 900 | |||
| 901 | ;;;###autoload | ||
| 902 | (defun comment-or-uncomment-region (beg end &optional arg) | ||
| 903 | "Call `comment-region', unless the region only consists of comments, | ||
| 904 | in which case call `uncomment-region'. If a prefix arg is given, it | ||
| 905 | is passed on to the respective function." | ||
| 906 | (interactive "*r\nP") | ||
| 907 | (funcall (if (save-excursion ;; check for already commented region | ||
| 908 | (goto-char beg) | ||
| 909 | (comment-forward (point-max)) | ||
| 910 | (<= end (point))) | ||
| 911 | 'uncomment-region 'comment-region) | ||
| 912 | beg end arg)) | ||
| 913 | |||
| 896 | ;;;###autoload | 914 | ;;;###autoload |
| 897 | (defun comment-dwim (arg) | 915 | (defun comment-dwim (arg) |
| 898 | "Call the comment command you want (Do What I Mean). | 916 | "Call the comment command you want (Do What I Mean). |
| @@ -905,14 +923,7 @@ Else, call `comment-indent'." | |||
| 905 | (interactive "*P") | 923 | (interactive "*P") |
| 906 | (comment-normalize-vars) | 924 | (comment-normalize-vars) |
| 907 | (if (and mark-active transient-mark-mode) | 925 | (if (and mark-active transient-mark-mode) |
| 908 | (let ((beg (min (point) (mark))) | 926 | (comment-or-uncomment-region (region-beginning) (region-end) arg) |
| 909 | (end (max (point) (mark)))) | ||
| 910 | (if (save-excursion ;; check for already commented region | ||
| 911 | (goto-char beg) | ||
| 912 | (comment-forward (point-max)) | ||
| 913 | (<= end (point))) | ||
| 914 | (uncomment-region beg end arg) | ||
| 915 | (comment-region beg end arg))) | ||
| 916 | (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$"))) | 927 | (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$"))) |
| 917 | ;; FIXME: If there's no comment to kill on this line and ARG is | 928 | ;; FIXME: If there's no comment to kill on this line and ARG is |
| 918 | ;; specified, calling comment-kill is not very clever. | 929 | ;; specified, calling comment-kill is not very clever. |
| @@ -969,13 +980,17 @@ unless optional argument SOFT is non-nil." | |||
| 969 | (setq comin (point)))))) | 980 | (setq comin (point)))))) |
| 970 | 981 | ||
| 971 | ;; Now we know we should auto-fill. | 982 | ;; Now we know we should auto-fill. |
| 972 | (delete-horizontal-space) | 983 | ;; Insert the newline before removing empty space so that markers |
| 984 | ;; get preserved better. | ||
| 973 | (if soft (insert-and-inherit ?\n) (newline 1)) | 985 | (if soft (insert-and-inherit ?\n) (newline 1)) |
| 986 | (save-excursion (forward-char -1) (delete-horizontal-space)) | ||
| 987 | (delete-horizontal-space) | ||
| 988 | |||
| 974 | (if (and fill-prefix (not adaptive-fill-mode)) | 989 | (if (and fill-prefix (not adaptive-fill-mode)) |
| 975 | ;; Blindly trust a non-adaptive fill-prefix. | 990 | ;; Blindly trust a non-adaptive fill-prefix. |
| 976 | (progn | 991 | (progn |
| 977 | (indent-to-left-margin) | 992 | (indent-to-left-margin) |
| 978 | (insert-and-inherit fill-prefix)) | 993 | (insert-before-markers-and-inherit fill-prefix)) |
| 979 | 994 | ||
| 980 | ;; If necessary check whether we're inside a comment. | 995 | ;; If necessary check whether we're inside a comment. |
| 981 | (unless (or compos (null comment-start)) | 996 | (unless (or compos (null comment-start)) |