From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jambunathan K Subject: Re: [BABEL] [PROPOSAL] Seemless editing of Babel Blocks Date: Sat, 04 Sep 2010 14:28:39 +0530 Message-ID: <81k4n13mww.fsf@gmail.com> References: <4C459236.3@gmail.com> <87k4opu5fk.fsf@gmail.com> <81hbivx88y.fsf@gmail.com> <8139ueykvc.fsf_-_@gmail.com> <878w3j1zos.fsf@stats.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=57797 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OroaJ-00064y-Cx for emacs-orgmode@gnu.org; Sat, 04 Sep 2010 04:58:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OroaH-00070a-Ta for emacs-orgmode@gnu.org; Sat, 04 Sep 2010 04:58:51 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:45978) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OroaH-00070I-P9 for emacs-orgmode@gnu.org; Sat, 04 Sep 2010 04:58:49 -0400 Received: by pvc30 with SMTP id 30so1599520pvc.0 for ; Sat, 04 Sep 2010 01:58:48 -0700 (PDT) In-Reply-To: <878w3j1zos.fsf@stats.ox.ac.uk> (Dan Davison's message of "Thu, 02 Sep 2010 16:41:07 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dan Davison Cc: emacs-orgmode@gnu.org >> Offer a command say 'org-to-org-src-view' which when invoked >> switches the org-mode buffer to target language mode and comments >> out all the non-src blocks. >> >> Offer a reverse command 'org-src-to-org-view' that switches the >> buffer to org-mode and uncomments the non-src blocks. Dan> My vote is that this proposal is too drastic. What I am proposing is tangling albeit in a loose sense of the word. Would it sound as drastic if one were to divorce the consideration of how often this operation gets performed - one time only or very often - during the lifetime of the org file. How about providing user-accessible tapping points within 'org-babel-map-src-blocks' (or a variation thereof) that would enable me have a custom command in my .emacs. For the sake of record, my suggestion is very closely related to what is discussed here. http://eschulte.github.com/babel-dev/PROPOSED-tangle-entire-org-mode-file-in-comments.html Thanks, Jambunathan K. > 5 Gross code > ~~~~~~~~~~~~~ > > > diff --git a/lisp/ob.el b/lisp/ob.el > index b5b9d8f..613139e 100644 > --- a/lisp/ob.el > +++ b/lisp/ob.el > @@ -662,19 +662,52 @@ portions of results lines." > (lambda () (org-add-hook 'change-major-mode-hook > 'org-babel-show-result-all 'append 'local))) > > -(defmacro org-babel-map-src-blocks (file &rest body) > + > +(defun org-to-org-src-view () > + "" > + (interactive) > + > + (emacs-lisp-mode) > + (org-babel-map-src-blocks (buffer-file-name) > + ( > + (comment-region beg-org end-org) > + ) > + ) > + ) > + > +(defmacro org-babel-map-src-blocks (file body1 &rest body) > "Evaluate BODY forms on each source-block in FILE." > (declare (indent 1)) > `(let ((visited-p (get-file-buffer (expand-file-name ,file))) > - to-be-removed) > + to-be-removed > + (beg-org (make-marker)) > + (end-org (make-marker)) > + (beg-babel (make-marker)) > + (end-babel (make-marker)) > + ) > + > (save-window-excursion > (find-file ,file) > (setq to-be-removed (current-buffer)) > + > + (move-marker end-babel (point-min)) > (goto-char (point-min)) > + > (while (re-search-forward org-babel-src-block-regexp nil t) > - (goto-char (match-beginning 0)) > - (save-match-data ,@body) > - (goto-char (match-end 0)))) > + > + (move-marker beg-org end-babel) > + (move-marker end-org (match-beginning 0)) > + (move-marker beg-babel (match-beginning 0)) > + (move-marker end-babel (match-end 0)) > + > + (goto-char beg-org) > + ,@body1 > + > + (goto-char beg-babel) > + ,@body > + > + > + (goto-char end-babel))) > (unless visited-p > (kill-buffer to-be-removed))))