emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: [BABEL] [PROPOSAL] Seemless editing of Babel Blocks


From: Jambunathan K
Subject: [Orgmode] Re: [BABEL] [PROPOSAL] Seemless editing of Babel Blocks
Date: Mon, 16 Aug 2010 14:50:23 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.91 (windows-nt)

1 Preface 
~~~~~~~~~~
  
  Continuing on my earlier note "Offer surrounding context in org-src
  buffers", I have another idea.
  
  The idea is a bit fanciful and questionable. I also have a prototype
  code that is quite gross. (Don't say that I haven't warned)

2 Motivation 
~~~~~~~~~~~~~
  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.

3 Setting the context 
~~~~~~~~~~~~~~~~~~~~~~

  I believe when I am doing literate programming, I am likely to work
  in phases.
  
  Note: I haven't done literate programming in even lighter sense of
  the word. My understanding down below could be naive and may not be
  as nuanced as that of a practitioner.
  

3.1 Phase-1 
============

   Fix up the overall design/structure. Here I am likely to work with
   a text file (orgmode buffer in our case).
   

3.2 Phase-2: 
=============

   Churn out code by filling out top-level blocks identified in
   Phase-1. Here I am likely to work with a code file (org-src buffer
   in our case).

3.3 Phase-3 
============

   Compile, Test and Fix. Here I am likely to switch quite frequently
   between the org and org-src blocks.
   
   I believe good amount of time would be spent in Phase-3.
   
   It is in this phase that offering of 'surrounding context' becomes
   crucial in org-src buffers. (Here is an item to the WISH list)
   

4 Crux of the idea 
~~~~~~~~~~~~~~~~~~~

  Think of an org buffer as a chain of alternating src and non-src
  blocks. 

  org-buffer = [non-src, src]+
  
  More specifically, when there is a mix of say python and emacs-lisp
  blocks and if I have my emacs-lisp goggles on, I could subsume
  python blocks as non-src blocks.

  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. 
  
  This way I never leave the buffer and I don't have to contend
  anymore with pop-ups (and importantly syncing of parent and daughter
  buffers). Yet I have 'all' the contexts available for my viewing and
  editing pleasure.
  
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.



reply via email to

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