emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BABEL] [PROPOSAL] Seemless editing of Babel Blocks
Date: Mon, 16 Aug 2010 14:50:23 +0530	[thread overview]
Message-ID: <8139ueykvc.fsf_-_@gmail.com> (raw)
In-Reply-To: <81hbivx88y.fsf@gmail.com> (Jambunathan K.'s message of "Mon, 16 Aug 2010 14:08:21 +0530")


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	other threads:[~2010-08-16  9:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-20 12:10 [BABEL] Seemless editing of Babel Blocks Jambunathan K
2010-07-20 22:58 ` Eric Schulte
2010-08-16  8:38   ` Jambunathan K
2010-08-16  9:20     ` Jambunathan K [this message]
2010-09-02 23:41       ` [BABEL] [PROPOSAL] " Dan Davison
2010-09-02 23:50         ` Erik Iverson
2010-09-03 19:08         ` Tom Short
2010-09-03 20:45           ` Dan Davison
2010-09-04  8:58         ` Jambunathan K
2010-09-04 15:04           ` Eric Schulte
2010-09-05  9:55             ` Jambunathan K
2010-09-05 15:58               ` Dan Davison
2010-09-05 19:12                 ` Eric Schulte
2010-09-05 20:22               ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8139ueykvc.fsf_-_@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).