From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.devel Subject: Re: awesome feature (yet to be added?) Date: Sat, 31 May 2014 12:46:55 +0200 Message-ID: <87lhti444g.fsf@gmail.com> References: <112075085.1028629.1399142864865.open-xchange@email.1and1.com> <53684CB6.1050601@lanl.gov> <87ppivne52.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1401533126 27910 80.91.229.3 (31 May 2014 10:45:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 31 May 2014 10:45:26 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 31 12:45:19 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wqgms-0002Id-0N for ged-emacs-devel@m.gmane.org; Sat, 31 May 2014 12:45:18 +0200 Original-Received: from localhost ([::1]:58843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wqgmr-0006c2-LA for ged-emacs-devel@m.gmane.org; Sat, 31 May 2014 06:45:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wqgmj-0006ac-Lr for emacs-devel@gnu.org; Sat, 31 May 2014 06:45:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wqgmd-0007ra-PL for emacs-devel@gnu.org; Sat, 31 May 2014 06:45:09 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:56457) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wqgmd-0007qH-Jx for emacs-devel@gnu.org; Sat, 31 May 2014 06:45:03 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Wqgmc-00025u-HN for emacs-devel@gnu.org; Sat, 31 May 2014 12:45:02 +0200 Original-Received: from g231234239.adsl.alicedsl.de ([92.231.234.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 31 May 2014 12:45:02 +0200 Original-Received: from tjolitz by g231234239.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 31 May 2014 12:45:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 74 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231234239.adsl.alicedsl.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:2JghBLa2mne8zjHOJYETqDeHVVk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:172210 Archived-At: Stefan Monnier 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