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: Thorsten Jolitz
Subject: Re: awesome feature (yet to be added?)
Date: Sat, 31 May 2014 12:46:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> 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.
>
> After uncommenting, how do you know which lines should be recommented?
> Do you remember them in some variable?  Or do you wrap the code parts
> in
> those (ugly) +begin...+end "brackets"?

Yes, ugly or not, the +begin...+end "brackets (i.e. code-blocks) are
quite convenient since they allows easy conversion between source code
buffers and org buffers: in source code buffers, code is code and text
is hidden behind comment chars, in org buffers text is text and source
code is hidden in those code blocks. Just two views on the same (well
structured) file, and in each view all buffer content is in one of only
two 'states': hidden (as comment or code block) or not.

> Do you uncomment all comments, or only those that "look like Org
> stuff"?

only comments that start at beginning of line, all other comments
(indented, at the end of line ...) are usually part of the code and
should not be touched (i.e. should go into the code-blocks together with
the code).

>> the original major-mode. I do this linewise, and in fact outorg
>> can't
>> handle those special multiline comments like in C or Java.
>
> Why do it line-wise?

Because it was easy and major-mode agnostic (I just mark the line and
call comment-region and uncomment-region on it), although I needed a few
variables to keep track of the current context (inside comment-section?
inside code-section?). Would comment-search-forward be much faster? But
it would probably find all kinds of comments not only those that start
at the beginning of line. 

>> 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.
>
> It looks like the exact meaning of such a function is slightly different
> for every one, so such a function would need lots of hooks and config
> vars to cover all cases.
>
> But you can write your own function starting with
>
>    (defun my-uncomment-region (beg end)
>      (let (spt)
>        (while (and (< (point) end)
>                    (setq spt (comment-search-forward end t)))
>          (let ((ept (progn
>                     (goto-char spt)
>                     (unless (or (comment-forward)
>                                 ;; Allow non-terminated comments.
>                                 (eobp))
>                       (error "Can't find the comment end"))
>                     (point))))
>            (uncomment-region spt ept)))))
>

Thanks, thats indeed a good starting point.

-- 
cheers,
Thorsten




reply via email to

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