help-gnu-emacs
[Top][All Lists]
Advanced

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

Continuing existing comment, with proper identation


From: Spencer Baugh
Subject: Continuing existing comment, with proper identation
Date: Sat, 21 Oct 2023 17:57:36 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

I'm writing a function to manipulate an existing commnet.  It should
insert a blank line, and then some data, at the end of a comment,
without creating a new comment.  I want it to work in a
major-mode-independent way, but I'm having a bit of trouble figuring out
what functions to call to get the same behavior across major-mode.

In Lisp, I'd like:

;; ...existing comment...
;; ...existing comment...

to be turned into

;; ...existing comment...
;; ...existing comment...
;;
;; new data

and in C:

/* ...existing comment...
   ...existing comment... */

to be turned into

/* ...existing comment...
   ...existing comment...

   new data */

(Keeping the same indentation level as the previous lines, of course, if
it's already in an indented block.)

The obvious thing to do is to put point at the end of the comment and
comment-indent-new-line twice.

But this behaves differently in Lisp and C - it's a one character
difference, but that's enough to break my major-mode-independence.

In C, I get

/* ...existing comment...
   ...existing comment...

   <point> */

so I can just go ahead and (insert "new data")

In Lisp though, I get:

;; ...existing comment...
;; ...existing comment...
;;
;;<point>

Note the lack of a space before <point>.  So if I (insert "new data"), I get

;; ...existing comment...
;; ...existing comment...
;;
;;new data

which is not what I want.  I want a space before ";;" and "new data", as
is normal in Lisp.

What should I do to get the behavior that I see in C, in Lisp
major-modes?




reply via email to

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