Mercurial > emacs
changeset 44999:a8d9e35048ff
(comment-fill-column): New var.
(comment-indent): Use it.
(comment-or-uncomment-region): New fun.
(comment-dwim): Use it.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 29 Apr 2002 23:43:11 +0000 |
parents | fe7cb28c1afd |
children | 34382d9145d7 |
files | lisp/newcomment.el |
diffstat | 1 files changed, 28 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/newcomment.el Mon Apr 29 23:24:28 2002 +0000 +++ b/lisp/newcomment.el Mon Apr 29 23:43:11 2002 +0000 @@ -5,7 +5,7 @@ ;; Author: code extracted from Emacs-20's simple.el ;; Maintainer: Stefan Monnier <monnier@cs.yale.edu> ;; Keywords: comment uncomment -;; Revision: $Id: newcomment.el,v 1.45 2002/03/04 01:10:55 monnier Exp $ +;; Revision: $Id: newcomment.el,v 1.46 2002/04/08 22:58:27 monnier Exp $ ;; This file is part of GNU Emacs. @@ -86,13 +86,17 @@ to understand comments or not in the given buffer. Major modes should set this variable.") +(defcustom comment-fill-column nil + "Column to use for `comment-indent'. If nil, use `fill-column' instead." + :type '(choice nil integer)) + ;;;###autoload (defcustom comment-column 32 "*Column to indent right-margin comments to. Each mode establishes a different default value for this variable; you can set the value for a particular mode using that mode's hook. Comments might be indented to a value smaller than this in order -not to go beyond `fill-column'." +not to go beyond `comment-fill-column'." :type 'integer) (make-variable-buffer-local 'comment-column) @@ -479,7 +483,7 @@ (setq indent (min indent (+ (current-column) - (- fill-column + (- (or comment-fill-column fill-column) (save-excursion (end-of-line) (current-column))))))) (unless (= (current-column) indent) ;; If that's different from current, change it. @@ -893,6 +897,20 @@ 'box-multi 'box))) (comment-region beg end (+ comment-add arg)))) + +;;;###autoload +(defun comment-or-uncomment-region (beg end &optional arg) + "Call `comment-region', unless the region only consists of comments, +in which case call `uncomment-region'. If a prefix arg is given, it +is passed on to the respective function." + (interactive "*r\nP") + (funcall (if (save-excursion ;; check for already commented region + (goto-char beg) + (comment-forward (point-max)) + (<= end (point))) + 'uncomment-region 'comment-region) + beg end arg)) + ;;;###autoload (defun comment-dwim (arg) "Call the comment command you want (Do What I Mean). @@ -905,14 +923,7 @@ (interactive "*P") (comment-normalize-vars) (if (and mark-active transient-mark-mode) - (let ((beg (min (point) (mark))) - (end (max (point) (mark)))) - (if (save-excursion ;; check for already commented region - (goto-char beg) - (comment-forward (point-max)) - (<= end (point))) - (uncomment-region beg end arg) - (comment-region beg end arg))) + (comment-or-uncomment-region (region-beginning) (region-end) arg) (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$"))) ;; FIXME: If there's no comment to kill on this line and ARG is ;; specified, calling comment-kill is not very clever. @@ -969,13 +980,17 @@ (setq comin (point)))))) ;; Now we know we should auto-fill. + ;; Insert the newline before removing empty space so that markers + ;; get preserved better. + (if soft (insert-and-inherit ?\n) (newline 1)) + (save-excursion (forward-char -1) (delete-horizontal-space)) (delete-horizontal-space) - (if soft (insert-and-inherit ?\n) (newline 1)) + (if (and fill-prefix (not adaptive-fill-mode)) ;; Blindly trust a non-adaptive fill-prefix. (progn (indent-to-left-margin) - (insert-and-inherit fill-prefix)) + (insert-before-markers-and-inherit fill-prefix)) ;; If necessary check whether we're inside a comment. (unless (or compos (null comment-start))