emacs-devel
[Top][All Lists]
Advanced

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

Re: awesome feature (yet to be added?)


From: Andreas Röhler
Subject: Re: awesome feature (yet to be added?)
Date: Sat, 31 May 2014 08:26:36 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0

On 30.05.2014 23:35, Thorsten Jolitz wrote:
Davis Herring <address@hidden> writes:

Judging by the uptake.  We are the only two to think this is useful.  :)

No, I would really like to see a generic `invert-comment' function in
Emacs. My use case is outorg.el that converts programming language buffers
(structured the outshine way, i.e. with outcommented Org-mode headers)
temporarily to org-mode for text editing and then back to the
programming major-mode.

That means all the comment sections of the source file are uncommented
when converting to Org, and outcommented again when converting back to
the original major-mode. I do this linewise, and in fact outorg can't
handle those special multiline comments like in C or Java.

A robust generic (= major-mode agnostic) `invert-comment' function as
part of Emacs that knows how to handle multiline comments too would come
very handy.

I thought about implementing `invert-comment' a few years ago, but I
wasn't sure what to do about code like this:

   /* old_implementation_prepare (); */
   /* old_implementation_go (); */

   new_implementation_prepare ();
   /* The new implementation needs a buffer allocated. */
   char *p = malloc (new_implementation_size ());
   new_implementation_go (p);

IMO such a function should only act on comments that start at the
beginning of line, indented comments should remain untouched.

What to do about the actual comment embedded in the "new" code?

   x = foo () + /* bar () + */ baz ();
   quux (x, x + 1);     /* quux now accounts for bar internally */

What does it mean to toggle commented-ness here?

Again, IMO these comments should remain untouched. E.g. when converting
source files to org-mode, code section are enclosed in source-blocks

#+begin_src lang
   x = foo () + /* bar () + */ baz ();
  quux (x, x + 1);     /* quux now accounts for bar internally */
#+end_src

and the embedded comments clearly belong to the code.

Your idea of markers likely works out better than "toggle the comments"
because of cases like these.

It would indeed be very useful if there is a way to further act on the
region/line that was inverted after the function has done its job. So
returning start/end position, set markers or running a hook or so would
be nice.

There were quite a lot of proposals in this thread. Any chance that this
is actually outdiscussed and included in Emacs any time soon?


AFAIU instrumenting `comment-dwim' should provide all you need here.

Grüße,

Andreas




reply via email to

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