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: Mon, 09 Jun 2014 13:01:28 +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"?
> Do you uncomment all comments, or only those that "look like Org stuff"?
>
>> 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?

While trying to reimplement outcommenting and uncommenting in outorg
based on the recommendations of this thread and the function below I
figured out that there was another reason to do it line-wise: the
special case of 'oldschool' elisp headers:

,--------
| ;;;; Level 2
`--------

instead of 

,----------
| ;; ** Level 1
`----------

With the usual outshine convention (outshine headers are outcommented
org-mode headers) it does not really matter if a comment line is a
headline or not (as long as it starts at BOL): conversion simply means
outcomment or uncomment.

But with the special case 'oldschool elisp headers' I have to look at
every line, decide if its an oldschool headline, and then convert e.g.

,--------
| ;;;; Level 2
`--------

into 

,--------
| ** Level 2
`--------

for editing in org-mode, and vice versa for copying back the edits. 

I don't really see how to avoid this. Its still pretty fast, ca. 4 sec
for an 8000 lines init.el, almost instantly for smaller files with just
a few hundred lines (org -> elisp is easier and thus much faster than
elisp -> org, ca. 0.1 sec for 8000 lines).

So I could only try to support multi-line comments too, but it seems a
function or variable identifying them (with point on a comment) like
`comment-multi-line-p' or so is missing?

>> 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)))))

-- 
cheers,
Thorsten




reply via email to

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