aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2000-11-21 21:31:16 +0000
committerStefan Monnier2000-11-21 21:31:16 +0000
commit2e1fbba4e531b5fa28432fc9f8b8a0ddc93dcaa0 (patch)
treefae54b9cea040bce62eb2a5374581bd9f8c8fc53 /lisp
parent02b2f510d0f511cd286785f6be7f024f194e174c (diff)
downloademacs-2e1fbba4e531b5fa28432fc9f8b8a0ddc93dcaa0.tar.gz
emacs-2e1fbba4e531b5fa28432fc9f8b8a0ddc93dcaa0.zip
(comment-indent): Insert comment before calling
comment-indent-function. Don't insert in column 0. (comment-dwim): Indent before inserting comment.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/newcomment.el75
1 files changed, 40 insertions, 35 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 2fe635b1a79..3466b429301 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -6,7 +6,7 @@
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;; Version: $Name: $ 8;; Version: $Name: $
9;; Revision: $Id: newcomment.el,v 1.23 2000/11/14 10:03:56 monnier Exp $ 9;; Revision: $Id: newcomment.el,v 1.24 2000/11/14 15:09:40 monnier Exp $
10 10
11;; This file is part of GNU Emacs. 11;; This file is part of GNU Emacs.
12 12
@@ -418,41 +418,43 @@ If CONTINUE is non-nil, use the `comment-continuation' markers if any."
418 (and empty block-comment-start) comment-start)) 418 (and empty block-comment-start) comment-start))
419 (ender (or (and continue comment-continue "") 419 (ender (or (and continue comment-continue "")
420 (and empty block-comment-end) comment-end))) 420 (and empty block-comment-end) comment-end)))
421 (cond 421 (unless starter (error "No comment syntax defined"))
422 ((null starter) 422 (beginning-of-line)
423 (error "No comment syntax defined")) 423 (let* ((eolpos (line-end-position))
424 (t (let* ((eolpos (line-end-position)) 424 (begpos (comment-search-forward eolpos t))
425 cpos indent begpos) 425 cpos indent)
426 (beginning-of-line) 426 ;; An existing comment?
427 (if (not (setq begpos (comment-search-forward eolpos t))) 427 (if begpos (setq cpos (point-marker))
428 (setq begpos (point)) 428 ;; If none, insert one.
429 (setq cpos (point-marker)) 429 (save-excursion
430 (goto-char begpos)) 430 ;; Some comment-indent-function insist on not moving comments that
431 ;; Compute desired indent. 431 ;; are in column 0, so we insert a space to avoid this special case
432 (setq indent (funcall comment-indent-function)) 432 (insert " ")
433 (if (not indent) 433 (setq begpos (point))
434 ;; comment-indent-function refuses delegates to indent.
435 (indent-according-to-mode)
436 ;; Avoid moving comments past the fill-column.
437 (setq indent
438 (min indent
439 (+ (current-column)
440 (- fill-column
441 (save-excursion (end-of-line) (current-column))))))
442 (if (= (current-column) indent)
443 (goto-char begpos)
444 ;; If that's different from current, change it.
445 (skip-chars-backward " \t")
446 (delete-region (point) begpos)
447 (indent-to (if (bolp) indent
448 (max indent (1+ (current-column)))))))
449 ;; An existing comment?
450 (if cpos
451 (progn (goto-char cpos) (set-marker cpos nil))
452 ;; No, insert one.
453 (insert starter) 434 (insert starter)
454 (save-excursion 435 (setq cpos (point-marker))
455 (insert ender)))))))) 436 (insert ender)))
437 (goto-char begpos)
438 ;; Compute desired indent.
439 (setq indent (funcall comment-indent-function))
440 (if (not indent)
441 ;; comment-indent-function refuses delegates to indent.
442 (indent-according-to-mode)
443 ;; Avoid moving comments past the fill-column.
444 (setq indent
445 (min indent
446 (+ (current-column)
447 (- fill-column
448 (save-excursion (end-of-line) (current-column))))))
449 (if (= (current-column) indent)
450 (goto-char begpos)
451 ;; If that's different from current, change it.
452 (skip-chars-backward " \t")
453 (delete-region (point) begpos)
454 (indent-to (if (bolp) indent
455 (max indent (1+ (current-column)))))))
456 (goto-char cpos)
457 (set-marker cpos nil))))
456 458
457;;;###autoload 459;;;###autoload
458(defun comment-set-column (arg) 460(defun comment-set-column (arg)
@@ -884,6 +886,9 @@ Else, call `comment-indent'."
884 (if arg (comment-kill (and (integerp arg) arg)) (comment-indent)) 886 (if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
885 (let ((add (if arg (prefix-numeric-value arg) 887 (let ((add (if arg (prefix-numeric-value arg)
886 (if (= (length comment-start) 1) comment-add 0)))) 888 (if (= (length comment-start) 1) comment-add 0))))
889 ;; Some modes insist on keeping column 0 comment in column 0
890 ;; so we need to move away from it before inserting the comment.
891 (indent-according-to-mode)
887 (insert (comment-padright comment-start add)) 892 (insert (comment-padright comment-start add))
888 (save-excursion 893 (save-excursion
889 (unless (string= "" comment-end) 894 (unless (string= "" comment-end)