From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [BABEL] [PROPOSAL] Seemless editing of Babel Blocks Date: Thu, 02 Sep 2010 16:41:07 -0700 Message-ID: <878w3j1zos.fsf@stats.ox.ac.uk> References: <4C459236.3@gmail.com> <87k4opu5fk.fsf@gmail.com> <81hbivx88y.fsf@gmail.com> <8139ueykvc.fsf_-_@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=56735 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrJP8-0004ly-SA for emacs-orgmode@gnu.org; Thu, 02 Sep 2010 19:41:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrJP7-0003V4-9Y for emacs-orgmode@gnu.org; Thu, 02 Sep 2010 19:41:14 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:54394) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrJP7-0003V0-2l for emacs-orgmode@gnu.org; Thu, 02 Sep 2010 19:41:13 -0400 In-Reply-To: <8139ueykvc.fsf_-_@gmail.com> (Jambunathan K.'s message of "Mon, 16 Aug 2010 14:50:23 +0530") 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: Jambunathan K Cc: emacs-orgmode@gnu.org Hi Jambunathan, > The primary motivation is that I find transitioning from and to an > org-src buffer a bit of a psychological drag. It would be good if I > don't leave the current buffer as such and still be able to edit > babel blocks. [...] > 4 Crux of the idea > ~~~~~~~~~~~~~~~~~~~ [...] > 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. My vote is that this proposal is too drastic. > This way I never leave the buffer and I don't have to contend > anymore with pop-ups > Have you investigated the different settings of the `org-src-window-setup' variable? > (and importantly syncing of parent and daughter > buffers). Could you expand on that a little bit? What syncing problems are you having? > Yet I have 'all' the contexts available for my viewing and > editing pleasure. There have been some recent changes with the aim of making code blocks more pleasant to use in Org, such as fontification and making TAB and other major-mode commands available in the Org buffer (with a current master branch, see the variable `org-src-tab-acts-natively' and `org-babel-do-key-sequence-in-edit-buffer' which is bound to key bindings C-c C-v x and C-c C-v C-x) If you really want to use language major mode commands without leaving the Org buffer, I suggest investigating Lennart Borgman's nxhtml package[1]. This features a function `org-mumamo-mode' which automatically switches Org code blocks into native major modes. I have encountered one bug whch makes R code blocks hard to use, but the author is responding to them at the bug tracker[2], so I think we should help out by reporting any bugs there. Here's my config for nxhtml/mumamo (the third line is just personal taste): --8<---------------cut here---------------start------------->8--- (load "/usr/local/src/emacs/nxhtml/autostart.el") (require 'mumamo) (add-hook 'org-mumamo-mode-hook (lambda () (mumamo-no-chunk-coloring +1))) --8<---------------cut here---------------end--------------->8--- Dan Footnotes: [1] http://www.emacswiki.org/emacs/NxhtmlMode [2] https://bugs.launchpad.net/nxhtml > 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)))) > > 6 Illustration > ~~~~~~~~~~~~~~~ > > For the sake of illustration, consider an org-mode buffer like this. > > > * Heading0 > ** Heading00 > Print Heading00. > > #+begin_src emacs-lisp > (message "Heading00") > #+end_src > > ** Heading01 > > Print Heading01. > #+begin_src emacs-lisp > (message "Heading01") > #+end_src > > org-to-org-src-view on this buffer puts it in emacs-lisp mode with > the following content. > > ;; * Heading0 > ;; ** Heading00 > ;; Print Heading00. > > #+begin_src emacs-lisp > (message "Heading00") > #+end_src > > ;; ** Heading01 > > ;; Print Heading01. > #+begin_src emacs-lisp > (message "Heading01") > #+end_src > > For the sake of brevity, I have left out the commenting of > meta-lines in the prototype code. > > Thanks for your consideration, > Jambunathan K. > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode