aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-10-05 22:43:22 +0000
committerStefan Monnier2000-10-05 22:43:22 +0000
commit87cf842124c811be3425fffc8d05d3d6650f4f62 (patch)
treeea1bb055638783fa184a1fc5e00f3935e6c7157b
parent34a1934628a42c7874712f712aee362707962329 (diff)
downloademacs-87cf842124c811be3425fffc8d05d3d6650f4f62.tar.gz
emacs-87cf842124c811be3425fffc8d05d3d6650f4f62.zip
(comment-indent):
Delegate to indent-according-to-mode if comment-indent-function returns nil. (comment-indent-default): New function. (comment-indent-function): Use it and document the new semantics.
-rw-r--r--lisp/newcomment.el59
1 files changed, 35 insertions, 24 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index bf6e3e104cc..9b36dde09a0 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.19 2000/07/06 13:25:31 monnier Exp $ 9;; Revision: $Id: newcomment.el,v 1.20 2000/09/29 19:11:42 monnier Exp $
10 10
11;; This file is part of GNU Emacs. 11;; This file is part of GNU Emacs.
12 12
@@ -115,11 +115,12 @@ at the place matched by the close of the first pair.")
115Should be an empty string if comments are terminated by end-of-line.") 115Should be an empty string if comments are terminated by end-of-line.")
116 116
117;;;###autoload 117;;;###autoload
118(defvar comment-indent-function 118(defvar comment-indent-function 'comment-indent-default
119 (lambda () (if (looking-at "\\s<\\s<\\s<") 0 comment-column))
120 "Function to compute desired indentation for a comment. 119 "Function to compute desired indentation for a comment.
121This function is called with no args with point at the beginning of 120This function is called with no args with point at the beginning of
122the comment's starting delimiter.") 121the comment's starting delimiter and should return either the desired
122column indentation or nil.
123If nil is returned, indentation is delegated to `indent-according-to-mode'.")
123 124
124(defvar block-comment-start nil) 125(defvar block-comment-start nil)
125(defvar block-comment-end nil) 126(defvar block-comment-end nil)
@@ -395,6 +396,13 @@ Point is assumed to be just at the end of a comment."
395;;;; Commands 396;;;; Commands
396;;;; 397;;;;
397 398
399(defun comment-indent-default ()
400 "Default for `comment-indent-function'."
401 (if (looking-at "\\s<\\s<\\s<") 0
402 (when (or (/= (current-column) (current-indentation))
403 (and (> comment-add 0) (looking-at "\\s<\\S<")))
404 comment-column)))
405
398;;;###autoload 406;;;###autoload
399(defun comment-indent (&optional continue) 407(defun comment-indent (&optional continue)
400 "Indent this line's comment to comment column, or insert an empty comment. 408 "Indent this line's comment to comment column, or insert an empty comment.
@@ -417,27 +425,30 @@ If CONTINUE is non-nil, use the `comment-continuation' markers if any."
417 (setq begpos (point)) 425 (setq begpos (point))
418 (setq cpos (point-marker)) 426 (setq cpos (point-marker))
419 (goto-char begpos)) 427 (goto-char begpos))
420 ;; Compute desired indent. 428 ;; Compute desired indent.
421 (setq indent (funcall comment-indent-function)) 429 (setq indent (funcall comment-indent-function))
422 ;; Avoid moving comments past the fill-column. 430 (if (not indent)
423 (setq indent 431 ;; comment-indent-function refuses delegates to indent.
424 (min indent 432 (indent-according-to-mode)
425 (+ (current-column) 433 ;; Avoid moving comments past the fill-column.
426 (- fill-column 434 (setq indent
427 (save-excursion (end-of-line) (current-column)))))) 435 (min indent
428 (if (= (current-column) indent) 436 (+ (current-column)
429 (goto-char begpos) 437 (- fill-column
430 ;; If that's different from current, change it. 438 (save-excursion (end-of-line) (current-column))))))
431 (skip-chars-backward " \t") 439 (if (= (current-column) indent)
432 (delete-region (point) begpos) 440 (goto-char begpos)
433 (indent-to (if (bolp) indent (max indent (1+ (current-column)))))) 441 ;; If that's different from current, change it.
434 ;; An existing comment? 442 (skip-chars-backward " \t")
435 (if cpos 443 (delete-region (point) begpos)
436 (progn (goto-char cpos) (set-marker cpos nil)) 444 (indent-to (if (bolp) indent (max indent (1+ (current-column))))))
437 ;; No, insert one. 445 ;; An existing comment?
438 (insert starter) 446 (if cpos
439 (save-excursion 447 (progn (goto-char cpos) (set-marker cpos nil))
440 (insert ender)))))))) 448 ;; No, insert one.
449 (insert starter)
450 (save-excursion
451 (insert ender)))))))))
441 452
442;;;###autoload 453;;;###autoload
443(defun comment-set-column (arg) 454(defun comment-set-column (arg)