emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CC Mode 5.28 (C++); comment-indent-newline does not insert a comm en


From: Stefan Monnier
Subject: Re: CC Mode 5.28 (C++); comment-indent-newline does not insert a comm ent delimiter after the new line.
Date: Tue, 20 Nov 2001 19:55:56 -0500

> Speaking of M-j, CC Mode currently overrides indent-new-comment-line
> with its own c-indent-new-comment-line in a fairly ugly way by using
> substitute-key-definition. This doesn't work in Emacs 21, due to the
> function name change. I can of course fix that by replacing the new
> comment-indent-new-line in the same way, but I think it'd be better to
> improve the integration possibilities to avoid such measures.
> 
> I'd like a function hook much like comment-line-break-function, which
> is currently used by auto-fill. Actually, in my case it'd work well to
> simply use that variable also in comment-indent-new-line.

Haven't looked at the code once more and thought about it etc...
I have a suggestion: make M-j behave even more like the line-breaking
of do-auto-fill.

Right now, M-j does pretty much the same thing as the line breaking
of do-auto-fill except for:

1 - it doesn't obey comment-line-break-function
2 - it doesn't obey adaptive-fill-prefix

I actually find both differences annoying.  So how about a new
function to bind to M-j:

(defun fill-here ()
  "Force soft line break at point, like auto-filling would do.
Break line at point, preserving any fill prefix and continuing comment
if we are inside a comment."
  (interactive)
  (let ((comment-auto-fill-only-comments nil)
        (fill-prefix fill-prefix))
    ;; Choose a fill-prefix automatically.
    (when (and adaptive-fill-mode
               (or (null fill-prefix) (string= fill-prefix "")))
      (let ((prefix
             (fill-context-prefix
              (save-excursion (fill-backward-paragraph) (point))
              (save-excursion (fill-forward-paragraph) (point)))))
        (and prefix (not (equal prefix ""))
             ;; Use auto-indentation rather than a guessed empty prefix.
             (not (and fill-indent-according-to-mode
                       (string-match "[ \t]*" prefix)))
             (setq fill-prefix prefix))))
    (funcall comment-line-break-function t)))


-- Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]