Mercurial > emacs
changeset 32186:964f10494360
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 05 Oct 2000 22:43:22 +0000 |
parents | f7460e78c02a |
children | 418444640a1e |
files | lisp/newcomment.el |
diffstat | 1 files changed, 35 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/newcomment.el Thu Oct 05 22:31:44 2000 +0000 +++ b/lisp/newcomment.el Thu Oct 05 22:43:22 2000 +0000 @@ -6,7 +6,7 @@ ;; Maintainer: Stefan Monnier <monnier@cs.yale.edu> ;; Keywords: comment uncomment ;; Version: $Name: $ -;; Revision: $Id: newcomment.el,v 1.19 2000/07/06 13:25:31 monnier Exp $ +;; Revision: $Id: newcomment.el,v 1.20 2000/09/29 19:11:42 monnier Exp $ ;; This file is part of GNU Emacs. @@ -115,11 +115,12 @@ Should be an empty string if comments are terminated by end-of-line.") ;;;###autoload -(defvar comment-indent-function - (lambda () (if (looking-at "\\s<\\s<\\s<") 0 comment-column)) +(defvar comment-indent-function 'comment-indent-default "Function to compute desired indentation for a comment. This function is called with no args with point at the beginning of -the comment's starting delimiter.") +the comment's starting delimiter and should return either the desired +column indentation or nil. +If nil is returned, indentation is delegated to `indent-according-to-mode'.") (defvar block-comment-start nil) (defvar block-comment-end nil) @@ -395,6 +396,13 @@ ;;;; Commands ;;;; +(defun comment-indent-default () + "Default for `comment-indent-function'." + (if (looking-at "\\s<\\s<\\s<") 0 + (when (or (/= (current-column) (current-indentation)) + (and (> comment-add 0) (looking-at "\\s<\\S<"))) + comment-column))) + ;;;###autoload (defun comment-indent (&optional continue) "Indent this line's comment to comment column, or insert an empty comment. @@ -417,27 +425,30 @@ (setq begpos (point)) (setq cpos (point-marker)) (goto-char begpos)) - ;; Compute desired indent. + ;; Compute desired indent. (setq indent (funcall comment-indent-function)) - ;; Avoid moving comments past the fill-column. - (setq indent - (min indent - (+ (current-column) - (- fill-column - (save-excursion (end-of-line) (current-column)))))) - (if (= (current-column) indent) - (goto-char begpos) - ;; If that's different from current, change it. - (skip-chars-backward " \t") - (delete-region (point) begpos) - (indent-to (if (bolp) indent (max indent (1+ (current-column)))))) - ;; An existing comment? - (if cpos - (progn (goto-char cpos) (set-marker cpos nil)) - ;; No, insert one. - (insert starter) - (save-excursion - (insert ender)))))))) + (if (not indent) + ;; comment-indent-function refuses delegates to indent. + (indent-according-to-mode) + ;; Avoid moving comments past the fill-column. + (setq indent + (min indent + (+ (current-column) + (- fill-column + (save-excursion (end-of-line) (current-column)))))) + (if (= (current-column) indent) + (goto-char begpos) + ;; If that's different from current, change it. + (skip-chars-backward " \t") + (delete-region (point) begpos) + (indent-to (if (bolp) indent (max indent (1+ (current-column)))))) + ;; An existing comment? + (if cpos + (progn (goto-char cpos) (set-marker cpos nil)) + ;; No, insert one. + (insert starter) + (save-excursion + (insert ender))))))))) ;;;###autoload (defun comment-set-column (arg)